AnchorEntity
class AnchorEntity : BaseEntity
| kotlin.Any | |||
| ↳ | 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 |
|---|
class AnchorEntity.State |
Public companion functions |
|
|---|---|
AnchorEntity |
Public factory for an AnchorEntity which uses an |
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. |
Public functions |
|
|---|---|
open Unit |
dispose()Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children. |
Anchor? |
Returns the ARCore for Jetpack XR Anchor associated with this AnchorEntity. |
open Pose |
Returns the pose of the |
open Float |
Returns the scale of the |
Unit |
setOnSpaceUpdatedListener(listener: Runnable?)Registers a listener to be called when the |
Unit |
setOnSpaceUpdatedListener(executor: Executor, listener: Runnable?)Registers a listener to be called when the |
Unit |
setOnStateChangedListener(listener: Consumer<AnchorEntity.State>?)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. |
Unit |
setOnStateChangedListener(Registers a listener to be invoked on the given |
Public properties |
|
|---|---|
AnchorEntity.State |
The current tracking state for this AnchorEntity. |
Inherited functions |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||
|
||||||||||||||||||||
|
Inherited properties |
||||||
|---|---|---|---|---|---|---|
|
||||||
Public companion functions
create
fun create(session: Session, anchor: Anchor): AnchorEntity
Public factory for an AnchorEntity which uses an Anchor from ARCore for Jetpack XR.
create
fun create(
session: Session,
minimumPlaneExtents: FloatSize2d,
planeOrientation: Int,
planeSemanticType: Int,
timeout: Duration = Duration.ZERO
): AnchorEntity
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 | |
|---|---|
session: Session |
|
minimumPlaneExtents: FloatSize2d |
The minimum extents (in meters) of the plane to which this AnchorEntity should attach. |
planeOrientation: Int |
|
planeSemanticType: Int |
|
timeout: Duration = Duration.ZERO |
The amount of time as a |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if |
Public functions
dispose
open fun dispose(): Unit
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
fun getAnchor(): Anchor?
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
open fun getPose(relativeTo: Space): Pose
Returns the pose of the AnchorEntity relative to the specified coordinate space.
| Parameters | |
|---|---|
relativeTo: Space |
The coordinate space to get the pose relative to. Defaults to |
| Returns | |
|---|---|
Pose |
The current pose of the |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if called with Space.PARENT since AnchorEntity has no parents. |
getScale
open fun getScale(relativeTo: Space): Float
Returns the scale of the AnchorEntity relative to the specified coordinate space.
| Parameters | |
|---|---|
relativeTo: Space |
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. |
setOnSpaceUpdatedListener
fun setOnSpaceUpdatedListener(listener: Runnable?): Unit
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 | |
|---|---|
listener: Runnable? |
The listener to register if non-null, else stops listening if null. |
setOnSpaceUpdatedListener
fun setOnSpaceUpdatedListener(executor: Executor, listener: Runnable?): Unit
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
fun setOnStateChangedListener(listener: Consumer<AnchorEntity.State>?): Unit
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
fun setOnStateChangedListener(
executor: Executor,
listener: Consumer<AnchorEntity.State>?
): Unit
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 | |
|---|---|
executor: Executor |
: The executor on which the specified listener will fire. |
listener: Consumer<AnchorEntity.State>? |
: The listener to fire upon invoking this method, and all subsequent state changes. |
Public properties
state
val state: AnchorEntity.State
The current tracking state for this AnchorEntity.