Wikitude SDK API Reference

API Docs for: 7.2.0
Show:

Model Class

Extends Drawable
Module: AR

A Model drawable represents an ARObject as a 3D Model.

A Model file consist of a link to a WT3 file that is created using the Wikitude 3D Encoder, as well as certain control properties and triggers that fire on certain events. You can find out more about 3D in the Wikitude SDK documentation.



3D content is rendered on top of 2D objects. This limitation exists because of some SDK internal restrictions and might change in an upcoming release.



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

Example:
//create a new Model and pass some setup parameters
var model = new AR.Model("models/my3dModel.wt3", {
  // scales it to half of the original size
  scale: {
    x: 0.5,
    y: 0.5,
    z: 0.5
  },
  // rotates it 90 degrees around the z-axis and 180 degrees around the x-axis
  rotate: {
    x: 180.0,
    y: 0.0,
    z: 90.0
  },
  // moves the 0bject 5 SDUs along the x- and the y-axis
  translate: {
    x: 5,
    y: 5,
    z: 0
  },
  onClick : function() {
    //something happens
  }
});

Constructor

Model

(
  • uri
  • options
)

Parameters:

  • uri String

    An URI pointing to the wt3 file including all model information/a>

  • options Object optional

    Setup-Parameters to customize additional object properties.

    Accepted options-properties are

    • enabled (defaults to true) Boolean optional
    • mirrored (defaults to true) Boolean optional
    • onClick Function optional
    • onDragBegan Function optional
    • onDragChanged Function optional
    • onDragEnded Function optional
    • onPanBegan Function optional
    • onPanChanged Function optional
    • onPanEnded Function optional
    • onRotationBegan Function optional
    • onRotationChanged Function optional
    • onRotationEnded Function optional
    • onScaleBegan Function optional
    • onScaleChanged Function optional
    • onScaleEnded Function optional
    • rotate.x (defaults to 0) Number optional
    • rotate.y (defaults to 0) Number optional
    • rotate.z (defaults to 0) Number optional
    • rotate.global.x (defaults to 0) Number optional
    • rotate.global.y (defaults to 0) Number optional
    • rotate.global.z (defaults to 0) Number optional
    • translate.x (defaults to 0) Number optional
    • translate.y (defaults to 0) Number optional
    • translate.z (defaults to 0) Number optional
    • translate.global.x (defaults to 0) Number optional
    • translate.global.y (defaults to 0) Number optional
    • translate.global.z (defaults to 0) Number optional
    • scale.x (defaults to 1) Number optional
    • scale.y (defaults to 1) Number optional
    • scale.z (defaults to 1) Number optional
    • onLoaded Function optional
    • onInitialized Function optional
    • onError Function optional

Methods

destroy

()

Inherited from ARchitectObject

Destroys the object.

isInitialized

() Boolean

Allows checking if the Model has already been initialized successfully. The model is initialized once it is about to be rendered for the first time.

Returns:

Boolean:

true if the Model is already initialized, false if the Model is not yet initialized.

isLoaded

() Boolean

Allows checking if the Model has already been loaded successfully.

Returns:

Boolean:

true if the Model is already loaded, false if the Model is not yet loaded.

Properties

destroyed

Boolean

Inherited from ARchitectObject

Indicates if the object has already been destroyed.

enabled

Boolean

Inherited from Drawable

Flag to enable/disable the Drawable. If the Drawable is disabled, it will never appear on the screen and triggers on this Drawable will never be fired. In case it is enabled, it can be rendered on the screen and fire triggers.

Default: true

mirrored

Boolean

Inherited from Drawable

Flag to enable/disable mirroring for this Drawable. When using the front camera, a mirrored drawable will be rotated 180 degree around its y axis.

Default: true for generic drawables, false for labels and HTMLDrawables

rotate

Object

Inherited from Drawable

Defines the rotation of the Drawable around its center. This property can be used to set the x, y and z components simultaneously in a single call to the native side of the Wikitude SDK for maximum performance. The Object may contain x, y and z or any subset thereof.

rotate.global.x

Number

Inherited from Drawable

Defines a rotation of the Drawable around the x-axis of the target image, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree. All global transformations will be applied after the local transformations.

Default: 0

rotate.global.y

Number

Inherited from Drawable

Defines a rotation of the Drawable around the y-axis of the target image, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree. All global transformations will be applied after the local transformations.

Default: 0

rotate.global.z

Number

Inherited from Drawable

Defines a rotation of the Drawable around the z-axis of the target image, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree. All global transformations will be applied after the local transformations.

Default: 0

rotate.heading

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.y or rotate.global.y instead.

rotate.roll

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.z or rotate.global.z instead.

rotate.tilt

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.x or rotate.global.x instead.

rotate.x

Number

Inherited from Drawable

Defines a rotation of the Drawable around the x-axis of the Drawable, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree.

Default: 0

rotate.y

Number

Inherited from Drawable

Defines a rotation of the Drawable around the y-axis of the Drawable, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree.

Default: 0

rotate.z

Number

Inherited from Drawable

