MeshUnwrapper object freeze bug

Hi @Jussi_Aaltonen,

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

_
c.

Is it a closed mesh?

Hi @Jussi_Aaltonen, no it can be any mesh eg. grid or half sphere.

_
c.

@Jussi_Aaltonen - I’ve logged the issue for you.

https://mcneel.myjetbrains.com/youtrack/issue/RH-69383

– Dale

2 Likes

@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()
1 Like

Thank you @Jussi_Aaltonen,

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 ?

thanks,
c.

There’s a C# sample on how to set up custom mesh mapping: https://github.com/mcneel/rhino-developer-samples/tree/7/rhinocommon/cs/SampleCsCustomMeshMapping

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.

Hi @Jussi_Aaltonen,

thank you for the example and reminder. I’ll see if i can make it work for brep’s rendermeshes.

_
c.