Android एनडीके में ARCore सेशन कॉन्फ़िगर करना

अपने ऐप्लिकेशन के लिए एआर (ऑगमेंटेड रिएलिटी) अनुभव तैयार करने के लिए, ARCore सेशन कॉन्फ़िगर करें.

सेशन क्या होता है?

सभी एआर (ऑगमेंटेड रिएलिटी) प्रोसेस, जैसे कि मोशन ट्रैकिंग, पर्यावरण को समझना, और रोशनी का आकलन करना, ARCore सेशन में ही पूरा होता है. ArSession, ARCore एपीआई का मुख्य एंट्री पॉइंट है. यह एआर सिस्टम की स्थिति को मैनेज करता है और सेशन की लाइफ़साइकल को हैंडल करता है. इससे ऐप्लिकेशन को कोई सेशन बनाने, कॉन्फ़िगर करने, शुरू करने या बंद करने की सुविधा मिलती है. सबसे अहम बात यह है कि इससे ऐप्लिकेशन को ऐसे फ़्रेम मिलते हैं जो कैमरे की इमेज और डिवाइस के पोज़ को ऐक्सेस करने की अनुमति देते हैं.

सेशन का इस्तेमाल, नीचे दी गई सुविधाओं को कॉन्फ़िगर करने के लिए किया जा सकता है:

पुष्टि करें कि 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 के पास काफ़ी नेटिव हीप मेमोरी है. सेशन को साफ़ तौर पर बंद न कर पाने पर, हो सकता है कि आपके ऐप्लिकेशन की नेटिव मेमोरी और क्रैश खत्म हो जाए. जब एआर (ऑगमेंटेड रिएलिटी) सेशन की ज़रूरत न हो, तो संसाधनों को रिलीज़ करने के लिए, ArSession_destroy() को कॉल करें.

// Release memory used by the AR session.
ArSession_destroy(session);

अगले चरण