From 6209743fda0841f5b59252c13d5da500ca0c9ffd Mon Sep 17 00:00:00 2001 From: Antonio Pisano Date: Mon, 21 Aug 2023 14:49:44 +0200 Subject: [PATCH] When fit = "ALL" and the mesh is not set, wait for it before trying to compute the collision shape --- src/components/shape/ammo-shape.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/shape/ammo-shape.js b/src/components/shape/ammo-shape.js index a8d039c..3465436 100644 --- a/src/components/shape/ammo-shape.js +++ b/src/components/shape/ammo-shape.js @@ -38,6 +38,21 @@ var AmmoShape = { multiple: true, init: function() { + if (this.data.fit !== FIT.MANUAL) { + if (this.el.object3DMap.mesh) { + this.mesh = this.el.object3DMap.mesh; + } else { + const self = this; + this.el.addEventListener("object3dset", function (e) { + if (e.detail.type === "mesh") { + self.init(); + } + }); + console.log("Cannot use FIT.ALL without object3DMap.mesh. Waiting for it to be set."); + return; + } + } + this.system = this.el.sceneEl.systems.physics; this.collisionShapes = []; @@ -53,13 +68,6 @@ var AmmoShape = { console.warn("body not found"); return; } - if (this.data.fit !== FIT.MANUAL) { - if (!this.el.object3DMap.mesh) { - console.error("Cannot use FIT.ALL without object3DMap.mesh"); - return; - } - this.mesh = this.el.object3DMap.mesh; - } this.body.addShapeComponent(this); },