Sunday, February 24, 2013

Motion-Control Baby Steps

Click here if all you care about is getting the Kinect working with Unity 3D so you can dance like me in the below video.

In my Glossary post, I tried to make sense of all the terminology necessary in order to create a 3D Virtual Reality game using the Kinect, the Oculus Rift, and Unity 3D.  However, just knowing the terminology isn't enough.  You also have to know what to do with it.

When I first got my Kinect 360 sensor, I just wanted to use it right away.  So I downloaded the latest official Microsoft Kinect SDK and... nothing.  I hadn't done any research up until that point, so that's when I had to start.  And one of the first phrases to frequently pop up in my searches was the Omek Beckon SDK. A quick glance at it's features made me think this was a magic bullet to all my challenges:
  • Motion Toolkit for Unity3D allows you to drag and drop ready to use components to quickly add gesture from within the Unity framework
  • Simple-to-use extension for developing in C# and .NET frameworks
  • Flash wrapper for quick development
  • Gesture Authoring Tool for the creation of custom gestures in minutes
  • Ability to track up to 5 skeletons simultaneously
  • Support for multiple camera positions
  • No calibration required
I admit, my first reaction was this was going to be too easy. I mean, what's the fun in learning how to program the Kinect into my game if I don't actually do any programming?

But using the magic bullet wasn't as easy as I thought.  After removing the previous SDK that I had downloaded (the official one), I was able to successfully install the Beckon SDK (the microsoft SDK and the Beckon SDK are incompatible).  To use the SDK with Unity 3D, I next had to import from the Asset Store the Motion Toolkit. It was then time to start up Unity and run through the sample scenes.

This is where I hit some problems.  When the sample scenes used my Kinect, many of my movements weren't being picked up.  In fact, the only movements which were picked up were moving right and left and forward and back. 

And I was suddenly at a loss.  After all, I knew nothing about ...well, pretty much anything, so it was impossible for me to debug this.  So I hit the forums and tried to find other people with my problem.

Unfortunately, this version of Beckon hasn't been out for too long, and there wasn't exactly a wealth of helpful material online.  ***UPDATE! --getting Beckon installed and running has been a bit problematic for me.  I'm currently in contact with the Beckon team on the matter.  Once it's installed and I've played around with it a bit, I'm going to write a post comparing it to Zigfu's ZDK, which I talk about below.

Following another lengthy visit to Google - during which I compiled the Glossary - I discovered this very helpful little video.  Not only did it have good background music, but it provided very nice instructions on just how to get the Kinect motion tracking working using nothing but OpenNI 2, NiTE 2, and the most updated official Kinect SDK (as of the time of this writing), and not Beckon.

So now I had motion tracking working!  Yay!!  ...but I had no idea how to translate that to something usable within Unity 3D.  Back to Google.

At this point, I kept running into search results regarding something called the UnityWrapper, written by Amir Hirsch (apparently an extremely smart fellow). This enabled people to incorporate Kinect functionality within Unity 3D games.  The problem was, the last time that wrapper was updated was early 2012.  However, the Read Me there pointed me to a Zigfu repository on github, so there I went. This quickly brought me to Zigfu and their ZDK.

I must admit, I had come across this page far earlier, in some of my initial searches, and quickly dismissed it.  At first, it seemed like a quick fix which costs money.  But as it turned out, I hadn't read the fine print, as it only cost money for commercial use.  And since by this time I was getting impatient, I decided to give it a try. But before doing so, I wiped my computer of any remnants of previous Kinect SDKs/drivers, as per a piece of advice I read in this article, which stated the following:

These libraries usually do not play well with each other, with each of them requiring their own driver’s and dependencies for using them. There are options to bridge these gaps but in general terms, it will be necessary to completely remove any legacy or conflicting installations before switching from one to the other. That includes drivers, .dll’s, and registry/environment path settings.

While the ZDK download page doesn't explicitly state what needs to be installed prior to using the software, I found this elsewhere on the site:  "Like all the ZDK offerings, the ZDK for Unity3D works with both Mac and PC, with OpenNI/NITE and the Microsoft Kinect SDK, and with all consumer-level 3D sensors."  So I figured it went without saying that I needed to install the latest OpenNI/NiTe, and the latest Microsoft Kinect SDK. 

Which meant I didn't actually have to uninstall the other SDKs, but whatever.

After finishing the reinstalls, I opening up Unity, imported the ZDK package, opened up a sample scene - the avatar one looked nice - and ran it.  And... it worked!! It worked fabulously!!

So now I feel obliged to do two things: First, thank the ZDK, OpenNI/NiTE guys.  Awesome job.

Second, I should probably summarize, in just a few words, what I actually did to get things working.  Here it is:

Quick Guide To Getting Kinect To Work in Unity: 
1. Download the latest versions of OpenNI, NiTE, and the Kinect SDK, and install them (in that order) 
2. Import the latest ZDK package into Unity 
3. Go have fun.

I should note, the method I chose was in large part influenced by the fact that I didn't want to shell out money for anything. If you don't care about money, the Beckon SDK may be for you; or the pro version of the ZDK.

K, now it's time to end this post and go reverse engineer these ZDK sample scenes.

No comments:

Post a Comment