- To use Kinect with Unity3D, you need to download the Academic or Premium version of our software. Among others, the Unity samples include an angle calculation demo. The C# code is identical to the one presented in this blog post: double angle = elbow.Angle(shoulder, wrist); More about Unity3D; More about Vitruvius and Unity3D.
- Using XBox One Kinect with Unity. An article by mgear 1 Comment.main image: Kinect GreenScreen example scene. Setting up Kinect with Windows 10.
NuGet and Unity Pro add-ons Install the Kinect SDK 2.0 and use the NuGet packages for a better.NET Framework development experience. You can also take advantage of the Unity Pro packages to build Kinect-based Unity apps. Microsoft released a Unity3D plugin for the Kinect v2. Unfortunately, Unity 4 only supported plugins if you owned a Unity Pro license. The next release of Unity, the fifth, includes plugin support in their free Personal edition. In this post, I will show you how to get started with the plugin and start running a Kinect v2 game.
After installing the Kinect v2 SDK from here http://www.microsoft.com/en-us/download/details.aspx?id=44561 you can also download the supporting Unity 3D plugins here http://go.microsoft.com/fwlink/?LinkID=513177. Note that the plugins require Unity 3D Pro and they expose APIs for Kinect for Windows core functionality, visual gesture builder and face to Unity apps. The zip file containing the Unity packages also contains two sample scenes Green Screen and Kinect View. Lets take a look at KinectView first:
So, I stumbled around a bit on the next step as initially I tried opening the KinectView scene from it’s existing location and this doesn’t seem to work very well. The result I got was that when I examined the game objects there was an error on each of the scripts. After some head-scratching I watched the video here http://channel9.msdn.com/Series/Programming-Kinect-for-Windows-v2/04 and at about 10:54 the presenter shows copying the scene locally to the current project. That fixed the issue for me so I was back up and running. You can plug in your Kinect sensor and run the game and then explore the scripts to see how the data is retrieved from the sensor and applied to GameObjects in your scene.
My idea was to create a very simple Kinect sample which will move particle systems around following the positions of the users hands. So lets step through what I did.
First, I chose File > New Project to bring up the Unity project wizard:
I added the Visual Studio Tools as I’m more comfortable editing and debugging in Visual Studio. You can download the tools from here https://visualstudiogallery.msdn.microsoft.com/20b80b8c-659b-45ef-96c1-437828fe7cf2.
Once the project is created I imported the Kinect Unity package; Assets > Import Package > Custom Package… I navigated to where I installed the Kinect package and chose Kinect.2.0.1410.19000.unitypackage.
I left everything selected and imported the various libraries and scripts. The editor shows that I have an empty scene just containing a Camera.
The first thing to do was to try to get the Kinect sensor data into the scene, so to do this I created a new c# script in the project and copied the code from the KinectView sample in the file BodySourceManager.cs. The code retrieves the sensor and opens a reader on it for the body data and also reads the current frame’s data in the scripts update() method. The update() method is called as part of the game loop so we are ‘pulling’ the Kinect skeleton data each time we are called. The class also has a method GetData() to allow the data to be accessed by other scripts.
I created an empty GameObject called BodySourceManager and associated the BodySourceManager.cs script with it so the code to set up the Kinect would be executed. Next, I created another empty GameObject and associated a new script which would get the body data and position the GameObject depending on the position of one of the joints in the skeleton. I made the joint type a variable so I could set up the positions of various GameObjects via the Unity editor. The intention was that if I then add a particle system as a child of this new GameObject then it would follow the tracked position of say, the left hand and I could add others for each joint that I wanted to track.
The code for the update loop showing how the game object position is set from the joint.
- void Update ()
- {
- if (_bodySourceManager null)
- {
- return;
- }
- _bodyManager = _bodySourceManager.GetComponent<BodyManager>();
- if (_bodyManager null)
- {
- return;
- }
- Body[] data = _bodyManager.GetData();
- if (data null)
- {
- return;
- }
- // get the first tracked body…
- foreach (var body in data)
- {
- if (body null)
- {
- continue;
- }
- if (body.IsTracked)
- {
- var pos = body.Joints[_jointType].Position;
- this.gameObject.transform.position =newVector3(pos.X, pos.Y, pos.Z);
- break;
- }
- }
- }
The next step was to add two new GameObjects, one for each hand and set their joint types to HandLeft and HandRight and then add particle system’s to each as a child. Then the particle systems had their parameters tweaked until they looked how I wanted. It seems to me that the combination of Unity and Kinect is a pretty powerful one and I’m looking forward to seeing the results in the Windows Store. Please find the sample project here http://1drv.ms/1tyKlIT.
-->This page has the download links for each version of the Azure Kinect Sensor SDK. The installer provides all of the needed files to develop for the Azure Kinect.
Azure Kinect Sensor SDK contents
- Headers and libraries to build an application using the Azure Kinect DK.
- Redistributable DLLs needed by applications using the Azure Kinect DK.
- The Azure Kinect Viewer.
- The Azure Kinect Recorder.
- The Azure Kinect Firmware Tool.
Windows installation instructions
You can find installation details for the latest and previous versions of Azure Kinect Sensor SDK and Firmware here.
You can find the source code here.
Note
When installing the SDK, remember the path you install to. For example, 'C:Program FilesAzure Kinect SDK 1.2'. You will find the tools referenced in articles in this path.
Linux installation instructions
Currently, the only supported distribution is Ubuntu 18.04. To request support for other distributions, see this page.
First, you'll need to configure Microsoft's Package Repository, following the instructions here.
Now, you can install the necessary packages. The k4a-tools
package includes the Azure Kinect Viewer, the Azure Kinect Recorder, and the Azure Kinect Firmware Tool. To install the package, run:
sudo apt install k4a-tools
This command installs the dependency packages that are required for the tools to work correctly, including the latest version of libk4a<major>.<minor>
. You will need to add udev rules to access Azure Kinect DK without being the root user. For instructions, see Linux Device Setup. As an alternative, you can launch applications that use the device as root.
The libk4a<major>.<minor>-dev
package contains the headers and CMake files to build your applications/executables against libk4a
.
The libk4a<major>.<minor>
package contains the shared objects needed to run applications/executables that depend on libk4a
.
The basic tutorials require the libk4a<major>.<minor>-dev
package. To install the package, run:
sudo apt install libk4a<major>.<minor>-dev
If the command succeeds, the SDK is ready for use.
Be sure to install the matching version of libk4a<major>.<minor>
with libk4a<major>.<minor>-dev
. For example, if you install the libk4a4.1-dev
package, install the corresponding libk4a4.1
package that contains the matching version of shared object files. For the latest version of libk4a
, see the links in the next section.
Kinect Unity Tutorial
Change log and older versions
You can find the change log for the Azure Kinect Sensor SDK here.
Kinect Unity
If you need an older version of the Azure Kinect Sensor SDK, find it here.