Skip to main content

ObjectTracking3D

Class

Used to track objects in 3D space, such as body, hands.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v142

Index

Example

// @input Component.ObjectTracking3D objectTracking3D

script.objectTracking3D.onTrackingStarted = function(){
print("ObjectTracking3D Started Tracking");
}

script.objectTracking3D.onTrackingLost = function(){
print("ObjectTracking3D Lost Tracking");
}

Using objectSpecificData to get additional information about the tracked object.

//@input Component.ObjectTracking3D objectTracking3D

script.createEvent("UpdateEvent").bind(()=> {
getHandVelocity();
})

function getHandVelocity() {
// In Lens Studio we do not have the objectSpecificData we need.
if (global.deviceInfoSystem.isEditor()) {
return new vec3(0, 1, -35);
}

// Each ObjectTracking3D Component might provide their own specific data
let objectSpecificData = this.objectTracking3D.objectSpecificData;
if (objectSpecificData) {
let handVelocity = objectSpecificData["global"];
let fingerVelocity = objectSpecificData["index-3"];

print("Hand Velocity: " + handVelocity);
print("Finger Velocity: " + fingerVelocity);

return handVelocity;
} else {
return vec3.zero();
}
}
@component
export class NewScript extends BaseScriptComponent {
@input
objectTracking3D: ObjectTracking3D;

onAwake() {
this.createEvent("UpdateEvent").bind(() => {
this.getHandVelocity();
});
}
getHandVelocity() {
// In Lens Studio we do not have the objectSpecificData we need.
if (global.deviceInfoSystem.isEditor()) {
return new vec3(0, 1, -35);
}

// Each ObjectTracking3D Component might provide their own specific data
let objectSpecificData = this.objectTracking3D.objectSpecificData;
if (objectSpecificData) {
let handVelocity = objectSpecificData["global"];
let fingerVelocity = objectSpecificData["index-3"];

print("Hand Velocity: " + handVelocity);
print("Finger Velocity: " + fingerVelocity);

return handVelocity;
} else {
return vec3.zero();
}
}
}

Extends

Properties

attachmentModeInheritRotation

attachmentModeInheritRotation: boolean

Whether world rotation is applied or not.

Since

Lens Scripting Version 188

Default Value

true

attachmentModeInheritScale

attachmentModeInheritScale: boolean

Whether world scale is applied or not.

Since

Lens Scripting Version 188

Default Value

false

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

Component.enabled


isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

Inherited from

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

Component.isEnabledInHierarchy


objectIndex

objectIndex: number

Index of the object to track, starting at 0. Useful when tracking multiple instances of the same type of object.

Since

Lens Scripting Version 142

Default Value

0

objectSpecificData

readonly objectSpecificData: ObjectSpecificData

SPECS only

The data provided by the tracker on this component.

See also

SpectaclesHandSpecificData

Since

Lens Scripting Version 142


onTrackingLost

onTrackingLost: () => void

Function called when tracking is lost.

Returns

void

Since

Lens Scripting Version 142

Default Value

null

onTrackingStarted

onTrackingStarted: () => void

Function called when tracking begins.

Returns

void

Since

Lens Scripting Version 142

Default Value

null

sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


trackingAsset

trackingAsset: Object3DAsset

Asset containing tracking parameters, such as the tracking model and specific options.

Since

Lens Scripting Version 142

Default Value

null

trackingMode

trackingMode: TrackingMode

Strategy for updating attached SceneObjects.

Since

Lens Scripting Version 142

Default Value

ObjectTracking3D.TrackingMode.ProportionsAndPose

trackPosition

trackPosition: boolean

When true, the attached root SceneObject's world position will be updated to match the tracked object's world position.

Since

Lens Scripting Version 143

Default Value

true

uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier

Methods

addAttachmentPoint()

addAttachmentPoint(name, object): void

Attaches the SceneObject to the specified attachment point.

Parameters

ParameterType
namestring
objectSceneObject

Returns

void

Since

Lens Scripting Version 142


createAttachmentPoint()

createAttachmentPoint(name): SceneObject

Creates a SceneObject which is attached to the specified attachment point.

Parameters

ParameterType
namestring

Returns

SceneObject

Since

Lens Scripting Version 142


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

Component.destroy


getAttachedObjects()

getAttachedObjects(name): SceneObject[]

Returns all SceneObjects currently attached to the specified point.

Parameters

ParameterType
namestring

Returns

SceneObject[]

Since

Lens Scripting Version 142


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): TypeName<ObjectTracking3D>

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

Since

Lens Scripting Version 142

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.getTypeName


isAttachmentPointTracking()

isAttachmentPointTracking(name): boolean

Returns whether the specified attachment point is being tracked.

Parameters

ParameterType
namestring

Returns

boolean

Since

Lens Scripting Version 142


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

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

Component.isSame


isTracking()

isTracking(): boolean

Returns whether this object is currently being tracked.

Returns

boolean

Since

Lens Scripting Version 142


removeAttachmentPoint()

removeAttachmentPoint(object): void

Parameters

ParameterType
objectSceneObject

Returns

void

Since

Lens Scripting Version 148

See also

3D Body and Hand Tracking guide.

Nested types

Enumerations

EnumerationDescription
TrackingModeStrategies for updating attached objects. Used by the ObjectTracking3D component.