Scripting API
Scripting API Overview

Scripting API

The following is a description of all scripting modules.

AnimationModule

The AnimationModule class implements object animation.

Classes

ClassDescription
AnimationClipThe AnimationClip class describes an animation clip asset.
AnimationClipsThe AnimationClips class allows access to animation clips.
AnimationPlaybackControllerThe AnimationPlaybackController class describes an animation playback controller asset.
AnimationPlaybackControllersThe AnimationPlaybackControllers class allows access to animation playback controllers.
ArrayOfScalarSamplersThe ArrayOfScalarSamplers class describes an array of scalar samplers.
It extends the implementation of Array<ScalarSampler> type in JavaScript,
and adds a single additional method to get a sampler at a particular index - get().
ArrayOfScalarSignalsThe ArrayOfScalarSignals class describes an array of scalar signals.
It extends the implementation of Array<ScalarSignal> type in JavaScript,
and adds a single additional method to get a sampler at a particular index - get().
ColorSamplerThe ColorSampler class encapsulates a color sampler.
DriverThe Driver class represents an animation driver, a class that can drive an animation using a sampler and time, value or other means.
All animation drivers extend this base class and it's used to represent any animation driver in all APIs.
RotationSamplerThe RotationSampler class is an animation sampler for object rotation.
SamplerFactoryThe SamplerFactory class creates different types of animation samplers.
ScalarSamplerThe ScalarSampler class encapsulates a scalar value sampler.
TimeDriverThe TimeDriver class allows driving an animation sampler using time.
ValueDriverThe ValueDriver class allows driving an animation sampler using raw values.

AudioModule

The AudioModule class enables sound effects.

Classes

ClassDescription
PlaybackControllerEnables control of audio playback.
Ensure that the Audio Playback Controller in the Spark AR Studio project has a supported audio file assigned.

BlocksModule

The BlocksModule class provides methods for interacting with the Blocks in your effect.

Classes

ClassDescription
BlockAssetThis class represents a single Block Asset.
BlockAssetsThis class allows access to the Block Assets.

BodyTrackingModule

The BodyTrackingModule class allows you to track the body and get Body details.

Classes

ClassDescription
BodyThe Body class exposes details of a tracked body.
Body2DArmRepresents a tracked arm in the body.
Body2DLegRepresents a tracked leg in the body.
Body2DPoseThe Body2DPose class exposes details of a tracked body's 2d key points.
Body2DTorsoRepresents a tracked torso in the body.
KeyPoint2DRepresents a single tracked 2d key point in the scene.

CameraInfoModule

The CameraInfoModule class provides access to details about the device camera.

Enums

EnumDescription
CameraPositionThe CameraPosition enum describes the direction the camera is facing.

DeepLinkModule

The DeepLinkModule class exposes methods and properties to read the values that an external app sent to an effect.

DeviceMotionModule

The DeviceMotionModule class enables device movement detection.

DiagnosticsModule

The DiagnosticsModule class enables diagnostic logging.

Classes

ClassDescription
TypeSystemMetadataThe TypeSystemMetadata class contains type system metadata.

FaceGesturesModule

Enables detection of various facial gestures for a given Face object.
Use of the FaceGestures module also requires the FaceTracking module to be imported.

FaceTracking2DModule

Enables the tracking of faces in two-dimensional space.
Importing this module automatically enables the *Face Tracking* capability within the project's *Properties*.

For three-dimensional face tracking, see the FaceTracking module.

Classes

ClassDescription
Face2DExposes details of a two-dimensionally tracked face.
For three-dimensional tracking to key points on a detected face, see the Face class instead.

FaceTrackingModule

Enables the tracking of faces in three-dimensional space and exposes classes that describe key points of a detected face.
Importing this module automatically enables the *Face Tracking* capability within the project's *Properties*.

For two-dimensional face tracking, see the FaceTracking2D module.

Classes

ClassDescription
CheekExposes key points of the cheek of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
ChinExposes key points of the chin of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
EyeExposes details and key points of the eye of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
EyebrowExposes key points of the eyebrow of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
FaceExposes details and key points of a three-dimensionally tracked face.
ForeheadExposes key points of the forehead of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
MouthExposes details and key points of the mouth of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.
NoseExposes key points of the nose of a detected Face object.
Key points are returned in the detected face's local coordinate system. Use Face.cameraTransform.applyToPoint() to convert the point to the camera's coordinate system.

FontsModule

The FontsModule class is used for working with custom fonts in effects.

Classes

