/// <summary> /// Returns an array of all currently tracked /// <see cref="KinectSkeletonJoint"/> components. /// </summary> /// <returns>A copy of the <see cref="KinectSkeletonJoint"/> component array.</returns> public KinectSkeletonJoint[] GetJoints() { var joints = new KinectSkeletonJoint[this.m_JointCount]; Array.Copy(this.m_Joints, joints, this.m_JointCount); return(joints); }
private void FixJointHierarchy(KinectSkeletonJoint joint) { // I'm not 100% sure if this is right, // but at the moment it works fine. for (int i = 0; i < this.m_JointCount; ++i) { if (this.m_Joints[i].transform.parent == joint.transform.parent && KinectHelper.InJointTypeHierachy(joint.jointType, this.m_Joints[i].jointType)) { SetJointParentWithoutRebuild(this.m_Joints[i], joint.transform); } } }
public int GetJointDepth(KinectSkeletonJoint joint) { var parent = joint.transform; var depth = 0; while (transform != parent && parent != null) { ++depth; parent = parent.parent; } return(parent != null ? depth : -1); }
/// <summary> /// Returns the parent <see cref="KinectSkeletonJoint"/> of a given /// <see cref="JointType"/> in the hierarchy. /// </summary> /// <param name="jointType">The parent joint.</param> /// <returns>The component instance or <c>null</c>.</returns> public KinectSkeletonJoint GetParentJoint(JointType jointType) { KinectSkeletonJoint joint = null; do { var nextType = KinectHelper.parentJointTypes[(int)jointType]; // Avoid endless loop on SpineBase. if (nextType == jointType) { break; } jointType = nextType; joint = GetJoint(jointType); } while(joint == null); return(joint); }
private void AddJointToHierarchy(KinectSkeletonJoint joint) { var depth = GetJointDepth(joint); // Fast path if the joint is added to the hierarchy of // the deepest child. if (this.m_JointCount == 0 || GetJointDepth(this.m_Joints[this.m_JointCount - 1]) <= depth) { InsertJointAt(joint, this.m_JointCount); return; } int index = 0; while (GetJointDepth(this.m_Joints[index]) < depth) { ++index; } Array.Copy(this.m_Joints, index, this.m_Joints, index + 1, this.m_JointCount - index); InsertJointAt(joint, index); }
/// <summary> /// Gets or creates a joint in the skeleton hierarchy. /// </summary> /// <param name="jointType">The target joint.</param> /// <returns>The created or found component instance.</returns> public KinectSkeletonJoint GetOrCreateJoint(JointType jointType) { var joint = GetJoint(jointType); if (joint != null) { return(joint); } var parent = GetParentJoint(jointType); joint = KinectSkeletonJoint.Create(jointType); joint.transform.position = transform.position + KinectHelper.tPose[(int)jointType]; // This is required because changing the parent transform fires // the OnTransformChildrenChanged directly. Since rebuilding the // hierarchy is useless here, it will be skipped. SetJointParentWithoutRebuild(joint, parent == null ? transform : parent.transform); AddJointToHierarchy(joint); FixJointHierarchy(joint); return(joint); }
private void SetJointParentWithoutRebuild(KinectSkeletonJoint joint, Transform parent) { this.m_SkipRebuild = true; joint.transform.parent = parent; this.m_SkipRebuild = false; }
private void InsertJointAt(KinectSkeletonJoint joint, int index) { this.m_Joints[index] = joint; this.m_JointTypeToJoint[(int)joint.jointType] = joint; ++this.m_JointCount; }
public static void DrawJointGizmos(KinectSkeletonJoint joint, GizmoType type) { Gizmos.color = KinectEditorUtils.darkGreen; Gizmos.DrawWireSphere(joint.transform.position, 0.02f); }
public void OnEnable() { this.m_Me = (KinectSkeletonJoint)target; }