Skip to content

Instantly share code, notes, and snippets.

@Dragorn421
Created October 30, 2021 10:57
Show Gist options
  • Save Dragorn421/441596a7331e45dcc25b13e1d0e755b3 to your computer and use it in GitHub Desktop.
Save Dragorn421/441596a7331e45dcc25b13e1d0e755b3 to your computer and use it in GitHub Desktop.
Display blender object transform loc/rot/scale in another coordinate system (same +x, but +y up)
import bpy
import mathutils
obj = bpy.context.active_object
blender_to_game = mathutils.Matrix(
[
[1, 0,0,0],
[0, 0,1,0],
[0,-1,0,0],
[0, 0,0,1],
]
)
location = mathutils.Matrix.Translation(obj.location)
prev_rot_mode = obj.rotation_mode
try:
obj.rotation_mode = "QUATERNION"
rotation = obj.rotation_quaternion.to_matrix().to_4x4()
finally:
obj.rotation_mode = prev_rot_mode
scale = mathutils.Matrix.Diagonal(obj.scale).to_4x4()
transform_blender = location @ rotation @ scale
transform_game = blender_to_game @ transform_blender @ blender_to_game.inverted()
print(transform_blender)
print(transform_game)
print("translation", transform_game.to_translation())
print("rotation", transform_game.to_euler("XYZ"))
print("scale", transform_game.to_scale()[:3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment