class AnchorSpace : 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 companion functions

AnchorSpace
create(session: Session, anchor: Anchor)

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

AnchorSpace
create(
    session: Session,
    minimumPlaneExtents: FloatSize2d,
    planeOrientations: Set<PlaneOrientation>,
    planeSemanticTypes: Set<PlaneSemanticType>,
    timeout: Duration
)

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.

Public functions

Unit

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

Unit
addOriginChangedListener(executor: Executor, listener: Runnable)

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

Unit

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

Unit
addStateChangedListener(
    executor: Executor,
    listener: Consumer<AnchorSpace.State>
)

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

Unit

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

Unit

Removes the given state changed listener.

Public properties

Anchor?

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

AnchorSpace.State

The current tracking state for this AnchorSpace.

Inherited functions

From androidx.xr.scenecore.BaseScenePose
open suspend HitTestResult?
hitTest(origin: Vector3, direction: Vector3)

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

open suspend HitTestResult?
hitTest(origin: Vector3, direction: Vector3, hitTestFilter: Int)

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

open Vector3
transformDirectionTo(direction: Vector3, destination: ScenePose)

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

open Pose
transformPoseTo(pose: Pose, destination: ScenePose)

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

open Vector3
transformPositionTo(position: Vector3, destination: ScenePose)

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

open Vector3
transformVectorTo(vector: Vector3, destination: ScenePose)

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

From androidx.xr.scenecore.Entity
Unit
addChild(child: Entity)

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

Boolean
addComponent(component: Component)

Adds a Component to this Entity.

@FloatRange(from = 0.0, to = 1.0) Float
getAlpha(relativeTo: Space)

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

List<Component>

Retrieves all components attached to this Entity.

List<T>

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

Boolean
isEnabled(includeParents: Boolean)

Returns the enabled status of this Entity.

Unit

Remove all components from this Entity.

Unit

Removes the given Component from this Entity.

Unit
setAlpha(alpha: @FloatRange(from = 0.0, to = 1.0) Float)

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

Unit
setEnabled(enabled: Boolean)

Sets the local enabled state of this Entity.

From androidx.xr.scenecore.SpaceEntity
open Pose
getPose(relativeTo: Space)

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

open Float
getScale(relativeTo: Space)

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

open Unit
setPose(pose: Pose, relativeTo: Space)

Throws UnsupportedOperationException if called.

open Unit
setScale(scale: Float, relativeTo: Space)

Throws UnsupportedOperationException if called.

Inherited properties

From androidx.xr.scenecore.BaseScenePose
open Pose

The current Pose relative to the activity space root.

From androidx.xr.scenecore.Entity
List<Entity>

Provides the list of all children of this entity.

CharSequence

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

From androidx.xr.scenecore.SpaceEntity
open Entity?

Throws UnsupportedOperationException if called.

Public companion functions

create

Added in 1.0.0-beta01
fun create(session: Session, anchor: Anchor): AnchorSpace

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

Parameters
session: Session

Session in which to create the AnchorSpace.

anchor: Anchor

The Anchor to use for this AnchorSpace.

create

Added in 1.0.0-beta01
fun create(
    session: Session,
    minimumPlaneExtents: FloatSize2d,
    planeOrientations: Set<PlaneOrientation>,
    planeSemanticTypes: Set<PlaneSemanticType>,
    timeout: Duration = Duration.ZERO
): AnchorSpace

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
session: Session

Session in which to create the AnchorSpace.

minimumPlaneExtents: FloatSize2d

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

planeOrientations: Set<PlaneOrientation>

PlaneOrientations of the plane to which this AnchorSpace should attach.

planeSemanticTypes: Set<PlaneSemanticType>

PlaneSemanticTypes of the plane to which this AnchorSpace should attach.

timeout: Duration = Duration.ZERO

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.

Public functions

addOriginChangedListener

Added in 1.0.0-beta01
fun addOriginChangedListener(listener: Runnable): Unit

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
listener: Runnable

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

addOriginChangedListener

Added in 1.0.0-beta01
fun addOriginChangedListener(executor: Executor, listener: Runnable): Unit

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
executor: Executor

The executor to run the listener on.

listener: Runnable

The listener to register.

addStateChangedListener

Added in 1.0.0-beta01
fun addStateChangedListener(listener: Consumer<AnchorSpace.State>): Unit

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
fun addStateChangedListener(
    executor: Executor,
    listener: Consumer<AnchorSpace.State>
): Unit

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
executor: Executor

: The executor on which the specified listener will fire.

listener: Consumer<AnchorSpace.State>

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

removeOriginChangedListener

Added in 1.0.0-beta01
fun removeOriginChangedListener(listener: Runnable): Unit

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

Parameters
listener: Runnable

The listener to remove.

removeStateChangedListener

Added in 1.0.0-beta01
fun removeStateChangedListener(listener: Consumer<AnchorSpace.State>): Unit

Removes the given state changed listener.

Parameters
listener: Consumer<AnchorSpace.State>

: The listener to be removed.

Public properties

anchor

Added in 1.0.0-beta01
val anchorAnchor?

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.

state

Added in 1.0.0-beta01
val stateAnchorSpace.State

The current tracking state for this AnchorSpace.