AnchorSpace
public final class AnchorSpace extends SpaceEntity
| java.lang.Object | ||||
| ↳ | androidx.xr.scenecore.BaseScenePose | |||
| ↳ | androidx.xr.scenecore.Entity | |||
| ↳ | androidx.xr.scenecore.SpaceEntity | |||
| ↳ | androidx.xr.scenecore.AnchorSpace |
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 |
addOriginChangedListener(@NonNull Runnable listener)Adds a listener to be called when the |
final void |
addOriginChangedListener(Adds a listener to be called when the |
final void |
addStateChangedListener(Adds a listener to be invoked on the main thread when the AnchorSpace's state changes. |
final void |
addStateChangedListener(Adds a listener to be invoked on the given |
static final @NonNull AnchorSpace |
Public factory for an AnchorSpace which uses an |
static final @NonNull AnchorSpace |
create(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 |
getState()The current tracking state for this AnchorSpace. |
final void |
removeOriginChangedListener(@NonNull Runnable listener)Removes the listener to be called when the |
final void |
removeStateChangedListener(Removes the given state changed listener. |
Inherited methods |
||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
Public methods
addOriginChangedListener
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.
addOriginChangedListener
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.
addStateChangedListener
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
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.
create
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.
create
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 |
|
@NonNull FloatSize2d minimumPlaneExtents |
The minimum extents (in meters) of the plane to which this AnchorSpace should attach. |
@NonNull Set<@NonNull PlaneOrientation> planeOrientations |
|
@NonNull Set<@NonNull PlaneSemanticType> planeSemanticTypes |
|
@NonNull Duration timeout |
The amount of time as a |
| Throws | |
|---|---|
IllegalStateException |
if |
getAnchor
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
public final @NonNull AnchorSpace.State getState()
The current tracking state for this AnchorSpace.
removeOriginChangedListener
public final void removeOriginChangedListener(@NonNull Runnable listener)
Removes the listener to be called when the Anchor's origin moves relative to its underlying space.
removeStateChangedListener
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. |