Skip to content

Commit f70798d

Browse files
authored
Merge pull request #857 from yck011522/main
Changes to draw_breps() to fix #854 #855
2 parents 6efe276 + 7493a13 commit f70798d

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8888
* Changed directory where ghuser components are installed.
8989
* Added ghuser components directory to those removed by the `clean` task.
9090
* Clean up the ghuser directory before building ghuser components.
91+
* Exposed function `draw_breps` in `compas_rhino.utilities`; example added.
92+
* Added `join` flag to function `draw_breps` in `compas_rhino.utilities`
9193
* Fixed bug in `compas.geometry.distance.closest_point_on_segment_xy`.
9294
* Fixed bug in Rhino implementations of `trimesh` curvature functions.
9395

@@ -281,9 +283,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
281283
* Fixed bug regarding a repeated call to `RobotModel.add_joint`.
282284
* Fixed bug in `compas_blender.RobotModelArtist.update`.
283285
* Fixed bug in `compas.datastructures.mesh_slice_plane`.
284-
* Fixed bug where initialising a `compas_blender.artists.Robotmodelartist` would create a new collection for each mesh and then also not put the mesh iton the created collection.
285-
* Changed the initialisation of `compas_blender.artists.Robotmodelartist` to include a `collection`-parameter instead of a `layer`-parameter to be more consistent with Blender's nomenclature.
286-
* Used a utility function from `compas_blender.utilities` to create the collection if none exists instead of using a new call to a bpy-method.
286+
* Fixed bug where initialising a `compas_blender.artists.Robotmodelartist` would create a new collection for each mesh and then also not put the mesh iton the created collection.
287+
* Changed the initialisation of `compas_blender.artists.Robotmodelartist` to include a `collection`-parameter instead of a `layer`-parameter to be more consistent with Blender's nomenclature.
288+
* Used a utility function from `compas_blender.utilities` to create the collection if none exists instead of using a new call to a bpy-method.
287289

288290
### Removed
289291

src/compas_rhino/utilities/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
draw_lines,
180180
draw_geodesics,
181181
draw_polylines,
182+
draw_breps,
182183
draw_faces,
183184
draw_cylinders,
184185
draw_pipes,
@@ -275,6 +276,7 @@
275276
'draw_lines',
276277
'draw_geodesics',
277278
'draw_polylines',
279+
'draw_breps',
278280
'draw_faces',
279281
'draw_cylinders',
280282
'draw_pipes',

src/compas_rhino/utilities/drawing.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'draw_lines',
7373
'draw_geodesics',
7474
'draw_polylines',
75+
'draw_breps',
7576
'draw_faces',
7677
'draw_cylinders',
7778
'draw_pipes',
@@ -421,7 +422,7 @@ def draw_polylines(polylines, **kwargs):
421422

422423

423424
@wrap_drawfunc
424-
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, **kwargs):
425+
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, join=False, **kwargs):
425426
"""Draw polygonal faces as Breps, and optionally set individual name, color,
426427
and layer properties.
427428
@@ -443,6 +444,8 @@ def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.
443444
spacing : float, optional
444445
flex : float, optional
445446
pull : float, optional
447+
join : bool, optional
448+
Join the individual faces as polysurfaces. Default is False.
446449
447450
Returns
448451
-------
@@ -461,8 +464,31 @@ def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.
461464
Optional('layer', default=None): str,
462465
})
463466
467+
Examples
468+
--------
469+
Using a compas Mesh as an example:
470+
471+
>>> from compas.datastructures import Mesh
472+
>>> from compas.geometry import Box, Frame
473+
>>> from compas_rhino.utilities import draw_breps
474+
>>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0)
475+
>>> mesh = Mesh.from_shape(box)
476+
477+
Draw convert each mesh face to brep dict schema:
478+
479+
>>> vertices = [mesh.vertex_attributes(vertex, 'xyz') for vertex in mesh.vertices()]
480+
>>> breps = []
481+
>>> for face in mesh.faces():
482+
>>> face = {'points' : [vertices[vertex] for vertex in mesh.face_vertices(face)]}
483+
>>> face['points'].append(face['points'][0])
484+
>>> breps.append(face)
485+
486+
Draw brep faces as one joined brep.
487+
488+
>>> guids = draw_breps(breps, join=True)
489+
464490
"""
465-
guids = []
491+
breps = []
466492
for f in iter(faces):
467493
points = f['points']
468494
name = f.get('name', '')
@@ -486,8 +512,14 @@ def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.
486512
TOL)
487513
else:
488514
brep = Brep.CreatePatch(geo, u, v, TOL)
489-
if not brep:
490-
continue
515+
if brep:
516+
breps.append(brep)
517+
518+
if join:
519+
breps = Brep.JoinBreps(breps, TOL)
520+
521+
guids = []
522+
for brep in breps:
491523
guid = add_brep(brep)
492524
if not guid:
493525
continue

0 commit comments

Comments
 (0)