Reputation: 11
So, I've got some models posed in Unity that I would like to recreate in Blender as part of a larger, static scene. I'm using the same model in Blender that I was in Unity and I have a file of all of the positions and rotations of each part/bone, adjusted for the move from XYZ to XZY. However, all of the rotations in Blender are wrong, and in such a way that I can't seem to find a pattern.
What I've been doing: I've made a basic little model of a box person in Blender and given it a basic armature (It's a very bad model- I'm not a modeler- but it works and it's simple). I've been attaching a script to each bone on the model so I can get the Quaternion values for their rotations in Unity, and negating the x, y, and z, and swapping the y and z values to convert from left-handed to right-handed coordinates before putting them back into Blender. You can see the results in the image below.
Model posed in Unity on left, same rotation values in Blender on right
For the record I've also tried using Euler values since I'm more familiar with them, but figured using Quaternions would give a more reliable result since the Euler values from Unity can be inconsistent from what I've read.
Everything I can find that seems related is, reasonably, in the other direction, from Blender to Unity.
Honestly, in this particular case I can just re-create the poses in Blender and move on. However, I'm interested in learning what it is that's so different between Blender and Unity that is causing these strange rotations.
Here are the .blend and .fbx of the block man for reference. https://drive.google.com/drive/folders/1p4jhh8CVMwN7RlP0YQvwqOQJ3Ft569G6?usp=sharing
Upvotes: 1
Views: 382
Reputation: 90580
what it is that's so different between Blender and Unity that is causing these strange rotations.
You basically already know that: Blender uses a right-handed whereas Unity uses a left-handed coordinate system
Afaik something like this should do it
For positions it is quite trivial:
Also for the scale
For the rotation
It should work in both directions the same (left-handed -> right-handed and right-handed -> left-handed)
public class Test : MonoBehaviour
{
public Vector3 BlenderPosition;
public Quaternion BlenderRotation;
public Vector3 BlenderScale;
[ContextMenu(nameof(ApplyTransformValuesFromBlender))]
private void ApplyTransformValuesFromBlender()
{
transform.localPosition = FlipLeftRightHanded(BlenderPosition);
transform.localRotation = FlipLeftRightHanded(BlenderRotation);
transform.localScale = FlipLeftRightHanded(BlenderScale);
}
[ContextMenu(nameof(ConvertTransformValuesToBlender))]
private void ConvertTransformValuesToBlender()
{
BlenderPosition = FlipLeftRightHanded(transform.localPosition);
BlenderRotation = FlipLeftRightHanded(transform.localRotation);
BlenderScale = FlipLeftRightHanded(transform.localScale);
}
private Vector3 FlipLeftRightHanded(Vector3 vector)
{
return new Vector3(vector.x, vector.z, vector.y);
}
private Quaternion FlipLeftRightHanded(Quaternion quaternion)
{
return new Quaternion (-quaternion.x, -quaternion.z, - quaternion.y, quaternion.w);
}
}
Upvotes: 0