Skip to content

Commit

Permalink
fixup! feat: export Blender cameras into the .skyc show files
Browse files Browse the repository at this point in the history
  • Loading branch information
vasarhelyi committed Dec 20, 2024
1 parent fcdc6b6 commit 9df1201
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/modules/sbstudio/plugin/utils/cameras.py
Original file line number Diff line number Diff line change
@@ -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",)
Expand All @@ -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
]
15 changes: 15 additions & 0 deletions src/modules/sbstudio/plugin/utils/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"create_position_evaluator",
"get_position_of_object",
"get_xyz_euler_rotation_of_object",
"get_quaternion_rotation_of_object",
)


Expand Down Expand Up @@ -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())

0 comments on commit 9df1201

Please sign in to comment.