Using Google ARCore for Unity

In August 2017, Google announced a new Android core SDK for augmented reality, called ARCore. Presumably, it directly derives from the Google project Tango. Tango is Google's augmented reality platform that has been in development, a beta release, for several years and is beginning to emerge in mobile devices equipped with depth sensing cameras. ARCore, on the other hand, does not require any specialized hardware other than a phone or tablet with an ordinary camera and a fast processor (such as Google Pixel or Samsung Galaxy S8 phones). For current supported devices, see https://developers.google.com/ar/discover/#supported_devices. Much like Apple's ARKit (as described later in this chapter), it is being rapidly adopted and promises to be a leading platform for augmented reality.

We are pleased to provide an introduction to Google ARCore in this book, but only an introduction. ARCore is brand new, and at the time of writing this, it is in preview release only. The documentation and demo scene they provide is very bare-bones. And, the setup will likely be different when Unity supports ARCore in the final release. Things such as installing the preview of AR Services APK will change. Refer to the GitHub repository for this book for new implementation notes and code using Google ARCore for Android: https://github.com/ARUnityBook/. The principles are very similar to ARKit, but the Unity SDK and components are different.

For some of your projects, you can use Google ARCore for Android instead of a general-purpose toolkit, such as Vuforia or ARToolkit. While Vuforia, for example, is best a target-based AR, ARCore is especially good at anchoring virtual objects in real-world 3D space and recognizing surfaces in the real world. In that sense, it shares similar use cases with Microsoft HoloLens and Apple ARKit.

At the time of this writing, ARCore requires Android SDK version 7.0 (API Level 24) and a supported device. The system requirements, API, and SDK are subject to change.

The arcore-unity-sdk project from Google provides a thin wrapper around the native ARCore SDK. Note that arcore-unity-sdk is an open source project hosted on GitHub at https://github.com/google-ar/arcore-unity-sdk. It provides Unity scripts, components, and prefabs that you can use. It also includes several example scenes.

To install arcore-unity-sdk, perform the following steps:

  1. Be sure you are using a compatible version of Unity (at time of this writing, Unity 2017.2 Beta 9 or later is required).

 

  1. Download the SDK Unitypackage file, using the link provided on the Getting Started page at https://developers.google.com/ar/develop/unity/getting-started
  2. Import the asset package into your Unity project (from the Unity main menu, choose Assets | Import Package | Custom Package... and then find the selected unitypackage file on your system).
  3. Then, press Import.

Review the folders and files installed in your Assets folder. The Assets/GoogleARCore folder contains the HelloAR example scene along with various supporting subfolders. The ARCore plugin's actual assets reside in the Assets/GoogleARCore/SDK/ folder.

The project's Asset folders are shown in the following screenshot, with SDK/Scripts/ selected:

Once installed, you can try ARCore by opening one of the example scenes. The HelloAR scene is a basic scene with an example Android robot. It demonstrates all of the basic functionality of ARCore. Open the scene as follows:

  1. In the Project window, navigate to Assets/GoogleARCore/HelloARExample/Scenes/.
  2. Double-click on HelloAR.

You will notice that the Hierarchy scene contains the following objects that are basic to any ARKit scenes:

  1. First is ARCore Device; it contains a child First Person Camera object. It includes Tracked Pose Driver, a component for tracking the camera pose in 3D space, and Session Component for managing the AR session connections.
  2. Then we have Environmental Light; this automatically adjusts the lighting settings for the scene to be in line with those estimated by ARCore from the real world.

The HelloAR hierarchy is shown in the following screenshot:

The other objects are examples specific to this demo application scene. Although subject to change as the plugin matures, the current scene includes the following:

  • ExampleController handles camera tracking, horizontal plane detection, plane visualization, and hit detections.
  • PointCloud visualizes the point cloud as ARCore detects 3D nodes in the spatial mesh construction of the real-world space.
  • Canvas and Event System are ordinary Unity objects for handling user interface (UI).

In preparation of building the scene, perform the following steps:

  1. From the main menu, navigate to File | Build Settings.
  2. Select Add Open Scenes and/or uncheck all the scenes in Scenes in Build, except HelloAR.
  3. In the Platform pane, ensure Android is selected and click on Switch Platform, if needed.

The Build Settings box is shown in the following screenshot:

There are build and player settings you should consider. If you load ARKit into a new Unity project, these settings (or similar) may already be set up. Let's take a look at the following steps:

  1. Click on Player Settings....
  2. In Inspector, under Other Settings, uncheck the Multithreaded Rendering checkbox.
  3. Enter a valid Bundle Identifier (in the form of com.company.product) as described previously.
  4. For Mininum API Level, choose Android 7.0 or higher.
  5. For Target API Level, choose Android 7.0 or 7.1.
  6. In XR Setting, check the Tango Supported checkbox.

At the time of this writing, there is no emulator for running and testing ARCore apps from within Unity and no remote option to let you use the play mode from Unity to test your app without the need to build and run each time. This is obviously subject to change and will hopefully be resolved by the time you are reading this, as time keeps on moving, into the future.

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

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