Tolerance ignored when using Rhino.Geometry.Unroller?

Good afternoon,
I’m trying to unroll a Brep in vb.net, or more accurately I’m trying to check if it is unrollable.
My issue is that the relativeTolerance does not seem to be taken in account, and a sligtly non linear edge always fail to unroll, while the same Brep is unrolled properly with rhino command using the same tolerance.
Do you have any idea on how to fix this?

Here is my code:

<System.Runtime.CompilerServices.Extension>
Public Function IsUnrollable(ByVal B As Brep, Optional ByVal tolerance As Double = 0.01) As Boolean
    Dim U As New Rhino.Geometry.Unroller(B)
    U.RelativeTolerance = tolerance
    Dim unrolledBreps As New List(Of Brep)
    Return U.PerformUnroll(unrolledBreps) > 0
End Function

and my test command:

    Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
    For Each obj As RhinoObject In doc.Objects.FindByObjectType(DocObjects.ObjectType.Brep)
        Dim MyBrepObj As BrepObject = TryCast(obj, BrepObject)

        'Color in green is unrollable, red otherwise
        MyBrepObj.Attributes.ColorSource = ObjectColorSource.ColorFromObject
        If MyBrepObj.BrepGeometry.IsUnrollable(0.3) Then
            MyBrepObj.Attributes.ObjectColor = Color.Green
        Else
            MyBrepObj.Attributes.ObjectColor = Color.Red
        End If
        MyBrepObj.CommitChanges()

    Next

    doc.Views.Redraw()
    Return Result.Success
End Function

I’m attaching a sample model: Bug-Unroll.3dm (38.4 KB)

Hi @Matthieu_from_NAVINN,

Try shrinking the underlying surface before unrolling. This works here:

import System
import Rhino
import scriptcontext as sc

def test_unroll():
    
    filter = Rhino.DocObjects.ObjectType.Surface
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select surface to unroll", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
        
    picked_brep = objref.Brep()
    if not picked_brep: 
        return
        
    in_brep = picked_brep.DuplicateBrep()
    in_brep.Faces.ShrinkFaces()
    
    unroller = Rhino.Geometry.Unroller(in_brep)
    unroller.AbsoluteTolerance = sc.doc.ModelAbsoluteTolerance
    unroller.RelativeTolerance = 0.3
    
    out_breps = System.Collections.Generic.List[Rhino.Geometry.Brep]()
    count = unroller.PerformUnroll(out_breps)
    if out_breps.Count > 0:
        for brep in out_breps:
          sc.doc.Objects.Add(brep)
    sc.doc.Views.Redraw()
    
test_unroll()

– Dale

3 Likes

Thanks a lot @dale, this is exactly what I needed. :+1: