Colouring Faces on a mesh?

Hi all, code snipper here.

I am trying to colour a mesh all green, unless its vertex normal is pointing within 45 degrees fo down.

in Rhino i iterate through every single face and can see the code changing some red, but on screen i see nothing in any shading mode?

What obvious little thing am i missing here?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var GetMesh = new GetObject();
GetMesh.GeometryFilter = ObjectType.Mesh;
GetMesh.SetCommandPrompt(“Select Mesh”);
GetMesh.Get();
if (GetMesh.CommandResult() != Result.Success) return GetMesh.CommandResult();

        var InputMesh = GetMesh.Object(0).Mesh();
        var Faces = InputMesh.FaceNormals;
        var ColourList = InputMesh.VertexColors;
        var MeshNormals = InputMesh.Normals;
      
        for (int i = 0; i < MeshNormals.Count; i++)
        {
            ColourList.SetColor(i, Color.Green);
            var angle = RhinoMath.ToDegrees(Vector3d.VectorAngle((Vector3d)MeshNormals[i], Vector3d.ZAxis));
            if(angle < 45)
            {
                ColourList.SetColor(i, Color.Red);
            }
        }
        return Result.Success;
    }

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out var objRef);
  if (rc != Result.Success || objRef == null) return rc;
  var mesh = objRef.Mesh();
  if (mesh == null || !mesh.IsValid) return Result.Failure;
  mesh.RebuildNormals();
  mesh.VertexColors.Clear();
  foreach (var t in mesh.Normals)
  {
    var angle = Vector3d.VectorAngle(t, Vector3d.ZAxis);
    mesh.VertexColors.Add(angle < Math.PI / 4 ? Color.Red : Color.Green);
  }
  doc.Objects.Replace(objRef, mesh);
  return Result.Success;
}
2 Likes

thanks! didnt realise the object had to be replaced as a finishing touch! love it, thanks again.