Skip to content

Commit 1577015

Browse files
committed
Bug: Account for axis change when calculating bounding box
1 parent e12bd23 commit 1577015

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

demosys/scene/loaders/gltf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ def __init__(self, accessor_id, data):
462462
self.byteOffset = data.get('byteOffset') or 0
463463
self.componentType = TYPE_INFO[data['componentType']]
464464
self.count = data.get('count')
465-
self.max = data.get('max')
466-
self.min = data.get('min')
465+
self.min = numpy.array(data.get('min') or [-0.5, -0.5, -0.5], dtype=numpy.float32)
466+
self.max = numpy.array(data.get('max') or [0.5, 0.5, 0.5], dtype=numpy.float32)
467467
self.type = data.get('type')
468468

469469
def read(self, target=None):

demosys/scene/mesh.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ def draw_bbox(self, proj_matrix, view_matrix, shader, vao):
4242
vao.draw()
4343

4444
def calc_global_bbox(self, view_matrix, bbox_min, bbox_max):
45-
bb1 = self.bbox_min[:]
46-
bb1.append(1.0)
47-
bb2 = self.bbox_max[:]
48-
bb2.append(1.0)
45+
# Copy and extend to vec4
46+
bb1 = numpy.append(self.bbox_min[:], 1.0)
47+
bb2 = numpy.append(self.bbox_max[:], 1.0)
4948

49+
# Transform the bbox values
5050
bmin = matrix44.apply_to_vector(view_matrix, bb1),
5151
bmax = matrix44.apply_to_vector(view_matrix, bb2),
52-
5352
bmin = numpy.asarray(bmin)[0]
5453
bmax = numpy.asarray(bmax)[0]
5554

55+
# If a rotation happened there is an axis change and we have to ensure max-min is positive
56+
for i in range(3):
57+
if bmax[i] - bmin[i] < 0:
58+
bmin[i], bmax[i] = bmax[i], bmin[i]
59+
5660
if bbox_min is None or bbox_max is None:
5761
return bmin[0:3], bmax[0:3]
5862

0 commit comments

Comments
 (0)