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 the framework when this component is being added to an Entity.

open Unit
onDetach(entity: Entity)

Called by the framework when this component is being removed from an Entity.

Unit

Unregisters a previously registered bounds update listener.

Public companion functions

create

Added in 1.0.0-alpha14
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-alpha14
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-alpha14
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

open fun onAttach(entity: Entity): Boolean

Called by the framework when this component is being added to an Entity.

This method is triggered when Entity.addComponent is invoked. It should not be called directly by applications. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided entity.

Parameters
entity: Entity

The Entity to which this component is being attached.

Returns
Boolean

true if the component was successfully attached; false if the entity does not support this component or if attachment failed.

onDetach

open fun onDetach(entity: Entity): Unit

Called by the framework when this component is being removed from an Entity.

This method is triggered when Entity.removeComponent is invoked. It should not be called directly by applications. Implementations should override this method to release resources or undo any changes made during onAttach.

Parameters
entity: Entity

The Entity from which this component is being detached.

removeOnBoundsUpdateListener

Added in 1.0.0-alpha14
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.