viewport.camera
Camera position, orientation, projection, and framing.
7 functions / 3 types
Index
| Function | Description |
|---|---|
| getCameraTransform | Get the position and rotation of one viewport camera. |
| getProjection | Get one viewport camera’s projection type. |
| setCameraTransform | Set the position and rotation of viewport cameras. |
| setProjection | Set viewport cameras to perspective or orthographic projection. |
| toggleProjection | Toggle viewport cameras between perspective and orthographic projection. |
| zoomExtents | Move viewport cameras to frame the scene. |
| zoomToAabb | 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. |
getCameraTransform
getCameraTransform(args?: { viewport?: string }, transactionId?: string): Promise<ViewportCameraCameraTransformResult>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: Result of GetCameraTransform.
Returns Promise<ViewportCameraCameraTransformResult>.
viewport optional : string
Label of the viewport to read. Absent, the only viewport is read.
transactionId optional : string
getProjection
getProjection(args?: { viewport?: string }, transactionId?: string): Promise<ViewportCameraProjectionKind | undefined>Get one viewport camera’s projection type.
Fails unless exactly one viewport camera matches viewport.
Returns Promise<ViewportCameraProjectionKind | undefined>.
viewport optional : string
Label of the viewport to read. Absent, the only viewport is read.
transactionId optional : string
setCameraTransform
setCameraTransform(args: { viewport?: string; x: number; xRot: number; y: number; yRot: number; z: number; zRot: number }, transactionId?: string): Promise<void>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:
xRotis applied around the Y axis (first rotation, horizontal heading).yRotis applied around the X axis (second rotation, vertical tilt).zRotis 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 Promise<void>.
viewport optional : string
Label of the viewports to move. Absent, every viewport moves.
x : number
World-space X position.
xRot : number
Rotation around the Y axis (horizontal heading), applied first.
y : number
World-space Y position.
yRot : number
Rotation around the X axis (vertical tilt), applied second.
z : number
World-space Z position.
zRot : number
Rotation around the Z axis (roll), applied third.
transactionId optional : string
setProjection
setProjection(args: { projection: ViewportCameraProjectionKind; viewport?: string }, transactionId?: string): Promise<void>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 Promise<void>.
projection : ViewportCameraProjectionKind
Target projection type.
viewport optional : string
Label of the viewports to change. Absent, every viewport changes.
transactionId optional : string
toggleProjection
toggleProjection(args?: { viewport?: string }, transactionId?: string): Promise<void>Toggle viewport cameras between perspective and orthographic projection.
Applies to cameras matching viewport, or all viewport cameras when omitted.
Returns Promise<void>.
viewport optional : string
Label of the viewports to change. Absent, every viewport changes.
transactionId optional : string
zoomExtents
zoomExtents(args?: { durationSeconds?: number; viewport?: string }, transactionId?: string): Promise<void>Move viewport cameras to frame the scene.
Returns Promise<void>.
durationSeconds optional : number
Animation length in seconds. A positive value eases the camera over that long. Absent, zero, negative or non-finite snaps it in one tick.
viewport optional : string
Label of the viewports to move. Absent, every viewport moves.
transactionId optional : string
zoomToAabb
zoomToAabb(args: { durationSeconds?: number; maxX: number; maxY: number; maxZ: number; minX: number; minY: number; minZ: number; viewport?: string }, transactionId?: string): Promise<void>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 Promise<void>.
durationSeconds optional : number
Animation length in seconds. A positive finite value animates; other values snap.
maxX : number
World-space maximum corner X.
maxY : number
World-space maximum corner Y.
maxZ : number
World-space maximum corner Z.
minX : number
World-space minimum corner X.
minY : number
World-space minimum corner Y.
minZ : number
World-space minimum corner Z.
viewport optional : string
Label of the viewports to move. Absent, every viewport moves.
transactionId optional : string
CameraTransform
World-space position and orientation of a camera. The three angles are the YXZ Euler decomposition of the camera rotation, in radians.
pitch : number
Rotation about the X axis (vertical tilt), applied second.
roll : number
Rotation about the Z axis (roll), applied third.
translation : MathVec3
Camera position in world space.
yaw : number
Rotation about the Y axis (horizontal heading), applied first.
CameraTransformResult
Result of GetCameraTransform.
transform optional : ViewportCameraCameraTransform
Camera position and orientation. Absent when the camera has no transform.
verticalFieldOfView optional : number
The vertical field of view of a perspective camera, in radians, as of the same frame as
transform. Absent for any other projection.
ProjectionKind
Enum
Camera projection type.
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.