BoundsComponent


public final class BoundsComponent extends 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 addBoundsUpdateListener method. The listener will be invoked on the provided Executor, which defaults to the main thread. Listeners should be unregistered using removeBoundsUpdateListener when no longer needed to prevent resource leaks.

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

Summary

Public methods

final void

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

final void

Registers a listener to receive bounds updates.

static final @NonNull BoundsComponent

Creates a BoundsComponent.

final void

Unregisters a previously registered bounds update listener.

Protected methods

boolean

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

void

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

Public methods

addBoundsUpdateListener

Added in 1.0.0-alpha15
public final void addBoundsUpdateListener(
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)

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

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

Parameters
@NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener

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

addBoundsUpdateListener

Added in 1.0.0-alpha15
public final void addBoundsUpdateListener(
    @NonNull Executor executor,
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)

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
@NonNull Executor executor

The executor on which the listener callbacks will be invoked.

@NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener

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

create

Added in 1.0.0-alpha15
public static final @NonNull BoundsComponent create(@NonNull Session session)

Creates a BoundsComponent.

Parameters
@NonNull Session session

The active Session.

Returns
@NonNull BoundsComponent

A new BoundsComponent instance.

removeBoundsUpdateListener

Added in 1.0.0-alpha15
public final void removeBoundsUpdateListener(
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)

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
@NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener

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

Protected methods

onAttach

protected boolean onAttach(@NonNull Entity entity)

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

This method is triggered when Entity.addComponent is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided entity.

Parameters
@NonNull 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

protected void onDetach(@NonNull Entity entity)

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

This method is triggered when Entity.removeComponent is invoked. Implementations should override this method to release resources or undo any changes made during onAttach.

Parameters
@NonNull Entity entity

The Entity from which this component is being detached.