GARSession
ARCore session class.
Adds ARCore
features to an app using ARKit
. All NSError
's returned by methods in this class have domain GARSessionErrorDomain
and code a value of GARSessionErrorCode
. For Augmented Faces, see GARAugmentedFaceSession
. See categories of this class for other features. Each feature must be turned on by using setConfiguration:error: (GARSession)
prior to use.
Summary
Inheritance
Inherits from:NSObject
Properties
ARFrame
passed into update:error:
and the corresponding returned GARFrame
.id< GARSessionDelegate
>
dispatch_queue_t
Public static methods
nullable instancetype
nullable instancetype
Public methods
nullable GARAnchor
*
GARStreetscapeGeometry
, and acquires a reference to it.nullable GARAnchor
*
nullable GARCreateAnchorOnRooftopFuture
*
nullable GARCreateAnchorOnTerrainFuture
*
nullable GARAnchor
*
nullable GARGeospatialTransform
*
nullable GARHostCloudAnchorFuture
*
anchor
to host a new Cloud Anchor.nullable GARAnchor
*
nullable GARAnchor
*
ARAnchor
.BOOL
BOOL
nullable NSArray< GARStreetscapeGeometryRaycastResult
* > *
void
nullable GARResolveCloudAnchorFuture
*
identifier
.nullable GARAnchor
*
void
void
matrix_float4x4
nullable GARFrame
*
Properties
currentFramePair
The most recent frame pair, containing the most recent ARFrame
passed into update:error:
and the corresponding returned GARFrame
.
delegateQueue
The dispatch queue on which the delegate receives calls.
If nil
, callbacks happen on the main thread.
Public static methods
sessionWithAPIKey:bundleIdentifier:error:
+ ( nullable instancetype ) sessionWithAPIKey :( NSString * ) apiKeybundleIdentifier :( nullable NSString * ) bundleIdentifiererror :( NSError ** ) error
Creates a GARSession
with an API key and bundle identifier.
apiKey
bundleIdentifier
nil
, defaults to [[NSBundle mainBundle] bundleIdentifier]
.error
NSError
. Possible errors: -
GARSessionErrorCodeDeviceNotCompatible
- this device or OS version is not currently supported. -
GARSessionErrorCodeInvalidArgument
- API key isnil
or empty.
sessionWithError:
+ ( nullable instancetype ) sessionWithError :( NSError ** ) error
Creates a GARSession
.
To authenticate with Google Cloud Services, use setAuthToken:
.
error
NSError
. Possible errors: -
GARSessionErrorCodeDeviceNotCompatible
- this device or OS version is not currently supported.
Public methods
checkVPSAvailabilityAtCoordinate:completionHandler:
(CLLocationCoordinate2D) coordinatecompletionHandler:
Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position.
The availability of VPS in a given location helps to improve the quality of Geospatial localization and tracking accuracy.
This launches an asynchronous operation used to query the Google Cloud ARCore API. See GARFuture
for information on obtaining results and cancelling the operation.
Your app must be properly set up to communicate with the Google Cloud ARCore API in order to obtain a result from this call. See Check VPS Availability for more details on setup steps and usage examples.
coordinate
|
The coordinate at which to check availability.
|
completionHandler
|
createAnchorOnStreetscapeGeometry:transform:error:
transform:(matrix_float4x4) transformerror:(NSError **) error
Creates an anchor at the given transform in the world coordinate space, attached to this GARStreetscapeGeometry
, and acquires a reference to it.
geometry
transform
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current geospatial mode is disabled, or Streetscape Geometry mode is disabled. -
GARSessionErrorCodeNotTracking
- Earth, Session or geometry'sARTrackingState
is notGARTrackingStateTracking
.
nil
if there was an error.createAnchorWithCoordinate:altitude:eastUpSouthQAnchor:error:
(CLLocationCoordinate2D) coordinatealtitude:(CLLocationDistance) altitudeeastUpSouthQAnchor:(simd_quatf) eastUpSouthQAnchorerror:(NSError **) error
Creates a Geospatial anchor at the specified geodetic location and orientation relative to the Earth.
Latitude and longitude are defined by the WGS84 specification , and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.
The rotation provided by eastUpSouthQAnchor
is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.
An anchor's GARAnchor.trackingState
will be GARTrackingStatePaused
while GAREarth
is GARTrackingStatePaused
. The tracking state will permanently become GARTrackingStateStopped
if the GARSession
configuration is set to GARGeospatialModeDisabled
.
Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90 °), this function will output GARSessionErrorCodeInvalidArgument
and the anchor will fail to be created.
coordinate
altitude
eastUpSouthQAnchor
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeInvalidArgument
- latitude is not within range.
nil
if there was an error.createAnchorWithCoordinate:altitudeAboveRooftop:eastUpSouthQAnchor:completionHandler:error:
(CLLocationCoordinate2D) coordinatealtitudeAboveRooftop:(CLLocationDistance) altitudeAboveRooftopeastUpSouthQAnchor:(simd_quatf) eastUpSouthQAnchorcompletionHandler:error:(NSError **) error
Asynchronously creates a Rooftop anchor at the specified horizontal position and altitude relative to the horizontal position's rooftop.
See the Rooftop anchors developer guide for more information.
The specified altitudeAboveRooftop
is interpreted to be relative to the top of a building at the given horizontal location, rather than relative to the WGS84 ellipsoid. If there is no building at the given location, then the altitude is interpreted to be relative to the terrain instead. Specifying an altitude of 0 will position the anchor directly on the rooftop whereas specifying a positive altitude will position the anchor above the rooftop, against the direction of gravity.
This launches an asynchronous operation used to query the Google Cloud ARCore API. See GARFuture
for information on obtaining results and cancelling the operation.
You may resolve multiple anchors at a time, but a session cannot be tracking more than 100 Rooftop or Terrain anchors at time. Attempting to resolve more than 100 Rooftop or Terrain anchors will result in GARSessionErrorCodeResourceExhausted
.
Latitude and longitude are defined by the WGS84 specification , and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.
The rotation provided by eastUpSouthQAnchor
is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.
An anchor's GARAnchor.trackingState
will be GARTrackingStateTracking
while GAREarth
is GARTrackingStateTracking
. The tracking state will permanently become GARTrackingStateStopped
if the GARSession
configuration is set to GARGeospatialModeDisabled
.
Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90°), this function will output GARSessionErrorCodeInvalidArgument
and the anchor will fail to be created.
coordinate
altitudeAboveRooftop
eastUpSouthQAnchor
completionHandler
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeInvalidArgument
- latitude is not within range. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Rooftop or Terrain anchors.
createAnchorWithCoordinate:altitudeAboveTerrain:eastUpSouthQAnchor:completionHandler:error:
(CLLocationCoordinate2D) coordinatealtitudeAboveTerrain:(CLLocationDistance) altitudeAboveTerraineastUpSouthQAnchor:(simd_quatf) eastUpSouthQAnchorcompletionHandler:error:(NSError **) error
Asynchronously creates a Terrain anchor at a specified horizontal position and altitude relative to the horizontal position's terrain.
See the Terrain anchors developer guide for more information.
The specified altitudeAboveTerrain
is interpreted to be relative to the Earth's terrain (or floor) at the specified latitude/longitude geodetic coordinates, rather than relative to the WGS-84 ellipsoid. Specifying an altitudeAboveTerrain
of 0 will position the anchor directly on the terrain whereas specifying a positive altitudeAboveTerrain
will position the anchor above the terrain, against the direction of gravity.
This launches an asynchronous operation used to query the Google Cloud ARCore API. See GARFuture
for information on obtaining results and cancelling the operation.
You may resolve multiple anchors at a time, but a session cannot be tracking more than 100 Rooftop or Terrain anchors at time. Attempting to resolve more than 100 Rooftop or Terrain anchors will result in GARSessionErrorCodeResourceExhausted
.
Latitude and longitude are defined by the WGS84 specification , and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.
The rotation provided by eastUpSouthQAnchor
is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.
An anchor's GARAnchor.trackingState
will be GARTrackingStateTracking
while GAREarth
is GARTrackingStateTracking
. The tracking state will permanently become GARTrackingStateStopped
if the GARSession
configuration is set to GARGeospatialModeDisabled
.
Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90°), this function will output GARSessionErrorCodeInvalidArgument
and the anchor will fail to be created.
coordinate
altitudeAboveTerrain
eastUpSouthQAnchor
completionHandler
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeInvalidArgument
- latitude is not within range. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Rooftop or Terrain anchors.
createAnchorWithCoordinate:altitudeAboveTerrain:eastUpSouthQAnchor:error:
(CLLocationCoordinate2D) coordinatealtitudeAboveTerrain:(CLLocationDistance) altitudeAboveTerraineastUpSouthQAnchor:(simd_quatf) eastUpSouthQAnchorerror:(NSError **) error
Creates a Terrain anchor at the specified geodetic location, altitude relative to the horizontal position’s terrain and orientation relative to the Earth.
Terrain means the ground, or ground floor inside a building with VPS coverage.
The specified altitudeAboveTerrain
is interpreted to be relative to the Earth's terrain (or floor) at the specified latitude/longitude geodetic coordinates, rather than relative to the WGS-84 ellipsoid. Specifying an altitudeAboveTerrain
of 0 will position the anchor directly on the terrain (or floor) whereas specifying a positive altitudeAboveTerrain
will position the anchor above the terrain (or floor), against the direction of gravity.
This function schedules a task to resolve the anchor's pose using the given parameters. You may resolve multiple anchors at a time, but a session cannot be tracking more than 100 Terrain anchors at time. Attempting to resolve more than 100 Terrain anchors will result in GARSessionErrorCodeResourceExhausted
.
If this function returns error nil, the terrain anchor's GARAnchor.terrainState
will be GARTerrainAnchorStateTaskInProgress
, and its tracking state will be GARTrackingStatePaused
. This anchor remains in this state until its pose has been successfully resolved. If the resolving task results in an error, the tracking state will be set to GARTrackingStateStopped
.
Latitude and longitude are defined by the WGS84 specification , and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.
The rotation provided by eastUpSouthQAnchor
is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.
An anchor's GARAnchor.trackingState
will be GARTrackingStateTracking
while GAREarth
is GARTrackingStateTracking
. The tracking state will permanently become GARTrackingStateStopped
if the GARSession
configuration is set to GARGeospatialModeDisabled
.
Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90°), this function will output GARSessionErrorCodeInvalidArgument
and the anchor will fail to be created.
coordinate
altitudeAboveTerrain
eastUpSouthQAnchor
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeInvalidArgument
- latitude is not within range. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Rooftop or Terrain anchors.
nil
if there was an error.estimateFeatureMapQualityForHosting:error:
(simd_float4x4) transformerror:(NSError **) error
Estimates the quality of the visual features seen by ARCore in the preceding few seconds and visible from the provided camera transform.
Cloud Anchors hosted using higher quality features will generally result in easier and more accurately resolved Cloud Anchor transforms.
transform
error
NSError
. Possible errors: -
GARSessionErrorCodeNotTracking
- bad currentARTrackingState
. -
GARSessionErrorCodeIllegalState
- current cloud anchor mode is disabled.
geospatialTransformFromTransform:error:
(matrix_float4x4) transformerror:(NSError **) error
Converts the provided transform to a GARGeospatialTransform
with respect to the Earth.
Its heading will be zero for a GARGeospatialTransform
returned from this method.
transform
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeNotTracking
- Earth's or Session'sARTrackingState
is notGARTrackingStateTracking
.
hostCloudAnchor:TTLDays:completionHandler:error:
TTLDays:(NSInteger) TTLDayscompletionHandler:(void(^)(NSString *_Nullable cloudIdentifier, GARCloudAnchorState cloudState)) completionHandlererror:(NSError **) error
Uses the transform and other data from anchor
to host a new Cloud Anchor.
A Cloud Anchor is assigned an identifier that can be used to create an GARAnchor
in the same position in subsequent sessions across devices using resolveCloudAnchorWithIdentifier:completionHandler:error: (GARSession(CloudAnchors))
. See the Cloud Anchors developer guide
for more information.
The duration that a Cloud Anchor can be resolved for is specified by TTLDays
. When using Token authorization
, the maximum allowed value is 365 days. When using an API Key
to authenticate with the ARCore API, the maximum allowed value is 1 day.
This launches an asynchronous operation used to query the Google Cloud ARCore API. See GARFuture
for information on obtaining results and cancelling the operation.
Cloud Anchors requires a GARSessionConfiguration
with GARCloudAnchorModeEnabled
set on this session. Use GARSessionConfiguration.cloudAnchorMode
to set the Cloud Anchor API mode and setConfiguration:error:
to configure the session.
Hosting a Cloud Anchor works best when ARCore is able to create a good feature map around the ARAnchor
. Use estimateFeatureMapQualityForHosting:error: (GARSession(CloudAnchors))
to determine the quality of visual features seen by ARCore in the preceding few seconds. Cloud Anchors hosted using higher quality features will generally result in quicker and more accurately resolved Cloud Anchor transforms.
ARCore can have up to 40 simultaneous Cloud Anchor operations, including resolved anchors and active hosting operations.
anchor
ARAnchor
with the desired transform to be used to create a hosted Cloud Anchor.TTLDays
completionHandler
error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
) anchor or invalid TTL. -
GARSessionErrorCodeNotTracking
- bad currentARTrackingState
. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Cloud Anchors. -
GARSessionErrorCodeIllegalState
- currentGARCloudAnchorMode
is disabled.
hostCloudAnchor:TTLDays:error:
TTLDays:(NSInteger) TTLDayserror:(NSError **) error
This will create a new Cloud Anchor with a given lifetime in days, using the transform of the provided anchor.
The cloud state of the returned anchor will be set to GARCloudAnchorStateTaskInProgress
and the initial transform will be set to the transform of the provided anchor. However, the returned anchor is completely independent of the original anchor, and the two transforms might diverge over time.
Hosting requires an active session for which the tracking state is ARTrackingStateNormal
, as well as a working internet connection. ARCore will continue to retry silently in the background if it is unable to establish a connection to the ARCore API service.
anchor
ARAnchor
with the desired transform to be used to create a hosted Cloud Anchor.TTLDays
error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
) anchor or invalid TTL. -
GARSessionErrorCodeNotTracking
- bad currentARTrackingState
. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Cloud Anchors. -
GARSessionErrorCodeIllegalState
- current cloud anchor mode is disabled.
hostCloudAnchor:error:
error:(NSError **) error
Hosts a new Cloud Anchor based on an ARAnchor
.
The new anchor will have a cloud state of GARCloudAnchorStateTaskInProgress
and its initial transform will be set to that of the passed-in anchor. However, the two transforms may differ over time.
anchor
ARAnchor
to host.error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
) anchor. -
GARSessionErrorCodeNotTracking
- bad currentARTrackingState
. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Cloud Anchors. -
GARSessionErrorCodeIllegalState
- current cloud anchor mode is disabled.
isGeospatialModeSupported:
- (BOOL)isGeospatialModeSupported:
Determines whether the given geospatial mode is supported on the current device and OS version.
If this returns NO, then configuring the session with the given geospatial mode will fail with the error code GARSessionErrorCodeConfigurationNotSupported
. A device may be incompatible with a given mode due to insufficient sensor capabilities.
geospatialMode
geospatialMode
is supported, NO otherwise.isSemanticModeSupported:
- (BOOL)isSemanticModeSupported:
Determines whether the given GARSemanticMode
is supported on the current device and OS version.
If this returns NO
, then using setConfiguration:error:
with the given semantic mode will fail with the error code GARSessionErrorCodeConfigurationNotSupported
. A device may be incompatible with a given mode due to insufficient sensor capabilities or compute performance.
semanticMode
YES
if the semanticMode
is supported, NO
otherwise.raycastStreetscapeGeometry:direction:error:
(simd_float3) origindirection:(simd_float3) directionerror:(NSError **) error
Performs a raycast against Streetscape Geometry loaded by the scene.
The raycast result contains the transform of the hit as well as the GARStreetscapeGeometry
that was hit.
Requires both GARSessionConfiguration.streetscapeGeometryMode
to be set to GARStreetscapeGeometryModeEnabled
and for GARSessionConfiguration.geospatialMode
to be set to GARGeospatialModeEnabled
.
origin
direction
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current geospatial mode is disabled, or Streetscape Geometry mode is disabled, or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeNotTracking
- Earth, Session, or the geometry's tracking state is notGARTrackingStateTracking
.
nil
if there was an error.removeAnchor:
- (void)removeAnchor:
Removes an anchor from the session.
anchor
resolveCloudAnchorWithIdentifier:completionHandler:error:
(NSString *) identifiercompletionHandler:error:(NSError **) error
Attempts to resolve a Cloud Anchor using the provided identifier
.
The Cloud Anchor must previously have been hosted by hostCloudAnchor:TTLDays:completionHandler:error: (GARSession(CloudAnchors))
or another Cloud Anchor hosting method within the allotted TTLDays
. See the Cloud Anchors developer guide
for more information.
This launches an asynchronous operation used to query the Google Cloud ARCore API. See GARFuture
for information on obtaining results and cancelling the operation.
When resolving a Cloud Anchor, the ARCore API periodically compares visual features from the scene against the anchor's 3D feature map to pinpoint the user's position and orientation relative to the anchor. When it finds a match, the task completes.
Cloud Anchors requires a GARSessionConfiguration
with GARCloudAnchorModeEnabled
set on this session. Use GARSessionConfiguration.cloudAnchorMode
to set the Cloud Anchor API mode and setConfiguration:error:
to configure the session.
ARCore can have up to 40 simultaneous Cloud Anchor operations, including resolved anchors and active hosting operations.
identifier
completionHandler
error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
or empty) identifier. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Cloud Anchors. -
GARSessionErrorCodeIllegalState
- currentGARCloudAnchorMode
is disabled.
resolveCloudAnchorWithIdentifier:error:
error:(NSError **) error
Resolves a Cloud Anchor with a given identifier.
The new anchor is immediately added to the session and returned, but without a valid transform. You don’t need to wait for a call to resolve a Cloud Anchor to complete before initiating another call. A session can be resolving up to 40 Cloud Anchors at a given time. If resolving fails, the anchor will be automatically removed from the session.
identifier
error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
or empty) identifier. -
GARSessionErrorCodeResourceExhausted
- tried to create too many Cloud Anchors. -
GARSessionErrorCodeIllegalState
- current cloud anchor mode is disabled.
setAuthToken:
- (void)setAuthToken:(NSString *) authToken
Provide an auth token to use when authenticating with Google Cloud Services.
If the session was created with an API Key, the token will be ignored and an error will be logged. Otherwise, the most recent valid auth token passed in will be used. Call this method each time you refresh your token.
authToken
setConfiguration:error:
- (void)setConfiguration:error:(NSError **) error
Sets the configuration for the session.
configuration
|
The new configuration to use.
|
---|---|
error
|
Out param for an
NSError
. |
transformFromGeospatialCoordinate:altitude:eastUpSouthQTarget:error:
- (matrix_float4x4)transformFromGeospatialCoordinate:(CLLocationCoordinate2D) coordinatealtitude:(CLLocationDistance) altitudeeastUpSouthQTarget:(simd_quatf) eastUpSouthQTargeterror:(NSError **) error
Converts the provided Earth specified horizontal position, altitude and rotation with respect to an east-up-south coordinate frame to a local transform in world coordinate space.
coordinate
altitude
eastUpSouthQTarget
error
NSError
. Possible error codes: -
GARSessionErrorCodeIllegalState
- current Geospatial mode is disabled or earth has trackingStateGARTrackingStateStopped
. -
GARSessionErrorCodeNotTracking
- Earth's or Session'sARTrackingState
is notGARTrackingStateTracking
. -
GARSessionErrorCodeInvalidArgument
- latitude is not within range.
update:error:
error:(NSError **) error
Updates the GARSession
with an ARFrame
.
Call this method with every ARFrame
to keep the sessions synced. Can be called on any thread. Normally, this should be called from your ARSessionDelegate
's session:didUpdateFrame:
method.
frame
ARFrame
from ARKit
.error
NSError
. Possible errors: -
GARSessionErrorCodeInvalidArgument
- invalid (nil
) frame. -
GARSessionErrorCodeFrameOutOfOrder
- frame has a smaller timestamp than previous.