Skip to content

Commit 1e696a6

Browse files
committed
Merge branch 'main' into remove-broken-links
2 parents 181ca78 + f6c0547 commit 1e696a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1752
-693
lines changed

CHANGELOG.md

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

1010
### Added
1111

12+
* Added `CircleArtist`, `LineArtist`, `PointArtist`, `PolygonArtist`, `PolylineArtist`, and `VectorArtist` to `compas_blender`.
13+
* Added `draw_circles` and `draw_planes` to `compas_blender`.
14+
* Added `compas_rhino.geometry.curves` plugins for `compas.geometry.curves` pluggables.
15+
* Added `compas_rhino.geometry.RhinoNurbsCurve`.
16+
1217
### Changed
1318

19+
* Replaced implementation of `RGBColour` and `Float` with deprecation warning in `compas.utilities.descriptors`.
20+
* Moved all Rhino geometry and objects wrappers to `compas_rhino.conversions`.
21+
* Fixed bug in `compas_rhino.conversions.RhinoSurface.from_geometry`.
22+
* Changed `compas_rhino.conversions.RhinoLine.from_geometry` to accept line curves.
23+
* Fixed bug in `compas_rhino.geometry.RhinoNurbsCurve.closest_point`.
24+
1425
### Removed
1526

1627

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# flake8: noqa
2-
cython
2+
cython <= 0.29.23
33
ezdxf
44
imageio <= 2.6; python_version < '3.5'
55
imageio >= 2.7; python_version >= '3.5'

src/compas/geometry/curves/nurbs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ def __str__(self):
122122
# Data
123123
# ==============================================================================
124124

