Rhino3dm.js SubD's UV map information?

It seems not possible to extract SubD uv mapping (cylinder etc) through Rhino3dm.js, is it possible?

rhino.Mesh.createFromSubDControlNet(subd, true) seems to only extracts/interpolates UVs if the SubD control net explicitly contains per-vertex coordinates. If texture mapping is assigned via Rhino’s projection or unwrapping, the resulting mesh has 0 texture coordinates.

Thanks @martinsiegrist, I need to stop trusting my typing with out checking :smiley:

Thanks for the report. createFromSubDControlNet(subd, true) only copies texture points stored on the SubD’s faces. A projection mapping like a cylinder doesn’t store any, so the mesh comes back without UVs. In rhino3dm.js 8.x there’s no way to read the object’s mapping from JS, so you can’t apply it yourself either.

That’s fixed in the upcoming rhino3dm 9.2, which adds File3dmObject.getTextureMapping. You read the mapping and apply it to the control-net mesh:

// rhino3dm.js 9.2: UVs for a SubD with a projection mapping (e.g. cylinder)
const doc = rhino.File3dm.fromByteArray(bytes)
for (const obj of doc.objects) {
  const subd = obj.geometry
  if (!(subd instanceof rhino.SubD)) continue
  const [mapping, xform] = obj.getTextureMapping(1)  // mapping channel (usually 1)
  if (!mapping) continue
  const mesh = rhino.Mesh.createFromSubDControlNet(subd)
  mesh.setTextureCoordinates(mapping, xform, false)
  // mesh.textureCoordinates now holds the UVs
}