|
@@ -1,33 +1,78 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
+using Kinect = Windows.Kinect;
|
|
|
|
|
|
public class PlayerReplay : MonoBehaviour
|
|
|
{
|
|
|
public Transform[] joints = new Transform[25];
|
|
|
public Material boneMaterial;
|
|
|
|
|
|
+ private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
|
|
|
+ {
|
|
|
+ { Kinect.JointType.FootLeft, Kinect.JointType.AnkleLeft },
|
|
|
+ { Kinect.JointType.AnkleLeft, Kinect.JointType.KneeLeft },
|
|
|
+ { Kinect.JointType.KneeLeft, Kinect.JointType.HipLeft },
|
|
|
+ { Kinect.JointType.HipLeft, Kinect.JointType.SpineBase },
|
|
|
+
|
|
|
+ { Kinect.JointType.FootRight, Kinect.JointType.AnkleRight },
|
|
|
+ { Kinect.JointType.AnkleRight, Kinect.JointType.KneeRight },
|
|
|
+ { Kinect.JointType.KneeRight, Kinect.JointType.HipRight },
|
|
|
+ { Kinect.JointType.HipRight, Kinect.JointType.SpineBase },
|
|
|
+
|
|
|
+ { Kinect.JointType.HandTipLeft, Kinect.JointType.HandLeft },
|
|
|
+ { Kinect.JointType.ThumbLeft, Kinect.JointType.HandLeft },
|
|
|
+ { Kinect.JointType.HandLeft, Kinect.JointType.WristLeft },
|
|
|
+ { Kinect.JointType.WristLeft, Kinect.JointType.ElbowLeft },
|
|
|
+ { Kinect.JointType.ElbowLeft, Kinect.JointType.ShoulderLeft },
|
|
|
+ { Kinect.JointType.ShoulderLeft, Kinect.JointType.SpineShoulder },
|
|
|
+
|
|
|
+ { Kinect.JointType.HandTipRight, Kinect.JointType.HandRight },
|
|
|
+ { Kinect.JointType.ThumbRight, Kinect.JointType.HandRight },
|
|
|
+ { Kinect.JointType.HandRight, Kinect.JointType.WristRight },
|
|
|
+ { Kinect.JointType.WristRight, Kinect.JointType.ElbowRight },
|
|
|
+ { Kinect.JointType.ElbowRight, Kinect.JointType.ShoulderRight },
|
|
|
+ { Kinect.JointType.ShoulderRight, Kinect.JointType.SpineShoulder },
|
|
|
+
|
|
|
+ { Kinect.JointType.SpineBase, Kinect.JointType.SpineMid },
|
|
|
+ { Kinect.JointType.SpineMid, Kinect.JointType.SpineShoulder },
|
|
|
+ { Kinect.JointType.SpineShoulder, Kinect.JointType.Neck },
|
|
|
+ { Kinect.JointType.Neck, Kinect.JointType.Head },
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
// (need to implement controller click to trigger save)
|
|
|
public void Save()
|
|
|
{
|
|
|
+ if(joints[0] == null)
|
|
|
+ {
|
|
|
+ Debug.Log("joints have not been assigned");
|
|
|
+ return;
|
|
|
+ }
|
|
|
SaveSystem.Save(this);
|
|
|
+ Debug.Log("Save success");
|
|
|
}
|
|
|
|
|
|
public void Load()
|
|
|
{
|
|
|
JointsData data = SaveSystem.Load();
|
|
|
|
|
|
- if(data == null)
|
|
|
+ if (data == null)
|
|
|
{
|
|
|
- Debug.LogError("Load failed");
|
|
|
+ Debug.Log("Load failed");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- for(int i = 0; i < joints.Length; i++)
|
|
|
+ // Create GameObject body
|
|
|
+ GameObject body = new GameObject("Recorded Body");
|
|
|
+ for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
{
|
|
|
+ // skip if head joint
|
|
|
+ if (jt == Kinect.JointType.Head)
|
|
|
+ continue;
|
|
|
+
|
|
|
// Create GameObject cubes for joints
|
|
|
GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
-
|
|
|
LineRenderer lr = jointObj.AddComponent<LineRenderer>();
|
|
|
lr.positionCount = 2;
|
|
|
lr.material = boneMaterial;
|
|
@@ -35,13 +80,33 @@ public class PlayerReplay : MonoBehaviour
|
|
|
lr.endWidth = 0.3f;
|
|
|
|
|
|
jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
|
|
+ jointObj.name = jt.ToString();
|
|
|
+ jointObj.transform.position = new Vector3(data.jointsPositionsX[(int)jt], data.jointsPositionsY[(int)jt], data.jointsPositionsZ[(int)jt]);
|
|
|
+ jointObj.transform.parent = body.transform;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Connect the joints with LineRenderer
|
|
|
+ for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
+ {
|
|
|
+ // skip if dictionary not contains the joint or neck joint
|
|
|
+ if (!_BoneMap.ContainsKey(jt) || jt == Kinect.JointType.Neck)
|
|
|
+ continue;
|
|
|
+
|
|
|
|
|
|
- // (need to test)
|
|
|
- jointObj.transform.position = new Vector3(data.jointsPositionsX[i], data.jointsPositionsY[i], data.jointsPositionsZ[i]);
|
|
|
+ Transform jointObj = body.transform.Find(jt.ToString());
|
|
|
+ LineRenderer lr = jointObj.GetComponent<LineRenderer>();
|
|
|
+
|
|
|
+
|
|
|
+ Transform targetJoint = body.transform.Find(_BoneMap[jt].ToString());
|
|
|
+
|
|
|
+ lr.SetPosition(0, jointObj.localPosition);
|
|
|
+ lr.SetPosition(1, targetJoint.localPosition);
|
|
|
|
|
|
|
|
|
- // Connect the joints with LineRenderer
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ Debug.Log("Load success");
|
|
|
}
|
|
|
}
|