Skip to content

Commit

Permalink
Merge pull request #1405 from compas-dev/from_loft
Browse files Browse the repository at this point in the history
Add Brep.from_loft for Rhino
  • Loading branch information
gonzalocasas authored Oct 25, 2024
2 parents a26b7e3 + fb6cba1 commit 42a4540
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added instructions for creating new data types to the dev guide.
* Added `compact=False`, `minimal=False` to `compas.data.Data.to_json()` to `compas.data.Data.to_jsonstring()`.
* Added `copy_guid=False` to `compas.data.Data.copy()`. If true, the copy has the same guid as the original.
* Added implementation of `Brep.from_loft()` to `compas_rhino`.

### Changed

Expand Down
5 changes: 5 additions & 0 deletions src/compas_rhino/geometry/brep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ def from_sphere(*args, **kwargs):
@plugin(category="factories", requires=["Rhino"])
def from_mesh(*args, **kwargs):
return RhinoBrep.from_mesh(*args, **kwargs)


@plugin(category="factories", requires=["Rhino"])
def from_loft(*args, **kwargs):
return RhinoBrep.from_loft(*args, **kwargs)
25 changes: 25 additions & 0 deletions src/compas_rhino/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ def from_mesh(cls, mesh):
rhino_mesh = mesh_to_rhino(mesh)
return cls.from_native(Rhino.Geometry.Brep.CreateFromMesh(rhino_mesh, True))

@classmethod
def from_loft(cls, curves):
"""Construct a Brep by lofting a set of curves.
Parameters
----------
curves : list[:class:`compas.geometry.Curve`]
Returns
-------
:class:`compas.geometry.Brep`
"""
rhino_curves = [curve_to_rhino(curve) for curve in curves]
start = Rhino.Geometry.Point3d.Unset
end = Rhino.Geometry.Point3d.Unset
loft_type = Rhino.Geometry.LoftType.Normal

results = Rhino.Geometry.Brep.CreateFromLoft(rhino_curves, start, end, loft_type, closed=False)
if not results:
raise BrepTrimmingError("Loft operation ended with no result")
result = results[0]

return cls.from_native(result)

# ==============================================================================
# Methods
# ==============================================================================
Expand Down

0 comments on commit 42a4540

Please sign in to comment.