Skip to main content

DeviceCamera

Class

Provides information about the device's camera.

  • 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.

Since Lens Scripting v148

Index

Example

print(global.deviceInfoSystem.getTrackingCamera().principalPoint);

Extends

Properties

focalLength

readonly focalLength: vec2

Provides the focal length of the device camera in pixels.

Since

Lens Scripting Version 148


pose

readonly pose: mat4

Provides the relative offset between a reference point on the device and the camera. On mobile, the reference point is same as the camera, so this transform is identity.

On Spectacles, the reference point is the device center and the transform converts points in camera space to points relative to device center. Together with pose from DeviceTracking, you can obtain the world positions of points in device camera space.

For example,

// @input SceneObject objectWithDeviceTracking

// Get device camera
const deviceCamera = global.deviceInfoSystem.getTrackingCamera();
// calculate 3d position in device camera space (using your custom code which uses snapml or a similar technique)
const pointInDeviceCamera = ...; // vec3
const pointInDeviceRef = deviceCamera.pose.multiplyPoint(pointInDeviceCamera);

const deviceWorldTransform = script.objectWithDeviceTracking.getTransform().getWorldTransform();
const pointInWorld = deviceWorldTransform.multiplyPoint(pointInDeviceRef);
// Use pointInWorld. For example, place a {@link SceneObject} at this world position

Since

Lens Scripting Version 148


principalPoint

readonly principalPoint: vec2

Provides the principal point of the device camera in pixels with origin at the center of the top-left pixel. Note: Principal point is typically in the center of the image, but it may not always be the case.

Since

Lens Scripting Version 148


resolution

readonly resolution: vec2

Provides the default resolution of the image returned by the device camera in pixels. The principal point and focal length are calculated relative to this resolution. If you resize the image to a different resolution than the default, then you also need to update the principal points and focal length appropriately.

Since

Lens Scripting Version 148

Methods

getTypeName()

static getTypeName(): TypeName<DeviceCamera>

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<DeviceCamera>

Since

Lens Scripting Version 148

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

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

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.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

ScriptObject.isSame


project()

project(pointInDeviceReferenceNode): vec2

Given a point in device reference space, first converts the point to 3d camera space, using extrinsics, and then projects it to produce a point in normalized screen space (origin at top left).

Parameters

ParameterType
pointInDeviceReferenceNodevec3

Returns

vec2

Since

Lens Scripting Version 272


unproject()

unproject(normalizedScreenSpacePoint, absoluteDepth): vec3

Unprojects the normalized screen space point normalizedScreenSpacePoint based on some distance absoluteDepth to produce a 3d position in device reference space. On Spectacles, this means that the returned position already includes the offset between the device center and the camera.

Parameters

ParameterType
normalizedScreenSpacePointvec2
absoluteDepthnumber

Returns

vec3

Since

Lens Scripting Version 148