I have a mesh exported from 3ds max (obj) which contains mapping coordinates.
I am referencing this geo in GH to be deconstructed, ‘distorted’ and then rebuilt with the same vertex order (this step is OK).
However I am looking for a component/workflow that enables me to extract the UV data to then reapply to the newly constructed mesh. Does such method exist or is it a scripting solution?
You can do this with the simplest of python scripts:
"""Extract Mesh UV coordinates
m: Mesh to extract UV coordinates from
uvs: List of Texture Coordinates (UVs)"""
__author__ = "jesterKing"
__version__ = "2018.07.20"
import rhinoscriptsyntax as rs
uvs = m.TextureCoordinates
m input type hint to Mesh, then connect a mesh parameter to it.
edit: attaching a GH definition with a script that does pretty much the same as the deconstruct mesh component, but in addition also gives you UVs
extract_mesh_uvs.gh (6.8 KB)
Thanks! looks great. Is it possible to then reapply these to a new mesh, assuming the vertex order is the same?
Order should be the same, yes.
Apologies, I am unsure of how to re-apply the UV data back to the reconstructed mesh. I am exporting from Rhino as an OBJ and have attempted to just manually paste the chunk of UV data into the .obj file in a text editor, however it appears that the syntax of the face data changes slightly after being deconstructed and then created again in grasshopper.
(left is the faces data exported from 3ds max, right is out of GH)
Therefore the when i re-import the geo into 3ds max the face and UV’s don’t appear to match up, Is there a way to construct the new mesh from the with the correct UV’s inside of grasshopper?
Hopefully this makes sense ! Thanks
The right side does not have uv coordinate indices, the right contains only vertex and vertex normal indices (
Regarding face vertex ordering I can’t say if one can expect them to be the same in a round-trip. I guess that strongly depends on the mesh representations possible in source and target.
That UV coordinate order is same as for vertex order inside Rhino still holds. Just make sure you also export texture coordinates.
Optionally, texture coordinate indices can be used to specify texture coordinates when defining a face.
To add a texture coordinate index to a vertex index when defining a face,
one must put a slash immediately after the vertex index and then put the
texture coordinate index. No spaces are permitted before or after the slash.
A valid texture coordinate index starts from 1 and matches the corresponding
element in the previously defined list of texture coordinates.
Each face can contain three or...
Optionally, normal indices can be used to specify normal vectors for vertices when defining a face.
To add a normal index to a vertex index when defining a face,
one must put a second slash after the texture coordinate index and then put
the normal index.
A valid normal index starts from 1 and matches the corresponding element
in the previously defined list of normals.
Each face can contain three or more elements.
Edit: you probably wanted to create OBJ with face in format:
f v1/uv1 v2/uv2 v3/uv3
Hey, I read your post. I was not able to use it correctly or I cannot apply it on my mesh. Do you know what I am doing wrong?
mesh 01.gh (9.7 KB)
I think there is a misconception about what the Mesh Surface component does. It doesn’t create a mesh with UV (texture) coordinates. Rather it creates a mesh based on the given surface UV parametrization.
Hi, is there a explanation the processing power for DeMesh is quicker than GhPython?
Grasshopper component will always be faster than ghpython script, as it is compiled.
To lower the run time of the ghpython script, you can:
Not set the type hint for the input ‘m’ parameter.
Another one is not to let the ghpython component ‘do’ the iteration, but do it on your own.
deconstructMesh.gh (182.1 KB)