viewport.camera
Camera position, orientation, projection, and framing.
7 functions / 3 types
Index
| Function | Description |
|---|---|
| get_camera_transform | Get the position and rotation of one viewport camera. |
| get_projection | Get one viewport camera’s projection type. |
| set_camera_transform | Set the position and rotation of viewport cameras. |
| set_projection | Set viewport cameras to perspective or orthographic projection. |
| toggle_projection | Toggle viewport cameras between perspective and orthographic projection. |
| zoom_extents | Move viewport cameras to frame the scene. |
| zoom_to_aabb | 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. |
| Type | Description |
|---|---|
| CameraTransform | World-space position and orientation of a camera. The three angles are the YXZ Euler decomposition of the camera rotation, in radians. |
| CameraTransformResult | Result of GetCameraTransform. |
| ProjectionKind | Camera projection type. |
get_camera_transform
def get_camera_transform(
*,
viewport: str | None = None,
_transaction_id: str | None = None
) -> types.viewport.camera.CameraTransformResultGet 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 | NoneGet 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
) -> NoneSet 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_rotis applied around the Y axis (first rotation, horizontal heading).y_rotis applied around the X axis (second rotation, vertical tilt).z_rotis 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
) -> NoneSet 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
) -> NoneToggle 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
) -> NoneMove 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
) -> NoneFit 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.