Giter Site home page Giter Site logo

kinect-unity-workshop's Introduction

kinect-unity-workshop

This is a sample app demonstrating how you can leverage Kinect with Unity3D

##Adding the Kinect plugin

  • Download the Unity Pro packages from http://developer.microsoft.com/windows/kinect/tools
  • After you finish downloading the zip file, extract it to a known location
  • The folder contains three Kinect plugins (the basic one, face recognition, gesture builder), each wrapping functionality from the Kinect v2 SDK
  • Open Unity and create a new project
  • Add the Kinect plugin into your new project by selecting Assets from the top menu and then 'Import Package' -> 'Custom Package …'
  • Drag and drop the KinectView samle project into the Assests directory in your project folder
  • Select KinectView and then double click on the MainScene scene contained inside it. This should open up your Kinect-enabled scene inside the game window. Click on the single arrow near the top center of the IDE to see your application in action. The Kinect will automatically turn on and you should see a color image, an infrared image, a rendering of any bodies in the scene and finally a point cloud simulation.

##Enabling motion tracking with Kinect

  • Create a new scene and save it as 'Gestures'
  • Create a new GameObject by clicking 'GameObject -> Create Empty'
  • Rename it to 'BodySourceManager'
  • Select it and add 'Body Source Management' as component
  • Create again a new GameObject by clicking 'GameObject' -> 'Create Empty'
  • Rename it to 'Object1 '
  • In Assets create a new folder and call it 'Script'
  • In this folder create a C# script and name it 'DetectJoints'
  • Drag and drop it on Object1
  • Now let’s create a particle system we will be able to move with our hand. Right click on Object1, create 3D Object, and give it a particle system
  • Double click on the 'DetectJoints' script will open Visual Studio
  • In the Visual Studio solution add the import statement: using.Windows.Kinect;
  • Asign the Body Source Manager game object that we just created to the script by adding a public variable public GameObject BodySrcManager; and assigning the GameObject to Object1 in Unity.
  • Create a JointType enum to enable selection of the joint you want to track public JointType TrackedJoint;
  • Save the script and go back to Unity and select from the drop down menu of TrackedJoint the joint you want to track. For this example, I chose HandLeft.
  • Add a private variable that takes care of the data that we get from the Body Source Manager component from the script. private BodySourceManager bodyManager; We assign it once and grab the data from there. We take care of that in the Start()-Method
// Use this for initialization
void Start () {

 if (BodySrcManager == null)
 {
   Debug.Log("Asign Game Object with Body Source Manager");
 }
   else
 {
   bodyManager = BodySrcManager.GetComponent<BodySourceManager>();
 }
}
  • With every frame we want to check if BodySrcManager is still null. In this case we return
  • Otherwise we grab the data
// Update is called once per frame
void Update () {
	
 if(BodySrcManager == null)
 {
 	return;
 }
 bodies = bodyManager.GetData();
 if(bodies == null)
 {
 	return;
 }
 foreach (var body in bodies)
 {
 if(body == null)
 {
 	continue;
 }
 if (body.IsTracked)
 {
 	var pos = body.Joints[TrackedJoint].Position;
 	gameObject.transform.position = new Vector3(pos.X, pos.Y);
 }
}
  • Kinect can track up to six bodies so we need to assign it to an array that will differentiate between the different bodies.

  • Declare the array private Body[] bodies;

  • We save the script and run the game. As you can see the object doesn’t move very far. That’s why we need a multiplier.

  • Let’s create one public float multiplier = 10f; and multiply it to the position of the object gameObject.transform.position = new Vector3(pos.X * multiplier, pos.Y*multiplier);

  • Let’s start the program again. You can see the movement has now a bigger impact

kinect-unity-workshop's People

Contributors

mpcdevs avatar nicol3ta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.