Wikitude SDK API Reference

API Docs for: 8.2.0
Show:

ObjectTrackable Class

Extends ARObject
Module: AR

An ObjectTrackable represents a virtual object bound to a specific target in a target collection. The target will be tracked in the camera scene, and Drawables will be projected onto the target as soon as it becomes visible and is detected in the scene. Any ObjectTrackable is linked to one target in a specific target collection.

A ObjectTrackable

  • is associated with one Tracker and target(s) inside the Tracker.
  • can have Drawables associated with it. These Drawables will represent the ObjectTrackable in the camera view.
  • can have triggers associated with it. Triggers fire on certain events and execute functions to react on these actions.

On creation, a reference to the Tracker, as well as the name of the target in the Tracker must be passed. The target name can either be the exact name or a regular expression. For example "*" will match all targets that are included in the given tracker. In that case the onObjectRecognized event will pass the recognized target name as parameter.

An ObjectTrackable can either be enabled or disabled (see ARObject.enabled). Enabled means that the ObjectTrackable will be considered in the tracking of objects in the camera, and its triggers will fire on the appropriate events. In case the ObjectTrackable is disabled, it will not be considered in the tracking process, and it will not fire any triggers. Note that the associated Tracker must also be enabled for the ObjectTrackable to be considered for tracking.

On creation, setup parameters can be passed to customize the properties of the ObjectTrackable.

ObjectTrackable example:
var World = {
    [...]

    init: function initFn() {
        World.createTracker();
    },

    createTracker: function createTrackerFn() {
        this.targetCollectionResource = new AR.TargetCollectionResource("assets/firetruck_map.wto", {
        });

        this.tracker = new AR.ObjectTracker(this.targetCollectionResource, {
            onError: function(errorMessage) {
                alert(errorMessage);
            }
        });

        this.objectTrackable = new AR.ObjectTrackable(this.tracker, "*", {
            drawables: {
                cam: [...]
            },
            onObjectRecognized: this.objectRecognized,
            onObjectLost: this.objectLost,
            onError: function(errorMessage) {
                alert(errorMessage);
            }
        });
    },

    objectRecognized: function objectRecognizedFn() {
        [...]
    },

    objectLost: function objectLostFn() {
        [...]
    }
}

World.init();

Constructor

ObjectTrackable

(
  • tracker
  • targetName
  • options
)

Parameters:

  • tracker ObjectTracker

    The ObjectTracker the target is stored in

  • targetName String

    The name of the target in the Tracker

  • options Object optional

    Setup-Parameters to customize additional object properties.

    Accepted options-properties are

Methods

destroy

()

Inherited from ARchitectObject

Destroys the object.

drawables.addCamDrawable

(
  • drawable
  • position
)

Inherited from ARObject

Adds Drawables to the ARObject in the camera.

Parameters:

  • drawable Drawable | Drawable[]

    The drawable(s) that should be added to the camera. Can either be a single Drawable, or an Array of Drawables.

  • position Number optional

    The position where the Drawable should be added in the array. If not specified, the Drawable will be added at the end of the array. Must be a whole number.

drawables.removeCamDrawable

(
  • drawable|position
)

Inherited from ARObject

Removes Drawables from the ARObject in the cam.

Parameters:

  • drawable|position Drawable | [Drawable] | Number

    When a single Drawable or an Array of Drawables is given, these Drawables will be removed from the array. When an integer is given, the Drawable at the specified position will be removed.

isVisible

() Boolean

Inherited from ARObject

Returns the current visibility state of the ARObject. An ARObject is defined visible when at least one of the ARObject's locations (geolocations or visual tracker) is projected onto a screen coordinate which is currently visible on the screen.

Returns:

Boolean:

Whether the ARObject is currently visible on the screen (true) or invisble (false).

stopExtendedTracking

()

Immediately stops extended tracking. If the target object is already outside ot the field of vision, this will stop tracking the scene. Resuming extended tracking is only possible if one of the associated target object is recognized again.

Properties

destroyed

Boolean

Inherited from ARchitectObject

Indicates if the object has already been destroyed.

drawables.cam

Drawable[]

Inherited from ARObject

The Drawables which will be used to represent the ARObject in the camera view.

