Color a Mesh on both sides with different colors

To my understanding there is no native way to color a mesh on both sides with different colors.
Has anybody managed to do it in any way? It is for viewing purposes only.

I can only think to duplicate the mesh, flip it’s face normals and give it a different colour but then its 2 meshes.

trouble is that the colors then will interfere with each other. Maybe if I create some space between the two meshes that could work… However I want to color them based on the initial mesh normals.

First I use a C component to flip the mesh if needed.

private void RunScript(object x, object y, ref object A)

Mesh mesh = (Mesh) x;
for(int i = 0; i < mesh.Faces.Count; i++)
  var normal = mesh.Normals[0];
  if(normal.Z < 0)
    mesh.Flip(true, true, true);

A = mesh;

Then just for visual purposes I want to color code the faces.

I usually use Mesh.Offset to avoid the faces clipping into each other.

1 Like

Hi David - Depending on what you want, you might just get away with using a backface color in your display mode.

1 Like

Did it with VB with a code like this

A = M.Offset(d)

Where M (mesh) and d (distance) are the input values.

I could not understand the syntax on this page. Coding is not my water whatsoever… Any idea how I can put an universal distance let’s say of 1 or 2 mm, which will be always 1 or 2 mm regardless of model units?

You’ll need to get the Rhino document unit type, and then set the offset distance based on this. I can’t quite remember which exact property this is, but it’s somewhere in the RhinoDoc you get through here:

1 Like

As @wim suggests, you can use DrawMeshShaded with different back and front face colors — see this code from wombat for an example:



It works with the Wombat plug-in. But how about this code? How can I use it?

You can only use it if you draw your own meshes using code.

1 Like

So it is more complicated.
It is not a bad tool at all.

Didn’t know wombat is open sourced on github. super cool! thanks @mswaidan

lots to learn from here…including the tetris tune: WombatGH/CanvasColor.cs at master · woodsbagot/WombatGH · GitHub