SumerianRunner

SumerianRunner

The main class that updates the world and calls the renderers.

Constructor

new SumerianRunner(optionsopt)

Parameters:
Name Type Attributes Description
options Object <optional>

SumerianRunner settings passed in a JSON object

Properties
Name Type Attributes Default Description
alpha boolean <optional>
false

Specifies if the canvas should have an alpha channel or not.

premultipliedAlpha boolean <optional>
true

Enables or disables premultiplication of color by alpha

antialias boolean <optional>
true

Specifies if antialiasing should be turned on or no

stencil boolean <optional>
false

Enables the stencil buffer

preserveDrawingBuffer boolean <optional>
false

By default the drawing buffer will be cleared after it is presented to the HTML compositor. Enable this option to not clear the drawing buffer

canvas HTMLCanvasElement <optional>

If not supplied, Renderer will create a new canvas

showStats boolean <optional>
false

If enabled a small stats widget showing stats will be displayed

useDevicePixelRatio boolean <optional>
false

Take into account the device pixel ratio (for retina screens etc)

autoStartEngine boolean <optional>
true

By default the engine's execution will start automatically.

autoStartWorld boolean <optional>
true

By default the world's execution will start automatically.

usePerformanceNowTiming boolean <optional>
true

By default tpf is calculated using performance.now(). Set to false to use browser-provided time

tpfSmoothingCount boolean <optional>
10

Specifies the amount of previous frames to use when computing the 'time per frame'

debugKeys boolean <optional>
false

If enabled the hotkeys Shift+[1..6] will be enabled

renderer boolean <optional>

Instance of Sumerian Renderer . If not set, the default Sumerian WebGL1/2 renderer is used

useTryCatch boolean <optional>
true

Members

callbacks :Array.<SumerianRunnerCallback>

A list of callbacks to call every frame, after the rendering is done.

callbacksNextFrame :Array.<SumerianRunnerCallback>

A list of callbacks to call once, in the following frame, before the world is processed.

callbacksPreProcess :Array.<SumerianRunnerCallback>

A list of callbacks to call every frame, before the world is processed.

callbacksPreRender :Array.<SumerianRunnerCallback>

A list of callbacks to call every frame, after the world is processed and before the rendering is done.

isEngineRunning

Indicates if the engine execution loop is currently running. Use {@link
startEngine} to start the execution loop and stopEngine to stop
the execution loop.

useTryCatch :boolean

Set to true to run user-defined callbacks within try/catch statements. Errors will be printed to console.

Default Value:
  • true

world :World

The Sumerian world.

Methods

addEventListener(type, callback)

Adds an event listener to the SumerianRunner.

Parameters:
Name Type Description
type string

Can currently be 'click', 'mousedown', 'mousemove', 'mouseup',
'touchstart', 'touchend' or 'touchmove'.

callback function

Callback function.

Properties
Name Type Description
event.entity Entity

Picked entity, undefined if no entity is picked.

event.intersection Vector3

Point of pick ray intersection with scene.

event.depth number

Depth of pick ray intersection.

event.x number

Canvas x coordinate.

event.y number

Canvas y coordinate.

event.type string

Type of triggered event ('mousedown', 'touchstart', etc).

event.domEvent Event

Original DOM event.

event.id number

Entity pick ID. -1 if no entity was picked.

Example
sumerianRunner.addEventListener('mousedown', function (event) {
  if (event.entity) {
    console.log('clicked entity', event.entity.name);
    console.log('clicked point', event.intersection);
  }
});

addStats()

Adds a small stats widget showing fps, rendercalls, vertices, indices, transform updates and cached shaders

clear()

Clears the SumerianRunner and anything associated with it. Once this method
is called this instanceof of SumerianRunner is unusable.

pick(x, y, callback, skipUpdateBuffer)

Requests a pick from screen space coordinates. A successful pick returns id and depth of the pick target.

Parameters:
Name Type Description
x number

screen coordinate

y number

screen coordinate

callback function

to handle the pick result

skipUpdateBuffer boolean

when true picking will be attempted against existing buffer

pickSync(x, y, skipUpdateBuffer)

Pick, the synchronous method. Uses the same pickbuffer so it will affect asynch picking. Also goes only through the normal render system.

Parameters:
Name Type Description
x number

screen coordinate

y number

screen coordinate

skipUpdateBuffer boolean

when true picking will be attempted against existing buffer

removeEventListener(type, callback)

Removes an event listener from the SumerianRunner.

Parameters:
Name Type Description
type string

Can currently be 'click', 'mousedown', 'mousemove', 'mouseup',
'touchstart', 'touchend' or 'touchmove'.

callback function

Callback to remove from event listener.

removeStats()

Removes stats widget

startEngine()

Starts the engine's execution loop. The engine can be stopped using {@link
stopEngine}. The engine is started automatically by the SumerianRunner
constructor unless the noStartEngine option was specified.

The world's execution state is independent from the engine's execution
state, and is controled by startWorld, pauseWorld,
resumeWorld, and stopWorld. When the engine is stopped
the world will not execute, and when the engine is restarted, the world
will continue to execute in whatever state it was in when the engine was
stopped.

stopEngine()

Stops the engine's execution loop. The engine can be restarted using {@link
startEngine}. The engine is started automatically by the SumerianRunner
constructor unless the noStartEngine option was specified.

The world's execution state is independent from the engine's execution
state, and is controled by World#start, World#pause,
World#resume, and World#stop. When the engine is stopped
the world will not execute, and when the engine is restarted, the world
will continue to execute in whatever state it was in when the engine was
stopped.

takeSnapshot(callback)

Takes an image snapshot from the 3d scene at next render call.

Parameters:
Name Type Description
callback function

triggerEvent(type, evt)

Triggers an event on the SumerianRunner (force).

Parameters:
Name Type Description
type string

Can currently be 'click', 'mousedown', 'mousemove', 'mouseup',
'touchstart', 'touchend' or 'touchmove'.

evt Object

The SumerianRunner-style event

Properties
Name Type Description
entity Entity

Event entity.

x number

Event canvas X coordinate.

y number

Event canvas Y coordinate.

domEvent Event

The original DOM event.