Drawables in the array will be printed starting with the Drawable at position 0, causing Drawables at later indices to overlap the previously drawn Drawables.

Remark:

The array content should not be manipulated via the [] operator, as it cannot be guaranteed that the changes will be propagated through to the native application. The property should only be manipulated with arobject.drawables.addCamDrawable() and arobject.drawables.removeCamDrawable(), or directly set with arobject.drawables.cam = new Array(...);.

enabled

Boolean

Inherited from ARObject

A boolean flag to enable or disable the ARObject.

Default: true

enableExtendedTracking

Boolean

If this property is set to true, this trackable object will trigger the extended tracking mode. In extended tracking mode, the tracker will keep track of the 3D scene and stay active even when the target is no longer visible. This property is read-only and can only be set on creation.

extendedTarget

String

Use this property to define which targets of an ObjectTrackable are treated as extended targets. In case a wildcard was used to define the targetName, this property also accepts the same wildcard settings ('*' and '?'). This property can be changed at any time. Changes take affect as soon as an ongoing extended tracking is lost or the stopExtendedTracking function is called.

onExtendedTrackingQualityChanged

Function

If this function is defined, it will be called everytime the extended tracking quality changes. The extended tracking quality is given in three values:

    * -1 The extended tracking quality is bad and extended tracking will most likely not work
    * 0 The extended tracking quality is not very good but extended tracking might work
    * 1 The extended tracking quality is good and extended tracking will most likely work
    Please note that this callback function has three parameters. The first one is the extended target name that was tracked, the second one is the previously extended tracking quality and the last one is the new extended tracking quality.

renderingOrder

Number

Inherited from ARObject

Drawables of different ARObjects might overlap. In this case, renderingOrder defines the rendering order of the Drawables of the ARObject. ARObjects with higher renderingOrder values cause their Drawables to be drawn on top of the Drawables of ARObjects with lower renderingOrder values. In case two ARObjects have set the same renderingOrder, the Drawables are rendered based on the distance, causing objects closer to the user to overlap objects further away.
For example, If you want to bring Drawables of a certain ARObject to the very front, set the renderingOrder value of the corresponding ARObject to a very high value.

For the printing order of Drawables within the same ARObject, refer to Drawable2D.zOrder.

Must be a whole number.

Default: 0

targetName

String

The name of the referenced target inside the target collection. This defines on which target image the ObjectTrackable will react. The value can be either the actual name of the image or a wildcard to match several. The following wildcards are supported: * and ? to be used in the same manner as in a regular expression. This property is read-only and can only be set on creation.

tracker

ObjectTracker

The ObjectTracker which contains the target referenced by this ObjectTracker. This property is read-only and can only be set on creation.

Events

onClick

Inherited from ARObject

Will be executed when any of the ARObject's Drawables have been clicked, and none of the clicked Drawables's onClick() triggers (might also be referenced by another ARObject) have been set to quit the click chain. ARObject.onClick() will be executed after any Drawable.onClick() triggers have been executed.

In case multiple ARObjects are hit by the click, the order of the execution is defined by the distance of the ARObject to the user, with the closest ARObject's click trigger executed first.

The return value of the function determines if, after the onClick()-function was executed for this ARObject, the queue shall continue to execute onClick() for the next ARObject in the queue. In case the last ARObject in the queue still requests to continue the click-queue, context.onScreenClick() will be executed.

The return value of the function decides what to do next. If false, the click-queue should not stop with this ARObject. Thus, the next ARObject's onClick() function will be executed. This is the default value in case no return value is set or the function is not defined for this ARObject. If true, the queue-execution will stop at the current ARObject, underlying ARObjects will not receive onClick() calls.

onDragBegan

Inherited from ARObject

Executed when the user starts dragging on at least one Drawable with a single finger and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch position and the updated touch position [-1, 1]; always 0 in onDragBegan as no change to the drag gesture has occurred yet

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]; always 0 in onDragBegan as no change to the drag gesture has occurred yet

onDragChanged

Inherited from ARObject

Executed when the user drags on at least one Drawable with a single finger and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch position and the updated touch position [-1, 1]

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]

onDragEnded

Inherited from ARObject

Executed when the user stops dragging on at least one Drawable with a single finger and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch position and the updated touch position [-1, 1]; always identical to the most recent distance received in onDragChanged

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]; always identical to the most recent distance received in onDragChanged

