I felt like playing around with the Kinect some more this evening, so I put together a point cloud in Unity3D. This takes the base code from TrackingNI and with a little help from Marshal, it can pull the depth data directly from a Unity3D script. This project does not use the OpenNI Unity Wrapper. Anyways, here’s a quick demo:

I may decide to build my own wrapper library at some point. We’ll just have to see.

Update: I’ve uploaded the source to this demo.  Feel free to download it.  If you make something cool with it, be sure to let me know, enjoy!

This entry was posted in C#, Kinect, Virtual Reality and tagged , , , , . Bookmark the permalink.
  • Delicious
  • Facebook
  • Reddit
  • StumbleUpon
  • Twitter
  • RSS Feed
  • Google
  • Digg

15 Responses to PointCloudNI

  1. Patemino says:

    Hi !

    Your rendering is pretty cool.
    Do you share your C# code ?


  2. Mani says:


    Your TackingNI: Depth Correction was great help for me.

    I would like to know ave you shared your code “PointCloudNI”.


  3. I totally forgot to upload it. It’s the end of term at school, so it’s kind of crunch time. I have a presentation today, but I’ll get it uploaded after that. Thanks for showing interest!

  4. Mani says:

    Thanks a lot

  5. Ruwan Yatawara says:

    This looks amazing. i tried to run the unity the application but it doesn’t function for me. It loads the background. But the black box in the middle remain static. I was able to run your past demos though.. wat could i have done wrong..

    Thanks a lot. :)

  6. Ruwan Yatawara says:

    Hi Piank,

    If its not too much trouble can u pls tell me as to how u imported the kinect data in to Unity? I want to animate a cloth based on the user input. Any information on how to import kinect data would be a lifesaver. :)


  7. All you need to do is put the libraries (.dlls) you want to use into the assets directory. This will probably include the OpenNI and NITE assemblies. When you open the project, it will load the libraries so your scripts can access them. At that point, you can basically just copy and paste code from the TrackingNI demo to get the data into Unity. If you’re having trouble, I can write a tutorial. Just let me know.

    What exactly was the problem you were experiencing with the PointCloudNI code? Did you build it from within the Unity editor?

    • Ruwan Yatawara says:

      I built the executable from the unity editor and now all is working fine. Thank you very much.
      What i dont quite get it is how u added the point cloud in unity(I’m sorry, I’m new to the whole scripting with unity thing so i’l have to read up on it a bit) . Your code is a wonderful resource. Again, thank you very much. :)

      • Thanks! I’m glad to hear you got it working. The point cloud generates a rectangle of evenly spaced spheres. Each sphere corresponds to one point in the depth data. However, rather than creating a sphere for every single (x,z) pair–which I think would create somewhere on the order of half a million spheres (800*600=480,000)–it takes every like 4 or 8 or so to actually pass in a depth value. Otherwise, the position of each sphere is just scaled based on the corresponding depth.

        For the record, spheres are probably not the best choice, computationally speaking. You would be better off using billboards, or modifying the vertices in a mesh if you’re trying to animate a cloth.

        • Ruwan Yatawara says:

          I think i will go with modifying the vertices of a mesh. It sounds more feasible. Thanks a lot for the explonation. :)


  8. Ruwan Yatawara says:

    Hi Richard,
    I’ve been trying to combine the point cloud animation with the Kinect Plugin available at Unity3D forum. I have noticed that when running your code i cannot hit the play button in the Editor (without combining projects). I get the following error.

    Loader:DoUpdate() (at Assets\Loader.cs:119)
    Loader:Reader() (at Assets\Loader.cs:202)

    Any help on this regard is greatly appreciated. :)

    • Are you calling this portion of the code?:

      spheres = new GameObject[x, y];
      for (int a = 0; a < x; a++)
      	for (int b = 0; b < y; b++)
      		spheres[a, b] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
      		spheres[a, b].transform.localScale = new Vector3(0.025f, 0.025f, 0.05f);
      		spheres[a, b].transform.position = new Vector3((float)a * 0.05f - 4.0f, (float)b * 0.05f - 2.0f, 0.0f);

      It would appear that the object doesn't exist or have a transform yet.

      The callstack is definitely helpful, do you have the Exception that's being thrown, though? Feel free to drop me an e-mail at richardpianka at gmail dot com if you want quicker responses.

  9. Ruwan Yatawara says:

    Hi Richard,
    The above mentioned portion of code is called in the start function, after that since the objects have been created it should be accessible via the background thread right?.

    The code runs without issue when i build an executable, the error appears only when running it through the editor.

    I dropped you a mail at the address you provided. Thanks in advance :)

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>