ObjectTracking3D
ClassUsed to track objects in 3D space, such as body, hands.
- Available on all platforms
Since Lens Scripting v142
Index
Properties
Methods
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
isBeingDestroyed
readonlyisBeingDestroyed: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
isEnabledInHierarchy
readonlyisEnabledInHierarchy: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
readonlyobjectSpecificData:ObjectSpecificData
SPECS only
The data provided by the tracker on this component.
See also
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
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
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
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
addAttachmentPoint()
addAttachmentPoint(
name,object):void
Attaches the SceneObject to the specified attachment point.
Parameters
| Parameter | Type |
|---|---|
name | string |
object | SceneObject |
Returns
void
Since
Lens Scripting Version 142
createAttachmentPoint()
createAttachmentPoint(
name):SceneObject
Creates a SceneObject which is attached to the specified attachment point.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Since
Lens Scripting Version 142
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getAttachedObjects()
getAttachedObjects(
name):SceneObject[]
Returns all SceneObjects currently attached to the specified point.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Since
Lens Scripting Version 142
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isAttachmentPointTracking()
isAttachmentPointTracking(
name):boolean
Returns whether the specified attachment point is being tracked.
Parameters
| Parameter | Type |
|---|---|
name | string |
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
| 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
isTracking()
isTracking():
boolean
Returns whether this object is currently being tracked.
Returns
boolean
Since
Lens Scripting Version 142
removeAttachmentPoint()
removeAttachmentPoint(
object):void
Parameters
| Parameter | Type |
|---|---|
object | SceneObject |
Returns
void
Since
Lens Scripting Version 148
See also
3D Body and Hand Tracking guide.
Nested types
Enumerations
| Enumeration | Description |
|---|---|
| TrackingMode | Strategies for updating attached objects. Used by the ObjectTracking3D component. |