Skip to content

Commit bdff919

Browse files
committed
fixed bugs in curve and surface conversions
1 parent 73f9efb commit bdff919

File tree

6 files changed

+88
-21
lines changed

6 files changed

+88
-21
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added pluggable `compas.geometry.surfaces.nurbs.new_nurbssurface_from_native`.
13+
* Added `compas.geometry.NurbsSurface.from_native`.
14+
* Added plugin `compas_rhino.geometry.surfaces.new_nurbssurface_from_plane`.
15+
1216
### Changed
1317

18+
* Fixed bug in `compas_blender.clear`.
19+
* Fixed bug in `compas_rhino.conversions.surface_to_compas`.
20+
* Fixed bug in `compas_rhino.conversions.surface_to_compas_mesh`.
21+
* Fixed bug in `compas_rhino.conversions.surface_to_compas_quadmesh`.
22+
* Fixed bug in plugin `compas_rhino.geometry.curves.new_nurbscurve_from_native`.
23+
* Fixed bug in plugin `compas_rhino.geometry.surfaces.new_nurbssurface_from_native`.
24+
1425
### Removed
1526

27+
* Removed plugin `compas_rhino.geometry.surfaces.new_surface_from_plane`.
28+
1629

1730
## [2.0.0] 2024-01-31
1831

src/compas/geometry/surfaces/nurbs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def new_nurbssurface(cls, *args, **kwargs):
1616
raise PluginNotInstalledError
1717

1818

19+
@pluggable(category="factories")
20+
def new_nurbssurface_from_native(cls, *args, **kwargs):
21+
raise PluginNotInstalledError
22+
23+
1924
@pluggable(category="factories")
2025
def new_nurbssurface_from_parameters(cls, *args, **kwargs):
2126
raise PluginNotInstalledError
@@ -186,6 +191,23 @@ def degree_v(self):
186191
# Constructors
187192
# ==============================================================================
188193

