Exploring Vuforia

Initially developed by Qualcomm, and currently run by PTC, Vuforia is one of the oldest and most well-known AR SDKs. It's one of the most stable and best-performing pieces of software on the market and, along with ARKit and ARCore, one of the favorite choices for AR developers.

Vuforia offers a wide variety of features, including 2D images and 3D objects tracking, markerless AR where there is no need for a reference image to launch AR content (the one we will be using in this chapter) and barcode-like markers called Vumarks. It provides multiple examples and extra features, such as virtual buttons, runtime image target creation, and background video texture manipulation. 

Like other AR software, Vuforia requires a license for it to be deployed on mobile devices. Vuforia offers a free development key generator, which will have to be switched to a deployment key when the app is in the production stage. You can consult its pricing options on their web page: https://developer.vuforia.com/pricing.

The Vuforia SDK can be downloaded for Android and iOS, and can also be used in the Unity 3D platform. Since the Unity 2017.2 version, it comes directly integrated into the Unity editor, just like any other main asset, and it has to be installed and activated inside it. Now, we'll incorporate Vuforia into a new project and set it up so that we can build it on an Android device. Let's get started:

  1. When you first installed Unity on your computer (see Chapter 2, Introduction to Unity for AR Development), you should have selected the option of adding the Vuforia module. If you didn't install it or you are in doubt, open the Unity Hub, go to the Installs tab, and check the installed modules at the bottom of your Unity version:

Current Unity installation with Vuforia support
  1. If Vuforia is not there, click on the top-right button and click on Add Modules. Select Vuforia and install it:

Adding new modules to the current Unity installation using Unity Hub
Vuforia usually comes included with stable versions; if you are trying a beta version or a very recent version of Unity, it's possible that Vuforia might not appear among the options and you will have to install a previous version to use it.
  1. Now, open the Unity Hub. On the Projects tab, click on NEW:

Creating a new project in the Unity Hub
  1. Fill in the Project Name and Location fields and click on CREATE:

Creating a new 3D project
  1. Click Ctrl + N or go to File|New Scene. Now, press Ctrl + S or go to File|Save. Name the file OnTheGo and save it in the Scenes folder:

 

Creating a new scene for the current project
  1. You can also delete the SampleScene that comes with the project from the Project window:

SampleScene is no longer needed
  1. AR requires a special camera that retrieves the physical camera feed and processes it so that we can integrate the virtual elements into the real image stream. Vuforia provides an asset called AR Camera that does this for us. Delete the existing Unity Main Camera, right-click on the Hierarchy window, and select Vuforia Engine|AR Camera:

 

Adding the AR Camera to the scene
  1. Since it's the first time we're using Vuforia in the project, a message will appear asking us to import Vuforia's assets. Click Import:

 

Message to import Vuforia and its assets into the project

A new folder called Vuforia will appear in the Project window, inside the Assets folder.

  1. Place the Directional Light inside the AR Camera so that the light moves along with the camera.
  2. Now, we have to enable Vuforia in the Player Settings so that we can use it in the scene:

Vuforia Behaviour component detecting that Vuforia isn't enabled yet
  1. Press Ctrl + Shift + B or go to File|Build Settings... to open the Build Settings window.
  2. Before anything else, click on Add Open Scenes to include our scene in the building scenes list.
  3. Then, switch platforms by clicking on Android and pressing Switch Platform in the bottom-right corner. With this, we will have configured our project so that it can be built on an Android device:

 Build Settings panel, allowing us to add new scenes, switch platforms, and access Player Settings
  1. Now, click on Player Settings... to open a new window.
  2. Fill in the Company Name and Product Name (the name the app will have when we install it on a device). 
  3. In the last tab, XR Settings, enable Vuforia Augmented Reality Supported to allow the use of Vuforia in this project:

 Player Settings with Company Name and Product Name filled and Vuforia activated in the XR Settings
  1. A new message will appear indicating that XR is not supported by the Vulkan graphics API. To fix this, open the Other Settings tab and remove Vulkan from Graphics APIs:

Removing Vulkan from the Graphics API under Other Settings|Rendering
  1. Below this, fill in the Identification section's Package Name and minimum API Level:

 Updating the Package Name and Minimum API Level under Other Settings|Identification
Currently, Vuforia supports Android 4.4 and above and iOS 11 and above. However, we recommend setting the Minimum API Level to 5 to ensure the devices running the apps are powerful enough to do so. You can check the minimum requirements for Vuforia here: https://library.vuforia.com/articles/Solution/Vuforia-Supported-Versions.
  1. This step is not always required but it might be the case that the Vuforia version that's been installed with your Unity version is not the latest one. If so, when selecting the ARCamera, a message will appear on the Vuforia Behaviour component indicating that a new version is available:

Link to the new Vuforia version in the Vuforia Behaviour component of the ARCamera
  1. Click on the link to download the executable and follow the steps to install it:

Vuforia AR Setup Wizard
  1. When updating Vuforia, make sure you install it in your Unity root folder, usually in C:/Program Files/Unity/Hub/Editor/{unity_version_name}, and close your currently running Unity session if asked. If a message appears asking you to update your project, click Update. Vuforia will now be up to date in your project:

Update message from Vuforia Engine

Now that we know how to integrate Vuforia into a new project, we will start using its Ground Plane feature to create an app that detects flat surfaces and places 3D content on them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.24.134