computeJointData method
Implementation
JointData computeJointData() {
final weights = this.weights?.get().typedData() ?? [];
// this are the indexes (0, 1, 2, 3) that have any relevance at all
final relevantIndexes = weights.expand((w) {
return w.storage.indexed
.where((e) => e.$2 > 0.0)
.map((e) => e.$1)
.toSet();
}).toSet();
final joints = this.joints?.get().typedData() ?? [];
final globalToLocalJointMap = Map.fromEntries(
joints
.expand((e) {
return e.storage.indexed
.where((e) => relevantIndexes.contains(e.$1))
.map((e) => e.$2);
})
.toSet()
.indexed
.map((e) => MapEntry(e.$2.toInt(), e.$1)),
);
final localizedJoints = joints.map((joint) {
return Vector4.array(
joint.storage.map((e) {
if (e == 0.0 && globalToLocalJointMap[e] == null) {
// this must be a 0 weight value that just happens to be id = 0
return 0.0;
}
return globalToLocalJointMap[e]!.toDouble();
}).toList(),
);
}).toList();
return JointData(
weights: weights,
localizedJoints: localizedJoints,
jointMap: globalToLocalJointMap,
);
}