194+
@classmethod
195+
def from_native(cls, surface):
196+
"""Construct a NURBS surface from a surface object.
197+
198+
Parameters
199+
----------
200+
surface : :class:`Rhino.Geometry.NurbsSurface`
201+
A CAD native surface object.
202+
203+
Returns
204+
-------
205+
:class:`compas.geometry.NurbsSurface`
206+
A COMPAS NURBS surface.
207+
208+
"""
209+
return new_nurbssurface_from_native(cls, surface)
210+
189211
@classmethod
190212
def from_parameters(
191213
cls,

src/compas_blender/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
try:
77
import bpy
8+
import compas_blender.data
9+
810
except ImportError:
911
pass
10-
else:
11-
from .utilities import * # noqa: F401 F403
1212

1313

1414
__version__ = "2.0.0"
@@ -51,7 +51,7 @@ def clear(guids=None):
5151
bpy.ops.object.select_all(action="SELECT")
5252
bpy.ops.object.delete(use_global=True, confirm=False)
5353
# delete data
54-
delete_unused_data() # noqa: F405
54+
compas_blender.data.delete_unused_data()
5555
# delete collections
5656
for collection in bpy.context.scene.collection.children:
5757
bpy.context.scene.collection.children.unlink(collection)

src/compas_rhino/conversions/surfaces.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from compas.tolerance import TOL
88

99
from compas.geometry import Point
10+
from compas.geometry import NurbsSurface
1011
from compas.datastructures import Mesh
1112
from compas.utilities import memoize
1213

@@ -155,21 +156,27 @@ def surface_to_compas(surface):
155156
:class:`compas.geometry.Surface`
156157
157158
"""
158-
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
159+
if isinstance(surface, Rhino.DocObjects.RhinoObject):
160+
surface = surface.Geometry
161+
162+
if not isinstance(surface, Rhino.Geometry.Brep):
163+
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
164+
else:
165+
brep = surface
159166

160167
if brep.Surfaces.Count > 1: # type: ignore
161-
raise ConversionError("Conversion of a BRep with multiple underlying surface is currently not supported.")
168+
raise ConversionError("Conversion of a Brep with multiple underlying surface is currently not supported.")
162169

163-
return Rhino.Geometry.NurbsSurface.from_rhino(brep.Surfaces[0])
170+
return NurbsSurface.from_native(brep.Surfaces[0])
164171

165172

166-
def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False):
173+
def surface_to_compas_mesh(surface, facefilter=None, cleanup=False, cls=None):
167174
"""Convert the surface b-rep loops to a COMPAS mesh.
168175
169176
Parameters
170177
----------
171-
cls : :class:`compas.datastructures.Mesh`, optional
172-
The type of COMPAS mesh.
178+
surface : :class:`Rhino.Geometry.Surface`
179+
A Rhino surface.
173180
facefilter : callable, optional
174181
A filter for selection which Brep faces to include.
175182
If provided, the filter should return True or False per face.
@@ -179,6 +186,8 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False):
179186
Flag indicating to clean up the result.
180187
Cleaning up means to remove isolated faces and unused vertices.
181188
Default is False.
189+
cls : :class:`compas.datastructures.Mesh`, optional
190+
The type of COMPAS mesh.
182191
183192
Returns
184193
-------
@@ -208,10 +217,16 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False):
208217
>>> scene.draw()
209218
210219
"""
220+
if isinstance(surface, Rhino.DocObjects.RhinoObject):
221+
surface = surface.Geometry
222+
211223
if not surface.HasBrepForm:
212224
return
213225

214-
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
226+
if not isinstance(surface, Rhino.Geometry.Brep):
227+
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
228+
else:
229+
brep = surface
215230

216231
if facefilter and callable(facefilter):
217232
brepfaces = [face for face in brep.Faces if facefilter(face)]
@@ -224,16 +239,16 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False):
224239
for face in brepfaces:
225240
loop = face.OuterLoop
226241
curve = loop.To3dCurve()
227-
segments = curve.Explode()
228-
a = segments[0].PointAtStart
229-
b = segments[0].PointAtEnd
242+
segments = list(curve.Explode())
243+
a = point_to_compas(segments[0].PointAtStart)
244+
b = point_to_compas(segments[0].PointAtEnd)
230245
a_gkey = TOL.geometric_key(a)
231246
b_gkey = TOL.geometric_key(b)
232247
gkey_xyz[a_gkey] = a
233248
gkey_xyz[b_gkey] = b
234249
face = [a_gkey, b_gkey]
235250
for segment in segments[1:-1]:
236-
b = segment.PointAtEnd
251+
b = point_to_compas(segment.PointAtEnd)
237252
b_gkey = TOL.geometric_key(b)
238253
face.append(b_gkey)
239254
gkey_xyz[b_gkey] = b
@@ -274,6 +289,8 @@ def surface_to_compas_quadmesh(surface, nu, nv=None, weld=False, facefilter=None
274289
275290
Parameters
276291
----------
292+
surface: :class:`Rhino.Geometry.Surface`
293+
A Rhino surface.
277294
nu: int
278295
The number of faces in the u direction.
279296
nv: int, optional
@@ -298,10 +315,16 @@ def surface_to_compas_quadmesh(surface, nu, nv=None, weld=False, facefilter=None
298315
nv = nv or nu
299316
cls = cls or Mesh
300317

318+
if isinstance(surface, Rhino.DocObjects.RhinoObject):
319+
surface = surface.Geometry
320+
301321
if not surface.HasBrepForm:
302322
return
303323

304-
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
324+
if not isinstance(surface, Rhino.Geometry.Brep):
325+
brep = Rhino.Geometry.Brep.TryConvertBrep(surface)
326+
else:
327+
brep = surface
305328

306329
if facefilter and callable(facefilter):
307330
faces = [face for face in brep.Faces if facefilter(face)]

src/compas_rhino/geometry/curves/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def new_nurbscurve(cls, *args, **kwargs):
2020

2121
@plugin(category="factories", requires=["Rhino"])
2222
def new_nurbscurve_from_native(cls, *args, **kwargs):
23-
return RhinoCurve.from_rhino(*args, **kwargs)
23+
return RhinoNurbsCurve.from_rhino(*args, **kwargs)
2424

2525

2626
@plugin(category="factories", requires=["Rhino"])

src/compas_rhino/geometry/surfaces/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@
88

99
@plugin(category="factories", requires=["Rhino"])
1010
def new_surface(cls, *args, **kwargs):
11-
return super(Surface, cls).__new__(cls)
11+
surface = super(Surface, cls).__new__(cls)
12+
surface.__init__(*args, **kwargs)
13+
return surface
1214

1315

1416
@plugin(category="factories", requires=["Rhino"])
15-
def new_surface_from_plane(cls, *args, **kwargs):
16-
return RhinoSurface.from_plane(*args, **kwargs)
17+
def new_nurbssurface(cls, *args, **kwargs):
18+
surface = super(NurbsSurface, cls).__new__(cls)
19+
surface.__init__(*args, **kwargs)
20+
return surface
1721

1822

1923
@plugin(category="factories", requires=["Rhino"])
20-
def new_nurbssurface(cls, *args, **kwargs):
21-
return super(NurbsSurface, cls).__new__(cls)
24+
def new_nurbssurface_from_native(cls, *args, **kwargs):
25+
return RhinoNurbsSurface.from_rhino(*args, **kwargs)
2226

2327

2428
@plugin(category="factories", requires=["Rhino"])
2529
def new_nurbssurface_from_parameters(cls, *args, **kwargs):
2630
return RhinoNurbsSurface.from_parameters(*args, **kwargs)
2731

2832

33+
@plugin(category="factories", requires=["Rhino"])
34+
def new_nurbssurface_from_plane(cls, *args, **kwargs):
35+
return RhinoNurbsSurface.from_plane(*args, **kwargs)
36+
37+
2938
@plugin(category="factories", requires=["Rhino"])
3039
def new_nurbssurface_from_points(cls, *args, **kwargs):
3140
return RhinoNurbsSurface.from_points(*args, **kwargs)

0 commit comments

Comments
 (0)