问题描述
我已经探索了如何在jupyter笔记本中内联呈现gltf/glb文件以保持查看器回调交互性完整的可用方法.我最终最终使用vtk和k3d实现了这一目标.我遇到的两个障碍是:
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:
-
如何使用vtkGLTFReader()从以下位置获取vtkPolyData对象:GLB和渲染这些在K3D? 解决方案:请参见评论中发布的方法.
How to use the vtkGLTFReader() to get vtkPolyData objects from theglb and render these in k3d? SOLUTION: See method posted in the comments.
如何显示gltf/glb中嵌入的颜色/纹理以显示它们k3d?
How to display colors/textures embedded in the gltf/glb to show them ink3d?
推荐答案
以下是获取vtkPolyData并将其传递给k3d的代码.
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()
这篇关于使用VTK和K3D在Jupyter Notebook中渲染gltf/glb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!