Is there a way to SET texture coordinates for an existing mesh?
I can read it via Rhino.MeshTextureCoordinates (RhinoScript) but I don’t see a way to set new ones on the existing mesh. Currently rebuilding the mesh and replacing the old one but ideally I need to keep the same object ID etc.
Hi Clement, thank you very much, I will check these out!
Have you used these methdos before? I am mostly interested in SetTextureCoordinates to set all of them in one go, so it would mean feeding an array of 2D points coordinates that equals the number of mesh vertices? Sorry, I am still not using RhinoCommon but looks like with this one there is no other choice.
Would you happen to have a sample snippet of code for this?
Hi @Jarek, yes, below is a cheesy example which just assigns the vertex positions as viewed from top view as texture coordinates to a sphere mesh. It is as you say, just make sure the amount of vertices equals the amount of texture coordinates in the Point2f type. The result of the example equals a planar projection from top where each tile is one unit large:
import rhinoscriptsyntax as rs
# create a mesh sphere
plane = Rhino.Geometry.Plane.WorldXY
sphere = Rhino.Geometry.Sphere(plane, radius=10.0)
mesh = Rhino.Geometry.Mesh.CreateFromSphere(sphere, 32, 64)
t = System.Array.CreateInstance(Rhino.Geometry.Point2f, mesh.Vertices.Count)
for i, v in enumerate(mesh.Vertices.ToPoint3dArray()):
t[i] = Rhino.Geometry.Point2f(v.X, v.Y)
you can code the unwrapping using this class. To do the layout the _UVEditor does you can either script the command or, in case you just need the unrolled meshes without connection to their originals, you could script the _ExtractUVMesh command.