onObjectLost

Will be executed when the ObjectTrackable's visibility has changed from visible to invisible.

The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onImageLost.

Event Payload:

  • targetName String

    Holds the name of the target that exited the field of vision.

onObjectRecognized

The trigger will fire when the ObjectTrackable's visibility has changed from invisible to visible.

The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onImageRecognized.

Event Payload:

  • targetName String

    Holds the name of the recognized target. Used in combination with wildcards for targetName.

onPanBegan

Inherited from ARObject

Executed when the user starts dragging on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch positions and the updated touch positions [-1, 1]; always 0 in onPanBegan as no change to the pan gesture has occurred yet; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]; always 0 in onPanBegan as no change to the pan gesture has occurred yet; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

onPanChanged

Inherited from ARObject

Executed when the user drags on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch positions and the updated touch positions [-1, 1]; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

onPanEnded

Inherited from ARObject

Executed when the user stops dragging on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • xNormalized Number

    the distance on the X-axis between the initiating touch positions and the updated touch positions [-1, 1]; always identical to the most recent distance received in onPanChanged; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

  • yNormalized Number

    the distance on the Y-axis between the initiating touch position and the updated touch position [-1, 1]; always identical to the most recent distance received in onPanChanged; the mid-points between the first and second touches are used to calculate the distances to allow co-operative behaviour with the scale and rotate gesture

onRotationBegan

Inherited from ARObject

Executed when the user starts rotating on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • angle Number

    the CCW angle in degree between the line defined by the initiating touch positions and the line defined by the updated touch positions [0, 360); always 0 in onRotationBegan as no change to the rotation gesture has occurred yet

onRotationChanged

Inherited from ARObject

Executed when the user rotates on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • angle Number

    the CCW angle in degree between the line defined by the initiating touch positions and the line defined by the updated touch positions [0, 360)

onRotationEnded

Inherited from ARObject

Executed when the user stops rotating on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • angle Number

    the CCW angle in degree between the line defined by the initiating touch positions and the line defined by the updated touch positions [0, 360); always identical to the most recent angle received in onRotationChanged

onScaleBegan

Inherited from ARObject

Executed when the user starts scaling on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • scale Number

    the scale value defined the ratio of the distance between the updated touches over the distance between the initiating touches [0, inf]; always 1 in onScaleBegan as no change to the scale gesture has occurred yet

onScaleChanged

Inherited from ARObject

Executed when the user scales on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • scale Number

    the scale value defined the ratio of the distance between the updated touches over the distance between the initiating touches [0, inf]

onScaleEnded

Inherited from ARObject

Executed when the user stops scaling on at least one Drawable with two fingers and none of these Drawables quits the event propagation by returning true. This callback behaves identically to the onClick callback in terms of event propagation.

Event Payload:

  • scale Number

    the scale value defined the ratio of the distance between the updated touches over the distance between the initiating touches [0, inf]; always identical to the most recent scale received in onScaleChanged

onTrackingPlaneClick

Executed when the user clicks on the plane of an object trackable. This callback does not propagate to the context as the regular onClick callback would; it is dedicated to the object trackable only.

Event Payload:

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray of the object tracking plane [-infinity, infinity]

  • yIntersection Number

    the world space Y-coordinate of the intersection position of the initiating touch ray of the object tracking plane [-infinity, infinity]

onTrackingPlaneDragBegan

Executed when the user starts dragging on the plane of an object trackable. This callback does not propagate to the context as the regular onDragBegan callback would; it is dedicated to the object trackable only.

Event Payload:

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]

  • yIntersection Number

    the world space Y-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]

onTrackingPlaneDragChanged

Executed when the user drags on the plane of an object trackable. This callback does not propagate to the context as the regular onDragChanged callback would; it is dedicated to the object trackable only.

Event Payload:

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]

  • yIntersection Number

    the world space Y-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]

onTrackingPlaneDragEnded

Executed when the user drags on the plane of an object trackable. This callback does not propagate to the context as the regular onDragEnded callback would; it is dedicated to the object trackable only.

Event Payload:

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]

  • yIntersection Number

    the world space Y-coordinate of the intersection position of the initiating touch ray and the object tracking plane [-infinity, infinity]