Skip to content

Commit

Permalink
When fit = "ALL" and the mesh is not set, wait for it before trying t…
Browse files Browse the repository at this point in the history
…o compute the collision shape
  • Loading branch information
Antonio Pisano committed Aug 21, 2023
1 parent 92ca1a1 commit 6209743
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/components/shape/ammo-shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

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

Expand Down

0 comments on commit 6209743

Please # to comment.