Skip to main content

Camera

Class

Renders SceneObjects to one or more Render Target textures.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Index

Remarks

A Camera will only render a SceneObject if its render layer is enabled on the Camera.

Extends

Properties

aspect

aspect: number

The aspect ratio of the camera (width/height).

Default Value

1

clearColor

clearColor: vec4

When enableClearColor is true and inputTexture is null, this color is used to clear this Camera's renderTarget before drawing to it.

Default Value

(0, 0, 0, 1)

colorRenderTargets

colorRenderTargets: ColorRenderTarget[]

Returns an array of Color Render Targets. The first color render target is always available.

Since

Lens Scripting Version 141

Default Value

[]

depthBufferMode

depthBufferMode: DepthBufferMode

Determines the way depth is handled on this Camera. Changing this can help sort objects at different distance ranges.

Default Value

Camera.DepthBufferMode.Regular

depthStencilRenderTarget

depthStencilRenderTarget: DepthStencilRenderTarget

Descriptor of depth/stencil textures and clear options.

Since

Lens Scripting Version 152


devicePropertiesSource

devicePropertiesSource: TextureTrackingScope

The Texture this Camera will be used to render content onto, and will be used to configure device properties which are set to physical. When unset it is assumed to be the DeviceCameraTexture. Relevant for cases where TextureTrackingScope will be used with 3D content like Face Mesh which will need the save fov used for the Camera.

Since

Lens Scripting Version 309

Default Value

null

devicePropertyUsage

devicePropertyUsage: DeviceProperty

Controls which Camera settings will be overridden by physical device properties. For example, this can be used to override the fov property to match the device camera's actual field of view.

Default Value

Camera.DeviceProperty.All

enableClearDepth

enableClearDepth: boolean

If enabled, this Camera will clear the depth buffer on its renderTarget before drawing to it.

Default Value

false

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

Component.enabled


far

far: number

The distance of the far clipping plane.

Default Value

100

fov

fov: number

The Camera's field of view in radians.

Default Value

1

inputTexture

inputTexture: Texture

When enableClearColor is true, this texture is used to clear this Camera's renderTarget before drawing. If this texture is null, clearColor will be used instead.

Default Value

null

isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

Inherited from

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

Component.isEnabledInHierarchy


maskTexture

maskTexture: Texture

A texture controlling which parts of the output texture the camera will draw to. The "red" value of each pixel determines how strongly the camera will draw to that part of the image. For example, a completely black section will cause the camera to not draw there at all. A completely white (or red) section will cause the camera to draw normally. Colors in between, like gray, will be semitransparent.

Default Value

null

near

near: number

The distance of the near clipping plane.

Default Value

1

rayTracing

rayTracing: RayTracingSettings

Toggles ray tracing for the camera. When true, ray tracing is enabled.

Default Value

null

renderLayer

renderLayer: LayerSet

Controls the set of layers this Camera will render.

Default Value

LayerSet.all()

renderOrder

renderOrder: number

The sorting order the Camera renders in. Every frame, Cameras render in ascending order determined by their renderOrder properties.

Default Value

0

renderTarget

renderTarget: Texture

The RenderTarget this Camera will draw to.

Default Value

null

renderTargetCubemapFace

renderTargetCubemapFace: CubemapFace

Sets which face of the cubemap this camera will render to.

Since

Lens Scripting Version 194

Default Value

Camera.CubemapFace.PositiveX

renderTargetMipmapLevel

renderTargetMipmapLevel: number

Sets the mipmap level for the camera's render target.

Since

Lens Scripting Version 340

Default Value

0

renderTargetSlice

renderTargetSlice: number

Sets the slice index for the camera's render target.

Since

Lens Scripting Version 340

Default Value

0

sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


size

size: number

The orthographic size of the camera.

Default Value

10

type

type: Type

Controls which type of rendering the camera uses.

Default Value

Camera.Type.Perspective

uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier

Methods

createColorRenderTarget()

static createColorRenderTarget(): ColorRenderTarget

Creates and returns a new Color Render Target.

Returns

ColorRenderTarget

Since

Lens Scripting Version 141


