Skip to main content

Scene.INode

Scene Node

A scene node is an object with a 3D transform: position, rotation, and scale. It can contain a collection of components and manages their life cycle.

A scene node has the following states:

Initializing - after construction but before start has been called

Updating - after start has been called but before stop has been called

Destroyed - after stop has been called

Components can only be added during the Initializing state. A scene node cannot be restarted.

const [sceneObject] = await sdk.Scene.createObjects(1);
const node = sceneObject.addNode();
node.addComponent('mp.gltfLoader', {
url: 'http://www.someModelSite.com/rabbit.gltf'
});

node.position.set(0, 1, 0);
node.start();

Setting the position, rotation, or scale of a scene node affects child components.

Properties​

name​

name: string

The node name.

Accessors​

id​

id: (readonly) string

A read-only unique id used to reference this node in a path binding. This id is autogenerated unless it is specifed and created via the Scene.Object.

position​

position: (readonly) THREE.Vector3

The scene node position. You can call methods on this object to set its values. See {@link https://threejs.org/docs/#api/en/math/Vector3}

quaternion​

quaternion: (readonly) THREE.Quaternion

The scene node rotation. You can call methods on this object to set its values. See {@link https://threejs.org/docs/#api/en/math/Quaternion}

scale​

scale: (readonly) THREE.Vector3

The scene node scale vector. You can call methods on this object to set its values. See {@link https://threejs.org/docs/#api/en/math/Vector3}

Methods​

addComponent​

addComponent: method — 2 overloads
addComponent(name: T, initialInputs?: SceneComponentOptions[T], id?: string): Scene.IComponent

Creates an instance of the component and adds it to the node. Does nothing if the node is in the Operating or Destroyed state.

ParameterType
nameT
The registered component name.
initialInputs?SceneComponentOptions[T]
Values for the component's inputs, set before onInit runs. Keys that aren't inputs are ignored.
id?string
The component id. Generated if omitted.

Returns: Scene.IComponent

The newly created component.

addComponent(name: SceneComponentName, initialInputs?: Partial<NonNullable<T['inputs']>>, id?: string): T

Creates an instance of the component, adds it to the node, and returns it typed as T. T is the component's type, such as its class or IComponentThis as registered. As with Scene.register, Inputs must be a type alias, not an interface.

type BoxInputs = { visible: boolean };
type BoxComponent = Scene.IComponentThis<BoxInputs>;
// registered earlier with sdk.Scene.register<BoxInputs>('myapp.box', ...)

const box = node.addComponent<BoxComponent>('myapp.box');
box.inputs.visible = false;
ParameterType
nameSceneComponentName
The registered component name.
initialInputs?Partial<NonNullable<T['inputs']>>
Values for the component's inputs, set before onInit runs.
id?string
The component id. Generated if omitted.

Returns: T

The newly created component.

componentIterator​

componentIterator(): IterableIterator<Scene.IComponent>

Returns in iterator iterating over all the components contained by this node.

Returns: IterableIterator<Scene.IComponent>

start​

start(): void

Transitions the node to Operating if it is in the Initializing state. Calling this function has no effect if the node is already Operating.

stop​

stop(): void

Transitions the node to Destroyed state if it is in any state. Calling this function has no effect if the node is already Destroyed.