While investigating Return to Rest not Behaving as Expected?, I came to two things that may be bugs, so I would need experts to have a look:
-
computeAbsoluteTransforms
does not compute the invert absolute transform matrix. I think it needs to be added just before the loop on the children:
public computeAbsoluteTransforms(): void {
this._compose();
if (this._parent) {
this._localMatrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
} else {
this._absoluteTransform.copyFrom(this._localMatrix);
var poseMatrix = this._skeleton.getPoseMatrix();
if (poseMatrix) {
this._absoluteTransform.multiplyToRef(poseMatrix, this._absoluteTransform);
}
}
this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform); // <== added
var children = this.children;
var len = children.length;
for (var i = 0; i < len; i++) {
children[i].computeAbsoluteTransforms();
}
}
-
translate
(same problem insetPosition
). When in thespace = World
case, if the bone has no parent, thetmat
matrix used to compute the translation values is undefined (it has values from some previous computations). I think the code should be updated as:
var tmat = Bone._tmpMats[0];
var tvec = Bone._tmpVecs[0];
if (this._parent) {
if (mesh && wm) {
tmat.copyFrom(this._parent.getAbsoluteTransform());
tmat.multiplyToRef(wm, tmat);
} else {
tmat.copyFrom(this._parent.getAbsoluteTransform());
}
} else { // <== added
Matrix.IdentityToRef(tmat); // <== added
}
tmat.setTranslationFromFloats(0, 0, 0);
tmat.invert();
Vector3.TransformCoordinatesToRef(vec, tmat, tvec);