Skip to main content

CameraModule

Class

Provides access to the SPECS cameras.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
1 platform note
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
    • Restricted when the Lens uses internet-connected APIs (see Privacy Restrictions).
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported. Restricted when the Lens uses internet-connected APIs (see Privacy Restrictions)

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Exposes user data

Provides access to the SPECS cameras.

Index

Remarks

Find a camera with CameraModule#getCameras, stream its frames with a CameraModule.StreamingSession, and take still images with a CameraModule.CaptureSession. Session frames do not carry camera intrinsics or extrinsics yet, so Lenses that project 3D points keep using requestCamera with DeviceCamera.

Example

The API is camera-first: pick a camera from CameraModule#getCameras, one of its stream capabilities from CameraModule.CameraInfo#getStreams, and receive frames from a session (see CameraModule#createStreamingSession and CameraModule.Frame):

//@input Component.MeshVisual mesh

let cameraModule = require('LensStudio:CameraModule');
let session = cameraModule.createStreamingSession();

session.onNewFrame.add(function (frame) {
if (frame.texture) script.mesh.mainPass.baseTex = frame.texture;
});

// Select the largest streaming capability on the RGB camera.
let rgb = cameraModule.getCameras().find(function (c) { return c.type == CameraModule.CameraType.Rgb; });
let stream = rgb && rgb.getStreams().find(function (s) {
return s.operation == CameraModule.Operation.Streaming;
});
if (stream) {
let config = new CameraModule.StreamConfig();
config.stream = stream;
config.minFrameRate = 15; // the camera may run faster, up to maxFrameRate
if (session.start(config) != CameraModule.Result.Success) print('Failed to start');
}

Extends

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

createCameraRequest()

static createCameraRequest(): CameraRequest

Exposes user dataSPECS

Creates a camera request object.

Returns

CameraRequest


createCaptureSession()

createCaptureSession(): CaptureSession

Exposes user dataSPECS

SPECS: Create a still-capture session. The capture pipeline is pre-warmed in CameraModule.CaptureSession#start; trigger individual captures with CameraModule.CaptureSession#capture which returns a Promise that resolves with the captured Frame. On device, throws an Error when the camera client cannot be created.

Returns

CaptureSession

A new capture session.

Since

Lens Scripting Version 368


createStreamingSession()

createStreamingSession(): StreamingSession

Exposes user dataSPECS

SPECS: Create a streaming camera session for continuous frame delivery. Configure with a CameraModule.StreamConfig and start with CameraModule.StreamingSession#start. Sessions are restartable; call CameraModule.StreamingSession#stop to release the camera. On device, throws an Error when the camera client cannot be created.

Returns

StreamingSession

A new streaming session.

Since

Lens Scripting Version 368


getCameras()

getCameras(): CameraInfo[]

Exposes user dataSPECS

SPECS: Enumerate the physical cameras. Pick one by type, location or facing, then choose one of its stream capabilities with CameraModule.CameraInfo#getStreams. Returns an empty array off device (for example in Lens Studio Preview). On device, throws an Error when the camera client cannot be created or camera discovery fails.

Returns

CameraInfo[]

Array of cameras.

Since

Lens Scripting Version 387

Example

let cameraModule = require('LensStudio:CameraModule');
cameraModule.getCameras().forEach(function (camera) {
print(camera.name);
});

getSupportedImageResolutions()

getSupportedImageResolutions(): vec2[]

Exposes user dataSPECS

Get the list of resolutions this hardware camera can provide.

Returns

vec2[]


getTypeName()

static getTypeName(): TypeName<CameraModule>

Exposes user dataSPECS

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

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

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

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

Asset.isSame


requestCamera()

requestCamera(request): Texture

Exposes user dataSPECS

Returns a Texture whose provider is CameraTextureProvider which provides images from the requested camera ID.

Parameters

ParameterType
requestCameraRequest

Returns

Texture

See also

Camera Module guide.

Nested types

Enumerations

EnumerationDescription
CameraFacingWhich way a camera faces, reported on CameraModule.CameraInfo#facing.
CameraIdA handle to specify which camera on the Spectacles to request from. Used with CameraModule.createCameraRequest.
CameraLocationCamera position on the device, reported on CameraModule.CameraInfo#location.
CameraTypeCamera sensor type, reported on CameraModule.CameraInfo#type.
ConfigKeyTyped keys for camera tuning parameters. AutoExposureRegion may be set on a CameraModule.StreamConfig before CameraModule.StreamingSession#start and changed mid-stream via CameraModule.StreamingSession#setConfig. It has no effect on capture sessions. SnapshotMfnrEnable only applies to snapshots: set it on the CameraModule.StreamConfig passed to CameraModule.CaptureSession#start.
ImageFormatImage format for camera image data. Growable — new formats may be added in future versions. Stream descriptors report which formats each stream supports.
MetadataKeyTyped keys for querying per-frame metadata.
OperationWhich session a stream capability works with, reported by CameraModule.StreamInfo#operation.
QualityProcessing quality tier of a stream configuration. Reported on stream descriptors.
ResultResult codes from camera session operations.
StreamStatusSession lifecycle status delivered via onStatusChanged event.

Classes

ClassDescription
CameraInfoA physical camera on SPECS, returned by CameraModule#getCameras.
CameraRequestAn object that is used to request the desired camera ID. It should be passed to the CameraModule to get back a camera texture.
CaptureSessionStill-capture camera session for SPECS. Created via CameraModule#createCaptureSession. After CameraModule.CaptureSession#start pre-warms the pipeline, individual snapshots are triggered with CameraModule.CaptureSession#capture, which returns a Promise that resolves with the captured Frame.
FrameA camera image, delivered by CameraModule.StreamingSession#onNewFrame or returned by CameraModule.CaptureSession#capture.
StreamConfigStream configuration for creating a camera session.
StreamConfigOverridesPer-shot overrides for CameraModule.CaptureSession#capture.
StreamInfoDescribes one stream capability of a camera (read-only).
StreamingSessionContinuous-frame camera session for SPECS. Created via CameraModule#createStreamingSession. After CameraModule.StreamingSession#start, frames are delivered via CameraModule.StreamingSession#onNewFrame until CameraModule.StreamingSession#stop is called.