using below snippet on a mesh object in the document leaves the object in a partially unselectable, invalid state. The mesh object can not be selected by clicking on it, however, it can be selected with a window selection.
import Rhino
import rhinoscriptsyntax as rs
def DoSomething():
mesh_id = rs.GetObject("Select Mesh to unwrap", 32, True, False)
if not mesh_id: return
mesh_obj = rs.coercerhinoobject(mesh_id, True, True)
unwrapper = Rhino.Geometry.MeshUnwrapper(mesh_obj.Geometry)
rc = unwrapper.Unwrap(Rhino.Geometry.MeshUnwrapMethod.LSCM)
DoSomething()
If you select the mesh, eg. using _SelMesh and the run _RebuildMesh the mesh object gets invisible (is not displayed anymore), but it still gets selected with _SelMesh. Running _SelBadObjects finds the mesh. Running _Check yields this:
Unable to create face normals on mesh.
This will cause problems if the ultimate goal is boolean operations.
I’ve tried to use _RebuildMeshNormals but the command returns that it failed. I can repeat above with any mesh object using Rhino version 7.21.22182.9001, 2022-07-01
@clement There’s a bug that has to do with double precision vertices. Here’s a script that works for now:
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def DoSomething():
mesh_id = rs.GetObject("Select Mesh to unwrap", 32, True, False)
if not mesh_id: return
mesh_obj = rs.coercerhinoobject(mesh_id, True, True)
# Make a copy of the object geometry
unwrapped_mesh = mesh_obj.Geometry.Duplicate()
# Use only single precision vertices because unwrapper does not work
# with double precision vertices
unwrapped_mesh.Vertices.UseDoublePrecisionVertices = False
unwrapper = Rhino.Geometry.MeshUnwrapper(unwrapped_mesh)
rc = unwrapper.Unwrap(Rhino.Geometry.MeshUnwrapMethod.LSCM)
# Remove surface parameters so that texture coordinates will not be regenerated from them
unwrapped_mesh.ClearSurfaceData()
# Use Replace to set the new geometry to the mesh object
sc.doc.Objects.Replace(mesh_id, unwrapped_mesh)
DoSomething()
initially i’ve been trying to set the unwrapped result to a brep. I’ll have to try if above works using CreateCustomMeshMapping method. Since my meshes have very high density (used for a custom displacement) will it be possible in the future to do this without making a duplicate ?
You should never modify object geometry directly. Always use something like doc.ReplaceObject. Otherwise things like undo will break. I don’t think that will be possible in the near future - it would require big changes and probably break SDK quite badly.