ClassDescription
FontIdThe FontsId class identifies a font in an effect.

HandTrackingModule

Enables the tracking of hands. Up to two hands can be tracked in the camera view.
References to detected Hand objects are not persistent. The same index argument passed to HandTrackingModule.hand() may refer to different Hand objects if a hand that was previously tracked has lost tracking.

Importing this module automatically enables the *Hand Tracking* capability within the project's *Properties*.

Classes

ClassDescription
HandExposes details of a tracked hand.

InstantGamingModule

The InstantGamingModule class.

InstructionModule

The InstructionModule class enables effects to provide instructions to the user.

IrisTrackingModule

The IrisTrackingModule class allows you to track the location of people's irises in your effect, to create effects such as eye color replacement.

Classes

ClassDescription
EyeballThe Eyeball class exposes details of a tracked eyeball.

LightingEstimationModule

The LightingEstimation module encapsulates access to estimations of lighting in the scene.

LiveStreamingModule

The LiveStreamingModule class enables to retrieve information from a live stream from within the effect, such as reactions and comments.

Classes

ClassDescription
LiveStreamingCommentsThe LiveStreamingComments class provides access to the Facebook Live comments stream.
LiveStreamingReactions

Enums

EnumDescription
StateThe LiveStreamingModule.State enum describes the state of a live stream.
@

LocaleModule

The LocaleModule class encapsulates access to the locale identifier of the device.

MaterialsModule

The Materials module provides access to the materials in an effect.

Classes

ClassDescription
BlendedMaterialThe BlendedMaterial class encapsulates materials blended from multiple textures.
BlendShapeToWarpMapMaterialThe BlendShapeToWarpMapMaterial class is the JS-side representation of the "Face Warp Material" in Spark AR Studio, used to create face warp effects.
ColorPaintMaterialThe ColorPaintMaterial class encapsulates a face-paint material.
ComposedMaterialThe ComposedMaterial class encapsulates patch asset materials.
DefaultMaterialThe DefaultMaterial class encapsulates an image-based material.
MaterialBaseThe MaterialBase class exposes properties common to all material types.
MetallicRoughnessPbrMaterialThe MetallicRoughnessPbrMaterial class encapsulates physically based materials.
RetouchingMaterialThe RetouchingMaterial class encapsulates parameters which define the extend of certain beautification techniques.
TextureTransformThe TextureTransform class encapsulates scaling and translation transforms about a textures UV axis.

Enums

EnumDescription
BlendModeThe BlendMode enum describes how material is blended.
CullModeThe CullMode enum describes how material is culled.

MultipeerModule

Allows an effect running in a video call to communicate with other instances of the same effect within the video call.
Multipeer communication is based around the broadcasting and receiving of JSON formatted messages on message channels.


Messages are broadcast to all peers except the instance that the message was broadcast from - an effect can’t broadcast a message to itself.


You can use the multipeer debugging tool to simulate message streams and debug multipeer effects.

Classes

ClassDescription
MessageChannelRepresents a named bidirectional communication channel.
Message channels are created on demand and persist for the duration of the effect's lifetime.


Channels are available to all participants active within the same instance of an effect.

NativeUIModule

Exposes the ability to edit a device's native UI elements including editable text, pickers and sliders.
Each of these require the relevant capability to be enabled under the *Native UI Control* capability within the project's *Properties*.

Use of text in your effect, including editable text, is subject to approval policies. See the Editable Text article for more information.

Classes

ClassDescription
PickerDescribes an object which controls the behavior of the NativeUI's picker.
Requires the *Native UI Control > Picker* capability within the project's *Properties* to be enabled.
SliderDescribes an object which controls the behavior of the NativeUI's slider.
Requires the *Native UI Control > Slider* capability within the project's *Properties* to be enabled.

Enums

EnumDescription
SliderTypeThe SliderType enum describes the Native UI slider types.

ParticipantsModule

Exposes the ability to retrieve the participants in a video call effect. Each user on the call is considered a participant, including the host.
When a new user joins the call a new Participant object is added to the array returned by getAllOtherParticipants() and otherParticipantCount is increased.


Participants are not removed from the array if they leave while the call is still active. This allows individual participants to retain the same unique ID that can be referenced for the duration of the video call, even after a dropout. Similarly, otherParticipantCount is not decreased when a participant leaves. However, if the the video call ends then the participant array and count are both reset.


Importing this module automatically enables the Participants capability within the project's Properties.

Classes

ClassDescription
ParticipantExposes details of an individual participant in a video call effect.

