Innovation in gaming and technology gets us pretty fired up at BLITZ. And when a new interaction peripheral (and engagement model) is released, the first thought that comes to our minds is “let’s see if we can hack it.” In this case, Director of Technology Noah Gedrich and Software Developer Yosef Flomin can take their bows for linking the Xbox Kinect™ hardware to Adobe Flash via Node.js.
Their interest was piqued after Hector Martin and PrimeSense™ released their open-source drivers, resulting in an online demo showing Kinect’s uses through a PC. Having worked with multiple UI technologies over the years, Gedrich and Flomin realized that if they could get Kinect to publish information that any UI platform could support, a slew of developers could use this same code to create breakthrough motion-based experiences using familiar markup languages.
The trick? A simple socket server. Using a C++ application to send all the skeleton data to a socket server, they were able to connect other technology to the socket, enabling use of the data.
When Kinect was first announced, we immediately began dreaming of the different ways we could use it to create engaging experiences that leveraged physical interaction for our clients. Unfortunately, in the earliest days, we would have been tied to Xbox’s proprietary XDK and only able to publish to the Xbox itself. With this breakthrough, we’re arming any Flash, Silverlight or Unity developer around the world with an intuitive way to implement physical interaction models into their work. Be it a large-scale installation or a desktop application, marketers, agencies and developers can save a great deal of time, energy and money — opening up the potential of Kinect beyond Xbox to any platform supporting socket connections increases the creative possibilities exponentially.
Watch the video below or on Vimeo
Flash Kinect Demo from BLITZ Agency on Vimeo.
Try it out for yourself. Follow Gedrich and Flomin’s personal process below, complete with necessary links and helpful sites.
Setting up Kinect Drivers:
Check out Dan Ivanovs blog on installing the drivers, OpenNi and NITE from PrimeSense.
http://cleoag.ru/2010/12/10/kinect-OpenNi/
Setting up our socket server:
For our socket server, we used node.js. To get started with node.js on Windows, we first needed cygwin installed with the appropriate packages. Grab the cygwin setup at:
http://cygwin.com/install.html
When you have setup running take a look on github at https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows) for the correct packages and steps that you’ll need to take to correctly install node.js
Great. Now let’s take a look at a simple node.js server at http://nodejs.org/. We’ve modified that basic server a bit to have our data coming through on an interval:
var dataToSend;
var socketServer;
net.createServer(function (socket)
{
socketServer = socket;
socket.write("Server Initialized.");
setInterval ( writeToSocketServer, 33 );
socket.on("data,:" function (data)
{
dataToSend = data
});
}).listen(8124, "127.0.0.1");
function writeToSocketServer()
{ if (dataToSend) socketServer.write(dataToSend);
}
Now that we have that setup, we can modify any of the PrimeSense samples to send off the Kinect data to the socket server and register any of our other platforms as listening tools.
A basic flash connection to the socket server will look something like this:
socket.addEventListener(Event.CONNECT, onSocketConnect);
socket.addEventListener(Event.CLOSE, onSocketClose);
socket.addEventListener(IOErrorEvent.IO_ERROR; onSocketError),socket.addEventListener(ProgressEvent.SOCKET_DATA,onSocketResponse);
function onSocketResponse(event:ProgressEvent): void
{
var str:String = socket.readUTFBytes(socket.bytesAvailable);
}
Now we can easily parse the string according to the format we sent from the Kinect sample. We can then use that data in Flash.
We hope that helps and will aid in your Kinect hackery. Shoot us a line or drop a note in the comments if you have any thoughts on this approach. And don’t be shy with your own workarounds and Kinect projects — we’d love to see what the community comes up with.
UPDATE:
We got a lot of requests for the modifications to the primesense sample that we used to connect the c++ side to the node.js server. For your downloading pleasure we now have this Kinect+Flash c++ code.
This file should update the main.cpp file from the SingleControl app example. The two modified sections are commented as “SOCKET SERVER INITIALIZATION” and “SEND DATA TO SOCKET SERVER.” As you can expect with code like this, BLITZ isn’t really offering any support and if somehow it manages to destroy your computer, we didn’t do it.
{ 13 comments }
I’m currently writing an HTML5 game engine that uses node.js as the server for all the networking aspects. Having seen this I’m now gonna rush off and see if I can get my Kinect to control my game engine with gestures.
Exciting stuff, thanks for the post!!
Hello we are very interested in using your code for a few tests, can you please provide your simple trace application as sample for the community?
That seems to be AS3 right, so maybe with a few samples we can all start working on a framework.
Thanks in advance for your time, keep up the good work.
Nice post, but i don’t understand why you use NODE.JS ?
You can communicate directly by socket from flash application to C++ server is’nt it ?
I just got back from Walmart with a brand new Kinect. I’ve worked with SoulWire’s web cam motion detection in the past and made a pretty cool API for detecting gestures. I am excited to have this blog at my finger tips. Thank you for sharing your findings.
That’s great, can this work with Unity ?
This is great, thanks so much. Any chance you could post your code changes to the main.cpp file in the Single Control example? Also, would you mind posting the FLA source for your basic Flash app reading the socket data? I get the idea, but would halp me along quite a bit!
Thanks!
Impressive work!
Btw, I was wondering if you could share the modified SingleControl source or describe a bit more detail about how to send off the kinect data to the socket server?
Thanks!
Great post! This is very exciting for us Flash Developers.
I’ve gotten everything working fine except for the C++ code meant to be added to samples. You mention “…we can modify any of the PrimeSense samples to send off the Kinect data to the socket server…” but don’t include any source.
Would it be possible to have this modified code provided? I’ll be working on an alternative in the meantime, but it would be great to see some up here to help out us stunted AS3 devs.
Thanks!
As someone without a ton of C++ Socket programming experience, I’d be interested in seeing what the sort of C++ code that sends the skeleton info to the node.js server looks like. That would be a huge help in getting some people to be able to start using this solution.
Cool idea and thanks for taking the time to post! I’d definitely appreciate that info. Thanks!
This is awesome!! I’ve been trying to recreate it but I’m a flash developer, not a C++ developer and I have no clue how to modify the prime sense samples to send the kinect data to the socket server. can you share your code for that? How’d you get the kinect data to the socket server?
Nice job!
I’ve tried to follow your example but the result is much slower than yours (it seems to be related to the receiving of data in flash…); do you have any ideas why? I don’t use 127.0.0.1:8124 but 192.167.1.68:8000; do you think it can explain the slowness?
To people wanting to try this example, be careful to correct some mistakes in the code above:
- for the node.js server: socket.on(”data:”, function (data)
- for the flash connexion: socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);
socket.addEventListener(ProgressEvent.SOCKET_DATA,onSocketResponse);
Are you guys planning on releasing the C++ source code to compile the PrimeSense file or perhaps a precompiled PrimeSense file, that will connect to the socket? As this is a really nice way of sending accurate blob/hand x,y,z data to flash. Ace job by the way
Jono
we just posted an update to the blog post that includes the c++ code in a zip file.