The Unity* Toolkit for Intel® RealSense™ technology is a standard Unity package. It contains all the DLLs and scripts that are needed to run Intel RealSense technology from Unity. The toolkit allows for ease of use by making scripting properties available in the Inspector.
Purpose
The purpose of this tutorial is to get you up and running a simple Intel RealSense application using the Unity Toolkit. As such, it will not dive into all the options available for the given rotation action script.
What this Tutorial Covers
This tutorial will cover the steps needed to get a cube to rotate based on hand movement.
Assumptions
You must have read the sdktoolkit.pdf file to get a general idea how this Unity add-on works. If you installed the Intel RealSense SDK in the default location, the file can be found in the Program Files (x86)\Intel\RSSDK\doc\PDF folder. This tutorial also assumes that you have some basic Unity skills such as importing an external package, adding a cube to a scene, and applying a script to a game object.
Requirements
Unity Professional 4.1 or higher.
An Intel® RealSense™ 3D camera either embedded in a device or an external camera.
Let’s Begin
Import the Visual Studio* Plugin (Optional)
While this step is not required, I use the plugin because I like Visual Studio more than the MonoDevelop* IDE. If you would like to use this free plugin, you can download it here http://unityvs.com/.
If you do not see this option, you will need to manually import it by navigating to the location where this plugin was installed on your hard drive.
Import the Unity* Enemy Ship
I thought it would make this demo a little more fun to use the enemy ship game object instead of a plain old cube. You can get this game object from Unity’s free Space Shooter package that’s available on the Unity store. I didn’t want the entire package so in a separate Unity project, I imported the Space Shooter package and then exported only the enemy ship. However, this is just a personal preference as you can use a simple cube object for this tutorial as well.
Import the Unity Toolkit
The package containing the Unity Toolkit for Intel RealSense technology contains everything you need for manipulating game objects. The Unity package is located in the \RSSDK\Framework\Unity folder. If you installed the Intel® RealSense™ SDK in the default location, the RSSDK folder will be in C:\Program Files (x86).
You can import the Unity Toolkit as you would any package. When doing so, you have the options to pick and choose what you want. For the purpose of this tutorial, we will use the defaults and import everything.
As you can see in the following image, there are now several new folders under the Assets folder.
- Plugins and Plugins.Managed contain DLLs required for using the Intel RealSense SDK.
- RSUnityToolkit is the folder that contains all the scripts and assets for running toolkit.
We won’t go into what all the folders are. I’ll leave that task for you to do on your own.
Add the ship to the scene. Note that you can use any 3D game object of your choosing. I just happen to like this one. All scripts will work fine on standard assets like a 3D cube.
Add a directional light to give the ship some light so you can see your game object better.
Adding Scale to the game object
To add scaling capabilities to the game object we have to add the ScaleAction script. The ScaleActionScript is under the RSUnityToolkit folder and in the Actions subfolder. Simply grab the script and drag and drop it directly onto the enemy ship in the scene view.
You can now see the ScaleAction script parameters in the Unity Inspector.
Here, I’ve collapsed all the parameters to show the three basic areas of the scale script: the Start Event, the Scale Trigger, and the Stop Event.
Now we are going to start setting parameters
- Starting with the Start Event, expand the arrow to show the default trigger. In this case, I don’t want to use “Gesture Detected.” I want to use “Hand Detected.” Right click on “Gesture Detected” and select Remove.
- On the Start Event’s Add button, click and select “Hand Detected.”
- Under “Which Hand,” select and choose ACCESS_ORDER_RIGHT_HANDS.
Your settings should now look like this.
Now we want to set the stop event.
- Expand the Stop event and remove the “Gesture Lost.”
- Click the Stop Event’s add button and choose “Hand Lost.”
- Next to “Which Hand,” select ACCESS_ORDER_RIGHT_HANDS.
Your settings should now look like this:
We won’t have to change the “Scale Trigger” because there is only one option for this anyway. So the default is what we will use.
Here is what the entire set of parameters should look like at this point.
Congratulations! Everything is ready to go.
Save your scene
Save your project and
run your game!