PatchesModule

The PatchesModule module allows interop between JS scripting and the AR Studio patches visual scripting system.

Classes

ClassDescription
PatchesInputsThe PatchesInputs class encapsulates methods for setting inputs to the Patch Editor.
PatchesOutputsThe PatchesOutputs class encapsulates methods for getting outputs of the Patch Editor.

PersistenceModule

The Persistence class encapsulates persistent objects.

Classes

ClassDescription
StorageScopeThe StorageScope class encapsulates different methods of storage for persistent objects.

PersonSegmentationModule

The PersonSegmentationModule class enables the separation of a person from a scene.

RandomModule

The RandomModule class enables random number generation.

ReactiveModule

The ReactiveModule class exposes methods for reactive programming.

Classes

ClassDescription
BoolSignalThe BoolSignal class monitors a boolean value.
BoolSignalSourceRepresents a source used to get and set the value of a BoolSignal.
Box2DSignalThe Box2DSignal class monitors 2D bounding box value.
Box3DSignalThe Box3DSignal class describes the bounds in 3D space.
ColorSignalThe ColorSignal class monitors a color.
EventSourceThe EventSource class provides methods for monitoring signals.
EventSourceHistoryThe EventSourceHistory encapsulates methods for accessing values of EventSource from previous frames.
HsvaSignalThe HsvaSignal class monitors a HSVA color value.
ISignalThe ISignal interface. The base class for ScalarSignal, PointSignal, VectorSignal, BoolSignal, and StringSignal.
Point2DThe Point2D class contains a 2D coordinate.
Point3DThe Point3D class contains a 3D coordinate.
PointSignalThe PointSignal class monitors a 3D coordinate.
PrimitiveOrShaderSignalThe PrimitiveOrShader represents a primitive or shader signal.
QuaternionSignalThe QuaternionSignal class monitors rotation in a quaternion representation.
RgbaSignalThe RgbaSignal class monitors a RGBA color value.
RotationThe Rotation class encapsulates an object's rotation in a quaternion representation.
ScalarSignalThe ScalarSignal class monitors a numerical value.
ScalarSignalSourceRepresents a source used to get and set the value of a ScalarSignal.
ShaderSignalThe ShaderSignal represents a shader signal. Scalar and Vector signals can automatically be converted to a ShaderSignal.
SignalHistoryThe SignalHistory<T> encapsulates methods for accessing values from previous frames.
StringSignalThe StringSignal class monitors a string value.
StringSignalSourceRepresents a source used to get and set the value of a StringSignal.
SubscriptionThe Subscription class implements object value monitoring.
TransformSignalThe TransformSignal class monitors a scene transform.
Vec2SignalThe Vec2Signal class monitors a 2D coordinate.
Vec4SignalThe Vec4Signal class monitors a 4D coordinate.
VectorSignalThe VectorSignal class monitors a vector.

Enums

EnumDescription
AntiderivativeOverflowBehaviourThe AntiderivativeOverflowBehaviour enum describes the recovery technique used when an
antiderivative overflows.

SceneModule

The SceneModule class exposes properties and methods to access the objects in a scene.

Classes

