Player API
  • Dark
    Light

Player API

  • Dark
    Light

Modules

Camera

This module is for manipulating the camera.

Configurator

This module is for manipulating the configuration.

Player

This is the root player api.

Scene

This module is a high level scene graph manipulation and query library.

  • Either id, name, or regex's can be used for node names.
  • All get functions return the value, or undefined if no match is found
  • All find functions return an id or a Path
  • All filter functions return an array of id or Path
Tools

This module is for manipulating tools. The default set of tools installed will handle scene navigation (orbit, pan, zoom) for both mice and touch interfaces.

Members

includesboolean

Check if a selectionSet includes a node.

Functions

toggle(query)

toggle nodes in a selectionSet

add(query)

add nodes to selectionSet.

remove(query)

remove nodes from selectionSet.

clear()

remove all nodes from selectionSet

set(query)

clear the selectionSet and add nodes from query equivalent to call clear and add together.

getStyle()

get the selectionSetStyle, including outlineColor, outlineThinkness, color and opacity

setStyle(selectionSetStyle)

set the selectionSetStyle, including outlineColor, outlineThinkness, color and opacity

Camera

This module is for manipulating the camera.

Camera~orbit(dx, dy)

Orbit the active camera.

Kind: inner method of Camera

Param Type
dx number
dy number

Example

player.camera.orbit(1, 0);

Camera~pan(dx, dy)

Pan the active camera.

Kind: inner method of Camera

Param Type
dx number
dy number

Example

player.camera.pan(1, 0);

Camera~zoom(delta)

Zoom the active camera.

Kind: inner method of Camera

Param Type
delta number

Example

player.camera.zoom(1);

Camera~frameBoundingSphere([assetIds], [direction], [options])

frame the active camera.

Kind: inner method of Camera

Param Type
[assetIds] Array.<String>
[direction] Vector3
[options] any

Example

player.cameraController.frameBoundingSphere();

Configurator

This module is for manipulating the camera.

Configurator~prefetchAttributes(attributes) ⇒ Promise

pretch all images for attributes options in 2d player

Kind: inner method of Configurator

Param Type
attributes Array.<string>

Example

await api.configurator.prefetchAttributes(['Rotation'])

Player

This is the root player api.

Player.assetId : string

The root asset id attached to the player

Kind: static property of Player

Player.camera : Camera

The camera controller module

Kind: static property of Player

Player.selectionSet : SelectionSet

The selectionSet controller module

Kind: static property of Player

Player.scene : Scene

The scene module

Kind: static property of Player

Player.THREE : THREE

The three.js math modules

Kind: static property of Player

Player.unload

Kind: static property of Player

Player.setImagePlaceholderMode

Kind: static property of Player

Player.getConfigurator() ⇒

Returns a promise that resolves to the active configurator.

Kind: static method of Player
Returns:

Promise


Player.on(event, handler)

Add event listener

Kind: static method of Player

Param Type
event string
handler function

Example

player.on(player.scene.PHASES.LOADED, () => console.log('loaded'));

Player.when(event) ⇒ Promise

Return a promise that resolves when phase has been reached

Kind: static method of Player

Param Type
event string

Example

await player.when(player.scene.PHASES.LOADED);

Player.setActiveCamera(id)

Set the active camera.

Kind: static method of Player

Param Type
id string

Example

player.setActiveCamera("42a3d1ef-5c42-4276-8a14-665d58d8174c");

Player.snapshot([options]) ⇒ string

Return a snapshot of the player encoded in base 64

Kind: static method of Player

Param Type Description
[options] Object
[options.mimeType] string

the type of the snapshot, image/png (default) or image/jpeg

[options.size] Object
[options.size.width] number

width of the snapshot

[options.size.height] number

height of the snapshot

Example

player.snapshot({ mimeType: "image/jpeg"});

Scene

This module is a high level scene graph manipulation and query library.

  • Either id, name, or regex's can be used for node names.
  • All get functions return the value, or undefined if no match is found
  • All find functions return an id or a Path
  • All filter functions return an array of id or Path

Scene~find(query)

Finds first matching node. (See {@tutorial sdk-SceneGraph})

Kind: inner method of Scene

Param Type Description
query QueryObject

The query object to filter on.

Example

