Skip to content

Commit 331c38b

Browse files
authored
Merge pull request #1074 from compas-dev/brep_artist
Brep artist
2 parents d5354c2 + fb2450f commit 331c38b

File tree

9 files changed

+113
-0
lines changed

9 files changed

+113
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* Added `format` task using `black` formatter.
2121
* Added a `test_intersection_circle_circle_xy` in the `test_intersections`
2222
* Added split operation to `compas_rhino.geometry.Brep`.
23+
* Added a `RhinoArtist` in `compas_rhino`.
24+
* Added a `RhinoArtist` in `compas_ghpython`.
2325

2426
### Changed
2527

src/compas_ghpython/artists/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
SurfaceArtist
3636
TorusArtist
3737
VectorArtist
38+
BrepArtist
3839
3940
4041
Datastructure Artists
@@ -91,6 +92,7 @@
9192
from compas.geometry import Surface
9293
from compas.geometry import Torus
9394
from compas.geometry import Vector
95+
from compas.geometry import Brep
9496

9597
from compas.datastructures import Mesh
9698
from compas.datastructures import Network
@@ -119,6 +121,7 @@
119121
from .torusartist import TorusArtist
120122
from .vectorartist import VectorArtist
121123
from .volmeshartist import VolMeshArtist
124+
from .brepartist import BrepArtist
122125

123126

124127
ShapeArtist.default_color = (255, 255, 255)
@@ -160,6 +163,7 @@ def register_artists():
160163
Artist.register(Torus, TorusArtist, context="Grasshopper")
161164
Artist.register(Vector, VectorArtist, context="Grasshopper")
162165
Artist.register(VolMesh, VolMeshArtist, context="Grasshopper")
166+
Artist.register(Brep, BrepArtist, context="Grasshopper")
163167
print("GH Artists registered.")
164168

165169

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from compas_ghpython.artists import GHArtist
2+
from compas_ghpython.utilities import draw_brep
3+
4+
5+
class BrepArtist(GHArtist):
6+
"""An artist for drawing a brep in Grasshopper.
7+
8+
Parameters
9+
==========
10+
brep : :class:`~compas_rhino.geometry.RhinoBrep`
11+
The brep to draw.
12+
13+
"""
14+
15+
def __init__(self, brep):
16+
super(BrepArtist, self).__init__()
17+
self._brep = brep
18+
19+
def draw(self):
20+
"""Draw the brep as a Grasshopper geometry.
21+
22+
Returns
23+
-------
24+
:rhino:`Rhino.Geometry.Brep`
25+
The Grasshopper geometry instance.
26+
27+
"""
28+
return draw_brep(self._brep)

src/compas_ghpython/utilities/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
draw_spheres
2424
draw_mesh
2525
draw_network
26+
draw_brep
2627
2728
2829
sets
@@ -69,6 +70,7 @@
6970
draw_mesh,
7071
draw_network,
7172
draw_circles,
73+
draw_brep,
7274
)
7375
from .sets import list_to_ghtree, ghtree_to_list
7476
from .timer import update_component
@@ -87,6 +89,7 @@
8789
"draw_mesh",
8890
"draw_network",
8991
"draw_circles",
92+
"draw_brep",
9093
"list_to_ghtree",
9194
"ghtree_to_list",
9295
"update_component",

src/compas_ghpython/utilities/drawing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,19 @@ def draw_circles(circles):
463463
radius = c["radius"]
464464
rg_circles.append(Circle(Plane(Point3d(*point), Vector3d(*normal)), radius))
465465
return rg_circles
466+
467+
468+
def draw_brep(brep):
469+
"""Draw a RhinoBrep in Grasshopper.
470+
471+
Parameters
472+
----------
473+
brep : :class:`~compas.geometry.RhinoBrep`
474+
The Brep to draw.
475+
476+
Returns
477+
-------
478+
:rhino:`Rhino.Geometry.Brep`
479+
480+
"""
481+
return brep.native_brep

