Camera
A mutable camera you can position and configure, then apply to the current view.
Build a camera with Camera.default() or get one from
scene.getCamera(). Use the fluent setters to adjust
orientation, field of view, and projection type, then pass
camera.build() to model.view.setCamera() to apply it.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();
// Position the camera looking at the model originlet cam = SketchUpApi.Camera.default() .setOrientation( [0, -500, 200], [0, 0, 0], [0, 0, 1] ) .setFieldOfView(35);
await model.view.setCamera(cam.build());- CameraReader
- View.setCamera
- Scene.getCamera
Constructor
Section titled “Constructor”Constructor
Section titled “Constructor”new Camera(
camera):Camera
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Camera
Accessors
Section titled “Accessors”aspectRatio
Section titled “aspectRatio”Get Signature
Section titled “Get Signature”get aspectRatio():
number
The ratio of viewport width to height.
Returns
Section titled “Returns”number
center_2d
Section titled “center_2d”Get Signature
Section titled “Get Signature”get center_2d():
Point2d
The 2D center point of the view on the plane orthogonal to
the direction vector. Only meaningful for perspective2d and
parallel2d camera types. Returns the origin for others.
Returns
Section titled “Returns”Point2d
computePerspectiveEye
Section titled “computePerspectiveEye”Get Signature
Section titled “Get Signature”get computePerspectiveEye():
Point3d
A reliable eye position for both parallel and perspective
cameras. For parallel cameras the position is recalculated
from height each time, so it is always consistent.
Useful when the camera is returned from SketchUp, as it
could have been set by a Ruby extension and be in an
invalid state
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get data():
CameraData
Return a copy of the underlying CameraData
SDK 2.35.0
Returns
Section titled “Returns”description
Section titled “description”Get Signature
Section titled “Get Signature”get description():
string|undefined
An optional description for this camera.
Returns
Section titled “Returns”string | undefined
direction
Section titled “direction”Get Signature
Section titled “Get Signature”get direction():
Vector3d
The normalized vector from eye to target — the direction the camera is looking.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get eye():
Point3d
The stored eye position. For parallel cameras, SketchUp does
not always keep this up to date — use computePerspectiveEye
when you need a reliable position for any camera type.
CameraReader.computePerspectiveEye
Returns
Section titled “Returns”fieldOfView
Section titled “fieldOfView”Get Signature
Section titled “Get Signature”get fieldOfView():
number
The horizontal field of view in degrees.
Returns
Section titled “Returns”number
focalLength
Section titled “focalLength”Get Signature
Section titled “Get Signature”get focalLength():
number
The focal length in mm, derived from fieldOfView and
imageWidth. When imageWidth is not set, 36 mm is used as
a fallback. Only meaningful for perspective cameras. Returns
1000 mm for parallel cameras.
Returns
Section titled “Returns”number
height
Section titled “height”Get Signature
Section titled “Get Signature”get height():
number
For parallel cameras, the distance along the direction vector that determines the zoom level. For perspective cameras, this is computed from the distance between eye and target and the field of view. Returned in inches.
Returns
Section titled “Returns”number
scale_2d
Section titled “scale_2d”Get Signature
Section titled “Get Signature”get scale_2d():
number
The 2D scale factor. Only meaningful for perspective2d
and parallel2d camera types. Returns 1.0 for others.
Returns
Section titled “Returns”number
target
Section titled “target”Get Signature
Section titled “Get Signature”get target():
Point3d
The point in the model the camera is aimed at.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get type():
CameraType
The camera projection type — perspective or parallel.
Use CameraTypeEnum values to compare.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get up():
Vector3d
The direction that appears “up” in the rendered view. Always perpendicular to the vector from eye to target.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get xAxis():
Vector3d
The camera’s right axis — a vector parallel to a line running left-to-right in screen coordinates.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get yAxis():
Vector3d
The camera’s up axis — a vector parallel to a line running bottom-to-top in screen coordinates.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get zAxis():
Vector3d
Same as direction. The normalized vector the camera is
looking along.
Returns
Section titled “Returns”Methods
Section titled “Methods”build()
Section titled “build()”build():
Readonly<CameraData>
Builds the camera data object to pass to view.setCamera().
Returns
Section titled “Returns”Readonly<CameraData>
toString()
Section titled “toString()”toString():
string
Returns
Section titled “Returns”string
withDescription()
Section titled “withDescription()”withDescription(
description):Camera
Returns a new camera with the given description
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Camera
SDK 2.35.0
withFieldOfView()
Section titled “withFieldOfView()”withFieldOfView(
fov):Camera
Returns a new camera with the horizontal field of view in degrees. Only applies to perspective cameras. Ignored with a warning for parallel. Clamped to the range 1–120 degrees.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
field of view in degrees |
Returns
Section titled “Returns”Camera
SDK 2.35.0
withFocalLength()
Section titled “withFocalLength()”withFocalLength(
focalLengthMM):Camera
Returns a new camera with the focal length in millimeters, adjusting the field of view accordingly. Only applies to perspective cameras. Clamped to 1–3000 mm.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
focal length in millimeters |
Returns
Section titled “Returns”Camera
SDK 2.35.0
withHeight()
Section titled “withHeight()”withHeight(
heightInches):Camera
Sets the height in inches for parallel cameras, controlling the zoom level. Only applies to parallel cameras. Ignored with a warning for perspective. Minimum value: 0.001 inches.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
height in inches |
Returns
Section titled “Returns”Camera
SDK 2.35.0
withImageWidth()
Section titled “withImageWidth()”withImageWidth(
imageWidth):Camera
Sets the image width in millimeters, used when computing focal length. Only applies to perspective cameras.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
image width in millimeters |
Returns
Section titled “Returns”Camera
SDK 2.35.0
withOrbit()
Section titled “withOrbit()”withOrbit(
radians):Camera
Returns a new camera with the eye horizontally around the target point, keeping the target fixed and the up vector unchanged.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
rotation angle in radians |
Returns
Section titled “Returns”Camera
SDK 2.35.0
withOrientation()
Section titled “withOrientation()”withOrientation(
eye,target,up):Camera
Returns a new camera with updated eye position, target, and up direction.
Accepts Point3d objects or [x, y, z] arrays for
convenience.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
camera position in 3D space |
|
|
|
point the camera is aimed at |
|
|
|
direction that appears “up” in the view |
Returns
Section titled “Returns”Camera
Throws
Section titled “Throws”if eye and target are the same point, or the up vector is parallel to the view direction
SDK 2.35.0
withPerspective()
Section titled “withPerspective()”withPerspective(
perspective):Camera
Returns a new camera that has either perspective (true) or parallel (false)
projection. The camera position and direction are preserved.
Only the projection type changes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
|
Returns
Section titled “Returns”Camera
SDK 2.35.0
withTransform()
Section titled “withTransform()”withTransform(
transform):Camera
Returns a new camera with a transformation to the camera’s eye, target, and up vector. Useful for aligning the camera to a component’s axes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”Camera
SDK 2.35.0
withVerticalOrbit()
Section titled “withVerticalOrbit()”withVerticalOrbit(
angle):Camera
Returns a new camera after rotating the eye vertically around the target point — tilts the camera up or down while keeping the target fixed.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
rotation angle in radians |
Returns
Section titled “Returns”Camera
SDK 2.35.0
default()
Section titled “default()”
staticdefault():Camera
Creates a camera with defaults: perspective projection, 30° field of view, looking down the negative Y axis.
Returns
Section titled “Returns”Camera
Deprecated
Section titled “Deprecated”orbit()
Section titled “orbit()”orbit(
radians):this
Rotates the eye horizontally around the target point, keeping the target fixed and the up vector unchanged.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
rotation angle in radians |
Returns
Section titled “Returns”this
orbitVertical()
Section titled “orbitVertical()”orbitVertical(
angle):this
Rotates the eye vertically around the target point — tilts the camera up or down while keeping the target fixed.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
rotation angle in radians |
Returns
Section titled “Returns”this
setDescription()
Section titled “setDescription()”setDescription(
description):this
Sets an optional description for this camera.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”this
setFieldOfView()
Section titled “setFieldOfView()”setFieldOfView(
fov):this
Sets the horizontal field of view in degrees. Only applies to perspective cameras. Ignored with a warning for parallel. Clamped to the range 1–120 degrees.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
field of view in degrees |
Returns
Section titled “Returns”this
setFocalLength()
Section titled “setFocalLength()”setFocalLength(
focalLengthMM):this
Sets the focal length in millimeters, adjusting the field of view accordingly. Only applies to perspective cameras. Clamped to 1–3000 mm.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
focal length in millimeters |
Returns
Section titled “Returns”this
setHeight()
Section titled “setHeight()”setHeight(
heightInches):this
Sets the height in inches for parallel cameras, controlling the zoom level. Only applies to parallel cameras. Ignored with a warning for perspective. Minimum value: 0.001 inches.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
height in inches |
Returns
Section titled “Returns”this
setImageWidth()
Section titled “setImageWidth()”setImageWidth(
imageWidth):this
Sets the image width in millimeters, used when computing focal length. Only applies to perspective cameras.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
image width in millimeters |
Returns
Section titled “Returns”this
setOrientation()
Section titled “setOrientation()”setOrientation(
eye,target,up):this
Sets the camera’s eye position, target, and up direction.
Accepts Point3d objects or [x, y, z] arrays for
convenience.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
camera position in 3D space |
|
|
|
point the camera is aimed at |
|
|
|
direction that appears “up” in the view |
Returns
Section titled “Returns”this
Throws
Section titled “Throws”if eye and target are the same point, or the up vector is parallel to the view direction
setPerspective()
Section titled “setPerspective()”setPerspective(
perspective):this
Switches between perspective (true) and parallel (false)
projection. The camera position and direction are preserved.
Only the projection type changes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
|
Returns
Section titled “Returns”this
transform()
Section titled “transform()”transform(
transform):this
Applies a transformation to the camera’s eye, target, and up vector. Useful for aligning the camera to a component’s axes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”this