Pārlūkot izejas kodu

FBXLoader: Matrix4 code clean up.

Mr.doob 4 gadi atpakaļ
vecāks
revīzija
3d0eac48a0
2 mainītis faili ar 20 papildinājumiem un 28 dzēšanām
  1. 10 14
      examples/js/loaders/FBXLoader.js
  2. 10 14
      examples/jsm/loaders/FBXLoader.js

+ 10 - 14
examples/js/loaders/FBXLoader.js

@@ -3745,16 +3745,15 @@
 
 		}
 
-		const lLRM = new THREE.Matrix4().copy( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM ); // Global Rotation
+		const lLRM = lPreRotationM.clone().multiply( lRotationM ).multiply( lPostRotationM ); // Global Rotation
 
 		const lParentGRM = new THREE.Matrix4();
 		lParentGRM.extractRotation( lParentGX ); // Global Shear*Scaling
 
 		const lParentTM = new THREE.Matrix4();
 		lParentTM.copyPosition( lParentGX );
-		const lParentGSM = new THREE.Matrix4();
-		const lParentGRSM = new THREE.Matrix4().copy( lParentTM ).invert().multiply( lParentGX );
-		lParentGSM.copy( lParentGRM ).invert().multiply( lParentGRSM );
+		const lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
+		const lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
 		const lLSM = lScalingM;
 		const lGlobalRS = new THREE.Matrix4();
 
@@ -3769,23 +3768,20 @@
 		} else {
 
 			const lParentLSM = new THREE.Matrix4().scale( new THREE.Vector3().setFromMatrixScale( lParentLX ) );
-			const lParentLSM_inv = new THREE.Matrix4().copy( lParentLSM ).invert();
-			const lParentGSM_noLocal = new THREE.Matrix4().copy( lParentGSM ).multiply( lParentLSM_inv );
+			const lParentLSM_inv = lParentLSM.clone().invert();
+			const lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );
 			lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );
 
 		}
 
-		const lRotationPivotM_inv = new THREE.Matrix4();
-		lRotationPivotM_inv.copy( lRotationPivotM ).invert();
-		const lScalingPivotM_inv = new THREE.Matrix4();
-		lScalingPivotM_inv.copy( lScalingPivotM ).invert(); // Calculate the local transform matrix
+		const lRotationPivotM_inv = lRotationPivotM.clone().invert();
+		const lScalingPivotM_inv = lScalingPivotM.clone().invert(); // Calculate the local transform matrix
 
-		let lTransform = new THREE.Matrix4();
-		lTransform.copy( lTranslationM ).multiply( lRotationOffsetM ).multiply( lRotationPivotM ).multiply( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM ).multiply( lRotationPivotM_inv ).multiply( lScalingOffsetM ).multiply( lScalingPivotM ).multiply( lScalingM ).multiply( lScalingPivotM_inv );
+		let lTransform = lTranslationM.clone().multiply( lRotationOffsetM ).multiply( lRotationPivotM ).multiply( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM ).multiply( lRotationPivotM_inv ).multiply( lScalingOffsetM ).multiply( lScalingPivotM ).multiply( lScalingM ).multiply( lScalingPivotM_inv );
 		const lLocalTWithAllPivotAndOffsetInfo = new THREE.Matrix4().copyPosition( lTransform );
-		const lGlobalTranslation = new THREE.Matrix4().copy( lParentGX ).multiply( lLocalTWithAllPivotAndOffsetInfo );
+		const lGlobalTranslation = lParentGX.clone().multiply( lLocalTWithAllPivotAndOffsetInfo );
 		lGlobalT.copyPosition( lGlobalTranslation );
-		lTransform = new THREE.Matrix4().copy( lGlobalT ).multiply( lGlobalRS ); // from global to local
+		lTransform = lGlobalT.clone().multiply( lGlobalRS ); // from global to local
 
 		lTransform.premultiply( lParentGX.invert() );
 		return lTransform;

+ 10 - 14
examples/jsm/loaders/FBXLoader.js

@@ -4049,7 +4049,7 @@ function generateTransform( transformData ) {
 
 	}
 
-	const lLRM = new Matrix4().copy( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM );
+	const lLRM = lPreRotationM.clone().multiply( lRotationM ).multiply( lPostRotationM );
 	// Global Rotation
 	const lParentGRM = new Matrix4();
 	lParentGRM.extractRotation( lParentGX );
@@ -4058,9 +4058,8 @@ function generateTransform( transformData ) {
 	const lParentTM = new Matrix4();
 	lParentTM.copyPosition( lParentGX );
 
-	const lParentGSM = new Matrix4();
-	const lParentGRSM = new Matrix4().copy( lParentTM ).invert().multiply( lParentGX );
-	lParentGSM.copy( lParentGRM ).invert().multiply( lParentGRSM );
+	const lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
+	const lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
 	const lLSM = lScalingM;
 
 	const lGlobalRS = new Matrix4();
@@ -4076,27 +4075,24 @@ function generateTransform( transformData ) {
 	} else {
 
 		const lParentLSM = new Matrix4().scale( new Vector3().setFromMatrixScale( lParentLX ) );
-		const lParentLSM_inv = new Matrix4().copy( lParentLSM ).invert();
-		const lParentGSM_noLocal = new Matrix4().copy( lParentGSM ).multiply( lParentLSM_inv );
+		const lParentLSM_inv = lParentLSM.clone().invert();
+		const lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );
 
 		lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );
 
 	}
 
-	const lRotationPivotM_inv = new Matrix4();
-	lRotationPivotM_inv.copy( lRotationPivotM ).invert();
-	const lScalingPivotM_inv = new Matrix4();
-	lScalingPivotM_inv.copy( lScalingPivotM ).invert();
+	const lRotationPivotM_inv = lRotationPivotM.clone().invert();
+	const lScalingPivotM_inv = lScalingPivotM.clone().invert();
 	// Calculate the local transform matrix
-	let lTransform = new Matrix4();
-	lTransform.copy( lTranslationM ).multiply( lRotationOffsetM ).multiply( lRotationPivotM ).multiply( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM ).multiply( lRotationPivotM_inv ).multiply( lScalingOffsetM ).multiply( lScalingPivotM ).multiply( lScalingM ).multiply( lScalingPivotM_inv );
+	let lTransform = lTranslationM.clone().multiply( lRotationOffsetM ).multiply( lRotationPivotM ).multiply( lPreRotationM ).multiply( lRotationM ).multiply( lPostRotationM ).multiply( lRotationPivotM_inv ).multiply( lScalingOffsetM ).multiply( lScalingPivotM ).multiply( lScalingM ).multiply( lScalingPivotM_inv );
 
 	const lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition( lTransform );
 
-	const lGlobalTranslation = new Matrix4().copy( lParentGX ).multiply( lLocalTWithAllPivotAndOffsetInfo );
+	const lGlobalTranslation = lParentGX.clone().multiply( lLocalTWithAllPivotAndOffsetInfo );
 	lGlobalT.copyPosition( lGlobalTranslation );
 
-	lTransform = new Matrix4().copy( lGlobalT ).multiply( lGlobalRS );
+	lTransform = lGlobalT.clone().multiply( lGlobalRS );
 
 	// from global to local
 	lTransform.premultiply( lParentGX.invert() );