generateTransform function

dynamic generateTransform(
  1. Map transformData
)

Implementation

generateTransform(Map transformData) {
  var lTranslationM = Matrix4();
  var lPreRotationM = Matrix4();
  var lRotationM = Matrix4();
  var lPostRotationM = Matrix4();

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

  var lParentGX = Matrix4();
  var lParentLX = Matrix4();
  var lGlobalT = 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 = Matrix4();
  lParentGRM.extractRotation(lParentGX);

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

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

  var lGlobalRS = 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 = Matrix4().scale(Vector3().setFromMatrixScale(lParentLX));
    var lParentLSMInv = lParentLSM.clone().invert();
    var lParentGSMNoLocal = lParentGSM.clone().multiply(lParentLSMInv);

    lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSMNoLocal).multiply(lLSM);
  }

  var lRotationPivotMInv = lRotationPivotM.clone().invert();
  var lScalingPivotMInv = lScalingPivotM.clone().invert();
  // Calculate the local transform matrix
  var lTransform = lTranslationM
      .clone()
      .multiply(lRotationOffsetM)
      .multiply(lRotationPivotM)
      .multiply(lPreRotationM)
      .multiply(lRotationM)
      .multiply(lPostRotationM)
      .multiply(lRotationPivotMInv)
      .multiply(lScalingOffsetM)
      .multiply(lScalingPivotM)
      .multiply(lScalingM)
      .multiply(lScalingPivotMInv);

  var lLocalTWithAllPivotAndOffsetInfo = 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;
}