gpt4 book ai didi

python-3.x - 使用 vtk 和 k3d 在 jupyter notebook 中渲染 gltf/glb 文件

转载 作者:行者123 更新时间:2023-12-04 09:18:57 27 4
gpt4 key购买 nike

我探索了如何在 jupyter notebook 中内联呈现 gltf/glb 文件以保持查看器回调交互性完整的可用方法。我最终使用 vtk 和 k3d 来实现这一目标。我遇到的两个障碍是:

  1. 如何使用 vtkGLTFReader() 从glb 并在 k3d 中渲染这些? 解决方案:参见评论中发布的方法。

  2. 如何显示嵌入在 gltf/glb 中的颜色/纹理以在k3d?

最佳答案

这是获取 vtkPolyData 并将其传递给 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()

关于python-3.x - 使用 vtk 和 k3d 在 jupyter notebook 中渲染 gltf/glb 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63130386/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com