generateTransform function

dynamic generateTransform(
  1. Map transformData
)

Implementation

generateTransform( Map transformData ) {

	var lTranslationM = new Matrix4();
	var lPreRotationM = new Matrix4();
	var lRotationM = new Matrix4();
	var lPostRotationM = new Matrix4();

	var lScalingM = new Matrix4();
	var lScalingPivotM = new Matrix4();
	var lScalingOffsetM = new Matrix4();
	var lRotationOffsetM = new Matrix4();
	var lRotationPivotM = new Matrix4();

	var lParentGX = new Matrix4();
	var lParentLX = new Matrix4();
	var lGlobalT = new Matrix4();

	var inheritType = ( transformData["inheritType"] != null ) ? transformData["inheritType"] : 0;

	if ( transformData["translation"] != null ) lTranslationM.setPosition( tempVec.fromArray( transformData["translation"] ) );

	if ( transformData["preRotation"] != null ) {

		List<double> array = List<double>.from(transformData["preRotation"].map( (e) => MathUtils.degToRad(e).toDouble() ).toList());
		array.add( THREE.Euler.RotationOrders.indexOf( transformData["eulerOrder"] ).toDouble() );
		lPreRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );

	}

	if ( transformData["rotation"] != null ) {

		List<double> array = List<double>.from( transformData["rotation"].map( (e) => MathUtils.degToRad(e).toDouble() ).toList() );
		array.add( THREE.Euler.RotationOrders.indexOf( transformData["eulerOrder"] ).toDouble() );
		lRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );

	}

	if ( transformData["postRotation"] != null ) {

		List<double> array = List<double>.from( transformData["postRotation"].map( (e) => MathUtils.degToRad ).toList() );
		array.add( THREE.Euler.RotationOrders.indexOf( transformData["eulerOrder"] ).toDouble() );
		lPostRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );
		lPostRotationM.invert();

	}

	if ( transformData["scale"] != null ) lScalingM.scale( tempVec.fromArray( transformData["scale"] ) );

	// Pivots and offsets
	if ( transformData["scalingOffset"] != null ) lScalingOffsetM.setPosition( tempVec.fromArray( transformData["scalingOffset"] ) );
	if ( transformData["scalingPivot"] != null ) lScalingPivotM.setPosition( tempVec.fromArray( transformData["scalingPivot"] ) );
	if ( transformData["rotationOffset"] != null ) lRotationOffsetM.setPosition( tempVec.fromArray( transformData["rotationOffset"] ) );
	if ( transformData["rotationPivot"] != null ) lRotationPivotM.setPosition( tempVec.fromArray( transformData["rotationPivot"] ) );

	// parent transform
	if ( transformData["parentMatrixWorld"] != null ) {

		lParentLX.copy( transformData["parentMatrix"] );
		lParentGX.copy( transformData["parentMatrixWorld"] );

	}

	var lLRM = lPreRotationM.clone().multiply( lRotationM ).multiply( lPostRotationM );
	// Global Rotation
	var lParentGRM = new Matrix4();
	lParentGRM.extractRotation( lParentGX );

	// Global Shear*Scaling
	var lParentTM = new Matrix4();
	lParentTM.copyPosition( lParentGX );

	var lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
	var lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
	var lLSM = lScalingM;

	var lGlobalRS = new Matrix4();

	if ( inheritType == 0 ) {

		lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM ).multiply( lLSM );

	} else if ( inheritType == 1 ) {

		lGlobalRS.copy( lParentGRM ).multiply( lParentGSM ).multiply( lLRM ).multiply( lLSM );

	} else {

		var lParentLSM = new Matrix4().scale( new Vector3().setFromMatrixScale( lParentLX ) );
		var lParentLSM_inv = lParentLSM.clone().invert();
		var lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );

		lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );

	}

	var lRotationPivotM_inv = lRotationPivotM.clone().invert();
	var lScalingPivotM_inv = lScalingPivotM.clone().invert();
	// Calculate the local transform matrix
	var 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 );

	var lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition( lTransform );

	var lGlobalTranslation = lParentGX.clone().multiply( lLocalTWithAllPivotAndOffsetInfo );
	lGlobalT.copyPosition( lGlobalTranslation );

	lTransform = lGlobalT.clone().multiply( lGlobalRS );

	// from global to local
	lTransform.premultiply( lParentGX.invert() );

	return lTransform;

}