瀏覽代碼

ArcballControls: Remove more clone() calls. (#23027)

* remove clones from arcballControls

* add underscore

* remove unnesscary copy
gero3 3 年之前
父節點
當前提交
81596221f9
共有 1 個文件被更改,包括 16 次插入14 次删除
  1. 16 14
      examples/jsm/controls/ArcballControls.js

+ 16 - 14
examples/jsm/controls/ArcballControls.js

@@ -67,7 +67,9 @@ const _endEvent = { type: 'end' };
 const _raycaster = new Raycaster();
 const _offset = new Vector3();
 
-
+const _gizmoMatrixStateTemp = new Matrix4();
+const _cameraMatrixStateTemp = new Matrix4();
+const _scalePointTemp = new Vector3();
 /**
  *
  * @param {Camera} camera Virtual camera used in the scene
@@ -1983,11 +1985,11 @@ class ArcballControls extends EventDispatcher {
 		_offset.copy( point ).sub( this._gizmos.position ).multiplyScalar( amount );
 		this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z );
 
-		const gizmoStateTemp = this._gizmoMatrixState.clone();
+		_gizmoMatrixStateTemp.copy( this._gizmoMatrixState );
 		this._gizmoMatrixState.premultiply( this._translationMatrix );
 		this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
 
-		const cameraStateTemp = this._cameraMatrixState.clone();
+		_cameraMatrixStateTemp.copy( this._cameraMatrixState );
 		this._cameraMatrixState.premultiply( this._translationMatrix );
 		this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
 
@@ -1998,8 +2000,8 @@ class ArcballControls extends EventDispatcher {
 
 		}
 
-		this._gizmoMatrixState.copy( gizmoStateTemp );
-		this._cameraMatrixState.copy( cameraStateTemp );
+		this._gizmoMatrixState.copy( _gizmoMatrixStateTemp );
+		this._cameraMatrixState.copy( _cameraMatrixStateTemp );
 
 	};
 
@@ -2600,7 +2602,7 @@ class ArcballControls extends EventDispatcher {
 	 */
 	scale = ( size, point, scaleGizmos = true ) => {
 
-		const scalePoint = point.clone();
+		_scalePointTemp.copy( point );
 		let sizeInverse = 1 / size;
 
 		if ( this.camera.isOrthographicCamera ) {
@@ -2635,12 +2637,12 @@ class ArcballControls extends EventDispatcher {
 
 
 			//move camera and gizmos to obtain pinch effect
-			scalePoint.sub( this._v3_1 );
+			_scalePointTemp.sub( this._v3_1 );
 
-			const amount = scalePoint.clone().multiplyScalar( sizeInverse );
-			scalePoint.sub( amount );
+			const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
+			_scalePointTemp.sub( amount );
 
-			this._m4_1.makeTranslation( scalePoint.x, scalePoint.y, scalePoint.z );
+			this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
 			this._m4_2.premultiply( this._m4_1 );
 
 			this.setTransformationMatrices( this._m4_1, this._m4_2 );
@@ -2652,7 +2654,7 @@ class ArcballControls extends EventDispatcher {
 			this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
 
 			//move camera
-			let distance = this._v3_1.distanceTo( scalePoint );
+			let distance = this._v3_1.distanceTo( _scalePointTemp );
 			let amount = distance - ( distance * sizeInverse );
 
 			//check min and max distance
@@ -2669,7 +2671,7 @@ class ArcballControls extends EventDispatcher {
 
 			}
 
-			_offset.copy( scalePoint ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
+			_offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
 
 			this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
 
@@ -2679,9 +2681,9 @@ class ArcballControls extends EventDispatcher {
 				//scale gizmos so they appear in the same spot having the same dimension
 				const pos = this._v3_2;
 
-				distance = pos.distanceTo( scalePoint );
+				distance = pos.distanceTo( _scalePointTemp );
 				amount = distance - ( distance * sizeInverse );
-				_offset.copy( scalePoint ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
+				_offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
 
 				this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
 				this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );