top of page

AR Foundation: Tap to Place Project

  • Photo du rédacteur: quentinaudy
    quentinaudy
  • 9 janv. 2023
  • 4 min de lecture

In this article, I will present you two tools I used for AR in a smartphone: Vuforia and AR Foundation. I will quickly go through Vuforia because we just tested one functionnality. I will also explain what we did with AR Foundation, and for the Tap to Place project. Finally, I will explain the parameters I had to change in order to build the application.



Summary


Vuforia


Vuforia is a toolkit available on Unity, which allow us to create simple AR applications. It was really easy to install in their website, and to import in the game engine. We also had to activate the package in the package manager.

The little exercise we made was to make a ball appear on a displayed image. It was really easy to do. In Unity, we created a plane with the reference image on it, and we added a sphere above it. In my case, I already had a 3D model of Flash McQueen in Cars, so I replace the sphere with that model. If we want this to properly work, we have to put the model as a child of the image.

Finally, in the Image Target Behaviour part, we must enter the picture we want to detect. And that's it ! If we run our Unity program, the camera starts working and if it detects the image, the car will appear on it:

We can also try to build the app in our smartphone: we film with our camera, and we can make the car appear on the image. However, we had several difficulties with the Android SDK, that I will explain in a separate part. So we decided to learn about AR Foundation, that we will use for the Tap to Place project.


AR Foundation


AR Foundation is another toolkit for AR applications, but for this one, we cannot test it in Unity: we must build the application to test if it works.

The installation was not really difficult, because we just had to add the AR Foundation and AR Core in the package manager. Then, we tried three little exercises:


Image Tracking

This exercise was similar to the one in Vuforia. Here, it was as easy as before. We just had to create an AR Session Origin, to create a reference library that will contain the image we want to track, and to create the object that will appear on this image (here it was a cube that I transformed into a prefab). With only that, it is supposed to work.

Here is the AR Script used for this purpose. And here is the library with the detected image:

I had some troubles with the building that I will explain in a separate part. When I managed to build the app, I didn't detect the cube on the image. In fact, the problem was simple: the volume of the cube was too important, so this latter appeared but I could not see it (I was inside the cube). After resolving that, I obtained what we were supposed to have.


Face Tracking

This one was easier. I added the AR Face Manager script, and put inside the default face which was available directly in AR Foundation.

Warning ! If we want this to work, we must change the camera of the smartphone that will be used. Here, we want the front camera to be used, and we can change it here:

And this is good:


Plane Detection

This last exercise will be really useful for the last project. Here, we will use the plane detection tool: it will change the color of each horizontal surface. It is really simple too: we just have to use the default plane available in AR Foundation, and import it in the AR Plane Manager.

After building, the planes are well detected.


Building the apps in Android


Before explaining what I did in order to create my Tap to Place application, I will go through the main difficulty I had here: the building of the application.

First, if we want to transfer the app in our phone, we must activate the developper mode, and disable the debug via USB. We can now link our phone to our computer. Then, we go to the building settings. We must select our scene, and we mustn't forget to select our device.

Now, we must go into the player settings, and make some changes. First, I activated the AR Core module in the XR Plugin Management panel:

I also had to deselect the Vulkan Graphic API, and to choose the Gamma Color Space:

For my application to be understood by my smartphone, I had to upgrade the Minimum API Level to Android 8.0 Oreo. I changed the scripting Backend to IL2CPP in order to be able to enable the ARM64 architecture.

After changing all these settings, everything worked properly. By clicking on "Build and Run", my smartphone automatically opened and saved the application. The results I obtained in the previous part were done with this.



Tap to Place Project


After what we have done before, this final project was really easy to do. The goal was to be able to put any object on the planes detected.

The plane detection part is already done. Now, we must import the 3D model, and create the script. For the 3D model, I imported an animated cat that was easy to put in Unity. Then, I added an AR Raycast Manager and wrote the entire script:


This code allow us to recognize where we touch, to obtain the intersection between the touch and the plane detected (thanks to the Raycast manager), and finally to put the object in this plane.

To conclude this article, here is a small video demonstration of this application.



Commentaires


bottom of page