Improvement(?)
See original GitHub issueThank you very much for this addon, it really makes with importing Blender models into Unity a lot easier!
While all the individual object’s positions and rotations are correct, it seems like I still need to rotate the whole model by 180° on the Y-axis in Unity to make it face in the right direction.
So I tried making a fix for it (the comments in the code should hopefully be self explanatory, although I am not 100% sure about why some of my code segments seem to be required for it to work correctly). Maybe there is a better way, but this seems to work in all scenarios I tested (including more than one child object).
This is the code starting from line 130. I have also attached the full file below (although as .txt, as .py files are not supported for uploading in this case):
# Reset parent's inverse so we can work with local transform directly
reset_parent_inverse(ob)
# Create a copy of the local matrix and set a X-90/Z-180 matrix
mat_original = ob.matrix_local.copy()
rot_x = mathutils.Matrix.Rotation(math.radians(-90.0), 4, 'X')
rot_z = mathutils.Matrix.Rotation(math.radians(-180.0), 4, 'Z')
ob.matrix_local = rot_x @ rot_z
# Apply the rotation to the object
apply_rotation(ob)
if (ob.parent):
# Reapply the previous local transform with an X+90 and Y+180 rotation
ob.matrix_local = mat_original @ mathutils.Matrix.Rotation(math.radians(90.0), 4, 'X') @ mathutils.Matrix.Rotation(math.radians(180.0), 4, 'Y')
else:
# Reapply the previous local transform with only an X+90 rotation
ob.matrix_local = mat_original @ mathutils.Matrix.Rotation(math.radians(90.0), 4, 'X')
# Correct position by inverting X and Y values
loc_or = ob.location
ob.location = (-loc_or.x, -loc_or.y, loc_or.z)
# Correct rotation by inverting Y value
rot_or = ob.rotation_euler
ob.rotation_euler = (rot_or.x, -rot_or.y, rot_or.z)
Hope this helps and of course please let me know if you have any suggestions or if there might be a better way!
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thank you for this graph, I didn’t know the coordinate systems were that arbitrary…
Personally, Z forward, Y up and X right makes the most sense to me, like Unity or DirectX have it. Unreal also seems good enugh to me, just with Y forward and Z up. But for the rest it looks a bit unintuitive to be honest.
I guess you have to make the best out of it, and at least your addon will work without any problems then.
Pretty much every 3D software out here arbitrarily chooses their coordinate system and the meaning of each axis. Here’s an (incomplete) example: