Skip to content

Commit

Permalink
add bounding box etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Jul 11, 2024
1 parent ee1f313 commit 96d005e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added `list` to accepted types for `Scene.add`.
* Added `list[float]` to accepted types for `Camera.position` and `Camera.target`.
* Added `bounding_box` and `_update_bounding_box` to `BufferObject`.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions src/compas_viewer/scene/bufferobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,30 @@ def __init__(
self.is_selected = False
self.background = False
self._matrix_buffer = None
self._bounding_box = None
self._bounding_box_center = None

@property
def buffergeometry(self) -> BufferGeometry:
return self.item

@property
def bounding_box(self) -> NDArray:
if self._bounding_box is None:
self._bounding_box = np.array([np.min(self.buffergeometry.points, axis=0), np.max(self.buffergeometry.points, axis=0)])
return self._bounding_box

@property
def bounding_box_center(self) -> NDArray:
if self._bounding_box_center is None:
self._bounding_box_center = np.mean(self.buffergeometry.points.reshape(-1, 3), axis=0)
return self._bounding_box_center

def _update_bounding_box(self):
self._bounding_box = None
self._bounding_box_center = None
# Set to None so that they are recalculated next time they are accessed

def init(self):
"""Initialize the object"""
self.instance_color = Color.from_rgb255(*next(self.scene._instance_colors_generator))
Expand Down

0 comments on commit 96d005e

Please sign in to comment.