Skip to content

Commit

Permalink
Merge branch 'main' into fix_expected_Array
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalocasas committed Aug 29, 2024
2 parents 5b007fd + 2d32ec0 commit 8abff35
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 216 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Replaced use of `Rhino.Geometry.VertexColors.SetColors` with a for loop and `SetColor` in `compas_ghpyton` since the former requires a `System.Array`.

### Removed


## [2.4.1] 2024-08-25

### Added

### Changed

* Changed supported Blender versions to latest LTS versions (3.3, 3.6, 4.2).
* Fixed bug in `compas_rhino.conversions.cone_to_compas`.
* Fixed bug in `compas_rhino.conversions.cylinder_to_compas`.
* Fixed bug in `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` (scale not used).
* Fixed bug in `compas_rhino.scene.RhinoMeshObject.draw_facenormals` (scale not used).
* Changed scene object registration to stop printing messages.

### Removed

## [2.4.0] 2024-08-22

### Added

* Added `compas.scene.Scene.redraw`.
* Added `compas.scene.Scene.context_objects` representing all objects drawn in the visualisation context by the scene.
* Added `compas.scene.Scene.clear_context` with optional `guids` to clear some or all objects from the visualisation context.
* 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).
* Added `compas_rhino.conversions.extrusion_to_compas_box` as direct conversion of extrusion breps.

### Changed

* 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.
* 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.
* Fixed bug in `Pointcloud.from_box()`.
* Changed `compas.scene.MeshObject` to not use vertex coordinate caching because it is too fragile.
* Changed `compas_rhino.scene.RhinoMeshObject` to keep track of element-guid pairs in dicts.
* Changed `compas.scene.Scene._guids` to a default value of `[]`.
* Fixed bug due to missing import in `compas_rhino.scene.graphobject`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the same selection of vertices as `draw_vertices`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the corresponding vertex color if no color is specified.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the same selection of vertices as `draw_faces`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the corresponding face color if no color is specified.

### Removed

Expand Down
19 changes: 10 additions & 9 deletions docs/userguide/cad.blender.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and :mod:`compas_blender` provides functionality for converting COMPAS objects t

.. note::

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

.. warning::

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

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

.. note::

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

.. code-block:: bash
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install --upgrade pip
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install --upgrade pip
Install from PyPI
Expand All @@ -63,7 +64,7 @@ For example on Mac:

.. code-block:: bash
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install compas
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install compas
Install from Source
Expand All @@ -72,7 +73,7 @@ Install from Source
.. code-block:: bash
$ cd path/to/compas
$ /Applications/Blender.app/Contents/Resources/4.0/python/bin/python3.10 -m pip install -e .
$ /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install -e .
Using ``compas_blender.install``
Expand All @@ -95,7 +96,7 @@ Optionally, you can specify the version of Blender using the ``-v`` flag.

.. code-block:: bash
$ python -m compas_blender.install -v 4.0
$ python -m compas_blender.install -v 4.2
To remove all previously installed symlinks before installing new ones, use the ``--clean`` flag.

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

>>> import compas
>>> print(compas.__version__)
'2.0.0'
'2.4.0'


