Skip to content

ObjectEntity

Entity in the scene

Access properties and representations, listen to events.

Example:

javascript
var entity = scene.findEntity({ name: "My Box" });
entity.position = Vector3(0, 1, 0);
entity.on('tap', function() {
    console.log('Tapped!');
});

Properties

id

  • Type: string
  • Unique entity identifier

representation

Methods

animateBy()

javascript
animateBy(properties: Object, duration: number, options?: Object): Promise<void>

Animate this entity's representation by relative values (additive animation)

Parameters:

  • properties (Object) - Relative change values
  • duration (number) - Animation duration in seconds
  • options (Object) (optional) - Animation options

Returns: Promise<void>

animateFromTo()

javascript
animateFromTo(fromProperties: Object, toProperties: Object, duration: number, options?: Object): Promise<void>

Animate this entity's representation from starting to target properties

Parameters:

  • fromProperties (Object) - Starting property values
  • toProperties (Object) - Target property values
  • duration (number) - Animation duration in seconds
  • options (Object) (optional) - Animation options

Returns: Promise<void>

animateTo()

javascript
animateTo(properties: Object, duration: number, options?: Object): Promise<void>

Animate this entity's representation to target properties

Parameters:

  • properties (Object) - Target properties to animate to
  • properties.position (Vector3) (optional) - Target position
  • properties.rotation (Rotation) (optional) - Target rotation
  • properties.scale (Vector3) (optional) - Target scale
  • properties.transform (Transform) (optional) - Target transform (overrides position/rotation/scale)
  • properties.opacity (number) (optional) - Target opacity (0-1)
  • duration (number) - Animation duration in seconds
  • options (Object) (optional) - Animation options
  • options.timingFunction (string | Object) (optional) - Easing: "linear", "easeIn", "easeOut", "easeInOut", or custom
  • options.delay (number) (optional) - Delay before animation starts (seconds)
  • options.repeatCount (number) (optional) - Number of times to repeat (-1 for infinite)
  • options.repeatMode (string) (optional) - "default", "autoReverse", or "cumulative"

Returns: Promise<void>

createAudioStream()

javascript
createAudioStream(options?: Object): AudioStream

Create a streaming audio player on this entity

Parameters:

  • options (Object) (optional) - Stream options

Returns: AudioStream

findRepresentation()

javascript
findRepresentation(query: any): RepresentationEntity

Find a representation by ID or name

Example:

javascript
// By ID
var rep = entity.findRepresentation("ABC123");

// By name
var rep = entity.findRepresentation({ name: "Main Model" });

Parameters:

  • query (any) - Representation ID string, or object with { id: "..." } or { name: "..." }

Returns: RepresentationEntity

off()

javascript
off(eventId: string): void

Remove an entity event listener

Example:

javascript
var eventId = entity.on('tap', function() {});
// Later...
entity.off(eventId);

Parameters:

  • eventId (string) - Event ID returned from on()

Returns: void

on()

javascript
on(type: string, options?: Object | function, listener?: function): string

Register an entity event listener

Example:

javascript
entity.on('tap', function(event) {
    console.log('Entity tapped!');
});

Parameters:

  • type (string) - Event type: "tap", "add", "collision", "distance", "lookAt", "mediaPlayback"
  • options (Object | function) (optional) - Event options or callback
  • listener (function) (optional) - Callback if options provided

Returns: string

once()

javascript
once(type: string, options?: Object | function, listener?: function): string

Register a one-time entity event listener

Example:

javascript
entity.once('tap', function(event) {
    console.log('First tap only!');
});

Parameters:

  • type (string) - Event type
  • options (Object | function) (optional) - Event options or callback
  • listener (function) (optional) - Callback if options provided

Returns: string

play()

javascript
play(animation: Animation): Promise<void>

Play an animation on this entity's representation

Parameters:

  • animation (Animation) - Animation object from Animation.to(), Animation.spin(), etc.

Returns: Promise<void>

playAudio()

javascript
playAudio(source: string, options?: Object): Promise<void>

Play audio asset on this entity

Parameters:

  • source (string) - HTTPS URL or asset ID from project
  • options (Object) (optional) - Playback options

Returns: Promise<void>

playAudioBuffer()

javascript
playAudioBuffer(base64: string, options?: Object): Promise<void>

Play audio buffer on this entity

Parameters:

  • base64 (string) - Base64-encoded PCM audio data
  • options (Object) (optional) - Buffer and playback options

Returns: Promise<void>

remove()

javascript
remove(): Promise<void>

Remove this entity from the scene

Returns: Promise<void>

setMaterial()

javascript
setMaterial(options?: Object): Promise<void>

Set material on this entity's representation

Parameters:

  • options (Object) (optional) - Material options, omit to clear

Returns: Promise<void>

setMaterials()

javascript
setMaterials(materials: Array<Object>): Promise<void>

Set materials on this entity's representation

Parameters:

  • materials (Array<Object>) - Array of material options

Returns: Promise<void>

stopAnimations()

javascript
stopAnimations(options?: Object): Promise<void>

Stop and remove animations from this entity's representation

Parameters:

  • options (Object) (optional) - Options
  • options.transitionDuration (number) (optional) - Fade out duration in seconds

Returns: Promise<void>

stopAudio()

javascript
stopAudio(): Promise<void>

Stop audio playback on this entity

Returns: Promise<void>

toggle()

javascript
toggle(enabled: boolean): Promise<void>

Enable or disable this entity's representation

Parameters:

  • enabled (boolean) - Enable (true) or disable (false)

Returns: Promise<void>

toggleAnimations()

javascript
toggleAnimations(options?: Object): Promise<void>

Toggle (pause/resume) animations on this entity's representation

Parameters:

  • options (Object) (optional) - Options
  • options.play (boolean) (optional) - Explicit play (true) or pause (false), toggles if omitted
  • options.animationIds (Array<string>) (optional) - Specific animation IDs to toggle

Returns: Promise<void>

waitUntilReady()

javascript
waitUntilReady(): Promise<void>

Wait until this entity's primary representation has finished loading.

Convenience that proxies to entity.representation.waitUntilReady(). Resolves immediately if there's no primary representation.

Returns: Promise<void>

Internal API dev only

WARNING

These methods are internal implementation details and not part of the public API.

subscribeToEvent() internal

javascript
subscribeToEvent(jsonValue: any, callback: any): string

Parameters:

  • jsonValue (any)
  • callback (any)

Returns: string

unsubscribeFromEvent() internal

javascript
unsubscribeFromEvent(eventId: string): void

Parameters:

  • eventId (string)

Returns: void