Embed SDK

Onirix Embed SDK allows you to listen to events and control the scene when embedding experiences in a custom domain or from the online code editor.

ar-engine-sdk

Include the library

If you use ESM modules, you can just import the library as:

import OnirixEmbedSDK from "https://sdk.onirix.com/embed/ox-embed-sdk.esm.js";

If not, use the UMD library instead by adding a new script tag inside your page's head section:

<script src="https://sdk.onirix.com/embed/ox-embed-sdk.umd.js"></script>

If you're using the online code editor, you'll have to create this script dinamically from the Javascript block in order to add it to the head section:

const script = document.createElement('script');
script.src = "https://sdk.onirix.com/embed/ox-embed-sdk.umd.js";
script.onload = async () => {

    // You're now ready to instantiate and use the embed SDK.

};
document.head.appendChild(script);

Instantiate and connect

Create a new instance of the SDK by passing the iframe HTML element in the constructor and call the connect method:

const iframeElement = document.getElementById("your_iframe_id_here");
const embedSDK = new OnirixEmbedSDK(iframeElement);
embedSDK.connect();

If there is not any iframe (when using the code editor), you can just instantiate the SDK with arguments:

const embedSDK = new OnirixEmbedSDK();
embedSDK.connect();

Connect method returns a promise. If you want to ensure there is not any error and connection was done successfully, you can add an await keyword before or use the old promise syntax with then and catch functions.

Listen to Events

You can listen to the following events for the experience:

Event Description
OnirixEmbedSDK.Events.READY Will be triggered when all permissions are accepted and the camera becomes visible
OnirixEmbedSDK.Events.SCENE_LOAD_START Will be triggered when the scene starts loading. This is, when an image is detected or you select a surface to place the scene
OnirixEmbedSDK.Events.SCENE_LOAD_END Will be triggered when the scene finishes loading, and thus, the assets are visible
OnirixEmbedSDK.Events.SCENE_LOST Will be triggered when you lose sight of the image and the scene is removed
OnirixEmbedSDK.Events.ELEMENT_CLICK Will be triggered when an element is clicked, receiving its oid as argument
OnirixEmbedSDK.Events.OPEN_MARKERS_PANEL Will be triggered when image markers panel is opened
OnirixEmbedSDK.Events.CLOSE_MARKERS_PANEL Will be triggered when image markers panel is closed

In order to listen to any of those events, you just need to use the subscribe method:

embedSDK.subscribe(OnirixEmbedSDK.Events.ELEMENT_CLICK, (params) => {
    console.log("Element with oid: " + params.oid + " was clicked!");
});

susbcribe method returns a subscription id you can use later to unsubscribe by calling the unsubscribe method.

Control the scene with Actions

Actions are useful to create custom behaviour and be able to trigger changes in the scene from HTML elements.

These are the actions you can run with Onirix Embed SDK:

Action Params
enable(oid) oid: element oid
disable(oid) oid: element oid
toggle(oid) oid: element oid
enableAll() -
disableAll() -
play(oid) oid: element oid
pause(oid) oid: element oid
translate(oid, x, y, z, time, loop) oid: element oid, x: amount on x axis, y: amount on y axis, z: amount on z axis: time: duration, loop: repeat indefinitely
rotate(oid, x, y, z, time, loop) oid: element oid, x: amount on x axis, y: amount on y axis, z: amount on z axis: time: duration, loop: repeat indefinitely
scale(oid, x, y, z, time, loop) oid: element oid, x: amount on x axis, y: amount on y axis, z: amount on z axis: time: duration, loop: repeat indefinitely
playAnimation(oid, name) oid: element oid, name: animation name
stopAnimation(oid) oid: element oid

In order to run an action, just call its method with required parameters:

embedSDK.disable('your_element_oid');

Results