createTransformMatrix function

Matrix4 createTransformMatrix(
  1. Matrix4? origin,
  2. Vector3? position,
  3. Vector3? scale,
  4. Vector4? rotation,
  5. Vector3? eulerAngles,
)

Helper function to create a Matrix4 from either a given matrix or from position, scale and rotation relative to the origin

Implementation

Matrix4 createTransformMatrix(Matrix4? origin, Vector3? position,
    Vector3? scale, Vector4? rotation, Vector3? eulerAngles) {
  final transform = origin ?? Matrix4.identity();

  if (position != null) {
    transform.setTranslation(position);
  }
  if (rotation != null) {
    transform.rotate(
        Vector3(rotation[0], rotation[1], rotation[2]), rotation[3]);
  }
  if (eulerAngles != null) {
    transform.matrixEulerAngles = eulerAngles;
  }
  if (scale != null) {
    transform.scale(scale);
  } else {
    transform.scale(1.0);
  }
  return transform;
}