Skip to content

Commit 96d005e

Browse files
committed
add bounding box etc.
1 parent ee1f313 commit 96d005e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

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

1516
### Changed
1617

src/compas_viewer/scene/bufferobject.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,30 @@ def __init__(
211211
self.is_selected = False
212212
self.background = False
213213
self._matrix_buffer = None
214+
self._bounding_box = None
214215
self._bounding_box_center = None
215216

216217
@property
217218
def buffergeometry(self) -> BufferGeometry:
218219
return self.item
219220

221+
@property
222+
def bounding_box(self) -> NDArray:
223+
if self._bounding_box is None:
224+
self._bounding_box = np.array([np.min(self.buffergeometry.points, axis=0), np.max(self.buffergeometry.points, axis=0)])
225+
return self._bounding_box
226+
220227
@property
221228
def bounding_box_center(self) -> NDArray:
222229
if self._bounding_box_center is None:
223230
self._bounding_box_center = np.mean(self.buffergeometry.points.reshape(-1, 3), axis=0)
224231
return self._bounding_box_center
225232

233+
def _update_bounding_box(self):
234+
self._bounding_box = None
235+
self._bounding_box_center = None
236+
# Set to None so that they are recalculated next time they are accessed
237+
226238
def init(self):
227239
"""Initialize the object"""
228240
self.instance_color = Color.from_rgb255(*next(self.scene._instance_colors_generator))

0 commit comments

Comments
 (0)