src/compas_rhino/artists/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
PolygonArtist
2222
PolylineArtist
2323
VectorArtist
24+
BrepArtist
2425
2526
2627
Shape Artists
@@ -106,6 +107,7 @@
106107

107108
from compas.geometry import Curve
108109
from compas.geometry import Surface
110+
from compas.geometry import Brep
109111

110112
from compas.datastructures import Mesh
111113
from compas.datastructures import Network
@@ -137,6 +139,7 @@
137139

138140
from .curveartist import CurveArtist
139141
from .surfaceartist import SurfaceArtist
142+
from .brepartist import BrepArtist
140143

141144
BaseArtist = RhinoArtist
142145

@@ -174,6 +177,7 @@ def register_artists():
174177
Artist.register(RobotModel, RobotModelArtist, context="Rhino")
175178
Artist.register(Curve, CurveArtist, context="Rhino")
176179
Artist.register(Surface, SurfaceArtist, context="Rhino")
180+
Artist.register(Brep, BrepArtist, context="Rhino")
177181
print("Rhino Artists registered.")
178182

179183

@@ -201,4 +205,5 @@ def register_artists():
201205
"RobotModelArtist",
202206
"CurveArtist",
203207
"SurfaceArtist",
208+
"BrepArtist",
204209
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import compas_rhino
2+
from .artist import RhinoArtist
3+
4+
5+
class BrepArtist(RhinoArtist):
6+
"""An artist for drawing a RhinoBrep.
7+
8+
Parameters
9+
==========
10+
brep : :class:`~compas_rhino.geometry.RhinoBrep`
11+
The Brep to draw.
12+
13+
"""
14+
15+
def __init__(self, brep):
16+
super(BrepArtist, self).__init__()
17+
self._brep = brep
18+
19+
def draw(self, color=None):
20+
"""Bakes the Brep into the current document
21+
22+
Returns
23+
-------
24+
list(:rhino:`System.Guid`)
25+
The guid of the baked Brep.
26+
27+
"""
28+
return [compas_rhino.draw_brep(self._brep, color)]

src/compas_rhino/utilities/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
draw_circles,
199199
draw_curves,
200200
draw_surfaces,
201+
draw_brep,
201202
)
202203
from .geometry import uv_points_from_surface
203204
from .constructors import volmesh_from_polysurfaces
@@ -297,6 +298,7 @@
297298
"draw_circles",
298299
"draw_curves",
299300
"draw_surfaces",
301+
"draw_brep",
300302
"uv_points_from_surface",
301303
"volmesh_from_polysurfaces",
302304
]

src/compas_rhino/utilities/drawing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"draw_mesh",
8383
"draw_circles",
8484
"draw_surfaces",
85+
"draw_brep",
8586
]
8687

8788

@@ -1096,3 +1097,27 @@ def draw_surfaces(surfaces, **kwargs):
10961097
obj.CommitChanges()
10971098
guids.append(guid)
10981099
return guids
1100+
1101+
1102+
@wrap_drawfunc
1103+
def draw_brep(brep, color=None, **kwargs):
1104+
"""Draw a brep to the Rhino document.
1105+
1106+
Parameters
1107+
----------
1108+
brep : :class:`~compas_rhino.geometry.RhinoBrep`
1109+
The brep to draw.
1110+
color : tuple[int, int, int] | tuple[float, float, float], optional
1111+
The color to draw the brep with.
1112+
1113+
Returns
1114+
-------
1115+
:rhino:`System.Guid`
1116+
The Rhino document GUID of the drawn Brep.
1117+
1118+
"""
1119+
native_brep = brep.native_brep
1120+
if color:
1121+
for face in native_brep.Faces:
1122+
face.PerFaceColor = FromArgb(*color)
1123+
return add_brep(native_brep)

0 commit comments

Comments
 (0)