BoundsComponent


public final class BoundsComponent implements 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 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.

boolean

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

void

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

final void

Unregisters a previously registered bounds update listener.

Public methods

addOnBoundsUpdateListener

Added in 1.0.0-alpha12
public final void addOnBoundsUpdateListener(
    @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 addOnBoundsUpdateListener 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.

addOnBoundsUpdateListener

Added in 1.0.0-alpha12
public final void addOnBoundsUpdateListener(
    @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-alpha12
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.

onAttach

Added in 1.0.0-alpha12
public boolean onAttach(@NonNull Entity entity)

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
@NonNull 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
public void onDetach(@NonNull Entity entity)

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
@NonNull Entity entity

Entity from which this Component was detached.

removeOnBoundsUpdateListener

Added in 1.0.0-alpha12
public final void removeOnBoundsUpdateListener(
    @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 addOnBoundsUpdateListener.