Skip to main content

Scene.IComponent

The runtime shape of a scene component instance, as returned by {@link INode.addComponent} or yielded by {@link INode.componentIterator}.

TypeScript users: see {@link IComponentFactory} to define a component.

function Box() {
this.inputs = {
visible: false,
};

this.onInit = function() {
var THREE = this.context.three;
var geometry = new THREE.BoxGeometry(1, 1, 1);
this.material = new THREE.MeshBasicMaterial();
var mesh = new THREE.Mesh( geometry, this.material );
this.outputs.objectRoot = mesh;
};

this.onEvent = function(type, data) {
}

this.onInputsUpdated = function(previous) {
};

this.onTick = function(tickDelta) {
}

this.onDestroy = function() {
this.material.dispose();
};
}

function BoxFactory() {
return new Box();
}

// Registering the component with the sdk
sdk.Scene.register('box', BoxFactory);

Extends: IComponentBase, Scene.IComponentRuntimeMembers

Properties

componentType

componentType: (readonly) string

The component type. This value is the same string used to identify the component factory.

context

The context provides access to the underlying rendering engine. The sdk framework adds it to the component during construction.

emits

emits: (optional) Record<string, boolean> | undefined

An optional dictionary of events emitted by this component. Setting an emit to a falsy value will prevent the component from emitting the event when using .notify. These properties can be changed by an external source at any time. If this dictionary is omitted, any and all events will be emitted from .notify.

events

events: Record<string, boolean>

Declared events; SDK initializes to {} when omitted

inputs

inputs: (optional) { [x: string]: unknown; } | undefined

An optional dictionary of properties that affects the behavior of the component. These properties can be changed by an external source at any time. It is up to the component to respond appropriately to the changes. These input properties can also be bind targets to an observable source e.g. the output property of another component.

isMeasurable

isMeasurable: (optional) boolean | undefined

Whether the outputs.collider of this component will be one of the meshes considered for intersection testing in the measurement tool. Put simply, is this component measurable.

Manual and more granular control of pointer intersection can be done by setting the .userData.isMeasurable on each THREE.js mesh.

outputs

Declared outputs, plus SDK-reserved outputs

Methods

bind

bind(prop: string, src: Scene.IComponent, srcProp: string): void
deprecated Use IObject.bindPath instead.

Call this function to bind an input property to an output property on another component.

ParameterType
propstring
inputs property name
srcScene.IComponent
source component
srcPropstring
source outputs property name

bindEvent

bindEvent(eventType: string, src: Scene.IComponent, srcEventType: string): void
deprecated Use IObject.bindPath instead.

Notifies this component of an eventType when the src Component calls notify with a srcEventType event

ParameterType
eventTypestring
srcScene.IComponent
srcEventTypestring

notify

notify(eventType: string, eventData?: unknown): void

Emit an event to other components

ParameterType
eventTypestring
eventData?unknown

onDestroy

onDestroy(): void

This function is called once right before the scene node has stopped.

onEvent

onEvent(eventType: string, eventData?: unknown): void

This function is called once for each interaction or event that occurred during the last frame. The component must set outputs.collider with an Object3D to get interaction callbacks or bindEvent to receive other events.

ParameterType
eventTypestring
eventData?unknown

onInit

onInit(): void

This function is called once after the scene node its attached to has started.

onInputsUpdated

onInputsUpdated(previousInputs: { [x: string]: unknown; }): void

This function is called after one or more input properties have changed. It will be called at most once a frame.

ParameterType
previousInputs{ [x: string]: unknown; }

onTick

onTick(tickDelta: number): void

This function is called once a frame after input changes have been detected.

ParameterType
tickDeltanumber

spyOnEvent

spyOnEvent(spy: Scene.IComponentEventSpy<unknown>): ISubscription
deprecated Use IObject.spyOnEvent instead.

Spy on a component's notify from outside of the component system

ParameterType
spyScene.IComponentEventSpy<unknown>

Returns: ISubscription

an object responsible for removing the spy