createDepthStencilRenderTarget()

static createDepthStencilRenderTarget(): DepthStencilRenderTarget

Create a depth/stencil render target descriptor for the camera.

Returns

DepthStencilRenderTarget

Since

Lens Scripting Version 152


depthStencilRenderTargetSupported()

static depthStencilRenderTargetSupported(): boolean

Return true if the device supports stencil operations and render to depth texture.

Returns

boolean

Since

Lens Scripting Version 152


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

Component.destroy


getOrthographicSize()

getOrthographicSize(): vec2

For orthographic cameras, returns the camera size as (width, height).

Returns

vec2


getProjectionMatrix()

getProjectionMatrix(): mat4

Returns the projection matrix for this camera.

Returns

mat4

Since

Lens Scripting Version 340


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getSupportedColorRenderTargetCount()

static getSupportedColorRenderTargetCount(): number

Returns the number of possible render target bindings to the camera.

Returns

number

Since

Lens Scripting Version 152


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): TypeName<Camera>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<Camera>

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.getTypeName


getViewMatrix()

getViewMatrix(): mat4

Returns the view matrix for this camera.

Returns

mat4

Since

Lens Scripting Version 340


getViewProjectionMatrix()

getViewProjectionMatrix(): mat4

Returns the combined view and projection matrix for this camera.

Returns

mat4

Since

Lens Scripting Version 340


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Component.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Component.isSame


isSphereVisible()

isSphereVisible(center, radius): boolean

Returns true if a sphere with the specified world space center position and radius is visible within the camera frustum, false otherwise.

Parameters

ParameterType
centervec3
radiusnumber

Returns

boolean


project()

project(worldSpacePoint): vec3

Converts a world space position to a raw screen space position. The screen space position will be returned as a vec3 with x,y representing normalized screen space, and z representing a raw depth value not directly convertible to world units. This returned value will mostly be useful for passing into unproject().

Parameters

ParameterType
worldSpacePointvec3

Returns

vec3


screenSpaceToWorldSpace()

screenSpaceToWorldSpace(normalizedScreenSpacePoint, absoluteDepth): vec3

Converts a screen space position to a world space position, given an absolute depth. The screen space position should be provided as a vec2 in the range ([0-1], [0-1]), (0,0) being the top-left of the screen and (1,1) being the bottom-right. The returned world space position will be the point absoluteDepth units away from the Camera's near plane at the point specified in screen space.

Parameters

ParameterType
normalizedScreenSpacePointvec2
absoluteDepthnumber

Returns

vec3


unproject()

unproject(clipSpacePoint): vec3

Converts a raw screen space position to a world space position. clipSpacePoint should be a vec3 returned from a previous project() call, since the z value represents a raw depth value not directly convertible to world units.

Parameters

ParameterType
clipSpacePointvec3

Returns

vec3


worldSpaceToScreenSpace()

worldSpaceToScreenSpace(worldSpacePoint): vec2

Converts the world space position worldSpacePoint to a screen space position. Screen positions are represented in the range ([0-1], [0-1]), (0,0) being the top-left of the screen and (1,1) being the bottom-right.

Parameters

ParameterType
worldSpacePointvec3

Returns

vec2

See also

Camera and Layers guide.

Nested types

Enumerations

EnumerationDescription
CubemapFaceDifferent faces of the cubemap that a camera can render into.
DepthBufferModeUsed in Camera's depthBufferMode property. Each mode is suited for handling objects at a certain distance range. For more information on depth modes, see the Camera and Layers guide.
DevicePropertyUsed in Camera's devicePropertyUsage property. Specifies which camera properties should be overridden by device properties.
TypeReturned from Camera's type property.

Classes

ClassDescription
BaseRenderTargetThe base class from which ColorRenderTarget and DepthStencilRenderTarget are derived from
ColorRenderTargetColor based RenderTarget.
DepthStencilRenderTargetThis class inherits from the BaseRenderTarget class. BaseRenderTarget class is not available for creation and is used like the base class for DepthStencilRenderTarget class to provide access to targetTexture, inputTexture and maskTexture properties.