Color mesh by faces (one single color for one face) using API

Hey guys! :slight_smile:

I want to color a mesh by faces (one single color for one face) in one take using API. It looks like there is no way to do that easily, because Rhino seems to color mesh only by vertices, so it means I can color vertices in one go.
I’ve found this method: MeshVertexColorList.SetColor Method (MeshFace, Color)
And this one seems to color only one input face. And if I understand correctly: I cannot use a simple for loop for all the faces using this method, because next faces will overwrite the vertices of a previous vertices if one vertex share same face (if I understand it correctly).
Also it seems to me that to have a mesh colored by single color for each mesh - each face should have it’s own vertex only to store the color. Is there any simple way to explode the mesh for such purpose then? Is it Mesh.ExplodeAtUnweldedEdges?

1 Like

You can use Mesh.Unweld before setting the face colors. There’s still a bit of unnecessary overhead (i.e. checking face normal angles), but it works well. Here’s an old topic that covers this:

Edit: Here’s the function I’ve been using since Rhino 6:

2 Likes

Thank you very much Anders! :slight_smile:

1 Like