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); },