Skip to main content

Scene.IObject

A factory and container for a collection of scene nodes and components connected via property bindings.

Methods

addEmitPath

addEmitPath(component: Scene.IComponent, property: string, id?: string): Scene.EmitPath
Introduced 3.1.71.14-0-gaf77add383

Add and receive an EmitPath for an IComponent. It is also possible to spy when an event is emitted by creating an ISceneObjectSpy and calling spyOnEvent. The path can be bound to an EventPath of another (or the same) component to automatically trigger the component's IComponent.onEvent.

class Clickable {
public events = {
clicked: true,
};
}
// create an `IObject`, add an `INode` and an `IComponent` to the node, see the relevant functions (createObject, addNode, addComponent)
const [object, node, component];

// create the path
const emitPath = object.addEmitPath(component, 'clicked');

// bind the emit path so that it triggers the `emitPath`'s associated component's onEvent when an event is emitted
object.bindPath(eventPath, emitPath);

// observe emissions of 'clicked' events in component
object.spyOnEvent({
path: emitPath,
onEvent(eventData) {
console.log(`a 'clicked' event was emitted with the data: ${eventData}`);
},
});
ParameterType
componentScene.IComponent
the component containing the emit property
propertystring
the name of the emit property
id?string
an optional unique identifier for the path

Returns: Scene.EmitPath

addEventPath

addEventPath(component: Scene.IComponent, property: string, id?: string): Scene.EventPath
Introduced 3.1.71.14-0-gaf77add383

Add and receive an EventPath for an IComponent. The path can be bound to an EmitPath of another (or the same) component to automatically trigger the component's IComponent.onEvent.

class Renderable {
public events = {
rerender: true,
};
}
// create an `IObject`, add an `INode` and an `IComponent` to the node, see the relevant functions (createObject, addNode, addComponent)
const [object, node, component];

// create the path
const eventPath = object.addEventPath(component, 'rerender');

// bind the event path so that it triggers the component's onEvent when `emitPath` emits an event
object.bindPath(eventPath, emitPath);
ParameterType
componentScene.IComponent
the component containing the event property
propertystring
the name of the event property
id?string
an optional unique identifier for the path

Returns: Scene.EventPath

addInputPath

addInputPath(component: Scene.IComponent, property: string, id?: string): Scene.InputPath
Introduced 3.1.71.14-0-gaf77add383

Add and receive an InputPath to the property of an IComponent. The returned InputPath can be used to read or set the value of property on component's inputs. Changes to the value can also be observed by creating an ISceneObjectSpy and calling spyOnEvent. The path can also be bound to an OutputPath of another (or the same) component to automatically update a component's input value.

class Counter {
public inputs = {
count: 1,
};
}
// create an `IObject`, add an `INode` and an `IComponent` to the node, see the relevant functions (createObject, addNode, addComponent)
const [object, node, component];

// create the path
const inputPath = object.addInputPath(component, 'count');

// observe changes to the value of `inputs.count` in component
object.spyOnEvent({
path: inputPath,
onEvent(newValue) {
console.log(`component.input.count's new value is ${newValue}`);
},
});
// read and change the value of the input in the component
const countValue = inputPath.get();
inputPath.set(count + 1);

// bind the path to the value from another (output) path
object.bindPath(inputPath, outputPath);
ParameterType
componentScene.IComponent
the component containing the input property
propertystring
the name of the input property
id?string
an optional unique identifier for the path

Returns: Scene.InputPath

addNode

addNode(id?: string): Scene.INode

Adds a scene node to this scene object and returns it. If an id isn't provided, one will be autogenerated.

ParameterType
id?string
a optional unique id

Returns: Scene.INode

The new scene node.

addNodes

addNodes(nodeCount: number): Scene.INode[]

Create an array of scene nodes.

ParameterType
nodeCountnumber
the number of nodes to create. This value must be greater than zero.

Returns: Scene.INode[]

An array of nodes.

addOutputPath

addOutputPath(component: Scene.IComponent, property: string, id?: string): Scene.OutputPath
Introduced 3.1.71.14-0-gaf77add383

Add and receive an OutputPath to the property of an IComponent. The returned OutputPath can be used to read the value of component's output property. Changes to the value can also be observed by creating an ISceneObjectSpy and calling spyOnEvent. The path can also be bound to an InputPath of another (or the same) component to automatically update a component's input value.

class NumberGenerator {
public outputs = {
current: 1,
};
}
// create an `IObject`, add an `INode` and an `IComponent` to the node, see the relevant functions (createObject, addNode, addComponent)
const [object, node, component];

// create the path
const outputPath = object.addOutputPath(component, 'current');

// observe changes to the value of `outputs.current` in component
object.spyOnEvent({
path: outputPath,
onEvent(newValue) {
console.log(`component.output.current's new value is ${newValue}`);
},
});
// read and bind the value of the output to another component's input value
const currentValue = outputPath.get();
object.bindPath(inputPath, outputPath);
ParameterType
componentScene.IComponent
the component containing the output property
propertystring
the name of the output property
id?string
an optional unique identifier for the path

Returns: Scene.OutputPath

addPath

addPath: method4 overloads
addPath(pathDesc: InputPathDescriptor): Scene.InputPath

Add a path identified by a unique string. They pathDesc.type will determine which path type is returned.

ParameterType
pathDescInputPathDescriptor
The path descriptor to the component property.

