You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.1 KiB
78 lines
3.1 KiB
import vtk
|
|
|
|
if __name__ == "__main__":
|
|
# Create renderer, render window, and interactor
|
|
renderer = vtk.vtkRenderer()
|
|
render_window = vtk.vtkRenderWindow()
|
|
render_window.AddRenderer(renderer)
|
|
render_window.SetSize(1200, 800)
|
|
render_window_interactor = vtk.vtkRenderWindowInteractor()
|
|
render_window_interactor.SetRenderWindow(render_window)
|
|
|
|
# 添加坐标轴
|
|
axes = vtk.vtkAxesActor()
|
|
axes_widget = vtk.vtkOrientationMarkerWidget()
|
|
axes_widget.SetOutlineColor(0.93, 0.57, 0.13)
|
|
axes_widget.SetOrientationMarker(axes)
|
|
axes_widget.SetInteractor(render_window_interactor)
|
|
axes_widget.SetViewport(0.0, 0.0, 0.2, 0.2)
|
|
axes_widget.EnabledOn()
|
|
axes_widget.InteractiveOn()
|
|
|
|
# Initialize OBJ importer
|
|
obj_importer = vtk.vtkOBJImporter()
|
|
obj_importer.SetFileName("halfpatch_final.obj") # Replace with your OBJ file path
|
|
obj_importer.SetFileNameMTL("halfpatch_final.mtl") # Replace with your MTL file path
|
|
obj_importer.SetTexturePath("./") # Directory containing texture files
|
|
# Set render window for the importer
|
|
obj_importer.SetRenderWindow(render_window)
|
|
obj_importer.Update()
|
|
|
|
# 获取导入模型的所有actor
|
|
actors = renderer.GetActors()
|
|
actors.InitTraversal()
|
|
|
|
# 创建线框actor列表
|
|
wireframe_actors = []
|
|
|
|
# 为每个模型actor创建对应的线框actor
|
|
for i in range(actors.GetNumberOfItems()):
|
|
actor = actors.GetNextActor()
|
|
|
|
# 创建线框表示
|
|
wireframe_mapper = vtk.vtkPolyDataMapper()
|
|
wireframe_mapper.SetInputData(actor.GetMapper().GetInput())
|
|
|
|
# 创建线框actor
|
|
wireframe_actor = vtk.vtkActor()
|
|
wireframe_actor.SetMapper(wireframe_mapper)
|
|
|
|
# 设置线框属性
|
|
wireframe_actor.GetProperty().SetRepresentationToWireframe() # 设置为线框模式
|
|
wireframe_actor.GetProperty().SetColor(1.0, 1.0, 1.0) # 设置线框颜色为白色
|
|
wireframe_actor.GetProperty().SetLineWidth(2.0) # 设置线框线条粗细,可以调整这个值
|
|
|
|
# 使线框显示在模型上方(通过调整渲染顺序)
|
|
wireframe_actor.GetProperty().SetOpacity(1.0) # 设置不透明度
|
|
wireframe_actor.GetProperty().LightingOff() # 关闭光照,使线框更清晰
|
|
|
|
# 设置线框actor的位置和方向与原始actor一致
|
|
wireframe_actor.SetPosition(actor.GetPosition())
|
|
wireframe_actor.SetOrientation(actor.GetOrientation())
|
|
wireframe_actor.SetScale(actor.GetScale())
|
|
|
|
# 添加到渲染器和列表
|
|
renderer.AddActor(wireframe_actor)
|
|
wireframe_actors.append(wireframe_actor)
|
|
|
|
# Set background color
|
|
renderer.SetBackground(0.1, 0.1, 0.1) # Dark gray background
|
|
|
|
# 设置默认交互器样式
|
|
style = vtk.vtkInteractorStyleTrackballCamera()
|
|
render_window_interactor.SetInteractorStyle(style)
|
|
style.SetMotionFactor(5.0) # 默认是10.0,较小的值会减慢移动速度
|
|
|
|
# Render and start interaction
|
|
render_window.Render()
|
|
render_window_interactor.Start()
|