From 62a81d8267168a260341f32c70d577ef078acb37 Mon Sep 17 00:00:00 2001 From: WestLangley Date: Sun, 14 Nov 2021 18:02:24 -0500 Subject: [PATCH] Avoid clone() --- src/cameras/StereoCamera.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cameras/StereoCamera.js b/src/cameras/StereoCamera.js index 2073a09e870b69..ae8f8485e1e99e 100644 --- a/src/cameras/StereoCamera.js +++ b/src/cameras/StereoCamera.js @@ -4,6 +4,7 @@ import { PerspectiveCamera } from './PerspectiveCamera.js'; const _eyeRight = /*@__PURE__*/ new Matrix4(); const _eyeLeft = /*@__PURE__*/ new Matrix4(); +const _projectionMatrix = /*@__PURE__*/ new Matrix4(); class StereoCamera { @@ -56,7 +57,7 @@ class StereoCamera { // Off-axis stereoscopic effect based on // http://paulbourke.net/stereographics/stereorender/ - const projectionMatrix = camera.projectionMatrix.clone(); + _projectionMatrix.copy( camera.projectionMatrix ); const eyeSepHalf = cache.eyeSep / 2; const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus; const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom; @@ -72,20 +73,20 @@ class StereoCamera { xmin = - ymax * cache.aspect + eyeSepOnProjection; xmax = ymax * cache.aspect + eyeSepOnProjection; - projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); - projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); - this.cameraL.projectionMatrix.copy( projectionMatrix ); + this.cameraL.projectionMatrix.copy( _projectionMatrix ); // for right eye xmin = - ymax * cache.aspect - eyeSepOnProjection; xmax = ymax * cache.aspect - eyeSepOnProjection; - projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); - projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); - this.cameraR.projectionMatrix.copy( projectionMatrix ); + this.cameraR.projectionMatrix.copy( _projectionMatrix ); }