Great work!
I tested by applying your fix on my local repo but could not make it work.
Note that I had to apply your previous fix too (that is not in the PR), else the mesh is completely off:
public returnToRest(): void {
for (var index = 0; index < this.bones.length; index++) {
if (this.bones[index]._index !== -1) {
this.bones[index].returnToRest();
}
}
}
With this fix and the PR, now we get:
when calling
skeleton.returnToRest()
(PG:
Babylon.js Playground): the skeleton is ok but not the mesh.
Which is the reverse of what we get without the PR (but still with the fix above):
The mesh is ok but not the skeleton.
So, I updated skeleton.returnToRest
to update the linked transform nodes:
public returnToRest(): void {
const _localScaling = Vector3.Zero();
const _localRotation = Quaternion.Zero();
const _localPosition = Vector3.Zero();
for (var index = 0; index < this.bones.length; index++) {
const bone = this.bones[index];
if (bone._index !== -1) {
bone.returnToRest();
if (bone._linkedTransformNode) {
bone.getRestPose().decompose(_localScaling, _localRotation, _localPosition);
bone._linkedTransformNode.position = _localPosition.clone();
bone._linkedTransformNode.rotationQuaternion = _localRotation.clone();
bone._linkedTransformNode.scaling = _localScaling.clone();
}
}
}
}
and now the display is ok (after calling returnToRest()
):
BUT it’s not the end of the story!
The display is ok when we call returnToRest
at start but if starting an animation for some seconds, then stopping the animation and calling returnToRest
it does not work (PG: https://playground.babylonjs.com/#2KRYP8#1): the skeleton is ok but the mesh has “disappeared”:
In fact the mesh is there: the bounding boxes in the screenshot are the bb of the 4 meshes, but the meshes are not displayed for some reason… Investigating…
[EDIT] In fact the bb are ok because they are never updated, but the transform matrices are wrong [/EDIT]