Open AR directly

I want to open the AR mode directly after scanning a QR code or on image tracking.

Hi Saad Baig,

To open AR mode directly after scanning a QR code or on image tracking, you can utilize the NeedleXRSession class from the Needle Engine. Here’s a structured approach to achieve this:

  1. Initiate AR Mode: You need to trigger the AR session as soon as the QR code is scanned or an image is detected.

  2. Set Up Listeners: Use event listeners that detect the QR code scan or image tracking.

  3. Call the AR Session Start Method: Use the NeedleXRSession.start("immersive-ar") method to initiate the AR session.

Here’s a pseudocode outline for this:

function onQRCodeScanned() {
    // Trigger AR session when QR code is scanned
    NeedleXRSession.start("immersive-ar")
        .then(session => {
            // Handle session start
            console.log("AR Session started");
        })
        .catch(error => {
            console.error("Error starting AR session:", error);
        });
}

function onImageTracked() {
    // Trigger AR session on image tracking
    NeedleXRSession.start("immersive-ar")
        .then(session => {
            // Handle session start
            console.log("AR Session started via image tracking");
        })
        .catch(error => {
            console.error("Error starting AR session:", error);
        });
}

// Add event listeners for QR code scanning and image tracking
document.getElementById("qrCodeButton").addEventListener("click", onQRCodeScanned);
setupImageTracking(onImageTracked);

You would need to implement the setupImageTracking function appropriately to detect image tracking events.

Make sure that you have appropriate permissions and that the scanning mechanism is properly set up to initiate these functions.

If you need any further details or specific integrations, feel free to ask! You can also check the documentation for more in-depth information on handling sessions and callbacks (see the documentation).

3 replies left
thread_mMWqClJDx7ECNDDDv4DP3bwk
Reply to this message to continue the conversation

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.