toJoints method
The reference skeleton (first frame) as MS3D-style joints whose bind pose is frame 0 and whose keys are every frame (absolute).
Implementation
List<Ms3dJoint> toJoints() {
final joints = <Ms3dJoint>[];
final nFrames = frames.length;
for (var b = 0; b < nodes.length; b++) {
final node = nodes[b];
final j = Ms3dJoint()
..name = node.name
..parentIndex = node.parent
..parentName = node.parent >= 0 && node.parent < nodes.length
? nodes[node.parent].name
: '';
final f0 = nFrames > 0 ? frames[0][b] : null;
if (f0 != null) {
j.position.setAll(0, [f0[0], f0[1], f0[2]]);
j.rotation.setAll(0, [f0[3], f0[4], f0[5]]);
}
final times = Float32List(nFrames);
final rot = Float32List(nFrames * 3);
final pos = Float32List(nFrames * 3);
for (var f = 0; f < nFrames; f++) {
times[f] = frameTimes[f].toDouble();
final v = frames[f][b] ?? f0 ?? const [0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
pos[f * 3] = v[0];
pos[f * 3 + 1] = v[1];
pos[f * 3 + 2] = v[2];
rot[f * 3] = v[3];
rot[f * 3 + 1] = v[4];
rot[f * 3 + 2] = v[5];
}
j.rotationKeys = Ms3dKeys(times, rot);
j.positionKeys = Ms3dKeys(times, pos);
joints.add(j);
}
return joints;
}