Defines a rotation of the Drawable around the z-axis of the Drawable, specified in degrees. Values will be applied modulo 360. A value of 361 degrees has the same effect as setting the value to 1 degree.

Default: 0

rotatesToCamera

Boolean

Inherited from Drawable

Defines if the drawable is oriented to face the camera. This is only possible for Drawables attached to a GeoObject.

Default: true for generic drawables, false for Models

scale

Object

Inherited from Drawable

Defines the scale of the Drawable. This property can be used to set the x, y and z components simultaneously in a single call to the native side of the Wikitude SDK for maximum performance.The Object may contain x, y and z or any subset thereof.

scale.x

Number

Inherited from Drawable

The scale in x-direction. Must be non-negative.

Default: 1

scale.y

Number

Inherited from Drawable

The scale in y-direction. Must be non-negative.

Default: 1

scale.z

Number

Inherited from Drawable

The scale in z-direction. Must be non-negative.

Default: 1

translate

Object

Inherited from Drawable

Defines the translation of the Drawable. This property can be used to set the x, y and z components simultaneously in a single call to the native side of the Wikitude SDK for maximum performance. The Object may contain x, y and z or any subset thereof.

translate.global.x

Number

Inherited from Drawable

The horizontal offset to the calculated position of the Drawable, in SDUs. A positive x causes the Drawable to move right, a negative x causes it to move left. All global transformations will be applied after the local transformations.

Default: 0

translate.global.y

Number

Inherited from Drawable

The vertical offset to the calculated position of the Drawable, in SDUs. A positive y causes the Drawable to move up, a negative y causes it to move down. All global transformations will be applied after the local transformations.

Default: 0

translate.global.z

Number

Inherited from Drawable

The depth-offset to the calculated position of the Drawable, in SDUs. A positive z causes the Drawable to move towards the user, a negative z causes it to move away. All global transformations will be applied after the local transformations.

Default: 0

translate.x

Number

Inherited from Drawable

The horizontal offset to the calculated position of the Drawable, in SDUs. A positive x causes the Drawable to move right, a negative x causes it to move left.

Default: 0

translate.y

Number

Inherited from Drawable

The vertical offset to the calculated position of the Drawable, in SDUs. A positive y causes the Drawable to move up, a negative y causes it to move down.

Default: 0

translate.z

Number

Inherited from Drawable

The depth-offset to the calculated position of the Drawable, in SDUs. A positive z causes the Drawable to move towards the user, a negative z causes it to move away.

Default: 0

uri

String

The uri pointing to the model file. This property is read-only and cannot be modified after creation.

Events

onClick

Inherited from Drawable

When the Model is clicked, the system will trigger Model.onClick(ARObject,String).

The return value (true or false) determines whether the event is consumed by this callback function (see also Drawable::onClick).

Event Payload:

  • arObject ARObject

    the ARObject the clicked Drawable is attached to.

  • modelPart String

    the name of the model part which was clicked. A model usually consists of hierarchy of model parts: nodes and mesh parts. Each node contains one or mesh parts. If a node holds only one mesh, modelPart is equal to node's name. If a node contains more than one mesh parts, modelPart is a string composed of XYZ[i], where XYZ is the node's name and i is the index of the model part enclosed in brackets. A list of model parts which can be clicked can be obtained from the Wikitude 3D Encoder.

onDragBegan

Inherited from Drawable

Executed when the user starts dragging on a Drawable with a single finger. 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

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

  • xIntersection Number

    the world space X-coordinate of the intersection position of the initiating touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

onDragChanged

Inherited from Drawable

Executed when the user drags on a Drawable with a single finger. 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]

  • xIntersection Number

    the world space X-coordinate of the intersection position of the updated touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

  • xIntersection Number

    the world space X-coordinate of the intersection position of the updated touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

onDragEnded

Inherited from Drawable

Executed when the user stops dragging on a Drawable with a single finger. 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

  • xIntersection Number

    the world space X-coordinate of the intersection position of the final touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

  • xIntersection Number

    the world space X-coordinate of the intersection position of the final touch ray and the instant tracking plane [-infinity, infinity]; undefined if no InstantTrackable is available

onError

The trigger will fire when the Model file cannot be loaded.

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 onLoaded. To get more detailed information why the model failed to load, the error trigger can have an error message parameter.

onInitialized

The trigger will fire when the Model file is successfully loaded and is about to be rendered.

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

onLoaded

The trigger will fire when the Model file is successfully loaded.

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

onPanBegan

Inherited from Drawable

Executed when the user starts dragging on a Drawable with two fingers. 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 Drawable

Executed when the user drags on a Drawable with two fingers. 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 Drawable

Executed when the user stops dragging on a Drawable with two fingers. 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 Drawable

Executed when the user starts rotating on a Drawable with two fingers. 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 Drawable

Executed when the user rotates on a Drawable with two fingers. 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 Drawable

Executed when the user stops rotating on a Drawable with two fingers. 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 Drawable

Executed when the user starts scaling on a Drawable with two fingers. 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 Drawable

Executed when the user scales on a Drawable with two fingers. 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 Drawable

Executed when the user stops scaling on a Drawable with two fingers. 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