generateRotationTrack method
dynamic
generateRotationTrack(
- dynamic modelName,
- Map curves,
- dynamic initialValue,
- dynamic preRotation,
- dynamic postRotation,
- dynamic eulerOrder,
Implementation
generateRotationTrack(modelName, Map curves, initialValue, preRotation, postRotation, eulerOrder) {
if (curves["x"] != null) {
interpolateRotations(curves["x"]);
curves["x"]["values"] = curves["x"]["values"].map((v) => MathUtils.degToRad(v).toDouble()).toList();
}
if (curves["y"] != null) {
interpolateRotations(curves["y"]);
curves["y"]["values"] = curves["y"]["values"].map((v) => MathUtils.degToRad(v).toDouble()).toList();
}
if (curves["z"] != null) {
interpolateRotations(curves["z"]);
curves["z"]["values"] = curves["z"]["values"].map((v) => MathUtils.degToRad(v).toDouble()).toList();
}
var times = getTimesForAllAxes(curves);
var values = getKeyframeTrackValues(times, curves, initialValue);
Quaternion? preRotationQuaternion;
if (preRotation != null) {
preRotation = preRotation.map((v) => MathUtils.degToRad(v).toDouble()).toList();
preRotation.add(eulerOrder);
if (preRotation.length == 4 && Euler.rotationOrders.contains(preRotation[3])) {
preRotation[3] = Euler.rotationOrders.indexOf(preRotation[3]).toDouble();
}
var preRotationEuler = Euler().fromArray(List<double>.from(preRotation));
preRotationQuaternion = Quaternion().setFromEuler(preRotationEuler);
}
if (postRotation != null) {
postRotation = postRotation.map((v) => MathUtils.degToRad(v).toDouble()).toList();
postRotation.push(eulerOrder);
postRotation = Euler().fromArray(postRotation);
postRotation = Quaternion().setFromEuler(postRotation).invert();
}
var quaternion = Quaternion();
var euler = Euler();
List<num> quaternionValues = List<num>.filled(((values.length / 3) * 4).toInt(), 0.0);
for (var i = 0; i < values.length; i += 3) {
euler.set(values[i], values[i + 1], values[i + 2], eulerOrder);
quaternion.setFromEuler(euler);
if (preRotationQuaternion != null) quaternion.premultiply(preRotationQuaternion);
if (postRotation != null) quaternion.multiply(postRotation);
quaternion.toArray(quaternionValues, ((i / 3) * 4).toInt());
}
return QuaternionKeyframeTrack('$modelName.quaternion', times, quaternionValues);
}