iOS 向け Cloud Anchors デベロッパー ガイド

ARCore SDK for iOS は ARKit とやり取りして Cloud Anchor 機能を提供します。これにより、同じ環境内の iOS デバイスと Android デバイス間でアンカーを共有できます。

ご自身のアプリで ARCore Cloud Anchor API または ARCore Cloud Anchor サービスを使用する方法をご確認ください。

前提条件

  • Xcode バージョン 13.0 以降
  • Cocoapods 1.4.0 以降(Cocoapods を使用する場合)
  • iOS 12.0 以降を搭載した ARKit 互換 Apple デバイス(iOS 12.0 以降のデプロイ ターゲットが必要)

Cloud Anchors を初めて使用する場合:

アプリで Cloud Anchors を有効にする

Cloud Anchors API を使用するには、iOS で ARCore セッションを構成するで説明されているように、GARSessionConfiguration を作成し、cloudAnchorMode プロパティを設定する必要があります。setConfiguration:error: (GARSession) を使用して構成を設定します。

また、アプリケーションで ARCore API を有効にする必要があります。

アンカーのホストと解決

ARCore Cloud Anchor API を使用すると、クラウド アンカーをホストして解決できます。この API には、完了したオペレーションのためのコールバック メソッドや、ポーリング可能な Future オブジェクトが含まれます。

アンカーをホストする

ARAnchor をホストすると、特定の物理空間に共通の座標系にアンカーが配置されます。

ホスト リクエストにより、ビジュアル データが Google サーバーに送信されます。Google サーバーは、現在の物理空間を表す座標系で ARAnchor の位置をマッピングします。ホスト リクエストが成功すると、新しい Cloud Anchor ID が返されます。この ID を共有して、後でアンカーを解決するために使用できます。

- (void)addAnchorWithTransform:(matrix_float4x4)transform {
  self.arAnchor = [[ARAnchor alloc] initWithTransform:transform];
  [self.sceneView.session addAnchor:self.arAnchor];

  __weak ExampleViewController *weakSelf = self;
  self.hostFuture = [self.cloudAnchorManager
      hostCloudAnchor:self.arAnchor
           completion:^(NSString *anchorId, GARCloudAnchorState cloudState) {
             [weakSelf handleHostAnchor:anchorId cloudState:cloudState];
           }
                error:nil];
  [self enterState:HelloARStateHosting];
}

アンカーを解決する

ARAnchor を解決すると、特定の物理スペースにある Android デバイスと iOS デバイスは、以前にホストしていたアンカーを新しいシーンに追加できます。

解決リクエストは、現在のフレームのビジュアル データとともにクラウド アンカー ID を Google サーバーに送信します。サーバーは、この視覚的データと、現在ホストされている Cloud Anchors がマッピングされている場所の画像を照合しようとします。解決が成功すると、新しいアンカーがセッションに追加され、返されます。

- (void)resolveAnchorWithIdentifier:(NSString *)identifier {
  GARResolveCloudAnchorFuture *garFuture =
      [self.gSession resolveCloudAnchorWithIdentifier:identifier
                                    completionHandler:completion
                                                error:&error];
}

// Pass the ARFRame to the ARCore session every time there is a frame update.
// This returns a GARFrame that contains a list of updated anchors. If your
// anchor's pose or tracking state changed, your anchor will be in the list.
- (void)cloudAnchorManager:(CloudAnchorManager *)manager didUpdateFrame:(GARFrame *)garFrame {
  for (GARAnchor *garAnchor in garFrame.updatedAnchors) {
    if ([garAnchor isEqual:self.garAnchor] && self.resolvedAnchorNode) {
      self.resolvedAnchorNode.simdTransform = garAnchor.transform;
      self.resolvedAnchorNode.hidden = !garAnchor.hasValidTransform;
    }
  }
}

オプションの GARSession ポーリング パターン

Metal を使用している場合、またはポーリング オプションが必要で、アプリが最小で 30 fps で実行されている場合は、次のパターンを使用して ARFrameGARSession に渡します。

-(void)myOwnPersonalUpdateMethod {
  ARFrame *arFrame = arSession.currentFrame;
  NSError *error = nil;
  GARFrame *garFrame = [garSession update:arFrame error:&error];
  // your update code here
}

API 割り当て

ARCore API には、リクエスト帯域幅に次の割り当てがあります。

割り当てのタイプ 最大 Duration 適用先
アンカーの数 無制限 なし プロジェクト
ホスト リクエストのアンカー 30 IP アドレスとプロジェクト
アンカーでリクエストをresolve 300 IP アドレスとプロジェクト

既知の問題と回避策

ARCore SDK for iOS の使用時に発生する既知の問題がいくつかあります。

デフォルトのスキーム設定により、アプリが断続的にクラッシュする

GPU フレーム キャプチャと Metal API 検証スキームの設定はデフォルトで有効になっているため、SDK 内でアプリがクラッシュする可能性があります。

アプリのクラッシュを診断する

クラッシュの発生が疑われる場合は、スタック トレースを調べます。スタック トレースに MTLDebugComputeCommandEncoder が表示される場合は、デフォルトのスキーム設定が原因である可能性があります。

回避策

  1. Product > Scheme > Edit Scheme… に移動します。

  2. [Run] タブを開きます。

  3. Options をクリックして、現在の設定を表示します。

  4. GPU Frame CaptureMetal API Validation の両方が無効になっていることを確認します。

  5. アプリをビルドして実行します。

その他の既知の問題については、Cocoapods CHANGELOG をご覧ください。

制限事項

ARCore SDK for iOS は、ARKit の setWorldOrigin(relativeTransform:) メソッド呼び出しをサポートしていません。

パフォーマンスに関する注意事項

ARCore API を有効にすると、メモリ使用量が増加します。ネットワーク使用率と CPU 使用率が高くなると、デバイスのバッテリー使用量が増加することが想定されます。

次のステップ