androidx.xr.arcore


Interfaces

Anchorable

An object that ARCore for Jetpack XR can track and that an Anchor can be attached to.

Trackable

An object that ARCore for Jetpack XR can track.

Trackable.State

The subset of data that is common to the state of all Trackable instances.

Classes

Anchor

An anchor describes a fixed location and orientation in the real world.

Anchor.State

The representation of the current state of an Anchor.

AnchorCreateIllegalState

Result of an unsuccessful Anchor.create call.

AnchorCreateNotAuthorized

Result of an unsuccessful Anchor.create call.

AnchorCreateResourcesExhausted

Result of an unsuccessful Anchor.create or Anchor.load call.

AnchorCreateResult

Result of a Anchor.create or Anchor.load call.

AnchorCreateSuccess

Result of a successful Anchor.create or Anchor.load call.

AnchorCreateTrackingUnavailable

Result of an unsuccessful Anchor.create call.

AnchorCreateUnsupportedLocation

Result of an unsuccessful Anchor.create call.

AnchorCreateUnsupportedObject

Result of an unsuccessful Anchor.create call.

AnchorLoadInvalidUuid

Result of an unsuccessful Anchor.load call.

ArDevice

Contains the information of the device that locates it with respect to the real world.

ArDevice.State

Contains the current state of the AR Device tracking.

AugmentedObject

A representation of a physical object in real space.

AugmentedObject.State

The representation of the current state of an AugmentedObject.

CreateGeospatialPoseFromPoseErrorInternal

Result of an unsuccessful Geospatial.createGeospatialPoseFromPose call.

CreateGeospatialPoseFromPoseNotTracking

Result of an unsuccessful Geospatial.createGeospatialPoseFromPose call.

CreateGeospatialPoseFromPoseResult

Result of a Geospatial.createGeospatialPoseFromPose call.

CreateGeospatialPoseFromPoseSuccess

Result of a successful Geospatial.createGeospatialPoseFromPose call.

CreatePoseFromGeospatialPoseErrorInternal

Result of an unsuccessful Geospatial.createPoseFromGeospatialPose call.

CreatePoseFromGeospatialPoseNotTracking

Result of an unsuccessful Geospatial.createPoseFromGeospatialPose call.

CreatePoseFromGeospatialPoseResult

Result of a call to Geospatial.createPoseFromGeospatialPose.

CreatePoseFromGeospatialPoseSuccess

Result of a successful Geospatial.createPoseFromGeospatialPose call.

DepthMap

Contains the depth map information corresponding to a specific RenderViewpoint.

DepthMap.State

Contains the current state of depth tracking.

Eye

A representation of a user's eye.

Eye.State

The representation of the current state of an Eye.

Face

Contains the tracking information of a detected human face.

Face.State

The representation of the current state of Face.

FaceBlendShapeType

Represents the type of face blend shape.

FaceConfidenceRegion

Represents the regions of face tracking confidence.

FaceMeshRegion

Regions of a tracked Face.

Geospatial

Provides localization ability in Earth-relative coordinates.

Geospatial.State

This class is deprecated. Use GeospatialState instead.

GeospatialSurface

The type of surface on which to create an anchor.

Hand

Contains the tracking information of one of the user's hands.

Hand.State

The representation of the current state of a Hand.

HitResult

Defines an intersection between a ray and estimated real-world geometry.

PerceptionState

Represents the state of ARCore for Jetpack XR at an specific point in time.

Plane

Describes the system's current best knowledge of a real-world planar surface.

Plane.Label

This class is deprecated. Use PlaneLabel instead.

Plane.State

The representation of the current state of a Plane.

Plane.Type

This class is deprecated. Use PlaneType instead.

RenderViewpoint

Represents a single viewpoint used for rendering, such as a left eye, right eye, or a mono view.

RenderViewpoint.State

Class that contains the current state of the render viewpoint.

Tilt

Represents the vertical tilt state of the device.

TiltGesture.State

Represents the tilt state of the device, transition progress.

VpsAvailabilityAvailable

