API Reference

Class List

XrImageTracking

Extends: EventHandler

Image Tracking provides the ability to track real world images by provided image samples and their estimated sizes.

Summary

Properties

available

True if Image Tracking is available.

images

List of XrTrackedImage that contain tracking information.

supported

True if Image Tracking is supported.

Methods

add

Add an image for image tracking.

remove

Remove an image from image tracking.

Events

error

Fired when the XR session is started, but image tracking failed to process the provided images.

Inherited

Methods

fire

Fire an event, all additional arguments are passed on to the event listener.

hasEvent

Test if there are any handlers bound to an event name.

off

Detach an event handler from an event.

on

Attach an event handler to an event.

once

Attach an event handler to an event.

Details

Properties

booleanavailable

True if Image Tracking is available. This property will be false if no images were provided for the AR session or there was an error processing the provided images.

XrTrackedImage[]images

List of XrTrackedImage that contain tracking information.

booleansupported

True if Image Tracking is supported.

Methods

add(image, width)

Add an image for image tracking. A width can also be provided to help the underlying system estimate the appropriate transformation. Modifying the tracked images list is only possible before an AR session is started.

// image with width of 20cm (0.2m)
app.xr.imageTracking.add(bookCoverImg, 0.2);

Parameters

imageHTMLCanvasElement, HTMLImageElement, SVGImageElement, HTMLVideoElement, Blob, ImageData, ImageBitmap

Image that is matching real world image as close as possible. Resolution of images should be at least 300x300. High resolution does NOT improve tracking performance. Color of image is irrelevant, so grayscale images can be used. Images with too many geometric features or repeating patterns will reduce tracking stability.

widthnumber

Width (in meters) of image in the real world. Providing this value as close to the real value will improve tracking quality.

Returns

XrTrackedImage, null

Tracked image object that will contain tracking information. Returns null if image tracking is not supported or if the XR manager is not active.

remove(trackedImage)

Remove an image from image tracking.

Parameters

trackedImageXrTrackedImage

Tracked image to be removed. Modifying the tracked images list is only possible before an AR session is started.

Events

error

Fired when the XR session is started, but image tracking failed to process the provided images.

Parameters

errorError

Error object related to a failure of image tracking.

Inherited

Methods

fire(name, [arg1], [arg2], [arg3], [arg4], [arg5], [arg6], [arg7], [arg8])

Fire an event, all additional arguments are passed on to the event listener.

obj.fire('test', 'This is the message');

Parameters

namestring

Name of event to fire.

arg1*

First argument that is passed to the event handler.

arg2*

Second argument that is passed to the event handler.

arg3*

Third argument that is passed to the event handler.

arg4*

Fourth argument that is passed to the event handler.

arg5*

Fifth argument that is passed to the event handler.

arg6*

Sixth argument that is passed to the event handler.

arg7*

Seventh argument that is passed to the event handler.

arg8*

Eighth argument that is passed to the event handler.

Returns

EventHandler

Self for chaining.

hasEvent(name)

Test if there are any handlers bound to an event name.

obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false

Parameters

namestring

The name of the event to test.

Returns

boolean

True if the object has handlers bound to the specified event name.

off([name], [callback], [scope])

Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

var handler = function () {
};
obj.on('test', handler);

obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this

Parameters

namestring

Name of the event to unbind.

callbackHandleEventCallback

Function to be unbound.

scopeobject

Scope that was used as the this when the event is fired.

Returns

EventHandler

Self for chaining.

on(name, callback, [scope])

Attach an event handler to an event.

obj.on('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console

Parameters

namestring

Name of the event to bind the callback to.

callbackHandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandler

Self for chaining.

once(name, callback, [scope])

Attach an event handler to an event. This handler will be removed after being fired once.

obj.once('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled

Parameters

namestring

Name of the event to bind the callback to.

callbackHandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandler

Self for chaining.