Callbacks property is used to add/remove/change callbacks called by the DeepAR SDK. See list of all callbacks at DeepARCallbacks.
Example: To add/change certain callback:
let deepAR = deepar.initialize({...});
deepAR.callbacks.onFaceVisibilityChanged = () => {
// do something
};
To remove certain callback:
deepAR.callbacks.onFaceTracked = undefined;
Scripting API property used to access all the scripting interop methods.
let scriptingVariable = deepAR.ScriptingAPI.getStringVar('variableName');
Switch the AR effect for preview.
A path (URL) to the AR effect file or an ArrayBuffer object of an already fetched AR effect file.
Optional
effectOptions: { Effect options.
Optional
slot?: stringDefault value is "DEFAULT_SLOT" if slot is not given. Slot is a container for a given AR effect. When replacing the already loaded AR effect, call switchEffect with that same slot. To remove AR effect entirely, call clearEffect with the same slot.
Optional
face?: numberIf AR effect is face filter, select to which face to attach it to. The value should be between 0 and 3. Default value is 0.
Optional
envmap?: string | ArrayBufferLikeOptional
diamondSwitchEffectCanceled If the switch effect is canceled by something.
// Switch filter 1.
await deepAR.switchEffect('url/path/to/filter1');
// Later switch fo filter 2.
await deepAR.switchEffect('url/path/to/filter2');
// Remove the current filter.
deepAR.clearEffect();
// Put two filters at the same time.
await deepAR.switchEffect('url/path/to/backgroundReplacement', {slot: 'background'});
await deepAR.switchEffect('url/path/to/glasses', {slot: 'faceMask'});
// Replace the glasses filter.
await deepAR.switchEffect('url/path/to/glasses2', {slot: 'faceMask'});
// Remove those filters.
deepAR.clearEffect('background');
deepAR.clearEffect('faceMask');
// Load filters for two people.
await deepAR.switchEffect('url/path/to/faceMask1', {face: 0, slot: 'mask1'});
await deepAR.switchEffect('url/path/to/faceMask2', {face: 1, slot: 'mask2'});
// Clear effect for the second person.
deepAR.clearEffect('mask2');
Captures a screenshot of the current screen.
Data URL promise containing the image in data:image/png
format.
Start video recording of the DeepAR preview.
To stop video recording call finishVideoRecording. By default, the audio is not recorded. To record audio set the recordAudio parameter. Note that if the user did not give the microphone permission, the recording will not start until the permission is granted. If permission is denied, the function will throw. The recorded video will be mp4 on all browsers except Firefox where it will be webm. Audio recording is currently not available on Android.
Optional
options: { Parameters that specify the format of recorded videos
Optional
recordIf set, microphone sound will be recorded as well. If this parameter is set, options.audioTrack is ignored.
Optional
audioIf passed, this audio track is going to be recorded.
Optional
audioSets audio bit rate. By default 128000.
Optional
audioSet audio sample rate. On firefox it is 48k. On other browsers defaults to audioTrack.getCapabilities().sampleRate.max or to the value passed here.
Optional
videoSets video bit rate. By default 4000000.
Optional
videoSets video frame rate. By default 30.
Enable background blur.
Background blur is usually used in video calling use cases.
Boolean indicating whether to enable or disable the background blur effect.
Blur strength. Integer number in range 1-10.
Enable background replacement (also known as background removal or green screen effect).
Boolean indicating whether to enable or disable the background replacement effect.
The URL of the image to be used as the background.
Request mode used while fetching the image.
Starts the camera preview. By default, the camera will be user facing. The returned promise will resolve after the camera starts or it will reject if camera permission was denied.
Optional
cameraOptions: { Camera options.
Optional
mirror?: booleanMirror the camera horizontally. True by default.
Optional
mediaOptions passed to MediaDevices.getUserMedia(). The default is the user facing camera.
Optional
cameraCallback called when camera permission is asked.
Optional
cameraCallback called when camera permission is granted.
Stops the camera preview or custom video preview set by setVideoElement.
Used to pass the HTMLVideoElement to the DeepAR SDK. The SDK will use this video as camera source. This method should be used instead of startCamera when you want to handle getUserMedia outside the SDK or you need to apply the masks to any video stream. To disable automatic camera preview by DeepAR:
const deepAR = deepar.initialize({
// ...
additionalOptions: {
cameraConfig: {
disableDefaultCamera: true
}
}
});
Video element.
Mirror the video horizontally.
Shutdown the DeepAR SDK and release all resources associated with it. It is invalid to call any function from this DeepAR object after shutdown. After shutdown call, it is possible to call initialize again.
Feed RGBA image to DeepAR as input instead of camera or video. Used for processing single image. Can be used instead of startCamera or setVideoElement. Can be called in a loop.
Image.
Width of the image.
Height of the image.
Mirror frame horizontally.
If you want to apply DeepAR processing on a single image instead of a camera stream use this method. Can be used instead of startCamera or setVideoElement. See example usage here.
Changes a node or component bool parameter of the currently loaded effect. For more details about changeParameter API read our docs here.
The name of the node from DeepAR Studio. If multiple nodes share the same name, only the first one will be affected.
The name of the component. If the name of the component is null or an empty string, the node itself will be affected.
The name of the parameter.
New parameter value.
Changes a node or component float parameter of the currently loaded effect. For more details about changeParameter API read our docs here.
The name of the node from DeepAR Studio. If multiple nodes share the same name, only the first one will be affected.
The name of the component. If the name of the component is null or an empty string, the node itself will be affected.
The name of the parameter.
New parameter value.
Changes a node or component vector parameter of the currently loaded effect. For more details about changeParameter API read our docs here.
The name of the node from DeepAR Studio. If multiple nodes share the same name, only the first one will be affected.
The name of the component. If the name of the component is null or an empty string, the node itself will be affected.
The name of the parameter.
X component of the new parameter vector.
Y component of the new parameter vector.
Z component of the new parameter vector.
W component of the new parameter vector.
Changes a node or component texture parameter of the currently loaded effect. For more details about changeParameter API read our docs here.
The name of the node from DeepAR Studio. If multiple nodes share the same name, only the first one will be affected.
The name of the component. If the name of the component is null or an empty string, the node itself will be affected.
The name of the parameter.
Url of the image that is going to be used as texture.
Request mode used while fetching the texture.
This method allows the user to fire a custom animation trigger for model animations from code. To fire a custom trigger, the trigger string must match the custom trigger set in the Studio when creating the effect. Read more here.
The name of the trigger.
Enable/disable forced rendering on the canvas. It is useful to enable offscreen rendering in scenarios when the browser
does not call requestAnimationFrame() function. DeepAR internally uses requestAnimationFrame() for the rendering loop.
For example, when the browser tab is not focused, the browser will not call requestAnimationFrame() and DeepAR will not
render. If offscreen rendering is enabled, DeepAR will use its internal timer for the rendering loop. Note that offscreen
rendering enabled will not have as good results in terms of FPS compared to offscreen rendering disabled.
If you need to use offscreen rendering. The best practice is to enable it only when needed - like when the browser tab is not focused. Otherwise, it is best to always disable offscreen rendering.
True - DeepAR will use its internal timer for the rendering loop. Rendering will work even when tab is not focused. False - DeepAR will use requestAnimationFrame() for the rendering loop.
Retrieves the HTML canvas element used for AR preview.
The returned canvas is used for DeepAR rendering of camera preview and AR filters. Most commonly canvas is needed when you want to do some postprocessing on it or feed it into some video calling library.
The HTML canvas element.
Initialize segmentation.
Segmentation is usually lazy loaded on demand when filter loaded with switchEffect requires it.
But this method will start loading the segmentation immediately.
To start initializing segmentation as soon as possible pass "segmentationInit" hint in the initialize function (see DeepARParams).
If the segmentation is already initialized it will do nothing. To check if segmentation is initialized call isSegmentationInitialized or wait onSegmentationInitialized callback.
Moves the selected game object from its current position in a tree and sets it as a direct child of a target game object. This is equivalent to moving around a node in the node hierarchy in the DeepAR Studio.
Node to move.
New node parent.
Informs DeepAR that the specified touch event occurred.
Touch event information.
Since version 5.4.0 DeepAR will automatically register touch events from canvas. There is no need to call this function anymore.
Gets the closest point on a mesh to a given point.
The name of the parent node of the mesh.
The point in the same space as a mesh.
closest point on the mesh to the given point.
Sets a new environment map
Sets a new environment map that will be used for rendering materials with new PBR glTF shader. If an effect file using the new PBR glTF shader is currently active, function changes the environment map to the one provided. Otherwise, it is going to override the one passed in with the effect file.
Path to fetch or ArrayBuffer with an image.
Sets tone mapping
Sets tone mapping. Value passed here will override value specified within an effect file. See here for more details about tone mapping functions: https://modelviewer.dev/examples/tone-mapping
tone mapping function
Gets currently active tone mapping function.
currently active tone mapping or undefined otherwise.
Sets new environment map that will be used for rendering materials with diamond shader.
Overrides environment map specified within an effect file.
Path to fetch or ArrayBuffer with an image.
Generated using TypeDoc
Main class for interacting with DeepAR SDK. To get a DeepAR object call initialize.