algorithmic modeling for Rhino
Hi all.
I have a mesh and a corresponding image that maps the color information on this mesh.
Similar than: http://www.outworldz.com/Secondlife/posts/uvmaps/images/Starlight_f...
I would like to know, if it is possible to transform this information into vertex color data.
Best regards,
Roger
Tags:
Yes, this should be possible. Do I understand that your mesh already has appropriate mesh texture vertices assigned to it? It would be great if you could upload your file. The following script works for my example - but it also assumes that your mesh vertex texture coordinates all fall within the domain {0,0} to {1,1}. If you upload your file we can try to come up with something more tuned to this particular scenario.
private void RunScript(Mesh mesh, string imagePath, ref object A)
{
mesh.VertexColors.Clear(); //in case there's existing mesh vertex colors assigned
//mesh.TextureCoordinates.NormalizeTextureCoordinates(); //uncomment if your texture coordinates need to be renormalized
Bitmap bmp = new Bitmap(imagePath);
for(int i = 0;i < mesh.Vertices.Count;i++){
Point2f coord = mesh.TextureCoordinates[i];
int xVal = (int) (bmp.Width * coord.X);
if(xVal >= bmp.Width) xVal = bmp.Width - 1;
if(xVal < 0) xVal = 0;
int yVal = (int) (bmp.Height * coord.Y);
yVal = bmp.Height - yVal;
if(yVal >= bmp.Height) yVal = bmp.Height - 1;
if(yVal < 0) yVal = 0;
Color c = bmp.GetPixel(xVal, yVal);
mesh.VertexColors.Add(c);
}
A = mesh;
}
HI Andrew!
This seems exactly what I need. Can you please help me understand how I should use this script? I copied into the C# scriptable component but I cannot seem to make it work. Any help would be extremely appreciated!!
In the long run I am trying to apply this transformation (texture to mesh vertex color) to export a csv file formatted as x,y,x,r,g,b for all the vertices. Hope this makes sense.
Thanks in advance for all your help,
Cheers
Daniele
I think to make a custom mapping from an image like that, the problem is you need to flatten the mesh, making the corresponding points snap into the correct position of the color image. So you use an image and a mesh very little complex, or need to adjust the points moving them by hand, which gh does not allow comfortably.
I have little experience mapping textures in 3DMax, but the texture images (like that) are made after making the flattened mesh (UVW unwrap, if I remember correctly). So if you manage to flatten the mesh (no overlap), make an image of the flat mesh and take it to photoshop, paint over her attending parties, and then in gh you use this color information to paint the flat mesh, and as you have not changed the topology of the mesh, that list of colors will serve to paint the texture on the original mesh.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by