12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Kinect = Windows.Kinect;
- public class StartStepPreview : MonoBehaviour
- {
- public Material boneMaterial;
- public Material transparentMat;
- private JointsData jointsData;
- private GameObject body;
- public void SetData(JointsData jointsData)
- {
- this.jointsData = jointsData;
- }
- public void ShowBody()
- {
- // Create GameObject body
- body = new GameObject("StartStepPreview body");
- body.transform.parent = gameObject.transform;
- for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
- {
- // Skip these joints
- if (jt == Kinect.JointType.Head || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
- || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
- || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
- continue;
- // Create GameObject cubes for joints
- GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- jointObj.GetComponent<MeshRenderer>().material = transparentMat;
- LineRenderer lr = jointObj.AddComponent<LineRenderer>();
- lr.positionCount = 2;
- lr.material = boneMaterial;
- lr.startWidth = 0.05f;
- lr.endWidth = 0.05f;
- jointObj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
- jointObj.name = jt.ToString();
- Vector3[] joints = HelperScript.ConvertJointsDataToVector3Array(jointsData);
- Vector3[] rescaledJoints = HelperScript.RescaleJoints(joints);
- jointObj.transform.position = rescaledJoints[(int)jt];
- jointObj.transform.parent = body.transform;
- // Set alpha
- Color newColor = new Color(0.5f, 0.5f, 0.5f, 0.5f);
- jointObj.GetComponent<MeshRenderer>().material.color = newColor;
- jointObj.GetComponent<LineRenderer>().startColor = newColor;
- jointObj.GetComponent<LineRenderer>().endColor = newColor;
- // Remove LineRenderer component from neck
- if (jt == Kinect.JointType.Neck)
- {
- Destroy(jointObj.GetComponent<LineRenderer>());
- }
- }
- // 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 other these joints
- if (!HelperScript._BoneMap.ContainsKey(jt) || jt == Kinect.JointType.Neck
- || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
- || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
- || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
- continue;
- Transform jointObj = body.transform.Find(jt.ToString());
- Transform targetJoint = body.transform.Find(HelperScript._BoneMap[jt].ToString());
- LineRenderer lr = jointObj.GetComponent<LineRenderer>();
- lr.SetPosition(0, jointObj.localPosition);
- lr.SetPosition(1, targetJoint.localPosition);
- }
- }
- public void DeleteBody()
- {
- Destroy(body);
- }
- }
|