OpenMesh文档中没有为面着色的示例。我应该使用哪个功能将fh0颜色设置为绿色?(我尝试了mesh.set_color,但未能成功。您可以看到我对代码第二部分的尝试)
import openmesh as om
import numpy as np
mesh = om.TriMesh()
# add a a couple of vertices to the mesh
vh0 = mesh.add_vertex([0, 1, 0])
vh1 = mesh.add_vertex([1, 0, 0])
vh2 = mesh.add_vertex([2, 1, 0])
vh3 = mesh.add_vertex([0,-1, 0])
vh4 = mesh.add_vertex([2,-1, 0])
# add a couple of faces to the mesh
fh0 = mesh.add_face(vh0, vh1, vh2)
fh1 = mesh.add_face(vh1, vh3, vh4)
fh2 = mesh.add_face(vh0, vh3, vh1)
# add another face to the mesh, this time using a list
vh_list = [vh2, vh1, vh4]
fh3 = mesh.add_face(vh_list)
# 0 ==== 2
# |\ 0 /|
# | \ / |
# |2 1 3|
# | / \ |
# |/ 1 \|
# 3 ==== 4
for face in mesh.faces():
mesh.set_color(face, [0.67578125, 0.296875, 0.3515625])
om.write_mesh('test.obj', mesh)
但这给了我
IndexError: index 3 is out of bounds for axis 0 with size 3
如何在OpenMesh中为面添加颜色
有几个问题:
mesh.request_face_colors()
是TriMesh
对象支持存储面部颜色所必需的李>mesh.set_color
需要一个alpha通道,因此您的颜色实际上是[0.67578125, 0.296875, 0.3515625, 1.]
write_mesh
需要face_color=True
参数李>完整代码:
控制台输出(颜色属性已成功添加到网格):
test.obj的内容:
test.mat的内容(该文件指定test.obj文件中“mat0”的含义):
test.ply的内容(单个文件中的所有内容):
面颜色是OpenMesh中的标准属性之一
在您的情况下,它将是
mesh.request_face_colors()
引用的documentation
相关问题 更多 >
编程相关推荐