Rendering a gltf/glb file in jupyter notebook using vtk and k3d

断了今生、忘了曾经 提交于 2021-02-08 03:41:36

问题


I have explored the available methods of how to render a gltf/glb file inline in a jupyter notebook to keep the viewer callback interactivity intact. I have eventually ended up using vtk and k3d to achieve this. The two hurdles I have are:

  1. How to use the vtkGLTFReader() to get vtkPolyData objects from the glb and render these in k3d? SOLUTION: See method posted in the comments.

  2. How to display colors/textures embedded in the gltf/glb to show them in k3d?


回答1:


Here is the code to get vtkPolyData and pass it to k3d.

import k3d
import vtk
import ipywidgets as widgets

reader = vtk.vtkGLTFReader() 
reader.SetFileName('sample_glb/GroundVehicle.glb')
reader.Update() 

plot = k3d.plot()
mb = reader.GetOutput()

iterator = mb.NewIterator()

vtk_polyobjects = []
while not iterator.IsDoneWithTraversal():
    item = iterator.GetCurrentDataObject()
    vtk_polyobjects.append(item)
    iterator.GoToNextItem()

    
for obj in vtk_polyobjects:
    plot += k3d.vtk_poly_data(obj, color=0x222222)
plot.display()

debug_info = widgets.HTML()


来源:https://stackoverflow.com/questions/63130386/rendering-a-gltf-glb-file-in-jupyter-notebook-using-vtk-and-k3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!