CameraModule
ClassProvides access to the SPECS cameras.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- 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
Exposes user data
Provides access to the SPECS cameras.
Index
Properties
Methods
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
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
createCameraRequest()
staticcreateCameraRequest():CameraRequest
Exposes user dataSPECS
Creates a camera request object.
Returns
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
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
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
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()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
requestCamera()
requestCamera(
request):Texture
Exposes user dataSPECS
Returns a Texture whose provider is CameraTextureProvider which provides images from the requested camera ID.
Parameters
| Parameter | Type |
|---|---|
request | CameraRequest |
Returns
See also
Camera Module guide.
Nested types
Enumerations
| Enumeration | Description |
|---|---|
| CameraFacing | Which way a camera faces, reported on CameraModule.CameraInfo#facing. |
| CameraId | A handle to specify which camera on the Spectacles to request from. Used with CameraModule.createCameraRequest. |
| CameraLocation | Camera position on the device, reported on CameraModule.CameraInfo#location. |
| CameraType | Camera sensor type, reported on CameraModule.CameraInfo#type. |
| ConfigKey | Typed 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. |
| ImageFormat | Image format for camera image data. Growable — new formats may be added in future versions. Stream descriptors report which formats each stream supports. |
| MetadataKey | Typed keys for querying per-frame metadata. |
| Operation | Which session a stream capability works with, reported by CameraModule.StreamInfo#operation. |
| Quality | Processing quality tier of a stream configuration. Reported on stream descriptors. |
| Result | Result codes from camera session operations. |
| StreamStatus | Session lifecycle status delivered via onStatusChanged event. |
Classes
| Class | Description |
|---|---|
| CameraInfo | A physical camera on SPECS, returned by CameraModule#getCameras. |
| CameraRequest | An object that is used to request the desired camera ID. It should be passed to the CameraModule to get back a camera texture. |
| CaptureSession | Still-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. |
| Frame | A camera image, delivered by CameraModule.StreamingSession#onNewFrame or returned by CameraModule.CaptureSession#capture. |
| StreamConfig | Stream configuration for creating a camera session. |
| StreamConfigOverrides | Per-shot overrides for CameraModule.CaptureSession#capture. |
| StreamInfo | Describes one stream capability of a camera (read-only). |
| StreamingSession | Continuous-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. |