AnchorEntity
public final class AnchorEntity extends BaseEntity
| java.lang.Object | |||
| ↳ | androidx.xr.scenecore.BaseScenePose | ||
| ↳ | androidx.xr.scenecore.BaseEntity | ||
| ↳ | androidx.xr.scenecore.AnchorEntity |
An AnchorEntity tracks a androidx.xr.runtime.math.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, setting the Entity.parent property on an AnchorEntity has no effect, as the parenting of an Anchor is controlled by the system.
Summary
Nested types |
|---|
public final class AnchorEntity.State |
Public methods |
|
|---|---|
static final @NonNull AnchorEntity |
Public factory for an AnchorEntity which uses an |
static final @NonNull AnchorEntity |
create(Factory for an AnchorEntity which searches for a real-world surface on which to anchor, from the set of tracked planes available to the perception system. |
void |
dispose()Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children. |
final Anchor |
Returns the ARCore for Jetpack XR Anchor associated with this AnchorEntity. |
@NonNull Pose |
Returns the pose of the |
float |
Returns the scale of the |
final @NonNull AnchorEntity.State |
getState()The current tracking state for this AnchorEntity. |
final void |
setOnSpaceUpdatedListener(Runnable listener)Registers a listener to be called when the |
final void |
setOnSpaceUpdatedListener(@NonNull Executor executor, Runnable listener)Registers a listener to be called when the |
final void |
setOnStateChangedListener(Registers a listener to be invoked on the main thread when the AnchorEntity's state changes, or unregisters the current listener if set to null. |
final void |
setOnStateChangedListener(Registers a listener to be invoked on the given |
Inherited methods |
||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
Public methods
create
public static final @NonNull AnchorEntity create(@NonNull Session session, @NonNull Anchor anchor)
Public factory for an AnchorEntity which uses an Anchor from ARCore for Jetpack XR.
create
public static final @NonNull AnchorEntity create(
@NonNull Session session,
@NonNull FloatSize2d minimumPlaneExtents,
int planeOrientation,
int planeSemanticType,
@NonNull Duration timeout
)
Factory for an AnchorEntity 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 AnchorEntity should attach. |
int planeOrientation |
|
int planeSemanticType |
|
@NonNull Duration timeout |
The amount of time as a |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if |
dispose
public void dispose()
Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children. Once disposed, this Entity is invalid and cannot be used again.
getAnchor
public final Anchor getAnchor()
Returns the ARCore for Jetpack XR Anchor associated with this AnchorEntity.
| Returns | |
|---|---|
Anchor |
the ARCore for Jetpack XR Anchor associated with this AnchorEntity. This may be null if the AnchorEntity is still searching for a suitable anchor. |
getPose
public @NonNull Pose getPose(@NonNull Space relativeTo)
Returns the pose of the AnchorEntity relative to the specified coordinate space.
| Parameters | |
|---|---|
@NonNull Space relativeTo |
The coordinate space to get the pose relative to. Defaults to |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if called with Space.PARENT since AnchorEntity has no parents. |
getScale
public float getScale(@NonNull Space relativeTo)
Returns the scale of the AnchorEntity relative to the specified coordinate space.
| Parameters | |
|---|---|
@NonNull Space relativeTo |
The coordinate space to get the scale relative to. Defaults to |
| Returns | |
|---|---|
float |
The current scale of the |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if called with Space.PARENT since AnchorEntity has no parents. |
getState
public final @NonNull AnchorEntity.State getState()
The current tracking state for this AnchorEntity.
setOnSpaceUpdatedListener
public final void setOnSpaceUpdatedListener(Runnable listener)
Registers a listener to be called when the Anchor moves relative to its underlying space.
The callback is triggered on the default SceneCore Executor 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. It will be automatically unregistered when the entity is disposed.
| Parameters | |
|---|---|
Runnable listener |
The listener to register if non-null, else stops listening if null. |
setOnSpaceUpdatedListener
public final void setOnSpaceUpdatedListener(@NonNull Executor executor, Runnable listener)
Registers a listener to be called when the Anchor moves relative to its underlying space.
The callback is triggered on the supplied Executor 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. It will be automatically unregistered when the entity is disposed.
setOnStateChangedListener
public final void setOnStateChangedListener(
Consumer<@NonNull AnchorEntity.State> listener
)
Registers a listener to be invoked on the main thread when the AnchorEntity's state changes, or unregisters the current listener if set to null.
The listener will fire with the current AnchorEntity.State value immediately upon registration. It will be automatically unregistered when the entity is disposed.
setOnStateChangedListener
public final void setOnStateChangedListener(
@NonNull Executor executor,
Consumer<@NonNull AnchorEntity.State> listener
)
Registers a listener to be invoked on the given Executor when the AnchorEntity's state changes, or unregisters the current listener if set to null.
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. |
Consumer<@NonNull AnchorEntity.State> listener |
: The listener to fire upon invoking this method, and all subsequent state changes. |