I’m fixing a bug in vtkX3DExporter. I can’t find an x3d viewer for MAC OS or Ubuntu. Can someone point me to a viewer that they have used? I’ve tried the x3d viewer plugin for chrome on both systems, but neither of display x3d files properly. They just show a plane and axes, but no model.
@lorensen, I have a working script to use VTK’s vtkX3DExporter that can send VTK render widows to X3D HTML which can be displayed in Jupyter notebooks or any web browser over in this (somewhat stale) pull request for PyVista: https://github.com/pyvista/pyvista/pull/300
Here is a script to make HTML of a vtkRenderWindow:
import vtk
X3D_JAVASCRIPT = '''
<?xml version="1.0" encoding ="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN"
"http://www.web3d.org/specifications/x3d-3.3.dtd">
<head>
<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'> </script>
<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>
</head>
<body>
{}
</body>
'''
def export_x3d(ren_win, binary=True, speed=4.0):
"""Exports the scene to an X3D (XML-based format) for
representation 3D scenes (similar to VRML). Check out
http://www.web3d.org/x3d/ for more details.
"""
exporter = vtk.vtkX3DExporter()
exporter.SetInput(ren_win)
exporter.FastestOff()
if speed:
exporter.SetSpeed(speed)
exporter.SetWriteToOutputString(True)
exporter.Update()
exporter.Write()
return X3D_JAVASCRIPT.format(exporter.GetOutputString())
Then you could display that output in Python using:
from IPython.core.display import display, HTML
display(HTML(the_output))
or you could save that HTML to a file and open it with any web browser