Result of a successful Geospatial.checkVpsAvailability call.

VpsAvailabilityErrorInternal

Result of an unsuccessful Geospatial.checkVpsAvailability call.

VpsAvailabilityNetworkError

Result of an unsuccessful androidx.xr.arcore.Geospatial.checkVpsAvailability call.

VpsAvailabilityNotAuthorized

Result of an unsuccessful Geospatial.checkVpsAvailability call.

VpsAvailabilityResourceExhausted

Result of an unsuccessful Geospatial.checkVpsAvailability call.

VpsAvailabilityResult

Result of a Geospatial.checkVpsAvailability call.

VpsAvailabilityUnavailable

Result of a successful Geospatial.checkVpsAvailability call.

Objects

TiltGesture

Container for device tilt gesture detection logic and the Tilt state representation.

Annotations

ExperimentalGesturesApi

Marks declarations that are part of the experimental Tilt Gesture API.

Enums

Hand.HandSide

This enum is deprecated. Use androidx.xr.arcore.HandSide instead.

HandJointType

Represents the type of hand joint.

HandSide

The handedness of the user's hand.

Type aliases

GeospatialState

Describes the state of Geospatial.

PlaneLabel

A semantic description of a Plane.

PlaneType

A simple summary of the normal vector of a Plane.

TrackingState

Describes the state of the tracking performed.

Top-level functions summary

List<HitResult>
hitTest(session: Session, ray: Ray)

Performs a hit-test using the given ray.

Top-level functions

fun hitTest(session: Session, ray: Ray): List<HitResult>

Performs a hit-test using the given ray.

A hit-test is a method of calculating the intersection of a ray with objects tracked by the session. Conducting a hit-test results in a list of hit objects, in other words, a hit-test does not stop at the first object hit.

import androidx.xr.arcore.Anchor
import androidx.xr.arcore.ArDevice
import androidx.xr.arcore.Plane
import androidx.xr.arcore.PlaneLabel
import androidx.xr.arcore.hitTest
import androidx.xr.runtime.math.Pose
import androidx.xr.runtime.math.Ray
import androidx.xr.scenecore.scene

val arDevice = ArDevice.getInstance(session)

// Assume hitOrigin and hitDirection are in Activity Space.
// We need to transform the ray into Perception Space for hitTest.

// Transform the origin point from Activity Space to Perception Space.
val perceptionOrigin =
    session.scene.activitySpace
        .transformPoseTo(Pose(hitOrigin), session.scene.perceptionSpace)
        .translation

// Transform the direction vector from Activity Space to Perception Space.
val perceptionDirection =
    session.scene.activitySpace
        .transformPoseTo(Pose(hitDirection), session.scene.perceptionSpace)
        .translation
        .toNormalized() // Ensure the direction is normalized after transformation.

val ray = Ray(perceptionOrigin, perceptionDirection)

hitTest(session, ray)
    // Use a valid plane label as a test to filter out any unreliable hits.
    .firstOrNull { (it.trackable as? Plane?)?.state?.value?.label != PlaneLabel.UNKNOWN }
    ?.let { hitResult ->
        // Do something with the hit result, like create an anchor representing where the ray
        // intersected the plane. The hitResult.hitPose is in Perception Space.
        val anchorResult = Anchor.create(session, hitResult.hitPose)

        // Anchor creation can fail, so it is important to properly handle the return value of
        // and `Anchor.create()` call. See `Anchor.create()` for more information.
        yourAnchorResultHandler(anchorResult)

        // If rendering is needed, transform hitResult.hitPose from Perception Space
        // to the desired Scene Space (e.g., Activity Space).
        val activitySpaceHitPose =
            session.scene.perceptionSpace.transformPoseTo(
                hitResult.hitPose,
                session.scene.activitySpace,
            )
        renderSomething(activitySpaceHitPose)
    }
Parameters
session: Session

the Session to perform the hit-test in

ray: Ray

the Ray to use for the hit-test

Returns
List<HitResult>

a list of HitResult objects, sorted by distance from the origin of the ray, nearest to farthest