I have a bone in a skeleton, which I want to rotate relative to a mesh’s Space. World or Local Space don’t work in my situation.
I there an easy way to do that?
I have some constraints that make this task easier:
The rotation Axis I want to achieve for the bone is perpendicular to the character it belongs to.
The character only turns around the Y Axis in world space.
I already did some research on the world matrices, but they only support converting locations.
I too tried to create my own quaternion with the above mentioned axis, but that only resulted in weird distortions. Though I think this is the way to go, I just can’t figure out the math + the right api functions to use.
I got a roughly working version, but it only works shortly. After a while, the floating point errors add up as I am only setting the delta rotation.
Is there a way to set an absolute position with the world axis as the reference? That would solve my problem.
const axisMeshRotation = axisMesh.rotationQuaternion.toEulerAngles();
boneToRotate.rotate(BABYLON.Axis.X, Math.cos(axisMeshRotation.y) * .3, BABYLON.Space.WORLD);
boneToRotate.rotate(BABYLON.Axis.Z, -Math.sin(axisMeshRotation.y) * .3, BABYLON.Space.WORLD);
Can you create a playground of what you have so far? That will help a lot.
Here is the playground:
https://www.babylonjs-playground.com/#JUKXQD#127
Just press any key to pause he rotations, there is a high chance, that the arm will stuck in the body.
Note: I rotate the arm by rotating the node associated with the bone.
Bones itself have methods to do absolute rotation, but if i change the arm rotation directly through the bone (no matter if by code, or in the inspector) it is ignored by babylon.
Probably something like this is what you want:
https://www.babylonjs-playground.com/#JUKXQD#128
For glTF, bone transforms are being linked to nodes which is why changing the bone transforms have no effect.
Thank you very much, this is exactly what I was looking for.