アプリの AR エクスペリエンスを構築する ARCore セッションを設定します。
セッションとは
モーション トラッキングなど、すべての AR プロセス
環境の理解と照明の推定は、ARCore 内で行われます。
あります。ArSession
は ARCore へのメインのエントリ ポイントです。
APIAR システムの状態を管理し、セッションのライフサイクルを処理するため、
セッションを作成、構成、開始、停止する。最も重要なのは
アプリがカメラ画像へのアクセスを可能にするフレームを受信し、
デバイスのポーズ。
このセッションを使用すると、次の機能を構成できます。
ARCore がインストールされ、最新の状態であることを確認する
ArSession
を作成する前に、ARCore がインストールされ、最新の状態であることを確認してください。
ARCore がインストールされていない場合、セッションの作成は失敗し、それ以降は
ARCore をインストールまたはアップグレードするには、アプリの再起動が必要です。
/*
* Check if ARCore is currently usable, i.e. whether ARCore is supported and
* up to date.
*/
int32_t is_arcore_supported_and_up_to_date(void* env, void* context) {
ArAvailability availability;
ArCoreApk_checkAvailability(env, context, &availability);
switch (availability) {
case AR_AVAILABILITY_SUPPORTED_INSTALLED:
return true;
case AR_AVAILABILITY_SUPPORTED_APK_TOO_OLD:
case AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED: {
ArInstallStatus install_status;
// ArCoreApk_requestInstall is processed asynchronously.
CHECK(ArCoreApk_requestInstall(env, context, true, &install_status) ==
AR_SUCCESS);
return false;
}
case AR_AVAILABILITY_UNSUPPORTED_DEVICE_NOT_CAPABLE:
// This device is not supported for AR.
return false;
case AR_AVAILABILITY_UNKNOWN_CHECKING:
// ARCore is checking the availability with a remote query.
// This function should be called again after waiting 200 ms
// to determine the query result.
handle_check_later();
return false;
case AR_AVAILABILITY_UNKNOWN_ERROR:
case AR_AVAILABILITY_UNKNOWN_TIMED_OUT:
// There was an error checking for AR availability.
// This may be due to the device being offline.
// Handle the error appropriately.
handle_unknown_error();
return false;
default: // All enum cases have been handled.
return false;
}
}
セッションを作成する
ARCore でセッションを作成して構成する。
// Create a new ARCore session.
ArSession* ar_session = NULL;
CHECK(ArSession_create(env, context, &ar_session) == AR_SUCCESS);
// Create a session config.
ArConfig* ar_config = NULL;
ArConfig_create(ar_session, &ar_config);
// Do feature-specific operations here, such as enabling depth or turning on
// support for Augmented Faces.
// Configure the session.
CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);
セッションを閉じる
ArSession
は、大量のネイティブ ヒープメモリを所有しています。失敗
セッションを明示的に閉じると、アプリでネイティブ メモリが不足したり、
発生します。AR セッションが不要になったら、
ArSession_destroy()
リソースを解放できます
// Release memory used by the AR session.
ArSession_destroy(session);