public final class AnchorSpace extends SpaceEntity


An AnchorSpace is a SpaceEntity tracks a Pose relative to some position or surface in the "Real World." Children of this SpaceEntity will remain positioned relative to that location in the real world.

Note that, as a SpaceEntity, the AnchorSpace's position is independent of the ActivitySpace. It is parentless and its position and scale is controlled by the system. Calling setPose, setScale, or setting the Entity.parent property on the AnchorSpace will result in an UnsupportedOperationException.

AnchorSpace users must maintain a strong reference while the instance is in use. If there's no strong references to anchor instance in client code, anchor instance may become phantom reachable, and it will be garbage collected.

Summary

Nested types

public final class AnchorSpace.State

Public methods

final void

Adds a listener to be called when the Anchor's origin moves relative to its underlying space.

final void
addOriginChangedListener(
    @NonNull Executor executor,
    @NonNull Runnable listener
)

Adds a listener to be called when the Anchor's origin moves relative to its underlying space.

final void

Adds a listener to be invoked on the main thread when the AnchorSpace's state changes.

final void

Adds a listener to be invoked on the given Executor when the AnchorSpace's state changes.

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

Public factory for an AnchorSpace which uses an Anchor from ARCore for Jetpack XR.

static final @NonNull AnchorSpace
create(
    @NonNull Session session,
    @NonNull FloatSize2d minimumPlaneExtents,
    @NonNull Set<@NonNull PlaneOrientation> planeOrientations,
    @NonNull Set<@NonNull PlaneSemanticType> planeSemanticTypes,
    @NonNull Duration timeout
)

Factory for an AnchorSpace which searches for a real-world surface on which to anchor, from the set of tracked planes available to the perception system.

final Anchor

Returns the ARCore for Jetpack XR Anchor associated with this AnchorSpace.

final @NonNull AnchorSpace.State

The current tracking state for this AnchorSpace.

final void

Removes the listener to be called when the Anchor's origin moves relative to its underlying space.

final void

Removes the given state changed listener.

Inherited methods

From androidx.xr.scenecore.BaseScenePose
@NonNull Pose

The current Pose relative to the activity space root.

HitTestResult
hitTest(@NonNull Vector3 origin, @NonNull Vector3 direction)

Perform a hit test from the specified origin in the specified direction into the Scene.

HitTestResult
hitTest(
    @NonNull Vector3 origin,
    @NonNull Vector3 direction,
    int hitTestFilter
)

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

@NonNull Vector3
transformDirectionTo(
    @NonNull Vector3 direction,
    @NonNull ScenePose destination
)

Transforms a direction from this ScenePose's local space to the destination ScenePose's local space.

@NonNull Pose
transformPoseTo(@NonNull Pose pose, @NonNull ScenePose destination)

Returns a Pose relative to this ScenePose, transformed into a Pose relative to the destination.

@NonNull Vector3
transformPositionTo(
    @NonNull Vector3 position,
    @NonNull ScenePose destination
)

Transforms a position from this ScenePose's local space to the destination ScenePose's local space.

@NonNull Vector3

Transforms a vector from this ScenePose's local space to the destination ScenePose's local space.

From androidx.xr.scenecore.Entity
final void

Sets an Entity to be a child of this Entity in the scene graph.

final boolean

Adds a Component to this Entity.

final @FloatRange(from = 0.0, to = 1.0) float
getAlpha(@NonNull Space relativeTo)

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

final @NonNull List<@NonNull Entity>

Provides the list of all children of this entity.

final @NonNull List<@NonNull Component>

Retrieves all components attached to this Entity.

final @NonNull List<@NonNull T>

Retrieves all Components of the given type T and its subtypes attached to this Entity.

final @NonNull CharSequence

Alternate text for this Entity to be consumed by Accessibility systems.

final boolean
isEnabled(boolean includeParents)

Returns the enabled status of this Entity.

final void

Remove all components from this Entity.

final void

Removes the given Component from this Entity.

final void
setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)

Sets the alpha transparency of the Entity relative to the parent Space.

final void

Alternate text for this Entity to be consumed by Accessibility systems.

final void
setEnabled(boolean enabled)

Sets the local enabled state of this Entity.

From androidx.xr.scenecore.SpaceEntity
Entity

Throws UnsupportedOperationException if called.

@NonNull Pose
getPose(@NonNull Space relativeTo)

Returns the pose of the SpaceEntity relative to the specified coordinate space.

float
getScale(@NonNull Space relativeTo)

Returns the scale of the SpaceEntity relative to the specified coordinate space.

