App Class

Module: Runtime

app is the main class of the runtime system, is used to embed projects into external webpages and applications.

Project files can be loaded directly from their project files into any kind of project. The app class handles all the runtime and control of the application lifecycle.

Constructor

App

(
  • canvas
)

Parameters:

  • canvas Component

    Canvas to be used by the runtime, if no canvas is provided a new one is created and added to the document.body, to create a new App without canvas a null value can be passed.

Methods

arAvailable

() Boolean

Check if augmented reality mode is available.

Returns:

Boolean:

True if VR mode available

exit

()

Exit from app.

Kills the app and disposes all internal elements to avoid memory leaks.

Should be called before exiting the webpage or before switching programs.

When loading new programs the same app instance can be used.

loadApp

(
  • url
  • canvas
)
static

Load a application and attach it to the canvas indicated.

This method automatically creates resize events, this single line should be enough to make a app run in a webpage.

Parameters:

  • url String

    URL for the nsp or isp file.

  • canvas String

    Canvas object or canvas id.

loadProgram

(
  • fname
)

Load program from file.

Parameters:

  • fname String

    Name of the file to load

loadProgramAsync

(
  • fname
  • onLoad
  • onProgress
)

Load program from file, asynchronously.

Parameters:

  • fname String

    Name of the file to load

  • onLoad Function

    onLoad callback. Receives as argument the loaded application.

  • onProgress Function

    onProgress callback, receives progress (percentage) and the xhr onprogress event as parameters.

loadRunProgram

(
  • fname
  • onLoad
  • onProgress
)

Load program asynchronously and run it after its loaded.

Parameters:

  • fname String

    Name of the file to load

  • onLoad Function

    onLoad callback

  • onProgress Function

    onProgress callback, receives progress (percentage) and the xhr onprogress event as parameters.

pause

()

Pause the running application.

resize

()

Resize the window.

Should be called whenether the host window is resized.

resume

()

Start or resume the paused application.

Starts a new update cycle and sets the running flag.

run

()

Start running program.

Creates renderer, mouse and keyboard objects, and starts running the loaded application.

A program must be loaded before calling this method.

sendData

(
  • data
)

Send data to running application.

The data sent using this method is received by scripts that implement the onAppData method.

Parameters:

  • data Object

    Data to send

setCanvas

(
  • canvas
)

Set the canvas to be used for rendering.

Should be set before starting the program.

Parameters:

  • canvas Component

    Canvas

setOnDataReceived

(
  • callback
)

Set on data receive callback.

Callback receives data as an argument.

Parameters:

  • callback Function

    Function executed whenether the app running sends data to the host

setOnExit

(
  • callback
)

Set on exit callback.

Callback is executed when exiting the app.

Parameters:

  • callback Function

    onExit callback

toggleAR

()

Toggle augmented reality mode, only works if augmented reality mode is available.

toggleFullscreen

(
  • element
)

Set a element to fullscreen mode, if none is passed the rendering canvas is used.

Parameters:

  • element Component

    DOM element to go fullscreen by default the rendering canvas is used

toggleVR

()

Toggle VR mode, only works if VR mode is available.

update

()

Update program state and render to the canvas.

Automatically called by the runtime handler.

vrAvailable

() Boolean

Check if virtual reality mode is available.

Returns:

Boolean:

True if VR mode available

Properties

canvas

Element

Canvas used to render graphics.

canvasFitWindow

Boolean

Flag used to control if the canvas element is resized automatically by the app instance.

If true the canvas is resized whether the resize method is called.

Default: false if a canvas is provided, else true

events

EventManager

Event manager used to create and manage events for this app.

program

Program

Program

renderer

Renderer

Graphics renderer in use by this app instance

running

Boolean

Runtime control, if true the app is running.