Monday 26 July 2021

How to color faces in OpenMesh?

There is no example in OpenMesh documentation for coloring faces. Which function should I use to color fh0 to green? (I tried mesh.set_color but could not succeed. You can see my attempt on second part of code)

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)

but this gives me

IndexError: index 3 is out of bounds for axis 0 with size 3

How can I add color to faces in OpenMesh?



from How to color faces in OpenMesh?

No comments:

Post a Comment