I feel like this is going to be a question that might make some of you go “Again?” but I’m out of brain cells to work this out… I feel like this is a trivial thing yet I’m really struggling here.
I’m parenting a transformNode (that contains a mesh) to a bone. The goal is to keep the same rotation and position after parenting to the bone. I’m not using attachToBone for some reasons, and I think attachToBone would lead to the same issue, so bear with me in trying this with parenting…
This is my current process:
Place the sword to the position I want (around the hand bone).
Rotate the sword appropriately so it looks good.
re-apply previous rotation and position
I got position to be re-applied fine using setAbsolutePosition, but the rotation is just always wrong;
I just can’t figure out how to re-apply exactly the same rotation to the mesh/node…
I tried something similar to this: sword.absoluteRotationQuaternion.toEulerAngles().subtract(myBone.getRotation())
to get the rotation of the sword relative to the bone’s rotation.
But to no avail…
I tried with every different spaces and at this point I’m just throwing ideas at the wall with nothing sticking.
I made a somewhat similar repro to what I’m doing but it has some scaling issues I think.
You can comment out from line 55 to 61 to get the original rotation and position of the “sword”.
Image is just to show one needs to zoom out to see the new position/rotation of the “sword”
I don’t think parenting to a bone in user code will work, because a bone is not exactly like a TransformNode, you don’t get its transformation by calling getWorldMatrix but by calling getFinalMatrix instead. That’s precisely the purpose of using attachToBone to trigger some special code in the TransformNode.computeWorldMatrix method:
If you really don’t want to use attachToBone, I think you will have to not parent your sword at all and update each frame the sword position/rotation so that it matches the position/rotation of the bone.