diff --git a/src/components/media-loader.js b/src/components/media-loader.js index 5dcd47beef202851c03b2cd28d8089875873914f..6aca6ec6eb0ce623c95eb143317953b29d48f2bb 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -42,7 +42,7 @@ AFRAME.registerComponent("media-loader", { if (this.el.body && this.shapeAdded && this.el.body.shapes.length > 1) { this.el.removeAttribute("shape"); this.shapeAdded = false; - } else if (!this.hasBakedShapes) { + } else if (!this.hasBakedShapes && !box.isEmpty()) { const center = new THREE.Vector3(); const { min, max } = box; const halfExtents = { diff --git a/src/utils/auto-box-collider.js b/src/utils/auto-box-collider.js index 0a8b69037f59147065a141273616e30a034d6ee6..cfb8882fae100ca7097bf36caa9d4d625587dc93 100644 --- a/src/utils/auto-box-collider.js +++ b/src/utils/auto-box-collider.js @@ -1,17 +1,25 @@ const rotation = new THREE.Euler(); export function getBox(entity, boxRoot) { const box = new THREE.Box3(); + rotation.copy(entity.object3D.rotation); entity.object3D.rotation.set(0, 0, 0); entity.object3D.updateMatrixWorld(true); + box.setFromObject(boxRoot); - entity.object3D.worldToLocal(box.min); - entity.object3D.worldToLocal(box.max); - entity.object3D.rotation.copy(rotation); + + if (!box.isEmpty()) { + entity.object3D.worldToLocal(box.min); + entity.object3D.worldToLocal(box.max); + entity.object3D.rotation.copy(rotation); + } + return box; } export function getScaleCoefficient(length, box) { + if (box.isEmpty()) return 1.0; + const { max, min } = box; const dX = Math.abs(max.x - min.x); const dY = Math.abs(max.y - min.y);