Introduction: Augmented Reality in Unity 3D
In this tutorial, I'll be showing you how to create a simple augmented reality world using Vuforia SDK for Unity 3D. The reason I choose the framework, was because it looked easy and is free. Let's get started!
Step 1: Prerequisites
Before build your app, you'll need to have the following:
Step 2: Licence Key
2.1 Go to Vuforia Developer Portal and LogIn with your account and create.
2.2 Go to Develop section.
2.3 Get your Licence Key, by clicking Add Key Licence on Licence Manager section.
2.3.1 Name your application.
2.3.2 Select the device that you are going to use.
2.3.3 Select your plan, you can choose Starter Plan for Free.
2.4 Copy your Licence Key, you are going to use later on Unity3D.
Step 3: Target Image
After everything is installed and set up, you'll need to go to the Target Manager from Vuforia. We'll be uploading the target image here. Make sure you'll select an image that has a high feature amount of features. The target manager will help you though.
3.1 Select the type of object that you are going to add AR.
3.2 Choose your file and upload.
3.3 Select the width of it, the height will be calculated automatically.
3.4 Add a name to your Target
3.5 Download the dataset. Select Unity Editor and it will download a .unitypackage file with your target. Save this file on your disk.
Step 4: Unity Project Start
The next step is to start up Unity. Create a new (empty) project on a selected location. When the project is loaded, delete the Main Camera in your Hierarchy to start with a clean plate.
We now need to import the Vuforia .unitypackage files (both the SDK and the image target).
After that you need to import also your 3D model that you want to show. You can create your own 3D model or download from different pages like:
Now that we have everything complete in Unity3D, we can start building our world!
Step 5: Setting Up ARCamera
In your Project windows, open the Assets/Qualcomm Augmented Reality/Prefabs-folder. In here, you'll find the ARCamera. Drag it into your Scene.
You need to set up first some parameters on Inspector of ARCamera:
- On Vuforia Behaviour (script) add your Key Licence from Vuforia. You can also select how many target your want to recognize simultaneous and also which camera you are going to use.
- On Database Load Behaviour (script) make sure that Load Data Set Control and Active is check.
Now your camera is ready to start recognizing, you just need add a Image Target.
Step 6: Image Target
From that same Prefabs-folder, drag an Image Target to the scene. With the Image Target still selected, scroll down in the Inspector and set your Data Set (Database name) as well as your Image Target. Your Image Target should now be visible (you might need to scroll in order to zoom in/out), don't forget to adjust the ARCamera view so your Target is center on it.
Step 7: Add 3D Model
Now, we'll need to add the model to the Image Target. Simply drag the model that you added in your Assets-folder to the scene. In your Hierarchy, make sure the model is under the Image Target. You might want to change the position of the model, change the values of the Scale / Rotation (inside the inspector) to get it into the right place. This might need some experience with the program, but once you got the hang of it, it's pretty simple.
From here on, it actually is your own creativity that can do all the work! Add more models to the scene (trees for example) to get an even cooler world.
Add some light to your models by going to GameObject > Create Other > Directional Light. This way, you can create a light source to light up your model.
And you now can Build your App for an Android, iOS or EyeWear Device. And you have your first Augmented Reality App.