I have a surface which acts weird when I unroll it using RhinoCommon. It’s easy to recreate using Python though. Run the following script on the surface in the file below:
import rhinoscriptsyntax as rs
obj = rs.GetObject()
rs.UnrollSurface(obj)
The left is the result I’m getting, notice the odd bump that shows up. This doesn’t happen when using the regular Rhino UnrollSrf command, but I cannot use that. Is this a bug or is there a way to prevent this from happening?
Thanks for the suggestion, but it’s not so much about workarounds since it works fine with the default Rhino unrollsrf command so I’d expect this to work the same using the RhinoCommon method. I use it in a plug-in for a client and I cannot rebuild every surface that gets chosen as input for the command.
This purely speculative, but in RhinoCommon there are two constructors for the Rhino.Geometry.Unroller class (cf. docs). One takes in a Rhino.Geometry.Brep and the other one a Rhino.Geometry.Surface.
Now, in rhinoscriptsyntax the first thing that rs.UnrollSurface() does, is cast the surface to a brep, and then it intialises a new Rhino.Geometry.Unroller() with that brep.
def UnrollSurface(surface_id, explode=False, following_geometry=None, absolute_tolerance=None, relative_tolerance=None):
"""Flattens a developable surface or polysurface
Parameters:
surface_id (guid): the surface's identifier
explode (bool, optional): If True, the resulting surfaces ar not joined
following_geometry ({guid, ...]): List of curves, dots, and points which
should be unrolled with the surface
Returns:
list(guid, ...): of unrolled surface ids
tuple((guid, ...),(guid, ...)): if following_geometry is not None, a tuple
[1] is the list of unrolled surface ids
[2] is the list of unrolled following geometry
Example:
import rhinoscriptsyntax as rs
surface = rs.GetObject("Select surface or polysurface to unroll", rs.filter.surface + rs.filter.polysurface)
if surface: rs.UnrollSurface(surface)
See Also:
"""
brep = rhutil.coercebrep(surface_id, True)
unroll = Rhino.Geometry.Unroller(brep)
unroll.ExplodeOutput = explode
if relative_tolerance is None: relative_tolerance = scriptcontext.doc.ModelRelativeTolerance
if absolute_tolerance is None: absolute_tolerance = scriptcontext.doc.ModelAbsoluteTolerance
unroll.AbsoluteTolerance = absolute_tolerance
unroll.RelativeTolerance = relative_tolerance
if following_geometry:
for id in following_geometry:
geom = rhutil.coercegeometry(id)
unroll.AddFollowingGeometry(geom)
breps, curves, points, dots = unroll.PerformUnroll()
if not breps: return None
rc = [scriptcontext.doc.Objects.AddBrep(brep) for brep in breps]
new_following = []
for curve in curves:
id = scriptcontext.doc.Objects.AddCurve(curve)
new_following.append(id)
for point in points:
id = scriptcontext.doc.Objects.AddPoint(point)
new_following.append(id)
for dot in dots:
id = scriptcontext.doc.Objects.AddTextDot(dot)
new_following.append(id)
scriptcontext.doc.Views.Redraw()
if following_geometry: return rc, new_following
return rc
Maybe something goes astray during the conversion from surface to brep?
Why they don’t use the surface unroller that’s readily available in the API instead, I have no clue.