ClassDescription
AmbientLightSourceThe AmbientLightSource class describes an ambient lighting source.
BlendShapeThe BlendShape class describes a shape attached to a mesh or face mesh which can be used to change the shape of that mesh.
BlockInstanceInputsThe BlockInstanceInputs class encapsulates methods for setting inputs to the block instance.
BlockInstanceOutputsThe BlockInstanceOutputs class encapsulates methods for getting outputs of the block instance.
BlockSceneRootThe BlockSceneRoot class describes the root scene object of a block.
CameraThe Camera class exposes details about the device camera focal area.
CameraVisibilityThe CameraVisibility class describes whether or not an object is visible from various camera views.
CanvasThe Canvas class describes a scene canvas.
DirectionalLightSourceThe DirectionalLightSource class describes a directional light source.
DynamicExtrusionThe DynamicExtrusion class provides functionality for creating extruded 3D objects using a brush.
EnvironmentLightSourceThe EnvironmentLightSource class describes an environment lighting source.
FaceMeshThe FaceMesh class describes a face mesh.
FaceTracker"The FaceTracker class propagates details of detected faces to the scene."
FocalDistanceThe FocalDistance class describes a focal distance in the scene.
Children of FocalDistance get automatically positioned in 3D space based on the the distance between the camera image and the camera scene object itself.
FocalPlaneThe FocalPlane class exposes details about the focal plane of the device camera.
HandTrackerThis class represents the hand tracker scene object, used to track the position of hands in the scene.
JointThe Joint class describes a joint of a given Skeleton object.
MeshThe Mesh class describes a scene mesh.
MeshSurfaceThe MeshSurface class describes a surface in a mesh.
OutputVisibilityThe OutputVisibility class describes whether or not an object is visible from various outputs.
ParticleSystemThe ParticleSystem class implements the particle management system for the scene.
ParticleTypeDescriptionThe ParticleTypeDescription class provides functionality for setting particle sprite densities in the scene.
PlanarDivThe PlanarDiv class describes a div on a plane.
PlanarFlexContainerThe PlanarFlexContainer class describes a flex container on a plane.
PlanarFlexItemThe PlanarFlexItem class describes a flex item on a plane.
PlanarImageThe PlanarImage class describes an image rendered on a plane.
PlanarObjectThe PlanarObject class describes an object on a plane.
PlanarStackThe PlanarStack class describes a stack of 2D Scene Elements.
PlanarTextThe PlanarText class describes text on a plane.
PlaneThe Plane class describes a plane.
PlaneTrackerThe PlaneTracker class provides functionality for locating a 3D plane based on 2D screen coordinates.
When accessing the realScaleActive and realScaleSupported properties, ensure that Real World Scale is enabled in the PlaneTracker object's Inspector panel. See the Real Scale for World article for more information.
PointLightSourceThe PointLightSource class describes a point light source.
SceneThe Scene class implements properties and methods to access the objects in a scene.
SceneObjectThe SceneObject class describes an object in a scene.
SceneObjectBase
ScreenPlaneThe ScreenPlane class describes a screen plane.
SkeletonThe Skeleton class describes a skeleton scene object.
All Joint scene object children of a given skeleton are considered part of this skeleton hierarchy.
SpeakerThe Speaker class encapsulates an speaker for a scene. Old class name is AudioSource.
SpotLightSourceThe SpotLightSource class describes a spot light source.
SvgImageThe SvgImage class describes an SVG asset for a scene.
TargetTrackerThe TargetTracker encapsulates a tracker for some target.
TextAlignmentWrapperThe TextAlignmentWrapper class contains text alignment details.
TextExtrusion"The TextExtrusion class describes a 3D text scene object.
ThreeDObjectThe ThreeDObject class describes a scene 3d object.
TransformThe Transform class describes an object transform for a scene.
WorldTransformThe WorldTransform class describes an object transform for a sceneObject in world space.

Enums

EnumDescription
DirectionThe Direction enum describes the stack layout's direction.
BrushTypeThe BrushType enum describes what kind of brush is used for dynamic extrusion.
HorizontalAlignmentThe HorizontalAlignment enum describes how an element is aligned horizontally.
RenderModeThe RenderMode enum describes how to render a scene object.
ScalingOptionThe ScalingOption enum describes how an element is scaled.
StackAlignThe StackAlign enum describes the stack children's alignment.
StackDistributeThe StackDistribute enum describes the stack children's distribution.
TextAlignmentThe TextAlignment enum describes how a text element is aligned horizontally.
TrackingModeThe TrackingMode enum describes how a PlaneTracker is tracking an object.
VerticalAlignmentThe VerticalAlignment enum describes how an element is aligned vertically.
VerticalTextAlignmentThe VerticalTextAlignment enum describes how a text element is aligned vertically.

SegmentationModule

The SegmentationModule class enables the separation of a person or hair or skin from a scene.

Classes

ClassDescription
HairSegmentationThe HairSegmentation class exposes the information about a person's hair.
PersonSegmentationThe PersonSegmentation class exposes the information about a person.
SkinSegmentationThe SkinSegmentation class exposes the information about a person's skin.

ShadersModule

The ShadersModule exposes APIs to create Visual Shaders using JavaScript.
The following is an explanation of the unique types and concepts specific to the ShadersModule.

PrimitiveOrShaderSignal is a union type of Vec2Signal, PointSignal, Vec4Signal, VectorSignal, TransformSignal, or ShaderSignal.
ShaderSignal is a graphics shader output that produces one of the types defined in the above union. As ShaderSignal is GPU bound, it can only be used in a GPU context.

ShaderSignal can also be of a function type, used for function mapping from one type to another.
For example, a shader with the signature function(Vec2Signal): Vec4Signal is a type of a function that maps a Vec2Signal to a Vec4Signal.

Enums

