From 92ca1a1a51fab2fa520af35ee231e7b3a28cdf79 Mon Sep 17 00:00:00 2001 From: Antonio Pisano Date: Fri, 18 Aug 2023 20:51:48 +0200 Subject: [PATCH] Handle the case where mesh2shape returns null 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. --- src/components/body/body.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/body/body.js b/src/components/body/body.js index 0f18936..f3e9781 100644 --- a/src/components/body/body.js +++ b/src/components/body/body.js @@ -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