Skip to content

Commit 5c2c296

Browse files
committed
add blender frame artist
1 parent 57a430d commit 5c2c296

File tree

4 files changed

+122
-4
lines changed

4 files changed

+122
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* Added support for multimesh files to OBJ reader/writer.
1717
* Added support for attaching and detaching meshes in `compas.robots.RobotModelArtist` and drawing them.
1818
* Added `meshes` method to artists of `compas.robots.RobotModel`.
19+
* Added `FrameArtist` class to `compas_blender`.
1920

2021
### Changed
2122

src/compas_blender/artists/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
.. autosummary::
2424
:toctree: generated/
2525
26+
FrameArtist
2627
NetworkArtist
2728
MeshArtist
2829
RobotModelArtist
2930
3031
"""
3132

3233
from ._artist import BaseArtist # noqa: F401
34+
from .frameartist import FrameArtist
3335
from .meshartist import MeshArtist
3436
from .networkartist import NetworkArtist
3537
from .robotmodelartist import ( # noqa: F401
@@ -38,6 +40,7 @@
3840
)
3941

4042
__all__ = [
43+
'FrameArtist',
4144
'NetworkArtist',
4245
'MeshArtist',
4346
'RobotModelArtist'
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import compas_blender
2+
from compas_blender.artists import BaseArtist
3+
4+
5+
__all__ = ['FrameArtist']
6+
7+
8+
class FrameArtist(BaseArtist):
9+
"""Artist for drawing frames.
10+
11+
Parameters
12+
----------
13+
frame: :class:`compas.geometry.Frame`
14+
A COMPAS frame.
15+
collection: str
16+
The name of the frame's collection.
17+
scale: float, optional
18+
Scale factor that controls the length of the axes.
19+
20+
Attributes
21+
----------
22+
frame: :class:`compas.geometry.Frame`
23+
A COMPAS frame.
24+
collection: str
25+
The name of the frame's collection.
26+
scale : float
27+
Scale factor that controls the length of the axes.
28+
Default is ``1.0``.
29+
color_origin : tuple of 3 int between 0 and 255
30+
Default is ``(0, 0, 0)``.
31+
color_xaxis : tuple of 3 int between 0 and 255
32+
Default is ``(255, 0, 0)``.
33+
color_yaxis : tuple of 3 int between 0 and 255
34+
Default is ``(0, 255, 0)``.
35+
color_zaxis : tuple of 3 int between 0 and 255
36+
Default is ``(0, 0, 255)``.
37+
38+
Examples
39+
--------
40+
.. code-block:: python
41+
42+
from compas.geometry import Pointcloud
43+
from compas.geometry import Frame
44+
45+
from compas_blender.artists import FrameArtist
46+
47+
pcl = Pointcloud.from_bounds(10, 10, 10, 100)
48+
tpl = Frame([0, 0, 0], [1, 0, 0], [0, 1, 0])
49+
50+
51+
for point in pcl.points:
52+
frame = tpl.copy()
53+
frame.point = point
54+
artist = FrameArtist(frame)
55+
artist.draw()
56+
57+
"""
58+
def __init__(self, frame, collection=None, scale=1.0):
59+
super(FrameArtist, self).__init__()
60+
self.collection = collection
61+
self.frame = frame
62+
self.scale = scale or 1.0
63+
self.color_origin = (0, 0, 0)
64+
self.color_xaxis = (255, 0, 0)
65+
self.color_yaxis = (0, 255, 0)
66+
self.color_zaxis = (0, 0, 255)
67+
68+
def draw(self):
69+
"""Draw the frame.
70+
71+
Returns
72+
-------
73+
``None``
74+
"""
75+
self.clear()
76+
self.draw_origin()
77+
self.draw_axes()
78+
79+
def draw_origin(self):
80+
"""Draw the origin of the frame.
81+
82+
Returns
83+
-------
84+
list of :class:`bpy.types.Object`
85+
"""
86+
points = [{
87+
'pos': self.frame.point,
88+
'name': f"{self.frame.name}.origin",
89+
'color': self.color_origin,
90+
'radius': 0.01
91+
}]
92+
objects = compas_blender.draw_points(points, self.collection)
93+
self.objects += objects
94+
return objects
95+
96+
def draw_axes(self):
97+
"""Draw the axes of the frame.
98+
99+
Returns
100+
-------
101+
list of :class:`bpy.types.Object`
102+
"""
103+
origin = list(self.frame.point)
104+
X = list(self.frame.point + self.frame.xaxis.scaled(self.scale))
105+
Y = list(self.frame.point + self.frame.yaxis.scaled(self.scale))
106+
Z = list(self.frame.point + self.frame.zaxis.scaled(self.scale))
107+
lines = [
108+
{'start': origin, 'end': X, 'color': self.color_xaxis, 'name': f"{self.frame.name}.xaxis"},
109+
{'start': origin, 'end': Y, 'color': self.color_yaxis, 'name': f"{self.frame.name}.yaxis"},
110+
{'start': origin, 'end': Z, 'color': self.color_zaxis, 'name': f"{self.frame.name}.zaxis"},
111+
]
112+
objects = compas_blender.draw_lines(lines, self.collection)
113+
self.objects += objects
114+
return objects

src/compas_rhino/artists/frameartist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class FrameArtist(PrimitiveArtist):
2828
scale : float
2929
Scale factor that controls the length of the axes.
3030
Default is ``1.0``.
31-
color_origin : tuple of 3 int between 0 abd 255
31+
color_origin : tuple of 3 int between 0 and 255
3232
Default is ``(0, 0, 0)``.
33-
color_xaxis : tuple of 3 int between 0 abd 255
33+
color_xaxis : tuple of 3 int between 0 and 255
3434
Default is ``(255, 0, 0)``.
35-
color_yaxis : tuple of 3 int between 0 abd 255
35+
color_yaxis : tuple of 3 int between 0 and 255
3636
Default is ``(0, 255, 0)``.
37-
color_zaxis : tuple of 3 int between 0 abd 255
37+
color_zaxis : tuple of 3 int between 0 and 255
3838
Default is ``(0, 0, 255)``.
3939
4040
Examples

0 commit comments

Comments
 (0)