Wikitude SDK API Reference

API Docs for: 4.0.2
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: {
    roll: 90.0,
    tilt: 180.0,
    heading: 0.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 zip 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
    • horizontalAnchor Number optional
    • rotate.roll (defaults to 0) Number optional
    • rotate.tilt (defaults to 0) Number optional
    • rotate.heading (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
    • translate.x (defaults to 0) Number optional
    • translate.y (defaults to 0) Number optional
    • translate.z (defaults to 0) Number optional
    • onClick Function optional
    • onLoaded Function optional
    • onError Function optional

Methods

destroy

()

Inherited from ARchitectObject

Destroys the object.

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

heading

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.heading instead.

roll

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.roll instead.

rotate.heading

Number

Inherited from Drawable

Defines a rotation of the Drawable around the y-axis, 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.roll

Number

Inherited from Drawable

Defines a rotation of the Drawable around the z-axis, 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.tilt

Number

Inherited from Drawable

Defines a rotation of the Drawable around the x-axis, 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

scale.x

Number

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

Default: 1

scale.y

Number

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

Default: 1

scale.z

Number

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

Default: 1

tilt

Number deprecated

Inherited from Drawable

Deprecated: Use rotate.tilt instead.

translate.x

Number

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

Default: 0

translate.y

Number

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

Default: 0

translate.z

Number

The depth-offset to the calculated position of the Model, in SDUs. A positive z causes the Model to move towards the user, a negative offsetX 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 Drawable is clicked, the system will trigger Drawable.onClick(ARObject). A click on the screen might hit multiple Drawables, thus a click creates a "clicked Drawables-queue", with the uppermost Drawable in the front of the queue. The return value of the function determines if, after the onClick()-Function was executed for this Drawable, the queue shall continue to execute onClick() for the next Drawable in the queue. In case the last Drawable in the queue still requests to continue the click-queue, ARObject.onClick() will be executed. If the queue still continues, context.onScreenClick() will be executed.

The return value of the function determines what happens next. If false, the click-queue should not stop with this Drawable. Thus, the next Drawable'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 Drawable. If true, the queue-execution will stop at the current Drawable, underlying Drawables will not receive onClick() calls.

Event Payload:

  • arObject ARObject

    the ARObject the clicked Drawable is attached to.

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

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.

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.

triggers.onClick

deprecated

Inherited from Drawable

Deprecated: Use onClick instead.