index file template

Javascript XR+ API

The XR+ javascript API let developpers add front-end functionalities that do not exist in XR+, it also allows for a deeper UI / screens customization.

How it works?

The API is a project module to enable in the studio

The API allows 1 javascript file and 1 css file to be loaded in the <body> of the experience web document, with the usual <script> and <style> tags.

You must host those 2 files and let us know their web address so we can set them up in our internal system.

We provide a simple example – a javascript class – on how we recommend to communicate with the XR+ elements of the experience.

You can register and listen to particular events such as when the experience starts, or when an image marker is found/lost.

You can also setup your own events with the XR+ studio action editor. By doing so you can setup an action on a composition item to call a function you have defined in your script.

download the javascript API class example

How to start?

Let us know on which project you would like to activate the API module and the url of the .js and .css you need to load in the <body> of the experience.

States interactions module tutorial

Let’s learn how to add interactions to XR.+ projects using the interactions module.

For this tutorial we’ll be using a simple 3D model file made of 3 objects (meshes): a sphere, a cube and a pyramid.

This tutorial will explain how to create states and buttons to hide and show those 3 objects.

You can download the Blender file and the fbx exported from Blender to make this tutorial by clicking here.

Create a new project in the studio, and start by importing the fbx file and adding it to the composition.

1. Activate the module

In the modules section, turn on the ‘states interactions’ module

2. The default state

For now there is only one state, the default one. This defaut state is applied as soon as the scene in loaded and ready.

States actions are applied when the scene switch into the corresponding state.

On this first state, we’ll only show the sphere and hide the cube and the pyramid, to do so, we need 2 actions.

The first action will show the sphere, the second one will hide the cube and the pyramid.

3. The other states

Let’s create another state, this new state will only show the cube. Again, we need 2 actions: one to show, another one to hide.

Then the the last state will show only the Pyramid, and like the other states, will hide the other 2 objects.

The 3 states now look like this, each with 2 actions:

4. Buttons

Now that we have created our 3 states add added action to each of them, we need buttons to switch between those.

Create a first button to switch to the state 1.

We need 3 buttons: one for each state. The second button will switch to state 2, and the third button will switch to state 3.

5. Adding buttons to states

And finally we need to add the buttons to each state so they can be visible during the experience, at the bottom of the screen.

Optional: adding some animations

We can add 3 actions to the first state to animates the objects. Choose ‘play basic animation’, select the mesh to animate and choose an animation.

Final result

Tracking modes

There are 3 possible webAR tracking modes in XR+:

  • Image tracking
  • Surface tracking (SLAM)
  • Fixed tracking

Image tracking

In the image tracking mode, the composition of the experience is displayed on top of a specific image target trained and recognized by the system.

To learn more about training an image target as an AR marker, see the AR image targets section.

Surface tracking (SLAM)

With surface tracking you don’t need a specific image target, the project composition can be displayed on any flat surface using the webXR web API.

With the webXR API, you can place AR content in your environment anchored with a precise flat surface tracking and move around, that 6 degrees of freedom (6DOF).

Currently only possible on Android Chrome, Edge, and Samsung internet, on a large selection of phones.
Check list of supported phones

In cases where the webXR API is not available on the phone browser, then a 3 degrees of freedom (3DOF) fallback is used, with a simpler tracking method, but compatible with absolutely all cases.

Fixed tracking

With the fixed tracking mode, the AR composition for your project is always visible, centered in the middle of the phone screen.