From 9df1201751d393d02d5708c47e47eaae4ed9a268 Mon Sep 17 00:00:00 2001 From: Gabor Vasarhelyi Date: Fri, 20 Dec 2024 10:26:17 +0100 Subject: [PATCH] fixup! feat: export Blender cameras into the .skyc show files --- src/modules/sbstudio/plugin/utils/cameras.py | 24 +++++++++---------- .../sbstudio/plugin/utils/evaluator.py | 15 ++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/modules/sbstudio/plugin/utils/cameras.py b/src/modules/sbstudio/plugin/utils/cameras.py index 303f627..381705a 100644 --- a/src/modules/sbstudio/plugin/utils/cameras.py +++ b/src/modules/sbstudio/plugin/utils/cameras.py @@ -1,6 +1,10 @@ from bpy.types import Context from sbstudio.model.cameras import Camera +from sbstudio.plugin.utils.evaluator import ( + get_position_of_object, + get_quaternion_rotation_of_object, +) __all__ = ("get_cameras_from_context",) @@ -18,17 +22,11 @@ def get_cameras_from_context(context: Context) -> list[Camera]: """ cameras = [obj for obj in context.scene.objects if obj.type == "CAMERA"] - retval = [] - for camera in cameras: - rotation_mode = camera.rotation_mode - camera.rotation_mode = "QUATERNION" - retval.append( - Camera( - name=camera.name, - position=tuple(camera.location), - orientation=tuple(camera.rotation_quaternion), - ) + return [ + Camera( + name=camera.name, + position=get_position_of_object(camera), + orientation=get_quaternion_rotation_of_object(camera), ) - camera.rotation_mode = rotation_mode - - return retval + for camera in cameras + ] diff --git a/src/modules/sbstudio/plugin/utils/evaluator.py b/src/modules/sbstudio/plugin/utils/evaluator.py index e63456f..d90dced 100644 --- a/src/modules/sbstudio/plugin/utils/evaluator.py +++ b/src/modules/sbstudio/plugin/utils/evaluator.py @@ -12,6 +12,7 @@ "create_position_evaluator", "get_position_of_object", "get_xyz_euler_rotation_of_object", + "get_quaternion_rotation_of_object", ) @@ -68,3 +69,17 @@ def get_xyz_euler_rotation_of_object(object: Object) -> Rotation3D: """ return tuple(degrees(angle) for angle in object.matrix_world.to_euler("XYZ")) + + +def get_quaternion_rotation_of_object(object: Object) -> Rotation3D: + """Returns the global rotation of an object at the current frame + in quaternions. + + Parameters: + object: a Blender object + + Returns: + rotation of object in the world frame, in quaternions. + """ + + return tuple(object.matrix_world.to_quaternion())