Skip to content

Commit 8abff35

Browse files
authored
Merge branch 'main' into fix_expected_Array
2 parents 5b007fd + 2d32ec0 commit 8abff35

File tree

21 files changed

+295
-216
lines changed

21 files changed

+295
-216
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
* Replaced use of `Rhino.Geometry.VertexColors.SetColors` with a for loop and `SetColor` in `compas_ghpyton` since the former requires a `System.Array`.
15+
16+
### Removed
17+
18+
19+
## [2.4.1] 2024-08-25
20+
21+
### Added
22+
23+
### Changed
24+
25+
* Changed supported Blender versions to latest LTS versions (3.3, 3.6, 4.2).
26+
* Fixed bug in `compas_rhino.conversions.cone_to_compas`.
27+
* Fixed bug in `compas_rhino.conversions.cylinder_to_compas`.
28+
* Fixed bug in `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` (scale not used).
29+
* Fixed bug in `compas_rhino.scene.RhinoMeshObject.draw_facenormals` (scale not used).
30+
* Changed scene object registration to stop printing messages.
31+
32+
### Removed
33+
34+
## [2.4.0] 2024-08-22
35+
36+
### Added
37+
38+
* Added `compas.scene.Scene.redraw`.
39+
* Added `compas.scene.Scene.context_objects` representing all objects drawn in the visualisation context by the scene.
40+
* Added `compas.scene.Scene.clear_context` with optional `guids` to clear some or all objects from the visualisation context.
41+
* Added `clear_scene` and `clear_context` parameters to `compas.scene.Scene.clear` to differentiate between removing objects from the scene internally or removing corresponding objects from the viz context, or both (default).
42+
* Added `compas_rhino.conversions.extrusion_to_compas_box` as direct conversion of extrusion breps.
43+
44+
### Changed
45+
1546
* Changed the `__str__` of `compas.geometry.Frame`, `compas.geometry.Plane`, `compas.geometry.Polygon`, `compas.geometry.Polyhedron`, `compas.geometry.Quaternion` to use a limited number of decimals (determined by `Tolerance.PRECISION`). Note: `__repr__` will instead maintain full precision.
1647
* Changed the `__str__` of `compas.geometry.Pointcloud` to print total number of points instead of the long list of points. Note: `__repr__` will still print all the points with full precision.
1748
* Fixed bug in `Pointcloud.from_box()`.
49+
* Changed `compas.scene.MeshObject` to not use vertex coordinate caching because it is too fragile.
50+
* Changed `compas_rhino.scene.RhinoMeshObject` to keep track of element-guid pairs in dicts.
51+
* Changed `compas.scene.Scene._guids` to a default value of `[]`.
52+
* Fixed bug due to missing import in `compas_rhino.scene.graphobject`.
53+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the same selection of vertices as `draw_vertices`.
54+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the corresponding vertex color if no color is specified.
55+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the same selection of vertices as `draw_faces`.
56+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the corresponding face color if no color is specified.
1857

1958
### Removed
2059

docs/userguide/cad.blender.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ and :mod:`compas_blender` provides functionality for converting COMPAS objects t
1010

1111
.. note::
1212

13-
These instructions are for the latest version of Blender (4.0) and for the current LTS versions (3.3 and 3.6).
13+
These instructions are for the current LTS versions of Blender (3.3, 3.6 and 4.2).
14+
Other versions are currently not supported.
1415

1516
.. warning::
1617

@@ -34,9 +35,9 @@ This procedure simply uses that Python installation and associated ``pip`` to in
3435
The location of the executable is different on different platforms.
3536
The default locations are:
3637

37-
* Windows: ``C:\Program Files\Blender Foundation\Blender 4.0\4.0\python\bin\python.exe``
38-
* macOS: ``/Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10``
39-
* Linux: ``/usr/share/blender/4.0/python/bin/python3.10`` (i think :)
38+
* Windows: ``C:\Program Files\Blender Foundation\Blender 4.2\4.2\python\bin\python.exe``
39+
* macOS: ``/Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10``
40+
* Linux: ``/usr/share/blender/4.2/python/bin/python3.10`` (i think :)
4041

4142
.. note::
4243

@@ -53,7 +54,7 @@ Before installing `compas` with `pip`, it is highly recommended that you update
5354

5455
.. code-block:: bash
5556
56-
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install --upgrade pip
57+
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install --upgrade pip
5758
5859
5960
Install from PyPI
@@ -63,7 +64,7 @@ For example on Mac:
6364

6465
.. code-block:: bash
6566
66-
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install compas
67+
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install compas
6768
6869
6970
Install from Source
@@ -72,7 +73,7 @@ Install from Source
7273
.. code-block:: bash
7374
7475
$ cd path/to/compas
75-
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install -e .
76+
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install -e .
7677
7778
7879
Using ``compas_blender.install``
@@ -95,7 +96,7 @@ Optionally, you can specify the version of Blender using the ``-v`` flag.
9596

