Skip to content

Commit 6209743

Browse files
author
Antonio Pisano
committed
When fit = "ALL" and the mesh is not set, wait for it before trying to compute the collision shape
1 parent 92ca1a1 commit 6209743

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

‎src/components/shape/ammo-shape.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ var AmmoShape = {
3838
multiple: true,
3939

4040
init: function() {
41+
if (this.data.fit !== FIT.MANUAL) {
42+
if (this.el.object3DMap.mesh) {
43+
this.mesh = this.el.object3DMap.mesh;
44+
} else {
45+
const self = this;
46+
this.el.addEventListener("object3dset", function (e) {
47+
if (e.detail.type === "mesh") {
48+
self.init();
49+
}
50+
});
51+
console.log("Cannot use FIT.ALL without object3DMap.mesh. Waiting for it to be set.");
52+
return;
53+
}
54+
}
55+
4156
this.system = this.el.sceneEl.systems.physics;
4257
this.collisionShapes = [];
4358

@@ -53,13 +68,6 @@ var AmmoShape = {
5368
console.warn("body not found");
5469
return;
5570
}
56-
if (this.data.fit !== FIT.MANUAL) {
57-
if (!this.el.object3DMap.mesh) {
58-
console.error("Cannot use FIT.ALL without object3DMap.mesh");
59-
return;
60-
}
61-
this.mesh = this.el.object3DMap.mesh;
62-
}
6371
this.body.addShapeComponent(this);
6472
},
6573

0 commit comments

Comments
 (0)