Visualisation
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ doctest_optionflags = [
# ============================================================================

[tool.bumpversion]
current_version = "2.3.0"
current_version = "2.4.1"
message = "Bump version to {new_version}"
commit = true
tag = true
Expand Down
2 changes: 1 addition & 1 deletion src/compas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__copyright__ = "Copyright 2014-2022 - ETH Zurich, Copyright 2023 - COMPAS Association"
__license__ = "MIT License"
__email__ = "tom.v.mele@gmail.com"
__version__ = "2.3.0"
__version__ = "2.4.1"


HERE = compas._os.realpath(os.path.dirname(__file__))
Expand Down
19 changes: 0 additions & 19 deletions src/compas/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import compas.colors # noqa: F401
import compas.datastructures # noqa: F401
import compas.geometry # noqa: F401
from compas.geometry import transform_points

from .descriptors.colordict import ColorDictAttribute
from .sceneobject import SceneObject
Expand Down Expand Up @@ -71,7 +70,6 @@ def __init__(
): # fmt: skip
# type: (...) -> None
super(MeshObject, self).__init__(**kwargs) # type: ignore
self._vertex_xyz = None
self.show_vertices = show_vertices
self.show_edges = show_edges
self.show_faces = show_faces
Expand Down Expand Up @@ -107,7 +105,6 @@ def mesh(self, mesh):
# type: (compas.datastructures.Mesh) -> None
self._item = mesh
self._transformation = None
self._vertex_xyz = None

@property
def transformation(self):
Expand All @@ -117,24 +114,8 @@ def transformation(self):
@transformation.setter
def transformation(self, transformation):
# type: (compas.geometry.Transformation) -> None
self._vertex_xyz = None
self._transformation = transformation

@property
def vertex_xyz(self):
# type: () -> dict[int, list[float]]
if self.mesh:
if self._vertex_xyz is None:
points = self.mesh.vertices_attributes("xyz")
points = transform_points(points, self.worldtransformation)
self._vertex_xyz = dict(zip(self.mesh.vertices(), points))
return self._vertex_xyz # type: ignore

@vertex_xyz.setter
def vertex_xyz(self, vertex_xyz):
# type: (dict[int, list[float]]) -> None
self._vertex_xyz = vertex_xyz

def draw_vertices(self):
"""Draw the vertices of the mesh.
Expand Down
91 changes: 80 additions & 11 deletions src/compas/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def objects(self):
# type: () -> list[SceneObject]
return [node for node in self.nodes if not node.is_root] # type: ignore

@property
def context_objects(self):
# type: () -> list
guids = []
for obj in self.objects:
guids += obj.guids
return guids

def add(self, item, parent=None, **kwargs):
# type: (compas.geometry.Geometry | compas.datastructures.Datastructure, SceneObject | TreeNode | None, dict) -> SceneObject
"""Add an item to the scene.
Expand Down Expand Up @@ -108,32 +116,82 @@ def add(self, item, parent=None, **kwargs):
super(Scene, self).add(sceneobject, parent=parent)
return sceneobject

def clear(self):
# type: () -> None
"""Clear everything from the current context of the scene."""
def clear_context(self, guids=None):
# type: (list | None) -> None
"""Clear the visualisation context.
Parameters
----------
guids : list, optional
The identifiers of the objects in the visualisation context.
Returns
-------
None
Notes
-----
If `guids=None`, this will clear all objects from the visualisation context.
For example, when used in Rhino, it will remove everything from the Rhino model.
This is equivalent to `compas_rhino.clear()`.
If `guids` is a list, only those objects in the list will be removed.
The method is used by `Scene.clear` to remove all objects previously drawn by the scene,
without removing other model objects.
"""
clear(guids)

def clear(self, clear_scene=True, clear_context=True):
# type: (bool, bool) -> None
"""Clear the scene.
Parameters
----------
clear_scene : bool, optional
If True, all scene objects will be removed from the scene tree.
clear_context : bool, optional
If True, all objects drawn by the scene in the visualisation context will be removed.
Returns
-------
None
clear()
Notes
-----
To redraw the scene, without modifying any of the other objects in the visualisation context:
def clear_objects(self):
# type: () -> None
"""Clear all objects inside the scene."""
>>> scene.clear(clear_scene=False, clear_context=True)
>>> scene.draw()
"""
guids = []

for sceneobject in self.objects:
guids += sceneobject.guids
sceneobject._guids = None
clear(guids=guids)

if clear_scene:
self.remove(sceneobject)

if clear_context:
self.clear_context(guids)

def draw(self):
"""Draw the scene."""
"""Draw the scene.
This will just draw all scene objects in the scene tree,
without making any modifications to the visualisation context.
For example, it will not remove any of the previously drawn objects.
"""

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

before_draw()

self.clear_objects()

drawn_objects = []
for sceneobject in self.objects:
if sceneobject.show:
Expand All @@ -142,3 +200,14 @@ def draw(self):
after_draw(drawn_objects)

return drawn_objects

def redraw(self):
"""Redraw the scene.
This removes all previously drawn objects from the visualisation context,
before drawing all scene objects in the scene tree.
"""

self.clear(clear_scene=False, clear_context=True)
self.draw()
2 changes: 1 addition & 1 deletion src/compas/scene/sceneobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
# which means that adding child objects will be added in context "None"
self.context = context
self._item = item
self._guids = None
self._guids = []
self._node = None
self._frame = frame
self._transformation = transformation
Expand Down
8 changes: 5 additions & 3 deletions src/compas_blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
pass


__version__ = "2.3.0"
__version__ = "2.4.1"


INSTALLABLE_PACKAGES = ["compas", "compas_blender"]
SUPPORTED_VERSIONS = ["3.3", "3.6", "4.0"]
DEFAULT_VERSION = "4.0"
SUPPORTED_VERSIONS = ["3.3", "3.6", "4.2"]
DEFAULT_VERSION = "4.2"

INSTALLATION_ARGUMENTS = None

Expand Down Expand Up @@ -200,6 +200,8 @@ def _get_default_blender_python_path(version):


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


Expand Down
8 changes: 3 additions & 5 deletions src/compas_blender/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def register_scene_objects():
register(Torus, ShapeObject, context="Blender")
register(Vector, VectorObject, context="Blender")
register(VolMesh, VolMeshObject, context="Blender")
print("Blender Objects registered.")

# print("Blender Objects registered.")


__all__ = [
"BlenderSceneObject",
"shapeObject",
"ShapeObject",
"BoxObject",
"CircleObject",
"CurveObject",
"CylinderObject",
"FrameObject",
"LineObject",
"MeshObject",
Expand All @@ -103,9 +103,7 @@ def register_scene_objects():
"PolygonObject",
"PolyhedronObject",
"PolylineObject",
"SphereObject",
"SurfaceObject",
"TorusObject",
"VectorObject",
"VolMeshObject",
]
2 changes: 1 addition & 1 deletion src/compas_ghpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from compas_rhino import unload_modules # noqa: F401


__version__ = "2.3.0"
__version__ = "2.4.1"

if compas.is_rhino():
from .utilities import * # noqa: F401 F403
Expand Down
3 changes: 2 additions & 1 deletion src/compas_ghpython/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def register_scene_objects():
register(Vector, VectorObject, context="Grasshopper")
register(VolMesh, VolMeshObject, context="Grasshopper")
register(Brep, BrepObject, context="Grasshopper")
print("GH SceneObjects registered.")

# print("GH SceneObjects registered.")


__all__ = [
Expand Down
Loading

0 comments on commit 8abff35

Please sign in to comment.