9697
.. code-block:: bash
9798
98-
$ python -m compas_blender.install -v 4.0
99+
$ python -m compas_blender.install -v 4.2
99100
100101
To remove all previously installed symlinks before installing new ones, use the ``--clean`` flag.
101102

@@ -111,7 +112,7 @@ To test if the installation was successful, you can run the following on the Ble
111112

112113
>>> import compas
113114
>>> print(compas.__version__)
114-
'2.0.0'
115+
'2.4.0'
115116

116117

117118
Visualisation

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ doctest_optionflags = [
8484
# ============================================================================
8585

8686
[tool.bumpversion]
87-
current_version = "2.3.0"
87+
current_version = "2.4.1"
8888
message = "Bump version to {new_version}"
8989
commit = true
9090
tag = true

src/compas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__copyright__ = "Copyright 2014-2022 - ETH Zurich, Copyright 2023 - COMPAS Association"
2121
__license__ = "MIT License"
2222
__email__ = "[email protected]"
23-
__version__ = "2.3.0"
23+
__version__ = "2.4.1"
2424

2525

2626
HERE = compas._os.realpath(os.path.dirname(__file__))

src/compas/scene/meshobject.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import compas.colors # noqa: F401
66
import compas.datastructures # noqa: F401
77
import compas.geometry # noqa: F401
8-
from compas.geometry import transform_points
98

109
from .descriptors.colordict import ColorDictAttribute
1110
from .sceneobject import SceneObject
@@ -71,7 +70,6 @@ def __init__(
7170
): # fmt: skip
7271
# type: (...) -> None
7372
super(MeshObject, self).__init__(**kwargs) # type: ignore
74-
self._vertex_xyz = None
7573
self.show_vertices = show_vertices
7674
self.show_edges = show_edges
7775
self.show_faces = show_faces
@@ -107,7 +105,6 @@ def mesh(self, mesh):
107105
# type: (compas.datastructures.Mesh) -> None
108106
self._item = mesh
109107
self._transformation = None
110-
self._vertex_xyz = None
111108

112109
@property
113110
def transformation(self):
@@ -117,24 +114,8 @@ def transformation(self):
117114
@transformation.setter
118115
def transformation(self, transformation):
119116
# type: (compas.geometry.Transformation) -> None
120-
self._vertex_xyz = None
121117
self._transformation = transformation
122118

123-
@property
124-
def vertex_xyz(self):
125-
# type: () -> dict[int, list[float]]
126-
if self.mesh:
127-
if self._vertex_xyz is None:
128-
points = self.mesh.vertices_attributes("xyz")
129-
points = transform_points(points, self.worldtransformation)
130-
self._vertex_xyz = dict(zip(self.mesh.vertices(), points))
131-
return self._vertex_xyz # type: ignore
132-
133-
@vertex_xyz.setter
134-
def vertex_xyz(self, vertex_xyz):
135-
# type: (dict[int, list[float]]) -> None
136-
self._vertex_xyz = vertex_xyz
137-
138119
def draw_vertices(self):
139120
"""Draw the vertices of the mesh.
140121

src/compas/scene/scene.py

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def objects(self):
7676
# type: () -> list[SceneObject]
7777
return [node for node in self.nodes if not node.is_root] # type: ignore
7878

79+
@property
80+
def context_objects(self):
81+
# type: () -> list
82+
guids = []
83+
for obj in self.objects:
84+
guids += obj.guids
85+
return guids
86+
7987
def add(self, item, parent=None, **kwargs):
8088
# type: (compas.geometry.Geometry | compas.datastructures.Datastructure, SceneObject | TreeNode | None, dict) -> SceneObject
8189
"""Add an item to the scene.
@@ -108,32 +116,82 @@ def add(self, item, parent=None, **kwargs):
108116
super(Scene, self).add(sceneobject, parent=parent)
109117
return sceneobject
110118

111-
def clear(self):
112-
# type: () -> None
113-
"""Clear everything from the current context of the scene."""
119+
def clear_context(self, guids=None):
120+
# type: (list | None) -> None
121+
"""Clear the visualisation context.
122+
123+
Parameters
124+
----------
125+
guids : list, optional
126+
The identifiers of the objects in the visualisation context.
127+
128+
Returns
129+
-------
130+
None
131+
132+
Notes
133+
-----
134+
If `guids=None`, this will clear all objects from the visualisation context.
135+
For example, when used in Rhino, it will remove everything from the Rhino model.
136+
This is equivalent to `compas_rhino.clear()`.
137+
138+
If `guids` is a list, only those objects in the list will be removed.
139+
140+
The method is used by `Scene.clear` to remove all objects previously drawn by the scene,
141+
without removing other model objects.
142+
143+
"""
144+
clear(guids)
145+
146+
def clear(self, clear_scene=True, clear_context=True):
147+
# type: (bool, bool) -> None
148+
"""Clear the scene.
149+
150+
Parameters
151+
----------
152+
clear_scene : bool, optional
153+
If True, all scene objects will be removed from the scene tree.
154+
clear_context : bool, optional
155+
If True, all objects drawn by the scene in the visualisation context will be removed.
156+
157+
Returns
158+
-------
159+
None
114160
115-
clear()
161+
Notes
162+
-----
163+
To redraw the scene, without modifying any of the other objects in the visualisation context:
116164
117-
def clear_objects(self):
118-
# type: () -> None
119-
"""Clear all objects inside the scene."""
165+
>>> scene.clear(clear_scene=False, clear_context=True)
166+
>>> scene.draw()
120167
168+
"""
121169
guids = []
170+
122171
for sceneobject in self.objects:
123172
guids += sceneobject.guids
124173
sceneobject._guids = None
125-
clear(guids=guids)
174+
175+
if clear_scene:
176+
self.remove(sceneobject)
177+
178+
if clear_context:
179+
self.clear_context(guids)
126180

127181
def draw(self):
128-
"""Draw the scene."""
182+
"""Draw the scene.
183+
184+
This will just draw all scene objects in the scene tree,
185+
without making any modifications to the visualisation context.
186+
For example, it will not remove any of the previously drawn objects.
187+
188+
"""
129189

130190
if not self.context:
131191
raise ValueError("No context detected.")
132192

133193
before_draw()
134194

135-
self.clear_objects()
136-
137195
drawn_objects = []
138196
for sceneobject in self.objects:
139197
if sceneobject.show:
@@ -142,3 +200,14 @@ def draw(self):
142200
after_draw(drawn_objects)
143201

144202
return drawn_objects
203+
204+
def redraw(self):
205+
"""Redraw the scene.
206+
207+
This removes all previously drawn objects from the visualisation context,
208+
before drawing all scene objects in the scene tree.
209+
210+
"""
211+
212+
self.clear(clear_scene=False, clear_context=True)
213+
self.draw()

src/compas/scene/sceneobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
# which means that adding child objects will be added in context "None"
112112
self.context = context
113113
self._item = item
114-
self._guids = None
114+
self._guids = []
115115
self._node = None
116116
self._frame = frame
117117
self._transformation = transformation

src/compas_blender/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
pass
1212

1313

14-
__version__ = "2.3.0"
14+
__version__ = "2.4.1"
1515

1616

1717
INSTALLABLE_PACKAGES = ["compas", "compas_blender"]
18-
SUPPORTED_VERSIONS = ["3.3", "3.6", "4.0"]
19-
DEFAULT_VERSION = "4.0"
18+
SUPPORTED_VERSIONS = ["3.3", "3.6", "4.2"]
19+
DEFAULT_VERSION = "4.2"
2020

2121
INSTALLATION_ARGUMENTS = None
2222

@@ -200,6 +200,8 @@ def _get_default_blender_python_path(version):
200200

201201

202202
def _get_default_blender_python_path_mac(version):
203+
if version == "4.2":
204+
return "/Applications/Blender.app/Contents/Resources/{}/python/bin/python3.11".format(version)
203205
return "/Applications/Blender.app/Contents/Resources/{}/python/bin/python3.10".format(version)
204206

205207

src/compas_blender/scene/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ def register_scene_objects():
8383
register(Torus, ShapeObject, context="Blender")
8484
register(Vector, VectorObject, context="Blender")
8585
register(VolMesh, VolMeshObject, context="Blender")
86-
print("Blender Objects registered.")
86+
87+
# print("Blender Objects registered.")
8788

8889

8990
__all__ = [
9091
"BlenderSceneObject",
91-
"shapeObject",
92+
"ShapeObject",
9293
"BoxObject",
9394
"CircleObject",
9495
"CurveObject",
95-
"CylinderObject",
9696
"FrameObject",
9797
"LineObject",
9898
"MeshObject",
@@ -103,9 +103,7 @@ def register_scene_objects():
103103
"PolygonObject",
104104
"PolyhedronObject",
105105
"PolylineObject",
106-
"SphereObject",
107106
"SurfaceObject",
108-
"TorusObject",
109107
"VectorObject",
110108
"VolMeshObject",
111109
]

src/compas_ghpython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from compas_rhino import unload_modules # noqa: F401
1010

1111

12-
__version__ = "2.3.0"
12+
__version__ = "2.4.1"
1313

1414
if compas.is_rhino():
1515
from .utilities import * # noqa: F401 F403

0 commit comments

Comments
 (0)