attachToBone
is implemented like this in TransformNode
:
public attachToBone(bone: Bone, affectedTransformNode: TransformNode): TransformNode {
this._transformToBoneReferal = affectedTransformNode;
this.parent = bone;
if (bone.getWorldMatrix().determinant() < 0) {
this.scalingDeterminant *= -1;
}
return this;
}
If I comment out the this.scalingDeterminant *= -1;
it does make work your use case.
Indeed, if calling this.skeleton.bones[boneIndex].getWorldMatrix().determinant()
in your PG attachToBone
method, we can see it returns a negative value when the mesh is visible when you attach the AK47 to the bone. When the mesh is not visible yet, the bone matrices are all 0 so the determinant is 0 and thus scalingDeterminant
is not multiplied by -1.
As scalingDeterminant
is a public property, you can reset it to 1
and make the PG work:
https://playground.babylonjs.com/#N3RH3R#30
However, I’m not sure it’s the right way to fix the problem…
I can’t help more, I don’t know anything about animation code, but maybe it can help someone more knowledgeable about this.