public final class AnchorEntity extends BaseEntity


An AnchorEntity is created to track a Pose relative to some position or surface in the "Real World." Children of this Entity will remain positioned relative to that location in the real world, for the purposes of creating Augmented Reality experiences.

Note that Anchors are only relative to the "real world", and not virtual environments. Also, calling setParent() on an AnchorEntity has no effect, as the parenting of an Anchor is controlled by the system.

Summary

Nested types

public enum AnchorEntity.PersistState extends Enum

Specifies the current persist state of the Anchor.

public static class AnchorEntity.State

Public methods

static final @NonNull AnchorEntity
create(@NonNull Session session, @NonNull Anchor anchor)

Public factory function for an AnchorEntity which uses an Anchor from ARCore for XR.

static final @NonNull AnchorEntity
create(
    @NonNull Session session,
    @NonNull Dimensions bounds,
    int planeType,
    int planeSemantic,
    @NonNull Duration timeout
)

Public factory function for an AnchorEntity which searches for a location to create an Anchor among the tracked planes available to the perception system.

final @NonNull Anchor

Loads the ARCore for XR Anchor using a Jetpack XR Runtime session.

final int

Returns the current tracking state for this AnchorEntity.

final void
setOnSpaceUpdatedListener(
    OnSpaceUpdatedListener listener,
    Executor executor
)

Registers a listener to be called when the Anchor moves relative to its underlying space.

final void
setOnStateChangedListener(
    OnStateChangedListener onStateChangedListener
)

Registers a listener callback to be issued when an anchor's state changes.

Inherited methods

From androidx.xr.scenecore.ActivityPose
abstract @NonNull Pose

Returns the activity space pose for this ActivityPose.

abstract @NonNull ListenableFuture<@NonNull HitTestResult>
hitTestAsync(@NonNull Vector3 origin, @NonNull Vector3 direction)

Creates a hit test from the specified origin in the specified direction into the scene.

abstract @NonNull ListenableFuture<@NonNull HitTestResult>
hitTestAsync(
    @NonNull Vector3 origin,
    @NonNull Vector3 direction,
    @ActivityPose.HitTestFilterValue int hitTestFilter
)

Creates a hit test from the specified origin in the specified direction into the scene.

abstract @NonNull Pose

Returns a pose relative to this ActivityPose transformed into a pose relative to the destination.

From androidx.xr.scenecore.BaseEntity
void

Sets an Entity to be represented in this coordinate space.

boolean

Adds a Component to this Entity.

void

Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children.

float
getAlpha(int relativeTo)

Returns the alpha transparency set for this Entity, relative to given space.

@NonNull List<@NonNull Component>

Retrieves all components attached to this Entity.

@NonNull List<@NonNull T>

Retrieves all Components of the given type T and its sub-types attached to this Entity.

Entity

Returns the parent of this Entity.

@NonNull Pose
getPose(int relativeTo)

Returns the pose for this entity, relative to the provided space.

float
getScale(int relativeTo)

Returns the scale of this entity, relative to given space.

boolean
isHidden(boolean includeParents)

Returns the hidden status of this Entity.

void

Remove all components from this Entity.

void

Removes the given Component from this Entity.

void
setAlpha(float alpha, int relativeTo)

Sets the alpha transparency of the Entity relative to given space.

void

Sets alternate text for this entity to be consumed by Accessibility systems.

void
setHidden(boolean hidden)

Sets the local hidden state of this Entity.

void
setParent(Entity parent)

Sets this Entity to be represented in the parent's coordinate space.

void
setPose(@NonNull Pose pose, int relativeTo)

Sets the pose for this Entity.

void
setScale(float scale, int relativeTo)

Sets the scale of this entity relative to given space.

From androidx.xr.scenecore.Entity
float

Returns the alpha transparency set for this Entity.

@NonNull Pose

Returns the pose for this entity, relative to its parent.

float

Returns the local scale of this entity, not inclusive of the parent's scale.

void
setAlpha(float alpha)

Sets the alpha transparency of the Entity and its children.

void

Sets the pose for this Entity, relative to its parent.

void
setScale(float scale)

Sets the scale of this entity relative to its parent.

Public methods

create

Added in 1.0.0-alpha04
public static final @NonNull AnchorEntity create(@NonNull Session session, @NonNull Anchor anchor)

Public factory function for an AnchorEntity which uses an Anchor from ARCore for XR.

Parameters
@NonNull Session session

Session to create the AnchorEntity in.

@NonNull Anchor anchor

The PerceptionAnchor to use for this AnchorEntity.

create

Added in 1.0.0-alpha04
public static final @NonNull AnchorEntity create(
    @NonNull Session session,
    @NonNull Dimensions bounds,
    int planeType,
    int planeSemantic,
    @NonNull Duration timeout
)

Public factory function for an AnchorEntity which searches for a location to create an Anchor among the tracked planes available to the perception system.

Parameters
@NonNull Session session

Session to create the AnchorEntity in.

@NonNull Dimensions bounds

Bounds for this AnchorEntity.

int planeType

Orientation of plane to which this Anchor should attach.

int planeSemantic

Semantics of the plane to which this Anchor should attach.

@NonNull Duration timeout

The amount of time as a Duration to search for the a suitable plane to attach to. If a plane is not found within the timeout, the returned AnchorEntity state will be set to AnchorEntity.State.TIMEDOUT. It may take longer than the timeout period before the anchor state is updated. If the timeout duration is zero it will search for the anchor indefinitely.

Throws
kotlin.IllegalStateException

if session.config.planeTracking is set to PlaneTrackingMode.Disabled.

getAnchor

Added in 1.0.0-alpha04
public final @NonNull Anchor getAnchor(@NonNull Session session)

Loads the ARCore for XR Anchor using a Jetpack XR Runtime session.

Parameters
@NonNull Session session

the Jetpack XR Runtime session to load the Anchor from.

Returns
@NonNull Anchor

the ARCore for XR Anchor corresponding to the native pointer.

getState

Added in 1.0.0-alpha04
public final int getState()

Returns the current tracking state for this AnchorEntity.

setOnSpaceUpdatedListener

Added in 1.0.0-alpha04
public final void setOnSpaceUpdatedListener(
    OnSpaceUpdatedListener listener,
    Executor executor
)

Registers a listener to be called when the Anchor moves relative to its underlying space.

The callback is triggered by any anchor movements such as those made by the underlying perception stack to maintain the anchor's position relative to the real world. Any cached data relative to the activity space or any other "space" should be updated when this callback is triggered.

Parameters
OnSpaceUpdatedListener listener

The listener to register if non-null, else stops listening if null.

Executor executor

The executor to run the listener on. Defaults to SceneCore executor if null.

setOnStateChangedListener

Added in 1.0.0-alpha04
public final void setOnStateChangedListener(
    OnStateChangedListener onStateChangedListener
)

Registers a listener callback to be issued when an anchor's state changes.