BoundsComponent


class BoundsComponent : Component


A component that monitors the bounds of an entity and notifies registered listeners of changes.

The bounds are represented as an axis-aligned bounding box (AABB). This component acts as a bridge to the underlying runtime, receiving bounds update events. These events are triggered whenever the entity's transformation changes, which can be caused by animations, direct pose manipulation, or changes to its parent's transformation.

Note: Currently, this component can only be attached to a GltfModelEntity. Attaching it to other entity types will fail.

To receive updates, register a BiConsumer<Entity, BoundingBox> listener using the addOnBoundsUpdateListener method. The listener will be invoked on the provided Executor, which defaults to the main thread. Listeners should be unregistered using removeOnBoundsUpdateListener when no longer needed to prevent resource leaks.

Create instances of this component using the BoundsComponent.create factory method.

Summary

Public companion functions

BoundsComponent
create(session: Session)

Creates a BoundsComponent.

Public functions

Unit

Registers a listener that will be invoked on the main application thread for bounds updates.

Unit
addOnBoundsUpdateListener(
    executor: Executor,
    listener: BiConsumer<EntityBoundingBox>
)

Registers a listener to receive bounds updates.

open Boolean
onAttach(entity: Entity)

Called by an Entity when it attempts to add this Component to itself.

open Unit
onDetach(entity: Entity)

Called by an Entity when it attempts to detach this Component from itself.

Unit

Unregisters a previously registered bounds update listener.

Public companion functions

create

Added in 1.0.0-alpha12
fun create(session: Session): BoundsComponent

Creates a BoundsComponent.

Parameters
session: Session

The active Session.

Returns
BoundsComponent

A new BoundsComponent instance.

Public functions

addOnBoundsUpdateListener

Added in 1.0.0-alpha12
fun addOnBoundsUpdateListener(listener: BiConsumer<EntityBoundingBox>): Unit

Registers a listener that will be invoked on the main application thread for bounds updates.

This is a convenience overload of addOnBoundsUpdateListener that defaults to using the main thread executor, which is useful for performing UI updates in response to bounds changes.

Parameters
listener: BiConsumer<EntityBoundingBox>

The BiConsumer to be invoked with bounds updates on the main thread.

addOnBoundsUpdateListener

Added in 1.0.0-alpha12
fun addOnBoundsUpdateListener(
    executor: Executor,
    listener: BiConsumer<EntityBoundingBox>
): Unit

Registers a listener to receive bounds updates.

The listener's accept(Entity, BoundingBox) method will be invoked on the specified Executor whenever the entity's bounds change. The updated bounds are provided as a BoundingBox.

Each listener instance can only be registered once. Registering the same listener instance multiple times will have no effect.

Parameters
executor: Executor

The executor on which the listener callbacks will be invoked.

listener: BiConsumer<EntityBoundingBox>

The BiConsumer to be invoked with the entity and its updated bounds.

onAttach

Added in 1.0.0-alpha12
open fun onAttach(entity: Entity): Boolean

Called by an Entity when it attempts to add this Component to itself.

This method is restricted because it is only called from Entity.addComponent.

Parameters
entity: Entity

Entity to which this Component was attached.

Returns
Boolean

True if the Component was attached to the given Entity. False if the Entity did not support having this Component attached.

onDetach

Added in 1.0.0-alpha12
open fun onDetach(entity: Entity): Unit

Called by an Entity when it attempts to detach this Component from itself.

This method is restricted because it is only called from Entity.removeComponent.

Parameters
entity: Entity

Entity from which this Component was detached.

removeOnBoundsUpdateListener

Added in 1.0.0-alpha12
fun removeOnBoundsUpdateListener(listener: BiConsumer<EntityBoundingBox>): Unit

Unregisters a previously registered bounds update listener.

The specified listener will no longer receive bounds updates. It is important to call this method when the listener is no longer needed to prevent potential resource and memory leaks.

If the listener was not previously registered, this method has no effect.

Parameters
listener: BiConsumer<EntityBoundingBox>

The BiConsumer instance to unregister. This must be the same object instance that was passed to addOnBoundsUpdateListener.