From 1b4881671b03d13bfc51fce9d87a70792ae0bdf5 Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Thu, 19 Jul 2018 14:19:54 -0700 Subject: [PATCH] Scale the mesh instead of the entity so that scale is networked correctly --- src/components/media-loader.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/media-loader.js b/src/components/media-loader.js index 473f4a4c8..1c2c71354 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -16,22 +16,19 @@ AFRAME.registerComponent("media-loader", { setShapeAndScale(resize) { const mesh = this.el.getObject3D("mesh"); const box = getBox(this.el, mesh); - if (resize) { - this.el.object3D.scale.multiplyScalar(getScaleCoefficient(0.5 / this.el.object3D.scale.x, box)); - } else { - this.el.object3D.scale.set(1, 1, 1); - } + const scaleCoefficient = resize ? getScaleCoefficient(0.5, box) : 1; + this.el.object3DMap.mesh.scale.multiplyScalar(scaleCoefficient); if (this.el.body && this.el.body.shapes.length > 1) { this.el.removeAttribute("shape"); } else { const center = new THREE.Vector3(); const { min, max } = box; const halfExtents = { - x: Math.abs(min.x - max.x) / 2, - y: Math.abs(min.y - max.y) / 2, - z: Math.abs(min.z - max.z) / 2 + x: Math.abs(min.x - max.x) / 2 * scaleCoefficient, + y: Math.abs(min.y - max.y) / 2 * scaleCoefficient, + z: Math.abs(min.z - max.z) / 2 * scaleCoefficient }; - center.addVectors(min, max).multiplyScalar(0.5); + center.addVectors(min, max).multiplyScalar(0.5 * scaleCoefficient); mesh.position.sub(center); this.el.setAttribute("shape", { shape: "box", -- GitLab