Skip to content

viewport.camera

Camera position, orientation, projection, and framing.

7 functions / 3 types

Index

FunctionDescription
get_camera_transformGet the position and rotation of one viewport camera.
get_projectionGet one viewport camera’s projection type.
set_camera_transformSet the position and rotation of viewport cameras.
set_projectionSet viewport cameras to perspective or orthographic projection.
toggle_projectionToggle viewport cameras between perspective and orthographic projection.
zoom_extentsMove viewport cameras to frame the scene.
zoom_to_aabbFit the world-space AABB in matching viewport cameras without changing their rotation. Moves a perspective camera; also adjusts scale for an orthographic camera. By default, the fit does not animate. Returning does not mean a new frame has rendered. No matching camera means no change.
TypeDescription
CameraTransformWorld-space position and orientation of a camera. The three angles are the YXZ Euler decomposition of the camera rotation, in radians.
CameraTransformResultResult of GetCameraTransform.
ProjectionKindCamera projection type.

get_camera_transform

def get_camera_transform(
    *,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> types.viewport.camera.CameraTransformResult

Get the position and rotation of one viewport camera.

Returns a CameraTransformResult containing the world-space position and YXZ Euler angles in radians. The transform is absent when the camera has no transform.

Fails unless exactly one viewport camera matches viewport.

Returns CameraTransformResult.

viewport optional : str | None

Label of the viewport to read. Absent, the only viewport is read. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

get_projection

def get_projection(
    *,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> types.viewport.camera.ProjectionKind | None

Get one viewport camera’s projection type.

Fails unless exactly one viewport camera matches viewport.

Returns ProjectionKind | None.

viewport optional : str | None

Label of the viewport to read. Absent, the only viewport is read. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

set_camera_transform

def set_camera_transform(
    *,
    x: float,
    y: float,
    z: float,
    x_rot: float,
    y_rot: float,
    z_rot: float,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> None

Set the position and rotation of viewport cameras.

The rotation is specified as three Euler angles in YXZ order, matching EulerRot.YXZ. Despite the field names, the angles are passed to DQuat.from_euler(EulerRot.YXZ, x_rot, y_rot, z_rot), so:

  • x_rot is applied around the Y axis (first rotation, horizontal heading).
  • y_rot is applied around the X axis (second rotation, vertical tilt).
  • z_rot is applied around the Z axis (third rotation, roll).

Angles are in radians. Camera-local forward is -Z and local up is +Y; rotate these vectors to obtain their world-space directions. The editor world is Z-up. With zero rotation, the camera looks along world -Z with world +Y at the top of the image. Values returned by GetCameraTransform can be passed directly back to this statement.

Acts on every viewport camera whose label is viewport, or on all of them when it is absent.

Returns None.

x : float

World-space X position.

y : float

World-space Y position.

z : float

World-space Z position.

x_rot : float

Rotation around the Y axis (horizontal heading), applied first.

y_rot : float

Rotation around the X axis (vertical tilt), applied second.

z_rot : float

Rotation around the Z axis (roll), applied third.

viewport optional : str | None

Label of the viewports to move. Absent, every viewport moves. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

set_projection

def set_projection(
    *,
    projection: types.viewport.camera.ProjectionKind,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> None

Set viewport cameras to perspective or orthographic projection.

Applies to cameras matching viewport, or all viewport cameras when omitted. Repeating the same request does not toggle the projection.

Returns None.

projection : ProjectionKind

Target projection type.

viewport optional : str | None

Label of the viewports to change. Absent, every viewport changes. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

toggle_projection

def toggle_projection(
    *,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> None

Toggle viewport cameras between perspective and orthographic projection.

Applies to cameras matching viewport, or all viewport cameras when omitted.

Returns None.

viewport optional : str | None

Label of the viewports to change. Absent, every viewport changes. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

zoom_extents

def zoom_extents(
    *,
    duration_seconds: float | None = None,
    viewport: str | None = None,
    _transaction_id: str | None = None
) -> None

Move viewport cameras to frame the scene.

Returns None.

duration_seconds optional : float | None

Animation length in seconds. A positive value eases the camera over that long. Absent, zero, negative or non-finite snaps it in one tick. Defaults to None.

viewport optional : str | None

Label of the viewports to move. Absent, every viewport moves. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

zoom_to_aabb

def zoom_to_aabb(
    *,
    min_x: float,
    min_y: float,
    min_z: float,
    max_x: float,
    max_y: float,
    max_z: float,
    viewport: str | None = None,
    duration_seconds: float | None = None,
    _transaction_id: str | None = None
) -> None

Fit the world-space AABB in matching viewport cameras without changing their rotation. Moves a perspective camera; also adjusts scale for an orthographic camera. By default, the fit does not animate. Returning does not mean a new frame has rendered. No matching camera means no change.

Returns None.

min_x : float

World-space minimum corner X.

min_y : float

World-space minimum corner Y.

min_z : float

World-space minimum corner Z.

max_x : float

World-space maximum corner X.

max_y : float

World-space maximum corner Y.

max_z : float

World-space maximum corner Z.

viewport optional : str | None

Label of the viewports to move. Absent, every viewport moves. Defaults to None.

duration_seconds optional : float | None

Animation length in seconds. A positive finite value animates; other values snap. Defaults to None.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

CameraTransform

CameraTransform(
    *,
    translation: types.math.Vec3,
    yaw: float,
    pitch: float,
    roll: float
)

World-space position and orientation of a camera. The three angles are the YXZ Euler decomposition of the camera rotation, in radians.

translation : Vec3

Camera position in world space.

yaw : float

Rotation about the Y axis (horizontal heading), applied first.

pitch : float

Rotation about the X axis (vertical tilt), applied second.

roll : float

Rotation about the Z axis (roll), applied third.

CameraTransformResult

CameraTransformResult(
    *,
    transform: types.viewport.camera.CameraTransform | None = None,
    vertical_field_of_view: float | None = None
)

Result of GetCameraTransform.

transform optional : CameraTransform | None

Camera position and orientation. Absent when the camera has no transform. Defaults to None.

vertical_field_of_view optional : float | None

The vertical field of view of a perspective camera, in radians, as of the same frame as transform. Absent for any other projection. Defaults to None.

ProjectionKind

Enum

class ProjectionKind(IntEnum)

Camera projection type.

Values: PERSPECTIVE = 0 Objects appear smaller as their distance from the camera increases. ORTHOGRAPHIC = 1 Object size on screen is independent of distance from the camera.

PERSPECTIVE = 0

Objects appear smaller as their distance from the camera increases.

ORTHOGRAPHIC = 1

Object size on screen is independent of distance from the camera.