I am using VTK 9.3.0 and have seen that vtkGLTFReader is unable to read “.glb” files. Altough it is able to read “.gltf” perfectly and this problem doesn’t occur in VTK 9.1.0. Please check my below code for the rendering pipeline and point me if any mistakes I have done.
import vtk
def render_gltf(input_filename):
# Read PolyData
reader = vtk.vtkGLTFReader()
reader.SetFileName(input_filename)
reader.Update()
# Convert to polydata
polydata = vtk.vtkCompositeDataGeometryFilter()
polydata.SetInputConnection(reader.GetOutputPort())
polydata.Update()
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(polydata.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create a renderer
renderer = vtk.vtkRenderer()
renderer.SetBackground(0.1, 0.1, 0.1)
# Create a render window
render_window = vtk.vtkRenderWindow()
render_window.SetWindowName("GLTF Example")
render_window.SetSize(800, 600)
render_window.AddRenderer(renderer)
# Create a render window interactor
render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
# Add the actor to the renderer
renderer.AddActor(actor)
# Set up camera and render
renderer.ResetCamera()
render_window.Render()
# Start the rendering loop
render_window_interactor.Start()
if __name__ == "__main__":
input_file = r"path\to\glb" # Replace with the path to your input GLTF file
render_gltf(input_file)
PS: This works with no problem if i read .gltf files in 9.3.0.
Thanks for quick response! Here is the GLB file. and FYI this is produced using unreal engine by setting mesh quantization property to true. I suppose this mesh quantization property is the one that caused the issue?
I’m afraid you are using an extension that is not supported by VTK yet.
ERROR: In vtkGLTFDocumentLoaderInternals.cxx, line 1308
vtkGLTFDocumentLoader (0x5e9622fdff00): glTF extension KHR_mesh_quantization is required in this model, but not supported by this loader. Aborting
I used to receive this as warning in 9.1.0 but I was able to render the glb file in the 9.1.0. Heres the pipeline I used in 9.1.0. It is same as the one above but it had vtkCleanPolyData too.
def render_gltf(input_filename):
# Read PolyData
reader = vtk.vtkGLTFReader()
reader.SetFileName(input_filename)
reader.Update()
# Remove any duplicate points.
cleanfilter = vtk.vtkCleanPolyData()
cleanfilter.SetInputConnection(reader.GetOutputPort())
cleanfilter.Update()
# Convert to polydata
polydata = vtk.vtkCompositeDataGeometryFilter()
polydata.SetInputConnection(cleanfilter.GetOutputPort())
polydata.Update()
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(polydata.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create a renderer
renderer = vtk.vtkRenderer()
renderer.SetBackground(0.1, 0.1, 0.1)
# Create a render window
render_window = vtk.vtkRenderWindow()
render_window.SetWindowName("GLTF Example")
render_window.SetSize(800, 600)
render_window.AddRenderer(renderer)
# Create a render window interactor
render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
# Add the actor to the renderer
renderer.AddActor(actor)
# Set up camera and render
renderer.ResetCamera()
render_window.Render()
# Start the rendering loop
render_window_interactor.Start()
if __name__ == "__main__":
input_file = r"path\to\Archvis_Empty.glb"# Replace with the path to your input gltf file
render_gltf(input_file)type or paste code here