Program Class

Extends ResourceManager
Module: Core

Program class contains all the data of a app.

Is stores and manages all available resources used by the children objects.

Is responsible for handling runtime tasks, initialization, update, resizes etc.

Methods

add

(
  • scene
)

Add new scene to this program.

On the program class only scenes can be added as children.

Parameters:

arAvailable

()

Check if augmented reality is available.

The program need to be configured for AR and the host device should support the required WebXR modes.

clone

() Program

Clone program, keeping uuids and every identification attribute.

Clone method uses the ObjectLoad to serialize and create a new program instance with the same data.

Returns:

Program:

Cloned program

dispose

()

Dispose program data to avoid memory leaks.

Called when exiting the program.

enterAR

()

Enter virtual reality mode.

enterVR

()

Enter virtual reality mode.

exitAR

()

Exit augmented reality mode.

exitVR

()

Exit virtual reality mode.

initialize

()

Select initial scene and initialize that scene.

Automatically called by the runtime.

receiveDataApp

(
  • data
)

Receive external data and pass it to all script instances.

Parameters:

  • data Object

remove

(
  • scene
)

Remove Scene from program.

Parameters:

render

(
  • renderer
)

Render current scene to canvas.

When rendering in VR mode all effects and camera parameters are ignored.

Renderer should be initialized and passed as argument.

Parameters:

  • renderer Renderer

resize

(
  • x
  • y
)

Resize the current scene elements.

Parameters:

  • x Number

    Width.

  • y Number

    Height.

sendDataApp

(
  • data
)

Send data to external app instance.

Parameters:

  • data Object

setInitialScene

(
  • uuid
)

Set a scene as initial scene using its uuid.

This method is used by the editor.

Parameters:

  • uuid String

    Scene uuid

setMouseKeyboard

(
  • mouse
  • keyboard
)

Set program mouse and keyboard.

Should be set before initialize() is called otherwise a keyboard and mouse are created by default.

Parameters:

setRenderer

(
  • renderer
  • configure
)

Set program renderer to be used by this program.

Gets the renderer canvas and uses the parent DOM element of the canvas for DOM division property.

Parameters:

  • renderer WebGLRenderer

    Three.js renderer to be used by this program

  • configure Bool

    If true also updates renderer configuration to match rendering quality specified in the program.

setScene

(
  • scene
)

Change scene during runtime, this method can receive booth a scene name or a scene object.

This method should be used inside of script objects during runtime.

Parameters:

  • scene Scene | string

    Scene object or name of the scene to be used.

toJSON

(
  • meta
  • exportResources
)
Object

Serialize the object to JSON format.

Parameters:

  • meta Object

    Metadata object passed to the objects and resources toJSON method to store data.

  • exportResources Boolean

    If true all resources in the program are exported, else only resources attached to objects are exported.

Returns:

Object:

json Serialized JSON data containing the program, all scenes and resources stored.

update

()

Update program state, this updated all current scene children elements.

updateRenderer

()

This method updated the webgl renderer configuration.

Should be called after changing any rendering related parameter.

vrAvailable

()

Check if virtual reality is available.

Properties

app

App

Runtime instance used to communication between app and the host webpage.

Inside the editor communication with the app is simulated on the debug console.

ar

Boolean

Enable augmented reality flag to allow the application to run using AR using WebXR.

author

String

Program author, will be stamped when the app is exported.

canvas

Element

Canvas being used to draw content by the renderer.

This canvas is where the WebGL rendering context was created.

clock

Clock

Clock object used to measure times between frames.

The time measured is passed down to the scene and its children elements.

defaultCamera

Camera

Default camera to be used by scenes where there is no camera.

On the editor this value is automatically set to the last editor camera point used

defaultScene

Scene

Scene loaded as default on startup.

description

String

Program description, will be stamped when the app is exported.

division

Element

DOM Division element that can be used to add html content to the app.

All content added to this division should be manually removed before the app exits.

handlePixelRatio

Boolean

Flag to indicate if the runtime should handle device pixel ratio.

If set false the runtime will ignore the pixel ratio, and use in browser coordinates.

keyboard

Keyboard

Keyboard input object, runtime variable.

lockPointer

Boolean

Flag to control pointer locking, when set true the cursor is locked into the application window.

Default: false

manager

EventManager

Event manager used to attach and manage program events.

Its created on initialization and destroys on disposal, scripts can attach events to the manager safely during runtime.

mouse

Mouse

Mouse input object, runtime variable.

name

String

Program name.

renderer

WebGLRenderer

Renderer being used during runtime.

rendererConfig

RendererConfiguration

Renderer configuration applied to the WebGL renderer.

scene

Scene

Scene currently running in the program, runtime variable.

Should never be manually defined, change it using the setScene(scene) method.

targetConfig

TargetConfig

Target related configurations applied when exporting the app.

version

String

Program version should adhere to semantic versioning, but it is not mandatory.

Default: "0.0.0"

vr

Boolean

Enable virtual reality flag, allows the application to run in VR mode.

VR mode can only be enabled if the system and browser have support for VR using WebXR or WebVR.

vrScale

Number

Virtual reality movement scale.

Indicates the relation between the real movement and virtual world movement.

xrEnabled

Boolean

WebX runtime control, true when the app is running in an XR environment.

XR environment can be VR or AR only one of them can be used at a time.

xrMode

Number

Indicates the XR mode currently active.

Attributes

XR_AR

Number static

XR is running in AR mode.

XR_NONE

Number static

No XR mode is enabled.

XR_VR

Number static

XR is running in VR mode.