Convert mesh vertex colors to texture map, export OBJ

I made a Python component that takes a Grasshopper mesh with colored vertices, puts texture coordinates on it, and creates a texture image file. I translated this from Vicente Soler’s C# component that I found here.

I added the option to export the textured mesh to an OBJ file.

NB the texture map that this creates is vile. It’s just a pile of pixels, one for each mesh face corner in no particular order, so no meaningful unwrapping has been done and you can’t use it to paint. All you can do with it is use a renderer, or export to a file format, that doesn’t support color-by-vertex.

meshtextureobj.gh (9.9 KB)

1 Like

meshtextureobj.gh (9.9 KB)

Update: this version doesn’t strip alphas from colors: if the vertex colors have alpha component, so will the texture PNG.

It also outputs the mesh with the texture map and with vertex colors stripped. This last because it doesn’t really make sense to have both sources of color active, but if you don’t want to strip the colors then comment out m.VertexColors.Clear().

And if you want a baked mesh that has a material with the texture map, comment out rs.DeleteObject at the end.

2 Likes

hey! cool stuff… i managed to do it with the c# component, but with the python one i get an error… what could it be?

ah found a solution… the mesh reference object needed to be “recolored” in grasshopper…