void
setParent(Entity <unused var>)

Throws UnsupportedOperationException if called.

void
setPose(@NonNull Pose pose, @NonNull Space relativeTo)

Throws UnsupportedOperationException if called.

void
setScale(float scale, @NonNull Space relativeTo)

Throws UnsupportedOperationException if called.

Public methods

addOriginChangedListener

Added in 1.0.0-beta01
public final void addOriginChangedListener(@NonNull Runnable listener)

Adds a listener to be called when the Anchor's origin moves relative to its underlying space.

The callback is triggered on the main thread by any anchor movements, for example when the perception system moves the anchor's origin 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. It will be automatically unregistered when the entity is disposed.

Parameters
@NonNull Runnable listener

The listener to register. Events will fire on the main thread.

addOriginChangedListener

Added in 1.0.0-beta01
public final void addOriginChangedListener(
    @NonNull Executor executor,
    @NonNull Runnable listener
)

Adds a listener to be called when the Anchor's origin moves relative to its underlying space.

The callback is triggered on the supplied Executor by any anchor movements, for example when the perception system moves the anchor's origin 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. It will be automatically unregistered when the entity is disposed.

Parameters
@NonNull Executor executor

The executor to run the listener on.

@NonNull Runnable listener

The listener to register.

addStateChangedListener

Added in 1.0.0-beta01
public final void addStateChangedListener(
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)

Adds a listener to be invoked on the main thread when the AnchorSpace's state changes.

The listener will fire on the main thread with the current AnchorSpace.State value immediately upon registration. It will be automatically unregistered when the entity is disposed.

addStateChangedListener

Added in 1.0.0-beta01
public final void addStateChangedListener(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)

Adds a listener to be invoked on the given Executor when the AnchorSpace's state changes.

The listener will fire with the current State value immediately upon registration. It will be automatically unregistered when the entity is disposed.

Parameters
@NonNull Executor executor

: The executor on which the specified listener will fire.

@NonNull Consumer<@NonNull AnchorSpace.State> listener

: The listener to fire upon invoking this method, and all subsequent state changes.

create

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

Public factory for an AnchorSpace which uses an Anchor from ARCore for Jetpack XR.

Parameters
@NonNull Session session

Session in which to create the AnchorSpace.

@NonNull Anchor anchor

The Anchor to use for this AnchorSpace.

create

Added in 1.0.0-beta01
public static final @NonNull AnchorSpace create(
    @NonNull Session session,
    @NonNull FloatSize2d minimumPlaneExtents,
    @NonNull Set<@NonNull PlaneOrientation> planeOrientations,
    @NonNull Set<@NonNull PlaneSemanticType> planeSemanticTypes,
    @NonNull Duration timeout
)

Factory for an AnchorSpace which searches for a real-world surface on which to anchor, from the set of tracked planes available to the perception system.

Parameters
@NonNull Session session

Session in which to create the AnchorSpace.

@NonNull FloatSize2d minimumPlaneExtents

The minimum extents (in meters) of the plane to which this AnchorSpace should attach.

@NonNull Set<@NonNull PlaneOrientation> planeOrientations

PlaneOrientations of the plane to which this AnchorSpace should attach.

@NonNull Set<@NonNull PlaneSemanticType> planeSemanticTypes

PlaneSemanticTypes of the plane to which this AnchorSpace should attach.

@NonNull Duration timeout

The amount of time as a Duration to search for the suitable plane to attach to. If a plane is not found within the timeout, the returned AnchorSpace state will be set to AnchorSpace.State.TIMED_OUT. 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.

getAnchor

Added in 1.0.0-beta01
public final Anchor getAnchor()

Returns the ARCore for Jetpack XR Anchor associated with this AnchorSpace.

Returns
Anchor

the ARCore for Jetpack XR Anchor associated with this AnchorSpace. This may be null if the AnchorSpace is still searching for a suitable anchor.

getState

Added in 1.0.0-beta01
public final @NonNull AnchorSpace.State getState()

The current tracking state for this AnchorSpace.

removeOriginChangedListener

Added in 1.0.0-beta01
public final void removeOriginChangedListener(@NonNull Runnable listener)

Removes the listener to be called when the Anchor's origin moves relative to its underlying space.

Parameters
@NonNull Runnable listener

The listener to remove.

removeStateChangedListener

Added in 1.0.0-beta01
public final void removeStateChangedListener(
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)

Removes the given state changed listener.

Parameters
@NonNull Consumer<@NonNull AnchorSpace.State> listener

: The listener to be removed.