// Return the node uuid
scene.find({ name: 'Box' }); -> ['uuid']
// Return the path to the transform operator
scene.find({ name: 'Box', plug: 'Transform', property: 'translation' }); -> ['uuid','plugs','Transform',0]
// Match the first node that starts with Box
scene.find({ name: 'Box*' });

Scene~fetch(id)

Fetch an asset, to make it available for querying sceneGraph data.

Kind: inner method of Scene

Param Type Description
id String

Asset id to fetch

Scene~alignNode(nodeId, alignNodeId)

Move nodeId to align with alignNodeId, optionally using anchorNodeId to do the alignment.

Kind: inner method of Scene

Param Type Description
nodeId String

The node that will be aligned.

alignNodeId String

The node nodeId will align with.

options.anchorNodeId String

Optionally, the child of nodeId that will be aligned with alignNodeId. If left undefined, nodeId itself will be aligned to alignNodeId.

options.withRotation boolean

Default is false. When set to true, both position and rotation of alignNodeId and anchorNodeId will be same after alignment.

Example

// Move the sword to place the sword handle in the hand
scene.alignNode(swordId, handId, { anchorNodeId: swordHandleId, withRotation: true });

"PHASES"

There are three events that are triggered in turn as the scene loads: PRELOADED, LOADED, and RENDERED.

Kind: event emitted by Scene
Read only: true
Properties

Name Description
PHASES.PRELOADED

Emitted when the scene and all assets necessary to render the scene have been loaded. Occurs before the 'loaded' event, and is an opportunity to modify the scene before it becomes visible. A change here might trigger more loading.

PHASES.LOADED

Emitted when the scene and all assets necessary to render the scene have been loaded.

PHASES.RENDERED

Emitted when the scene is ready for display.

Tools

This module is for manipulating tools. The default set of tools installed will handle scene navigation (orbit, pan, zoom) for both mice and touch interfaces.

Tools~addTool(toolName)

Add a tool to the player.

Kind: inner method of Tools

Param Type
toolName string

Example

player.addTool('orbit')

Tools~addTools(toolNames)

Add an array of tools to the player.

Kind: inner method of Tools

Param Type
toolNames array

Example

player.addTools(['pan', 'orbit', 'zoom'])

Tools~removeTool(toolName)

Remove a tool from the player.

Kind: inner method of Tools

Param Type
toolName string

Example

player.removeTool('orbit')

Tools~removeTools(toolNames)

Remove an array of tools from the player.

Kind: inner method of Tools

Param Type
toolNames array

Example

player.removeTools(['pan', 'orbit', 'zoom'])

Tools~setPrimary(toolName)

Set a tool as Primary tool.

Kind: inner method of Tools

Param Type
toolName string

Example

player.setPrimary('zoom')

Tools~getPrimaryTool() ⇒ string

Get the current primary tool.

Kind: inner method of Tools
Returns: string -

primaryToolName


Example

player.getPrimaryTool()

includes ⇒ boolean

Check if a selectionSet includes a node.

Kind: global variable

Param Type Description
query Object | string | Array.<string>

query object or nodeId or array of nodeIds

toggle(query)

toggle nodes in a selectionSet

Kind: global function

Param Type Description
query Object | string

query object or nodeId

Example

selectionSet.add({ name: 'Box' });

add(query)

add nodes to selectionSet.

Kind: global function

Param Type Description
query Object | string

query object or nodeId

Example

selectionSet.add({ name: 'Box' });

remove(query)

remove nodes from selectionSet.

Kind: global function

Param Type Description
query Object | string | Array.<string>

query object or nodeId or array of nodeIds

Example

selectionSet.remove({ name: 'Box' });

clear()

remove all nodes from selectionSet

Kind: global function

set(query)

clear the selectionSet and add nodes from query equivalent to call clear and add together.

Kind: global function

Param Type Description
query Object | string

query object or nodeId

getStyle()

get the selectionSetStyle, including outlineColor, outlineThinkness, color and opacity

Kind: global function

setStyle(selectionSetStyle)

set the selectionSetStyle, including outlineColor, outlineThinkness, color and opacity

Kind: global function

Param Type Description
selectionSetStyle Object

query object or nodeId

Example

selectionSet.setStyle({ outlineColor: '#00ff00', outlineThinkness: 5, color: '#ff0000', opacity: 0.5 });
Was this article helpful?