Returns: Scene.InputPath

addPath(pathDesc: OutputPathDescriptor): Scene.OutputPath
ParameterType
pathDescOutputPathDescriptor

Returns: Scene.OutputPath

addPath(pathDesc: EventPathDescriptor): Scene.EventPath
ParameterType
pathDescEventPathDescriptor

Returns: Scene.EventPath

addPath(pathDesc: EmitPathDescriptor): Scene.EmitPath
ParameterType
pathDescEmitPathDescriptor

Returns: Scene.EmitPath

bind

bind(targetComponent: Scene.IComponent, targetProp: string, sourceComponent: Scene.IComponent, sourceProp: string): void
deprecated Use IObject.bindPath instead.

Call this function to bind an input property of the target component to an output property of the source component between any nodes contained by this scene object.

ParameterType
targetComponentScene.IComponent
The component listening to property changes.
targetPropstring
The component input property name.
sourceComponentScene.IComponent
The component broadcasting property changes.
sourcePropstring
The component output property name.

bindPath

bindPath: method2 overloads
bindPath(inputPath: Scene.InputPath, outputPath: Scene.OutputPath): void

Bind the value referenced by inputPath to the value of outputPath. As the value at outputPath changes, the value of inputPath will reflect it.

const [sceneObject] = await sdk.Scene.createObjects(1);
const node = sceneObject.addNode();

// mp.objLoader has an outputs.visible property
const comp1 = node.addComponent('mp.objLoader');
const outputPath = sceneObject.addOutputPath(comp1, 'visible', 'objLoader-visible');

// myComponent has an inputs.toggleState property
const comp2 = node.addComponent('myComponent');
const inputPath = sceneObject.addInputPath(comp2, 'toggleState', 'myComponent-toggle');
sceneObject.bindPath(inputPath, outputPath);

node.start();
// comp1.inputs.visible will now always equal comp2.outputs.toggleState
ParameterType
inputPathScene.InputPath
the input path to receive value updates
outputPathScene.OutputPath
the output path providing value updates
bindPath(eventPath: Scene.EventPath, emitPath: Scene.EmitPath): void

Bind an event referenced by eventPath to a IComponent.notify call at emitPath

const [sceneObject] = await sdk.Scene.createObject(1);
const node = sceneObject.addNode();

// myReceiver has an `onEvent` lifecycle function and an `events['do.update']` property
const receiver = node.addComponent(`myReceiver');
const eventPath = sceneObject.addEventPath(receiver, 'do.update', 'my-reciever-update');

// myEmitter calls notify with an 'updated' event and has an `emits['updated']` property
const emitter = node.addComponent('myEmitter');
const emitPath = sceneObject.addEmitPath(emitter, 'updated', 'my-component-updated');
sceneObject.bindPath(eventPath, emitPath);

node.start();
// receiver.onEvent('do.update', ...) will now be called whenever emitter calls notify('updated')
ParameterType
eventPathScene.EventPath
the event path to receive emitted events
emitPathScene.EmitPath
the emit path that triggers events

getValueAtPath

getValueAtPath(pathId: string): unknown
deprecated Use InputPath.get or OutputPath.get instead.

Reads the output property of a path. The path must be added prior to calling this function.

ParameterType
pathIdstring
the path id to read from

Returns: unknown

the value of the output property.

nodeIterator

nodeIterator(): IterableIterator<Scene.INode>

Returns in iterator iterating over all the nodes contained by this object.

Returns: IterableIterator<Scene.INode>

pathIterator

pathIterator(): IterableIterator<Scene.PathInfo>

Returns an iterator containing a path and its descriptor. Typically used to access the paths from a deserialized scene object.

// This example sets the values of all input paths provided by deserialized scene object.

const deserialized = await sdk.Scene.deserialize(myString);
const paths = deserialized.pathIterator();
for (const { desc, path } of paths) {
if (desc.type === Scene.PathType.INPUT) {
// we know this path is an input path
const inputPath = desc.path as Scene.InputPath;

// Now you can set the value at the path
// You can cache the returned input path to use it later.
inputPath.set(10);
}
}

Returns: IterableIterator<Scene.PathInfo>

setValueAtPath

setValueAtPath(pathId: string, value: unknown): void
deprecated Use InputPath.set instead.

Sets the input property of a path. The path must be added prior to calling this function.

ParameterType
pathIdstring
The path id.
valueunknown
The value to set.

spyOnEvent

Spy on events or input and output value changes

const [sceneObject] = await sdk.Scene.createObjects(1);
const node = sceneObject.addNode();

// mp.objLoader has an outputs.visible property
const comp1 = node.addComponent('mp.objLoader');
const outputPath = sceneObject.addOutputPath(comp1, 'visible', 'objLoader-visible');

const outputSpy = {
path: outputPath,
onEvent(type, data) {
console.log('outputs updated', type, data);
}
};

sceneObject.spyOnEvent(outputSpy);

node.start();
// outputSpy.onEvent('outputsUpdated', comp1.outputs.visible) will now be called whenever comp1.outputs.visible changes
ParameterType
spyScene.ISceneObjectSpy
the spy object to attach for event or value change notifications

Returns: ISubscription

start

start(): void

Starts all nodes referenced by this scene object.

stop

stop(): void

Stops all nodes referenced by this scene object. The scene object cannot be restarted after this function has been called.