Skip to content

Commit

Permalink
Merge pull request #1172 from hummat/extend_camera
Browse files Browse the repository at this point in the history
feat(camera): add camera utility functions
  • Loading branch information
cornerfarmer authored Dec 12, 2024
2 parents 06b190f + 7a8a6f5 commit b350c4a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion blenderproc/python/camera/CameraUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
from blenderproc.python.utility.Utility import KeyFrame


def get_camera(frame: Optional[int] = None) -> Entity:
""" Retrieves the active camera in the current Blender scene and frame.
:param frame: The frame number whose assigned camera should be returned. If None is give, the current frame
is used.
:return: The camera entity.
"""
with KeyFrame(frame):
return Entity(bpy.context.scene.camera)


def add_camera_pose(cam2world_matrix: Union[np.ndarray, Matrix], frame: Optional[int] = None) -> int:
""" Sets a new camera pose to a new or existing frame
Expand Down Expand Up @@ -46,7 +57,7 @@ def get_camera_pose(frame: Optional[int] = None) -> np.ndarray:
:return: The 4x4 cam2world transformation matrix.
"""
with KeyFrame(frame):
return np.array(Entity(bpy.context.scene.camera).get_local2world_mat())
return np.array(get_camera(frame).get_local2world_mat())


def get_camera_frustum(clip_start: Optional[float] = None, clip_end: Optional[float] = None,
Expand Down Expand Up @@ -135,6 +146,14 @@ def rotation_from_forward_vec(forward_vec: Union[np.ndarray, Vector], up_axis: s
return np.array(rotation_matrix)


def get_resolution() -> Tuple[int, int]:
""" Returns the render resolution.
:return: The render width and height in pixels.
"""
return bpy.context.scene.render.resolution_x, bpy.context.scene.render.resolution_y


def set_resolution(image_width: int = None, image_height: int = None):
""" Sets the camera resolution.
Expand Down

0 comments on commit b350c4a

Please sign in to comment.