I discovered a bug or at least I can no get this to work
Below you see on he left twice the same mesh with a UV mapped texture.
The lower one circled in blue is a SubD created by the Rhino command “_ToSubd”.
The upper one circled in red is a SubD created with Rhino.Geometry.CreateFromMesh() method.
In he one created with Rhino Common method, he UV mapping seems to be parametrized and does no keep as on the original mesh.
I also found this and tried to implement it, but it did not seem to help:
This is the python script I used to create the Subd from a mesh
#! python 3
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc
import System
def mesh_to_subd():
# Select a mesh
mesh_id = rs.GetObject("Select mesh to convert to SubD", rs.filter.mesh, preselect=True)
if not mesh_id:
print("No mesh selected")
return
# Get the mesh object
mesh = rs.coercemesh(mesh_id)
if not mesh:
print("Invalid mesh")
return
# Create SubD creation options
options = rg.SubDCreationOptions()
# Set to 1 for CopyMapping (0=Unset, 1=None, 2=Automatic, 3=Packed, CopyMapping=4, CopyCoordinates=5)
# https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.subdcreationoptions.texturecoordinateoption
options.TextureCoordinateOption = 5
# Convert mesh to SubD with options
subd = rg.SubD.CreateFromMesh(mesh, options)
if subd:
# Add the SubD to the document
subd_id = sc.doc.Objects.AddSubD(subd)
rs.SelectObject(subd_id)
sc.doc.Views.Redraw()
# Run the function
if __name__ == "__main__":
mesh_to_subd()
In general the Rhino Common SubD generation API is very limited currently it seems.
Would be great if someone could help wih this.
Do I miss something here or is this indeed a bug?
Unfortunately the rs.Command is not option for me, hence I am working on a generic USD ex- and importer and the meshes are loaded in memory, not in the scene yet.
The shared file and script where only used to localize the error.
Is this a functionality/fix I can expect an upcoming Rhino update?
Also would this be exposed in C++ - so Rhino SDK and/or Open Nurbs?
The issue (above) has already been fixed and should be available in this week’s Rhino 8 SR28 release candidate. Using the Rhino C++ SDK is always an option.
Amazing, thank you very much for the quick action.
I have another follow up quesiton - same topic but reverse.
I could also not find functionality exposed to extract the UVs / Texture Coordinates from a USD.
While I Rhino I can gather that very easily by iterating over mesh.TextureCoordinates, I couldn’t find any way to get the texture coordinates from a Subd - is that somewhere hidden in the API or is this not exposed currently?
Implementing it with Rhino C++ SDK would have been probably the better choice from the very beginning, but I got quite for with python and do not have the time to fully restart now unfortunately