diff --git a/src/systems/camera-system.js b/src/systems/camera-system.js index 488c2279c0..bf94604068 100644 --- a/src/systems/camera-system.js +++ b/src/systems/camera-system.js @@ -74,6 +74,7 @@ const decompose = (function () { })(); const IDENTITY = new THREE.Matrix4().identity(); +const V_ONE = new THREE.Vector3(1, 1, 1); const orbit = (function () { const owq = new THREE.Quaternion(); const owp = new THREE.Vector3(); @@ -418,7 +419,10 @@ export class CameraSystem { } tick = (function () { - const translation = new THREE.Matrix4(); + const tmpMat = new THREE.Matrix4(); + const position = new THREE.Vector3(); + const quat = new THREE.Quaternion(); + const scale = new THREE.Vector3(); let uiRoot; const hoveredQuery = defineQuery([HoveredRemoteRight]); return function tick(scene, dt) { @@ -431,9 +435,6 @@ export class CameraSystem { const isGhost = !entered && uiRoot && uiRoot.firstChild && uiRoot.firstChild.classList.contains("isGhost"); if (isGhost && this.mode !== CAMERA_MODE_FIRST_PERSON && this.mode !== CAMERA_MODE_INSPECT) { this.mode = CAMERA_MODE_FIRST_PERSON; - const position = new THREE.Vector3(); - const quat = new THREE.Quaternion(); - const scale = new THREE.Vector3(); this.viewingRig.object3D.updateMatrices(); this.viewingRig.object3D.matrixWorld.decompose(position, quat, scale); position.setFromMatrixPosition(this.viewingCamera.matrixWorld); @@ -489,16 +490,18 @@ export class CameraSystem { setMatrixWorld(this.avatarPOV.object3D, this.viewingCamera.matrixWorld); } else { this.avatarPOV.object3D.updateMatrices(); - setMatrixWorld(this.viewingCamera, this.avatarPOV.object3D.matrixWorld); + this.avatarPOV.object3D.matrixWorld.decompose(position, quat, scale); + tmpMat.compose(position, quat, V_ONE); + setMatrixWorld(this.viewingCamera, tmpMat); } } else if (this.mode === CAMERA_MODE_THIRD_PERSON_NEAR || this.mode === CAMERA_MODE_THIRD_PERSON_FAR) { if (this.mode === CAMERA_MODE_THIRD_PERSON_NEAR) { - translation.makeTranslation(0, 1, 3); + tmpMat.makeTranslation(0, 1, 3); } else { - translation.makeTranslation(0, 2, 8); + tmpMat.makeTranslation(0, 2, 8); } this.avatarRig.object3D.updateMatrices(); - this.viewingRig.object3D.matrixWorld.copy(this.avatarRig.object3D.matrixWorld).multiply(translation); + this.viewingRig.object3D.matrixWorld.copy(this.avatarRig.object3D.matrixWorld).multiply(tmpMat); setMatrixWorld(this.viewingRig.object3D, this.viewingRig.object3D.matrixWorld); this.avatarPOV.object3D.quaternion.copy(this.viewingCamera.quaternion); this.avatarPOV.object3D.matrixNeedsUpdate = true;