125+
@property
126+
def dtype(self):
127+
"""str : The type of the object in the form of a '2-level' import and a class name."""
128+
return 'compas.geometry/NurbsCurve'
129+
125130
@property
126131
def data(self):
127132
return {

src/compas/utilities/colors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
BASE16 = '0123456789abcdef'
5757

58-
5958
try:
6059
HEX_DEC = {v: int(v, base=16) for v in [x + y for x in BASE16 for y in BASE16]}
6160
except Exception:

src/compas/utilities/descriptors.py

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,22 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
from compas.utilities import color_to_rgb
6-
7-
try:
8-
basestring
9-
except NameError:
10-
basestring = str
5+
import warnings
116

127

138
__all__ = [
14-
'Float', 'RGBColour',
9+
'Float',
10+
'RGBColour',
1511
]
1612

1713

1814
class Float(object):
19-
"""Descriptor for properties of type float.
20-
21-
Parameters
22-
----------
23-
value : float
24-
The value of the property.
25-
minval : float, optional
26-
The minimum value of the property.
27-
maxval : float, optional
28-
The maximum value of the property.
29-
"""
30-
31-
__slots__ = ('value', 'minval', 'maxval')
32-
33-
def __init__(self, value, minval=None, maxval=None):
34-
self.minval = None
35-
self.maxval = None
36-
if minval is not None:
37-
self.minval = float(minval)
38-
if maxval is not None:
39-
self.maxval = float(maxval)
40-
if self.minval is not None and self.maxval is not None:
41-
if self.minval > self.maxval:
42-
raise ValueError("The minimum value cannot be greater than the maximum value.")
43-
value = float(value)
44-
if self.minval is not None:
45-
if value < self.minval:
46-
raise ValueError("The value cannot be smaller than the minimum value.")
47-
if self.maxval is not None:
48-
if value > self.maxval:
49-
raise ValueError("The value cannot be greater than the maximum value.")
50-
self.value = value
51-
52-
def __get__(self, obj, objtype):
53-
return self.value
54-
55-
def __set__(self, obj, value):
56-
value = float(value)
57-
if self.minval is not None:
58-
if value < self.minval:
59-
raise ValueError("The value cannot be smaller than the minimum value.")
60-
if self.maxval is not None:
61-
if value > self.maxval:
62-
raise ValueError("The value cannot be greater than the maximum value.")
63-
self.value = value
15+
def __init__(self):
16+
warnings.warn("This class will be removed.",
17+
DeprecationWarning)
6418

6519

6620
class RGBColour(object):
67-
"""Descriptor for RGB color properties.
68-
69-
Parameters
70-
----------
71-
default : tuple
72-
The default color.
73-
normalize : bool, optional
74-
Normalize the color components, if true.
75-
description : str, optional
76-
A description of the purpose of the color property.
77-
78-
Attributes
79-
----------
80-
value : tuple
81-
The current value of the color property.
82-
"""
83-
84-
__slots__ = ('default', 'normalize', 'description', 'value')
85-
86-
def __init__(self, default, normalize=False, description=""):
87-
self.default = default
88-
self.normalize = normalize
89-
self.description = description
90-
self.value = None
91-
92-
def __get__(self, obj, objtype):
93-
if self.value is None:
94-
return self.default
95-
return self.value
96-
97-
def __set__(self, obj, value):
98-
self.value = color_to_rgb(value, normalize=self.normalize)
21+
def __init__(self):
22+
warnings.warn("This class will be removed.",
23+
DeprecationWarning)

src/compas_blender/artists/__init__.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
.. currentmodule:: compas_blender.artists
77
8-
Artists for visualising (painting) COMPAS data structures in Blender.
8+
Artists for visualizing (painting) COMPAS data structures in Blender.
99
1010
1111
Primitive Artists
@@ -14,7 +14,13 @@
1414
.. autosummary::
1515
:toctree: generated/
1616
17+
CircleArtist
1718
FrameArtist
19+
LineArtist
20+
PointArtist
21+
PolygonArtist
22+
PolylineArtist
23+
VectorArtist
1824
1925
2026
Shape Artists
@@ -28,8 +34,8 @@
2834
CapsuleArtist
2935
ConeArtist
3036
CylinderArtist
31-
SphereArtist
3237
PolyhedronArtist
38+
SphereArtist
3339
3440
3541
Datastructure Artists
@@ -39,8 +45,8 @@
3945
:toctree: generated/
4046
:nosignatures:
4147
42-
NetworkArtist
4348
MeshArtist
49+
NetworkArtist
4450
4551
4652
Robot Artist
@@ -71,28 +77,40 @@
7177

7278
from compas.geometry import Box
7379
from compas.geometry import Capsule
80+
from compas.geometry import Circle
7481
from compas.geometry import Cone
7582
from compas.geometry import Cylinder
7683
from compas.geometry import Frame
84+
from compas.geometry import Line
85+
from compas.geometry import Point
86+
from compas.geometry import Polygon
7787
from compas.geometry import Polyhedron
88+
from compas.geometry import Polyline
7889
from compas.geometry import Sphere
7990
from compas.geometry import Torus
91+
from compas.geometry import Vector
8092
from compas.datastructures import Mesh
8193
from compas.datastructures import Network
8294
from compas.robots import RobotModel
8395

8496
from .artist import BlenderArtist
8597
from .boxartist import BoxArtist
8698
from .capsuleartist import CapsuleArtist
99+
from .circleartist import CircleArtist
87100
from .coneartist import ConeArtist
88101
from .cylinderartist import CylinderArtist
89102
from .frameartist import FrameArtist
103+
from .lineartist import LineArtist
90104
from .meshartist import MeshArtist
91105
from .networkartist import NetworkArtist
106+
from .pointartist import PointArtist
107+
from .polygonartist import PolygonArtist
92108
from .polyhedronartist import PolyhedronArtist
109+
from .polylineartist import PolylineArtist
93110
from .robotmodelartist import RobotModelArtist
94111
from .sphereartist import SphereArtist
95112
from .torusartist import TorusArtist
113+
from .vectorartist import VectorArtist
96114

97115

98116
@plugin(category='drawing-utils', pluggable_name='clear', requires=['bpy'])
@@ -116,15 +134,21 @@ def new_artist_blender(cls, *args, **kwargs):
116134
if not artists_registered:
117135
BlenderArtist.register(Box, BoxArtist)
118136
BlenderArtist.register(Capsule, CapsuleArtist)
137+
BlenderArtist.register(Circle, CircleArtist)
119138
BlenderArtist.register(Cone, ConeArtist)
120139
BlenderArtist.register(Cylinder, CylinderArtist)
121140
BlenderArtist.register(Frame, FrameArtist)
141+
BlenderArtist.register(Line, LineArtist)
122142
BlenderArtist.register(Mesh, MeshArtist)
123143
BlenderArtist.register(Network, NetworkArtist)
144+
BlenderArtist.register(Point, PointArtist)
145+
BlenderArtist.register(Polygon, PolygonArtist)
124146
BlenderArtist.register(Polyhedron, PolyhedronArtist)
147+
BlenderArtist.register(Polyline, PolylineArtist)
125148
BlenderArtist.register(RobotModel, RobotModelArtist)
126149
BlenderArtist.register(Sphere, SphereArtist)
127150
BlenderArtist.register(Torus, TorusArtist)
151+
BlenderArtist.register(Vector, VectorArtist)
128152
artists_registered = True
129153

130154
data = args[0]
@@ -140,13 +164,19 @@ def new_artist_blender(cls, *args, **kwargs):
140164
'BlenderArtist',
141165
'BoxArtist',
142166
'CapsuleArtist',
167+
'CircleArtist',
143168
'ConeArtist',
144169
'CylinderArtist',
145170
'FrameArtist',
171+
'LineArtist',
146172
'MeshArtist',
147173
'NetworkArtist',
174+
'PointArtist',
175+
'PolygonArtist',
148176
'PolyhedronArtist',
177+
'PolylineArtist',
149178
'RobotModelArtist',
150179
'SphereArtist',
151180
'TorusArtist',
181+
'VectorArtist',
152182
]

