Color Mesh Faces (No Bleeding) - Best Practice?

@AndersDeleuran - A little faster, albeit in Debug.

Still thinking…

– Dale

1 Like

@AndersDeleuran

How do you see this working? What are the parameters?

– Dale

One final thought - SubDs support per-face color.

– Dale

Sorry for interupting, just wanted to add my 2 cents, that for me face coloring also seems to be quite important, because in BIM world it’s much often to have a face coloring, not vertex coloring (vertex coloring is more used for some analysis results visualization). This ended up with adding face_colors in dotbim format, and with coloring elements via Grasshopper by using unweld for each mesh: dotbimGH/dotbimGH/Tools.cs at master · paireks/dotbimGH · GitHub

However, the bigger problem I have is the fact described there, that there is no catching of vertex colors meshes (unless something changed and I didn’t noticed :slight_smile: ): Slow render of Monochrome Mesh - #5 by w.radaczynski

That’s already quite awesome, thanks so much Dale!

Similar to the VertexColors.AppendColors description: “Appends a collection of colors to the vertex color list. For the Mesh to be valid, the number of colors must match the number of vertices”, but where each color is added to face vertices (i.e. first color in list is added to vertices of first face, second color in list is added to vertices of second face). Maybe the appending logic gets/is a bit confusing, it could maybe be simply AddFaceColors. But then that also gets into if the mesh class ought have a FaceColors properties in the first place, which is probably taking things a bit far. Anywho, here’s an example:


240822_AddFaceColors_00.gh (9.6 KB)

Sidenotes/questions:

  1. Why does one have to add colors to the mesh (e.g. with CreateMonotoneMesh), before calling VertexColors.SetColor(MeshFace,Color)?
  2. It would be nice if VertexColors.AppendColors would take a Python tuple/list (i.e. not a typed .NET array).

Thanks again.

2 Likes

Hi @AndersDeleuran,

I’ve added a new Mesh.CreateUnweldedMesh static function to RhinoCommon to help with the performance issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-83456

  1. I’ll look info the “do this before I can do that” issue.
  2. Seems like VertexColors.AppendColors should take an IEnumerable<Color> parameter. Let me think about this.

Thanks,

– Dale

4 Likes

That’s fantastic, thanks so much Dale :pray:

Hi @AndersDeleuran,

One last followup (I hope).

  1. The reason for calling MeshVertexColorList.CreateMonotoneMesh before calling MeshVertexColorList.SetColor is to ensure that memory for the internal vertex colors array is allocated. MeshVertexColorList.SetColor tries to colors by vertex index, so you need to make sure there is an index to dereference. I guess you could call MeshVertexColorList.AppendColors, but the former is faster.

  2. Yep, MeshVertexColorList.AppendColors isn’t very Python-friendly, so I’ve added a new MeshVertexColorList.AddRange which is.

https://mcneel.myjetbrains.com/youtrack/issue/RH-83467

Thanks,

– Dale

4 Likes

Cheers Dale, much appreciated. These new additions should really help speed up much of my analysis/visualisation code! And I’m sure the code of many other computational designers that work with similar problems. Thanks again, you guys truly rock.

2 Likes

Just updated my Rhino 8 and ran a quick test. This will indeed be very useful:

Thanks again @dale.

2 Likes

Thanks for testing.

– Dale

1 Like

Sorry for bumping old post, but it’s kinda related and i don’t understand the full range of the possibilities you guys mentioned in this conversation.

I am looking for a quick/fast way to toggle between vertex & face coloring. So when I importing an image as a mesh using “import Image” node, by default the resulting mesh has vertex colors applied.

How to best convert that mesh so it uses face colors instead.

My current approach works ok, but this willl get slow very fast when using larger mesh.


mesh_face_colors.gh (37.6 KB)