AR Foundation: Image Tracking
My last post was about setting up a scene to be AR Ready, today we will actually have some fun with the AR Foundation Plugin. Once again this tutorial revolves around IOS, but should be very similar for android if you use the AR Core package rather than AR Kit. Our scene should look something like this:
Where we last left off was with a scene that contained an AR Session Origin, and an AR Session. With those two in the scene you can grab any object you want, drop it in the scene and it will appear in AR when you build to Iphone. Pretty easy! But there are some downsides to how a simple scene like this works. If you got ahead of yourself and gave this a shot you will notice that the Object is floating in space where you first opened the app, which may not be desirable. Instead we are going to set it up so that your object only appears when the camera recognizes the correct image.
Step 1: Creating and AR Tracked Image Manager
On your AR Session origin object we are going to add an AR Tracked Image Manager Component. We will handle the Reference Image Library You can set the max number of moving images to 1. The tracked image prefab can be whatever object you want to spawn over the text. In mine I created and animated a rotating monkey I quickly exported from blender but it would work with any prefab you load in there. Feel free to use any basic 3d shape from unity for your project. Remember 1 unity is 1 real life meter. So keep that in mind when you are sizing your object for AR use.
Step 2: Creating a Reference Image Library
For this step we are first going to need to load the image we want into unity. For my project I choose the GameDevHQ Logo.
This image is what you will be printing out for your object to spawn onto. Any simple image will work. Once the image is imported we are going to right click in the Project Folder and Select Create ->XR -> Reference Image Library. You can leave the name as its default name. Select the new Reference image library From there we will press “Add Image” in the inspector.
Select the new Reference image library From there we will press “Add Image” in the inspector.
We will now click select and navigate to the image we loaded in earlier. It is important that we check the “Specify Size” box and set the physical size to .1 by .1 (It will automatically alter your dimensions to fit the aspect ratio of your image). Make sure the Specify Size is checked or the build will fail!
Step 3: Set your Reference Image Library in the AR Tracked Image Manager
Take that Reference Library you just created and set it in the AR Tracked Image Manager.
Step 4: Build To XCODE
Go into build setting, make sure you have the platform set to IOS (if not select iOS and press Switch Platform at the bottom) and press build.
Run the build in XCode and don’t forget to set a developer profile in the signing options. Print out your image that you are using and you should have something like this!
There are lots of applications for using this type of Image tracking. From advertising, to training, AR image tracking is a powerful tool that's easy to get started with.