Blog Infos
Author
Published
Topics
Author
Published
Topics

AI -> 🙂

 

Hey, folks! As Augmented Reality (AR) technology continues to evolve, new and innovative features are being developed to enhance the user experience. One such feature is AR Cloud Anchors, which are now available on the Android ARCore platform. In this blog, we will explore what AR Cloud Anchors are and how they work.

AR Cloud Anchors 🔥

AR Cloud Anchors are virtual markers that are placed in a real-world environment to provide a fixed reference point for AR experiences. These markers can be placed on any surface in the environment, including walls, floors, and ceilings. Once placed, these anchors can be used to synchronize multiple AR devices, enabling users to share the same AR experience in real-time.

AR Cloud Anchors are hosted on a cloud-based platform, which means they are not tied to any specific device or application. This allows developers to create AR experiences that can be shared across multiple platforms, including Android and iOS.

How do AR Cloud Anchors work?🌨️

AR Cloud Anchors work by using a combination of computer vision and cloud-based processing to track the position and orientation of the marker in the real-world environment. When a user points their AR device at the marker, the device uses its camera to capture the image of the marker and sends it to the cloud for processing.

The cloud-based processing then uses machine learning algorithms to identify the marker and determine its position and orientation relative to the device. Once the position and orientation of the marker are determined, the AR experience can be overlaid onto the real-world environment, creating an immersive and interactive experience for the user.

We going to use SceneView Library which brings creating and placing node very handy and easy. [Since ArCore uses OpenGL to load model, as a Normal Android Developer its difficult to understand and use,.]

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin.

You need to know this
  • Cloud Anchors were introduced in 2018 for multi-user AR experiences.
  • Persistent Cloud Anchors were introduced in 2020 for AR experiences to persist across sessions.
  • You need to enable the ARCore Cloud Anchor API for a new or existing Google Cloud Platform project. Don’t worry no need of Billing Its FREE.
  • If you use API KEY in Manifest, the Maximum limit to store anchors are 24 Hours. If you use OAuth Client ID, the Maximum limit will be up to 365 Days.
  • Sadly, it is not possible to store more then 365 days. We have to create and store the anchors again!
  • It has two concepts, Host and Resolve. Before Hosting the anchor its need to verify that camera/ArSceneView have sufficient data , otherwise anchor will not host. Once hosted need to store the CloudAnchorID, we will use to resolve later.

Boring?😵‍💫

Lets see an example👨🏻‍💻

  1. Implement the SceneView Library in app level build.gradle.
implementation "io.github.sceneview:arsceneview:0.9.5"

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, ,

Migrating to Jetpack Compose – an interop love story

Most of you are familiar with Jetpack Compose and its benefits. If you’re able to start anew and create a Compose-only app, you’re on the right track. But this talk might not be for you…
Watch Video

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer for Jetpack Compose
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engin ...
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer f ...
Google

Jobs

2. Create ArNode with custom model.

val cloudAnchorNode = ArModelNode(placementMode = PlacementMode.PLANE_HORIZONTAL).apply {
            parent = sceneView
            isSmoothPoseEnable = false
            isVisible = false
            loadModelGlbAsync(
                context = requireContext(),
                lifecycle = lifecycle,
                glbFileLocation = "models/car.glb"
            ) {
                isLoading = false
            }
}

3. Once you created Node, its time to check the data is there or not to host CloudAnchor.

if (sceneView.arSession?.estimateFeatureMapQualityForHosting(frame.camera.pose) == Session.FeatureMapQuality.INSUFFICIENT) {
Toast.makeText(context, R.string.insufficient_visual_data, Toast.LENGTH_LONG).show()
return
}

In above code, if we don’t have sufficient data to host, we want to move the camera around 180 degree to the node place.

4. Host ArNode — Uploading to cloud.

cloudAnchorNode.hostCloudAnchor { anchor: Anchor, success: Boolean ->
                    if (success) {
//We have to store the cloud Anchor Id. we can only retrieve the Anchor via this id.
                        saveCloudAnchorId(anchor.cloudAnchorId)
                        print("UPLOADED SUCCESS")
                    } else {
                        print("UPLOADED FAILED")
                    }
            }

In above code, If host is SUCCESS , we will get cloudAnchorId. we have to store in DB or somewhere for resolve purpose.

By default, it will store in the Cloud for 24 hours. If you want more than that, you have to enable the Cloud Anchor API by using OAuth. The maximum we can store is 365 days (aka TTL — Time To Live).

Create an OAuth client ID for your Android app in the Google Cloud Console.

5. Resolve ArNode — Retrieve node from cloud (It can be any device, any ArSession.)

cloudAnchorNode.resolveCloudAnchor("CloudAnchorId") { anchor: Anchor, success: Boolean ->
                    if (success) {
                        print("RESOLVE SUCCESS")
                    } else {
                        print("RESOLVE FAILED")
                    }
}

SOURCE Ar Cloud Anchor Multiple Nodes host / Resolve

That’s it!

Happy Coding 🥳

If you learned something new, please don’t forget to clap👏, follow🤩, like😻, and support me. 👍😊

This article was previously published on proandroiddev.com

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
This is the second article in an article series that will discuss the dependency…
READ MORE
blog
Let’s suppose that for some reason we are interested in doing some tests with…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu