Find the offset between the rotation of a bone in Unity and in the original rig

Viewed 682

Goal:

Calculate a rotation, that can be used, to correct the Transform of the bones, so they get rotated as expected when manually rotated.

In Detial:

Character's bone Transform is not imported to Unity correctily, ie. the left hand's Z axis does not looks towards the top of the hand, but backwards, while the right hand's Z axis looks forward.

The bones default rotation is not the same as you would expect if you have seen the rig in another application before.

I had the idea to create a class, that puts the character in T-Pose, then maps the bones rotation. (I would assume that Unity does something similiar under the hood, that's how I got the idea.) So the class would be used with an API like this:

/// This should return the rotation, where the bone pointing forward rotated by rotation.
/// Ie. when rotation = Quaternion.Identity the left hand should look forward.
Quaternion CorrectRotation(HumanBodyBones bone, Quaternion rotation)
{
    return Quaternion.Inverse(tPoseRotations[bone]) * rotation;
}

The problem is, that I can't seem to find a good way to map theese rotations.

My last attempt was this:

Vector3 boneDirection = (boneTransform.position - parentTransform.position).normalized;
Quaternion mappedRotation = Quaternion.LookRotation(boneDirection, parentTransform.up);

As you can see in this image, with this method the hands look in the same direction, forward, but still not rotated correctly, they have an offset from the desired result. (The correct rotation is shown by the purple hands.)

When given other rotations, the hands follow with the same offset, so other then this unwanted offset they work correctly.

So basically, I would appriciate any help to fix my problem, either this way, or with a different solution, that works with different rigs.

0 Answers
Related