Reversing trimmed surface of brep with Rhinocommon

Hi,

I have a brep with just one surface that is trimmed. I would like to update the brep such that the surface’s x and y directions are inverted and swapped while still maintaining the trims. I’ve tried to figure it out myself but run into various road blocks, like the trims of a brep be readonly etc. I’m hoping someone could provide me some code to update a brep this way (using rhinocommon).

Thanks,
Sam

Hi @samlochner,

To properly swap the u-v directions of a face’s underlying surface, you’ll need access to ON_BrepFace::Transpose, which is not currently available.

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

– Dale

Hi Dale,

What about reversing the direction of just u so u points the other way? I see how to do this for a surface, but I’m hoping you can show me how to do this directly for a brep with a single trimmed surface while maintaining the trims.

Thanks,
Sam

Hi Sam,

You should be able to use BrepFace.Reverse(0).

– Dale

Hi Dale,

That works though I loose the trims. I used it like this:

Dim BrepReversed = BrepOriginal.Faces(0).Reverse(0).ToBrep

The problem I’m running into is that trims are readonly so I can’t set them… and I tried AddTrimCurve and using the original breps trims but that didn’t work for me.

Any suggestions how I can reverse while maintaining the original trims?

Thanks,
Sam

Sorry for not being more detailed in my reply.

Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result

  Dim go As New GetObject()
  go.SetCommandPrompt("Select surface")
  go.GeometryFilter = DocObjects.ObjectType.Surface
  go.SubObjectSelect = False
  go.Get()
  If go.CommandResult() <> Result.Success Then
    Return go.CommandResult()
  End If

  Dim brep_ref = go.Object(0)
  Dim brep As Brep = brep_ref.Brep()
  If (brep Is Nothing) Then
    Return Result.Failure
  End If

  Dim brep_copy = brep.DuplicateBrep()
  brep_copy.Faces(0).Reverse(0, True)

  doc.Objects.Replace(brep_ref, brep_copy)
  doc.Views.Redraw()

  Return Rhino.Commands.Result.Success

End Function

– Dale

That worked, thanks Dale!

Sam

Hi,

I’m now trying to do something similar: Rebuild the single surface of a brep while maintaining the trims. I figured I’d post this here as the only difference is that I’m rebuilding rather than reversing directions.

For the “reverse” direction function, the “InPlace” boolean did the trick. But for rebuilding the surface, the “InPlace” option isn’t available. So I’m wondering if anyone has any suggestions on the best way to take a brep with a single trimmed surface and rebuild it while maintaining the trims.

Thanks,
Sam

Hi @samlochner, using Surface.Rebuild and then Brep.CreateTrimmedSurface should do the trick.

– Dale

Hi Dale,

So something like this?

Dim MyRebuiltSurface = MyTrimmedBrep.Surfaces(0).Rebuild(3, 3, 100, 100)
Dim MyRebuiltTrimmedBrep = Brep.CreateTrimmedSurface(?, MyRebuiltSurface).tobrep

But I’m not quite sure what goes where the question mark is. Is it a face of the original breps trims, or something else?

Thanks,
Sam

Here is a cheap C# function:

public Brep RebuildSurfaceAndRetrim(
  BrepFace face,
  int uDegree, int vDegree,
  int uPointCount, int vPointCount,
  double tolerance
)
{
  var brep = face?.Brep;
  var srf = brep?.Surfaces[face.SurfaceIndex];
  var nurb = srf?.Rebuild(uDegree, vDegree, uPointCount, vPointCount);
  return nurb != null ? Brep.CreateTrimmedSurface(face, nurb, tolerance) : null;
}

– Dale

1 Like

Hi Dale,

I’m getting a result, though seems to be an invalid surface…

Below is my conversion to VB.net, perhaps I missed something… Attached is the trimmed surface I’m trying it on. Suggestions?

Thanks,
Sam

Dim objectRef As Rhino.DocObjects.ObjRef = Nothing
Rhino.Input.RhinoGet.GetOneObject(“select trimmed brep”, False, Rhino.DocObjects.ObjectType.Brep, objectRef)
Dim TrimmedBrep = TryCast(objectRef.Object(), Rhino.DocObjects.BrepObject).BrepGeometry
Dim face = TrimmedBrep.Faces(0)
Dim brep = face.ToBrep
Dim srf = brep.Surfaces(face.SurfaceIndex)
Dim nurb = srf.Rebuild(3, 3, 10, 10)
Dim RebuiltTrimmedBrep = Brep.CreateTrimmedSurface(face, nurb)
doc.Objects.AddBrep(RebuiltTrimmedBrep)

BrepWithTrim.3dm (185.4 KB)

Hi @samlochner,

I’ll look into this.

– Dale

okay, thanks Dale.

Sam

Hey Dale, any progress on this?

Thanks,
Sam

Hi @samlochner,

I’ve logged an issue for this:

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

– Dale

is this issue resolved? I am having the same problem with CreateTrimmedSurface method

Hi @torabiarchitect,

The issue mentioned above was resolved 2 years ago.

Can you provide more details on what problem you are having? Samples models and source code that isn’t working for you is always helpful.

Thanks,

– Dale

Hi @dale I posted in a new thread , Reverse face U-direction maintaining the normal direction