Skip to content

Commit

Permalink
Merge pull request #42 from Elettrotecnica/ammo-wait-for-mesh
Browse files Browse the repository at this point in the history
Wait for mesh to be there before computing the shape
  • Loading branch information
diarmidmackenzie authored Aug 29, 2023
2 parents 7c21c23 + 06722c8 commit 0253cbe
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 0253cbe

Please sign in to comment.