Potential problems in Bone class

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:

  1. 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();
    }
}
  1. translate (same problem in setPosition). When in the space = World case, if the bone has no parent, the tmat 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);
2 Likes

Would you be ok to do a Pr of the suggested changes? This will help evaluating the issue

Thanks a million

Done:

The fixes in this thread are unrelated to this problem (or at least they don’t fix it), I think it’s better to keep Return to Rest not Behaving as Expected? going.

Ill move it

Im seeing a lot of skeleton stuff pop up about how the last build broke things.

Is this related?