提交 3d0eac48 编写于 作者: M Mr.doob

FBXLoader: Matrix4 code clean up.

上级 a40bb1ae
...@@ -3745,16 +3745,15 @@ ...@@ -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(); const lParentGRM = new THREE.Matrix4();
lParentGRM.extractRotation( lParentGX ); // Global Shear*Scaling lParentGRM.extractRotation( lParentGX ); // Global Shear*Scaling
const lParentTM = new THREE.Matrix4(); const lParentTM = new THREE.Matrix4();
lParentTM.copyPosition( lParentGX ); lParentTM.copyPosition( lParentGX );
const lParentGSM = new THREE.Matrix4(); const lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
const lParentGRSM = new THREE.Matrix4().copy( lParentTM ).invert().multiply( lParentGX ); const lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
lParentGSM.copy( lParentGRM ).invert().multiply( lParentGRSM );
const lLSM = lScalingM; const lLSM = lScalingM;
const lGlobalRS = new THREE.Matrix4(); const lGlobalRS = new THREE.Matrix4();
...@@ -3769,23 +3768,20 @@ ...@@ -3769,23 +3768,20 @@
} else { } else {
const lParentLSM = new THREE.Matrix4().scale( new THREE.Vector3().setFromMatrixScale( lParentLX ) ); const lParentLSM = new THREE.Matrix4().scale( new THREE.Vector3().setFromMatrixScale( lParentLX ) );
const lParentLSM_inv = new THREE.Matrix4().copy( lParentLSM ).invert(); const lParentLSM_inv = lParentLSM.clone().invert();
const lParentGSM_noLocal = new THREE.Matrix4().copy( lParentGSM ).multiply( lParentLSM_inv ); const lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );
lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM ); lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );
} }
const lRotationPivotM_inv = new THREE.Matrix4(); const lRotationPivotM_inv = lRotationPivotM.clone().invert();
lRotationPivotM_inv.copy( lRotationPivotM ).invert(); const lScalingPivotM_inv = lScalingPivotM.clone().invert(); // Calculate the local transform matrix
const lScalingPivotM_inv = new THREE.Matrix4();
lScalingPivotM_inv.copy( lScalingPivotM ).invert(); // Calculate the local transform matrix
let lTransform = new THREE.Matrix4(); 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 );
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 );
const lLocalTWithAllPivotAndOffsetInfo = new THREE.Matrix4().copyPosition( lTransform ); 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 ); 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() ); lTransform.premultiply( lParentGX.invert() );
return lTransform; return lTransform;
......
...@@ -4049,7 +4049,7 @@ function generateTransform( transformData ) { ...@@ -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 // Global Rotation
const lParentGRM = new Matrix4(); const lParentGRM = new Matrix4();
lParentGRM.extractRotation( lParentGX ); lParentGRM.extractRotation( lParentGX );
...@@ -4058,9 +4058,8 @@ function generateTransform( transformData ) { ...@@ -4058,9 +4058,8 @@ function generateTransform( transformData ) {
const lParentTM = new Matrix4(); const lParentTM = new Matrix4();
lParentTM.copyPosition( lParentGX ); lParentTM.copyPosition( lParentGX );
const lParentGSM = new Matrix4(); const lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
const lParentGRSM = new Matrix4().copy( lParentTM ).invert().multiply( lParentGX ); const lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
lParentGSM.copy( lParentGRM ).invert().multiply( lParentGRSM );
const lLSM = lScalingM; const lLSM = lScalingM;
const lGlobalRS = new Matrix4(); const lGlobalRS = new Matrix4();
...@@ -4076,27 +4075,24 @@ function generateTransform( transformData ) { ...@@ -4076,27 +4075,24 @@ function generateTransform( transformData ) {
} else { } else {
const lParentLSM = new Matrix4().scale( new Vector3().setFromMatrixScale( lParentLX ) ); const lParentLSM = new Matrix4().scale( new Vector3().setFromMatrixScale( lParentLX ) );
const lParentLSM_inv = new Matrix4().copy( lParentLSM ).invert(); const lParentLSM_inv = lParentLSM.clone().invert();
const lParentGSM_noLocal = new Matrix4().copy( lParentGSM ).multiply( lParentLSM_inv ); const lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );
lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM ); lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );
} }
const lRotationPivotM_inv = new Matrix4(); const lRotationPivotM_inv = lRotationPivotM.clone().invert();
lRotationPivotM_inv.copy( lRotationPivotM ).invert(); const lScalingPivotM_inv = lScalingPivotM.clone().invert();
const lScalingPivotM_inv = new Matrix4();
lScalingPivotM_inv.copy( lScalingPivotM ).invert();
// Calculate the local transform matrix // Calculate the local transform matrix
let lTransform = new Matrix4(); 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 );
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 );
const lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition( lTransform ); const lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition( lTransform );
const lGlobalTranslation = new Matrix4().copy( lParentGX ).multiply( lLocalTWithAllPivotAndOffsetInfo ); const lGlobalTranslation = lParentGX.clone().multiply( lLocalTWithAllPivotAndOffsetInfo );
lGlobalT.copyPosition( lGlobalTranslation ); lGlobalT.copyPosition( lGlobalTranslation );
lTransform = new Matrix4().copy( lGlobalT ).multiply( lGlobalRS ); lTransform = lGlobalT.clone().multiply( lGlobalRS );
// from global to local // from global to local
lTransform.premultiply( lParentGX.invert() ); lTransform.premultiply( lParentGX.invert() );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册