Skip to content

Commit 4ba76f4

Browse files
committed
surface to compas conversion
1 parent b6c8444 commit 4ba76f4

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/compas_rhino/conversions/surface.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,25 @@ def geometry(self, geometry):
4040
raise TypeError("Geometry cannot be interpreted as a `Rhino.Geometry.Surface`: {}".format(type(geometry)))
4141
self._geometry = geometry
4242

43-
def to_compas_mesh(self, cls=None, facefilter=None, cleanup=True):
43+
def to_compas(self):
44+
"""Convert the surface to a COMPAS surface.
45+
46+
Returns
47+
-------
48+
:class:`compas_rhino.geometry.RhinoNurbsSurface`
49+
"""
50+
from compas.geometry import NurbsSurface
51+
52+
brep = Rhino.Geometry.Brep.TryConvertBrep(self.geometry)
53+
surface = NurbsSurface()
54+
if brep.Surfaces.Count > 1:
55+
raise Exception('Conversion of a BRep with multiple underlying surface is currently not supported.')
56+
for geometry in brep.Surfaces:
57+
surface.rhino_surface = geometry
58+
break
59+
return surface
60+
61+
def to_compas_mesh(self, cls=None, facefilter=None, cleanup=False):
4462
"""Convert the surface b-rep loops to a COMPAS mesh.
4563
4664
Parameters
@@ -55,7 +73,7 @@ def to_compas_mesh(self, cls=None, facefilter=None, cleanup=True):
5573
cleanup : bool, optional
5674
Flag indicating to clean up the result.
5775
Cleaning up means to remove isolated faces and unused vertices.
58-
Default is ``True``.
76+
Default is ``False``.
5977
6078
Returns
6179
-------
@@ -131,9 +149,10 @@ def to_compas_mesh(self, cls=None, facefilter=None, cleanup=True):
131149
mesh.name = self.name
132150
# remove isolated faces
133151
if cleanup:
134-
for face in list(mesh.faces()):
135-
if not mesh.face_neighbors(face):
136-
mesh.delete_face(face)
152+
if mesh.number_of_faces() > 1:
153+
for face in list(mesh.faces()):
154+
if not mesh.face_neighbors(face):
155+
mesh.delete_face(face)
137156
mesh.remove_unused_vertices()
138157
return mesh
139158

0 commit comments

Comments
 (0)