src/compas_blender/artists/boxartist.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from typing import Optional
21
from typing import Any
2+
from typing import List
3+
from typing import Optional
34
from typing import Union
45

56
import bpy
67
import compas_blender
8+
from compas_blender.utilities import RGBColor
79
from compas.geometry import Box
810
from compas.artists import ShapeArtist
911
from .artist import BlenderArtist
@@ -27,7 +29,7 @@ def __init__(self,
2729

2830
super().__init__(shape=box, collection=collection or box.name, **kwargs)
2931

30-
def draw(self, color=None):
32+
def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]:
3133
"""Draw the box associated with the artist.
3234
3335
Parameters

src/compas_blender/artists/capsuleartist.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from typing import Optional
21
from typing import Any
2+
from typing import List
3+
from typing import Optional
34
from typing import Union
45

56
import bpy
67

78
import compas_blender
9+
from compas_blender.utilities import RGBColor
810
from compas.geometry import Capsule
911
from compas.artists import ShapeArtist
1012
from .artist import BlenderArtist
@@ -28,12 +30,12 @@ def __init__(self,
2830

2931
super().__init__(shape=capsule, collection=collection or capsule.name, **kwargs)
3032

31-
def draw(self, color=None, u=None, v=None):
33+
def draw(self, color: Optional[RGBColor] = None, u: int = None, v: int = None) -> List[bpy.types.Object]:
3234
"""Draw the capsule associated with the artist.
3335
3436
Parameters
3537
----------
36-
color : tuple of float, optional
38+
color : tuple of float or tuple of int, optional
3739
The RGB color of the capsule.
3840
u : int, optional
3941
Number of faces in the "u" direction.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from typing import Any
2+
from typing import List
3+
from typing import Optional
4+
from typing import Union
5+
6+
import bpy
7+
8+
import compas_blender
9+
from compas_blender.utilities import RGBColor
10+
from compas.geometry import add_vectors
11+
from compas.geometry import Circle
12+
from compas.artists import PrimitiveArtist
13+
from .artist import BlenderArtist
14+
15+
16+
class CircleArtist(BlenderArtist, PrimitiveArtist):
17+
"""Artist for drawing circles.
18+
19+
Parameters
20+
----------
21+
circle : :class:`compas.geometry.Circle`
22+
A COMPAS circle.
23+
collection : str or :class:`bpy.types.Collection`
24+
The name of the collection the object belongs to.
25+
"""
26+
27+
def __init__(self,
28+
circle: Circle,
29+
collection: Optional[Union[str, bpy.types.Collection]] = None,
30+
**kwargs: Any):
31+
super().__init__(primitive=circle, collection=collection or circle.name, **kwargs)
32+
33+
def draw(self, color: Optional[RGBColor] = None, show_point=False, show_normal=False) -> List[bpy.types.Object]:
34+
"""Draw the circle.
35+
36+
Parameters
37+
----------
38+
color : tuple of float or tuple of int, optional
39+
The RGB color of the capsule.
40+
show_point : bool, optional
41+
Default is ``False``.
42+
show_normal : bool, optional
43+
Default is ``False``.
44+
45+
Returns
46+
-------
47+
list
48+
The objects created in Blender.
49+
"""
50+
color = color or self.color
51+
point = self.primitive.plane.point
52+
normal = self.primitive.plane.normal
53+
plane = point, normal
54+
radius = self.primitive.radius
55+
objects = []
56+
if show_point:
57+
points = [{'pos': point, 'color': color, 'name': self.primitive.name, 'radius': 0.01}]
58+
objects += compas_blender.draw_points(points, collection=self.collection)
59+
if show_normal:
60+
end = add_vectors(point, normal)
61+
lines = [{'start': point, 'end': end, 'color': color, 'name': self.primitive.name}]
62+
objects += compas_blender.draw_lines(lines, collection=self.collection)
63+
circles = [{'plane': plane, 'radius': radius, 'color': color, 'name': self.primitive.name}]
64+
objects += compas_blender.draw_circles(circles, collection=self.collection)
65+
return objects

0 commit comments

Comments
 (0)