Lens Scripting API

    Class ObjectTracking3D

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

    // @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();
    }
    }
    }

    Hierarchy (View Summary, Expand)

    Index

    Constructors

    Properties

    attachmentModeInheritRotation: boolean

    Whether world rotation is applied or not.

    attachmentModeInheritScale: boolean

    Whether world scale is applied or not.

    enabled: boolean

    If disabled, the Component will stop enacting its behavior.

    objectIndex: number

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

    objectSpecificData: ObjectSpecificData

    The data provided by the tracker on this component.

    onTrackingLost: () => void

    Function called when tracking is lost.

    onTrackingStarted: () => void

    Function called when tracking begins.

    sceneObject: SceneObject

    The scene object this component is on.

    trackingAsset: Object3DAsset

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

    trackingMode: TrackingMode

    Strategy for updating attached SceneObjects.

    trackPosition: boolean

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

    uniqueIdentifier: string

    Methods

    • Attaches the SceneObject to the specified attachment point.

      Parameters

      Returns void

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

      Parameters

      • name: string

      Returns SceneObject

    • Destroys the component.

      Returns void

    • Returns all SceneObjects currently attached to the specified point.

      Parameters

      • name: string

      Returns SceneObject[]

    • Returns the name of this object's type.

      Returns string

    • Returns whether the specified attachment point is being tracked.

      Parameters

      • name: string

      Returns boolean

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

      Parameters

      • type: string

      Returns boolean

    • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

      Parameters

      Returns boolean

    • Returns whether this object is currently being tracked.

      Returns boolean

    MMNEPVFCICPMFPCPTTAAATR