EnumDescription
BlendedMaterialTexturesThe BlendedMaterialTextures enum describes the different texture slots for a flat material.
BlendModeThe BlendMode enum describes the blending mode.
BuiltinUniformThe BuiltinUniform enum describes the bultin shader uniforms.
ColorSpaceThe ColorSpace enum describes the color space.
DefaultMaterialTexturesThe DefaultMaterialTextures enum describes the different texture slots for a default material.
DerivativeTypeThe DerivativeType enum describes the shader derivative type.
FacePaintMaterialTexturesThe FacePaintMaterialTextures enum describes the different texture slots for a face paint
material.
GradientTypeThe GradientType enum describes the type of the shader gradient.
PhysicallyBasedMaterialTexturesThe PhysicallyBasedMaterialTextures enum describes the different texture slots for a
physically based material.
SdfVariantThe SdfVariant enum describes the SDF variant.
VertexAttributeThe VertexAttribute enum describes the bultin vertex attributes.

SvgsModule

The SvgsModule module enables working with SVGs.

Classes

ClassDescription
SvgThe Svg class describes an SVG in an effect.

TexturesModule

The TexturesModule class enables images, animation sequences, videos, colors, and other visual artifacts to be combined to form materials.

Classes

ClassDescription
CameraTextureThe CameraTexture class represents a texture type that contains image data coming in from system camera, or captured photo/video in case of using the effect with "Media Library".
CanvasTextureThe CanvasTexture class enables painting with a brush to a texture.
ColorTextureThe ColorTexture class encapsulates a texture that has a color (including alpha channel).
DeepLinkTextureThe DeepLinkTexture class represents an image texture passed in via the sharing SDK.
GalleryTextureThe GalleryTexture class encapsulates a texture that was picked from the gallery.
GalleryTextureMediaBaseGalleryTextureMediaBase is a base class for different types of media that can be selected from gallery and used in a gallery texture.
GalleryTextureMediaImageGalleryTextureMediaImage represents image media that was picked from the gallery that is being used by a given GalleryTexture.
GalleryTextureMediaVideoGalleryTextureMediaVideo represents "video" media that was picked from the gallery that is being used by a given GalleryTexture.
It exposes a set of APIs that are specifically tailored for controlling video playback.
ImageTextureThe ImageTexture class encapsulates an image that may be used to form materials for rendering in the scene.
SegmentationTextureThe SegmentationTexture class encapsulates a texture that will be used for image segmentation.
SequenceTextureThe SequenceTexture class is a collection of still images that form an animation.
SourceImageRegionTextureThe SourceImageRegionTexture class represents a texture type that contains extracted texture image from a certain region of an object or a set of objects in the scene.
E.g. Face extracted texture that contains a region of a camera image with a face as extracted using a face tracker.
SubTextureThe SubTexture class exposes details of a texture in UV coordinates.
TextureBaseThe TextureBase class describes a texture.

Enums

EnumDescription
MediaTypeThe MediaType enum describes the media types of a GalleryTexture.
StateThe State enum describes the state of a GalleryTexture.

TimeModule

The TimeModule class enables time-based events.

TouchGesturesModule

Enables detection of touch gestures and exposes classes that describe various types of touch interaction.
By default touch gestures will be registered on the entire screen unless an object is specified in the gesture method call, for example: TouchGestures.onTap(plane).

Importing this module automatically enables the *Touch Gestures* capability within the project's *Properties*. Gesture types must be individually enabled within the capability to enable detection.

Classes

ClassDescription
GestureExposes details of a detected gesture, common to all touch gesture types.
LongPressGestureExposes details of a detected long press gesture.
Ensure Long Press Gesture is enabled under the project's Touch Gestures capability.
PanGestureExposes details of a detected pan gesture.
Ensure Pan Gesture is enabled under the project's Touch Gestures capability.
PinchGestureExposes details of a detected pinch gesture.
Ensure Pinch Gesture is enabled under the project's Touch Gestures capability.
RotateGestureExposes details of a detected rotation gesture.
Ensure Rotate Gesture is enabled under the project's Touch Gestures capability.
TapGestureExposes details of a detected tap gesture.
Ensure Tap Gesture is enabled under the project's Touch Gestures capability.

Enums

EnumDescription
StateThe State enum describes the state of a Gesture.
GestureTypeThe GestureType enum describes the type of a given Gesture.

UnitsModule

The UnitsModule class provides functionality for converting values into world-space units.

WeatherModule

The WeatherModule class provides information about the current weather.

Was this article helpful?