Skip to content

Commit 8496686

Browse files
authored
Merge pull request #1452 from obucklin/clean_brep_from_cuves
RhinoBrep.from_curves
2 parents 0fa6bcb + 15ea5fe commit 8496686

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Added `compas.geometry.Brep.cap_planar_holes`.
1414
* Added `compas_rhino.geometry.RhinoBrep.cap_planar_holes`.
1515
* Added `compas.geometry.angle_vectors_projected`.
16+
* Added `compas.geometry.Brep.from_curves`.
17+
* Added `compas_rhino.geometry.RhinoBrep.from_curves`.
1618

1719
### Changed
1820

src/compas/geometry/brep/brep.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,15 @@ def from_cone(cls, cone):
358358

359359
@classmethod
360360
def from_curves(cls, curves):
361-
"""Construct a Brep from a set of curves.
361+
"""Construct a Brep from a set of closed, planar curves.
362362
363363
Parameters
364364
----------
365365
curves : list[:class:`compas.geometry.NurbsCurve`]
366366
367367
Returns
368368
-------
369-
:class:`compas.geometry.Brep`
369+
list [:class:`compas.geometry.Brep`]
370370
371371
"""
372372
return from_curves(curves)

src/compas_rhino/geometry/brep/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def from_extrusion(*args, **kwargs):
3535
return RhinoBrep.from_extrusion(*args, **kwargs)
3636

3737

38+
@plugin(category="factories", requires=["Rhino"])
39+
def from_curves(*args, **kwargs):
40+
return RhinoBrep.from_curves(*args, **kwargs)
41+
42+
3843
@plugin(category="factories", requires=["Rhino"])
3944
def from_loft(*args, **kwargs):
4045
return RhinoBrep.from_loft(*args, **kwargs)

src/compas_rhino/geometry/brep/brep.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,39 @@ def from_cylinder(cls, cylinder):
302302
rhino_cylinder = cylinder_to_rhino(cylinder)
303303
return cls.from_native(rhino_cylinder.ToBrep(True, True))
304304

305+
@classmethod
306+
def from_curves(cls, curves):
307+
"""Create a RhinoBreps from a list of planar face boundary curves.
308+
309+
Parameters
310+
----------
311+
curves : list of :class:`~compas.geometry.Curve` or :class:`~compas.geometry.Polyline`
312+
The planar curves that make up the face borders of brep faces.
313+
314+
Returns
315+
-------
316+
list of :class:`~compas_rhino.geometry.RhinoBrep`
317+
318+
"""
319+
if not isinstance(curves, list):
320+
curves = [curves]
321+
faces = []
322+
for curve in curves:
323+
if isinstance(curve, Polyline):
324+
rhino_curve = polyline_to_rhino_curve(curve)
325+
else:
326+
rhino_curve = curve_to_rhino(curve)
327+
face = Rhino.Geometry.Brep.CreatePlanarBreps(rhino_curve, TOL.absolute)
328+
if face is None:
329+
raise BrepError("Failed to create face from curve: {} ".format(curve))
330+
if len(face) > 1:
331+
raise BrepError("Failed to create single face from curve: {} ".format(curve))
332+
faces.append(face[0])
333+
rhino_brep = Rhino.Geometry.Brep.JoinBreps(faces, TOL.absolute)
334+
if rhino_brep is None:
335+
raise BrepError("Failed to create Brep from faces: {} ".format(faces))
336+
return [cls.from_native(brep) for brep in rhino_brep]
337+
305338
@classmethod
306339
def from_extrusion(cls, curve, vector, cap_ends=True):
307340
"""Create a RhinoBrep from an extrusion.

0 commit comments

Comments
 (0)