我正在尝试操作一个STL文件,使它们在屏幕上显示为不同的颜色。
这是我现在的代码,我正在循环处理多个STL文件。我想唯一的问题是我的语法,因为我找不到一个将数据设置为我想要的颜色的命令。
filenames = ['C1.stl','C2.stl']
print(filenames)
actors = []
for name in filenames:
reader = vtk.vtkSTLReader()
reader.SetFileName(name)
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(reader.GetOutput())
else:
mapper.SetInputConnection(reader.GetOutputPort())
if name is 'C1.stl':
mapper.getPointData().SetColor(1.0,0,1.0)
任何帮助将是非常感激! 先谢谢你。
我想出了答案。
import vtk
filenames = ['C1.stl','C2.stl']
print(filenames)
actors = []
for name in filenames:
reader = vtk.vtkSTLReader()
reader.SetFileName(name)
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(reader.GetOutput())
else:
mapper.SetInputConnection(reader.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetPosition([0.0, 0.0, 0.0])
actor.SetScale([1.0, 1.0, 1.0])
#Changes the colour to purple for the first stl file
if name is 'C1.stl':
actor.GetProperty().SetColor(1.0,0,1.0)
actors.append(actor)
我需要把这段代码插入到我的actor中去。
随着 维多:
from vedo import load, show
filenames = ['C1.stl','C2.stl']
acts = load(filenames) # list of Mesh(vtkActor)
acts[0].color([1.0,0,1.0]).scale(1).pos(1,2,3)
show(acts)