Grasshopper

algorithmic modeling for Rhino

Hi all,

 

I'm trying to develop a custom component which adds a colour gradient to a mesh created from a Brep (inputBrep), however I can't get the hang of working with the MeshVertexColorList collection. The (summarised) code below (just adding the colour red to all vertices in this example) leaves me with an error unfortunately.

 

Could someone give an explanation on

1) how to work with the MeshVertexColorList to output it as a collection of colours so I could use this as an input for the GH MCol (Mesh Colours) component together with the generated mesh in the custom component?

or

2) to output a coloured mesh directly?

 

Thanks,

 

Roel.

 

 

pManager.Register_MeshParam("Mesh", "Mesh", "Mesh");
pManager.Register_ColourParam("MeshColour", "MeshColour", "MeshColour");

 

Rhino.Geometry.Mesh[] outputMesh = null;            Rhino.Geometry.Collections.MeshVertexColorList outputMeshColour = null;

 

meshParameters = Rhino.Geometry.MeshParameters.Smooth;

outputMesh = Rhino.Geometry.Mesh.CreateFromBrep(inputBrep, meshParameters);           

numPoints = outputMesh[0].Vertices.Count();

 

for (int i = 0; i < numPoints; i++)
{

outputMeshColour.SetColor(i, 255, 0, 0);

}

 

DA.SetDataList(0, outputMesh);
DA.SetData(1, outputMeshColour);

Views: 2918

Replies to This Discussion

Hi Roel,

 

I don't get it, are you creating meshes or requesting them as an input parameter?

 

Basically Mesh Vertex Colours need to be applied for every vertex. The easiest way is to create a monotone mesh (the same colour for all vertices) then iterate over the list of colours and assign them:

 

Dim mesh As Mesh = GetMeshFromSomewhere()

mesh.VertexColors.CreateMonotoneMesh(Color.White)    

Dim rnd As New Random(5)    

For i As Int32 = 0 To mesh.VertexColors.Count - 1      

  mesh.VertexColors(i) = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256))    

Next 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you David,

 

to -hopefully- be a bit more clear, I am creating a mesh in the custom component and I would like to assign colours to the vertices. This in order to get a similar output when using for instance the Gaussian curvature analysis in Rhino. I was assuming that this could be done in two ways:

1) assigning colours to the mesh in the component and have a coloured mesh as output of the component

2) fill a MeshVertexColorList with colours for every vertex and have this collection of colours as an output and the colourless mesh as output. The mesh can then be coloured with the GH MCol component

 

It seems to me that you are providing the first way in your answer. So was I looking in the wrong place by trying to use the methods of the MeshVertexColorList class?

 

Regards, Roel.

Yes, if you supply a mesh with VertexColors then Grasshopper will draw it like that. But you need to make sure you supply the exact same number of colours as there are vertices, otherwise the colours will be ignored.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Great! Thank you.

 

Roel.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service