ARCore, Google's augmented reality SDK, was officially released to the public last week! The 1.0 update comes with some handy new features, including what Google calls "oriented feature points". A feature point is any fixed plane that the SDK can place a virtual object, and 'oriented' feature points make it so that we can put virtual stuff just about anywhere!
Even more exciting is the fact that these oriented feature points work just like the old kind, so allowing users to anchor virtual objects to their walls is just as easy as allowing them to place stuff on the ground. All we need to do is set up a standard ARCore scene in Unity, and it does the rest.
I followed along with Google's "Unity Quickstart Guide" in order to create this ARCore template project.
Before you can use it to create stuff like this, you need to make sure your computer is set up to build and run Android projects. As the guide says:
Install the Android SDK version 7.0 (API Level 24) or higher.
You will need to get the ARCore SDK for Unity. You can either:
You will need a supported Android device.
Once all that's sorted, then, the first thing you need to do is open Unity. Once you do, you should be greeted by the project manager window. Click the "new" tab and then enter your project's name as ARCoreTemplate. You don't need to call it that, I guess - Just name it whatever!
Just click "create project" and then let everything set itself up. Once you're greeted with an empty Unity canvas, we're ready to get started!
First thing you'll want to do is import this Unity Package!
The way to do that is to click "Assets -> Import Package -> Custom Package..." and then select the file you've downloaded from above!
Once you've imported the package, your Unity window should look something like this.
Click the file marked "AR_TEMPLATE" in your "Project" window, at the bottom of the screen. Opening it will take you into our AR template scene!
This scene has everything you need already set-up to build out an AR-Core compatible Android application. To modify it for your own purposes, all you'll need to do is replace the "TEMPLATE_OBJECT" prefab's content with something more to your liking! I'll explain how.
Open the UnityChan folder, then "Prefabs", then grab "unitychan" and drag her into the scene heirarchy, and place her in the heirarchy next to VLWLogo, so that she is a child of "TEMPLATE OBJECT". then, go ahead and delete "VLWLOGO". Finally, click on "TEMPLATE_OBJECT" and then look at it in the "inspector" window. To view the inspector window, go to Window -> Inspector or, just look to your right! The inspector window should be one of the tabs on the right hand pane of your unity window.
Click on the button marked "APPLY" in the top-right hand corner of the inspector window. This will apply the changes we've made to the TEMPLATE_OBJECT prefab, so that, once we load up our new AR project, instead of projecting little alien dudes or VLW logos, you'll be placing unity chan in your environment!
now, simply DELETE the TEMPLATE_OBJECT prefab from your scene entirely. Don't delete it out of your assets folder at the bottom of the screen, just delete it from the scene heirarchy, so that it looks like this.
And we're DONE! All that's left to do is to build the project out to your ARCore compatible android device, and you should be off to the races! I'll give you some tips about how best to do that, but first, we need to put some lights in our scene!
For certain AR applications, we'll want to make use of ARCore's ability to match the lighting of a virtual object to the lighting of the environment you're in, thanks to a couple of shaders called "ARCore - DiffuseWithLightEstimation" and "ARCore - SpecularWithLightEstimation". You can find these on any object by clicking on them in the heirarchy to highlight them in the inspector, then checking out their "Material" slot, if applicable - then clicking on the "Shader" drop down menu. Then go ARCore -> DiffusewithLightEstimation OR ARCore-> SpecularWithLightEstimation.
These two shaders are far less complex than Unity's Standard Shader, but they have the added benefit of allowing your virtual lighting to match up with your real life lighting environment. our VLW_Logo object had the ARCore - diffuse with light estimation setting attached, so we didn't need any lights in our virtual scene. But since UnityChan's model won't support these ARCore specific shaders, we're going to need to add a light to our scene, so that when we build out to mobile, you'll be able to see her! This will be true of MOST objects you import into the AR_template, so before you start creating, you might want to add a light to your scene!
To add a light to your scene, simply click "GameObject -> Light -> Directional Light"
You'll notice that your scene has become a fair bit brighter! This is because a Directional Light simulates a light source like the Sun, with it's default coordinates mimicking mid-day. This should be more than enough light for any model that doesn't support ARCore's shader package.
Now that we can see, hit CTRL+S or CMD+S on Mac to save your scene, then click "File - > Build Settings" to continue!
You should then be greeted with the Build Settings menu. Then, change the following settings:
Once all that's done, just click "Build and Run" in the build menu, and, if you've got a compatible android device connected, you should be off to the races!
Enjoy your new AR application!
In our next lesson I'll provide you with a quick and easy ARKit template for iOS devices! Then - ANIMATION!