Class: Viewer

Viewer(domElement, opts)

A Viewer is a single-stage container for multiple scenes.

Constructor

new Viewer(domElement, opts)

Parameters:
Name Type Description
domElement HTMLElement

the HTML element inside which the viewer should be initialized.

opts Object
Properties
Name Type Description
stageType null | 'webgl' | 'css' | 'flash'

stage type to use.

controls Object

options to be passed to registerDefaultControls.

stage Object

options to be passed to the Stage constructor.

Methods

breakIdleMovement()

Stop the idle movement. It will be started again after the timeout set by Viewer#setIdleMovement.

controls() → {Controls}

Return the underlying Controls.

Returns:
Type
Controls

createScene(opts) → {Scene}

Create a new scene.

Parameters:
Name Type Description
opts Object
Properties
Name Type Description
source Source

The underlying Source.

geometry Geometry

The underlying +Geometry.

view View

The underlying View.

pinFirstLevel boolean

Pin the first level to provide a last-resort fallback at the cost of memory consumption.

textureStore Object

Options to pass to the TextureStore constructor.

layerOpts Object

Options to pass to the Layer constructor.

Returns:
Type
Scene

destroy()

Destructor.

destroyAllScenes()

Destroy all scenes.

destroyScene(scene)

Destroy a Scene.

Parameters:
Name Type Description
scene Scene

domElement() → {Element}

Return the underlying DOM element.

Returns:
Type
Element

hasScene(scene) → {boolean}

Return whether the viewer contains a scene.

Parameters:
Name Type Description
scene Scene
Returns:
Type
boolean

listScenes() → {Array.<Scene>}

Get a list of all scenes.

Returns:
Type
Array.<Scene>

lookTo()

Tween the view for the current scene, as would be obtained by calling Scene#lookTo.

renderLoop() → {RenderLoop}

Return the underlying RenderLoop.

Returns:
Type
RenderLoop

scene() → {Scene}

Get the current scene, i.e., the last scene for which Viewer#switchScene was called.

Returns:
Type
Scene

setIdleMovement(timeout, movement)

Schedule an automatic movement to be started when the view remains unchanged for the given timeout period.

Parameters:
Name Type Description
timeout Number

Timeout period in milliseconds.

movement function

Automatic movement function, or null to disable.

stage() → {Stage}

Return the underlying Stage.

Returns:
Type
Stage

startMovement()

Start a movement, as would be obtained by calling Scene#startMovement on the current scene.

stopMovement()

Stop the current movement, as would be obtained by calling Scene#stopMovement on the current scene.

switchScene(newScene, opts, done)

Switch to another scene with a fade transition.

Parameters:
Name Type Description
newScene Scene

The scene to switch to.

opts Object
Properties
Name Type Attributes Default Description
transitionDuration Number <optional>
1000

Transition duration in milliseconds.

transitionUpdate Number <optional>
defaultTransitionUpdate

Transition function with signature f(t, newScene, oldScene). The function is called on each frame with t increasing from 0 to 1. An initial call with t=0 and a final call with t=1 are guaranteed. The default function sets the scene opacity to t.

done function

Called when the transition finishes or is interrupted.

updateSize()

Update the stage size to fill the containing element.

This method is automatically called when the browser window is resized. Most clients won't need to explicitly call it to keep the size up to date.

view() → {View}

Get the view for the current scene, as would be obtained by calling Scene#view.

Returns:
Type
View

Events

sceneChange

Signals that the current scene has changed.

viewChange

Signals that the view of the current scene has changed. See View#event:change.