Skip to content

Commit

Permalink
Handle the case where mesh2shape returns null
Browse files Browse the repository at this point in the history
This can happen, for instance, when a gltf-model has not finished loading, hence a bounding box cannot be calculated. We try again after the object3D has been set in this case, the same as when "shape" is missing.
  • Loading branch information
Antonio Pisano committed Aug 18, 2023
1 parent 7c21c23 commit 92ca1a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/body/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ var Body = {
type: ShapeType[data.shape.toUpperCase()]
});

var { shape, offset, orientation } = mesh2shape(this.el.object3D, options);
const shapeInfo = mesh2shape(this.el.object3D, options);
let shape, offset, orientation;
if (shapeInfo) {
({ shape, offset, orientation } = shapeInfo);
}

if (!shape) {
el.addEventListener('object3dset', this.initBody.bind(this));
return;
}

this.body.addShape(shape, offset, orientation);

// Show wireframe
Expand Down

0 comments on commit 92ca1a1

Please # to comment.