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.
SwitchEffectCanceled 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');
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.
Captures a screenshot of the current screen.
Data URL promise containing the image in data:image/png
format.
Starts video recording of the canvas.
Optional
options: { Parameters that specify the format of recorded videos
Optional
mimeA MIME type specifying the format for the resulting video, such as video/webm
or video/mp4
. Corresponds to the MIME type used by Blobobjects and MediaRecorderfrom the MediaStream Recording API. Note that video/mp4
may not be supported in all browsers.
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.
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.
Informs DeepAR that the specified touch event occurred.
Touch event information.
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.
Initialize foot tracking.
Foot tracking is usually lazy loaded on demand when filter loaded with switchEffect requires it.
But this method will start loading the foot tracking immediately.
To start initializing foot tracking as soon as possible pass "footInit" hint in the initialize function (see DeepARParams).
If the foot tracking is already initialized it will do nothing. To check if foot tracking is initialized call isFootTrackingInitialized or wait onFootTrackingInitialized callback.
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.
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.
Generated using TypeDoc
Main class for interacting with DeepAR SDK. To get a DeepAR object call initialize.