public void MergeSkeleton(RATKinectSkeleton srcData, Matrix4x4 transform)
        {
            if (!srcData.valid)
            {
                return;
            }

            //TODO utilize jointStates
            if (mergeCount == 0)
            {
                //first skeleton, set data
                for (int i = 0; i < JOINT_COUNT; i++)
                {
                    jointPositions3D[i] = transform.MultiplyPoint(srcData.jointPositions3D[i]);
                    jointStates[i]      = srcData.jointStates[i];
                }
                for (int i = 0; i < FACE_POSITION_COUNT; i++)
                {
                    facePositions3D[i] = transform.MultiplyPoint(srcData.facePositions3D[i]);
                }
                faceOrientationYPR = srcData.faceOrientationYPR;
                faceOrientation    = srcData.faceOrientation;
                glasses            = srcData.glasses;
                happy          = srcData.happy;
                engaged        = srcData.engaged;
                lookingAway    = srcData.lookingAway;
                leftEyeClosed  = srcData.leftEyeClosed;
                rightEyeClosed = srcData.rightEyeClosed;
                mouthOpen      = srcData.mouthOpen;
                mouthMoved     = srcData.mouthMoved;
            }
            else
            {
                for (int i = 0; i < JOINT_COUNT; i++)
                {
                    jointPositions3D[i] += transform.MultiplyPoint(srcData.jointPositions3D[i]);
                    if (jointStates[i] > srcData.jointStates[i])
                    {
                        jointStates[i] = srcData.jointStates[i];
                    }
                }
                for (int i = 0; i < FACE_POSITION_COUNT; i++)
                {
                    facePositions3D[i] += transform.MultiplyPoint(srcData.facePositions3D[i]);
                }
                faceOrientationYPR = srcData.faceOrientationYPR;
                faceOrientation    = srcData.faceOrientation;
                glasses            = srcData.glasses;
                happy          = srcData.happy;
                engaged        = srcData.engaged;
                lookingAway    = srcData.lookingAway;
                leftEyeClosed  = srcData.leftEyeClosed;
                rightEyeClosed = srcData.rightEyeClosed;
                mouthOpen      = srcData.mouthOpen;
                mouthMoved     = srcData.mouthMoved;
            }
            valid = true;
            mergeCount++;
        }
Example #2
0
        public void Update()
        {
            if (skeletonProvider != null)
            {
                RATKinectSkeleton skeleton = GetSkeleton();

                if (skeleton != null && skeleton.valid)
                {
                    if (updateFromKinect)
                    {
                        transform.position = getHeadPosition();
                        if (lookAt != null)
                        {
                            transform.LookAt(lookAt.transform.position);
                        }
                        //else transform.localRotation = Quaternion.identity;
                    }
                }
            }
        }
 public void CopyFrom(RATKinectSkeleton templateSkel, Matrix4x4 transform)
 {
     mergeCount = 0;
     MergeSkeleton(templateSkel, transform);
     FinishMerging();
 }
        protected virtual void OnDrawGizmos()
        {
            if (Application.isPlaying && showSkeletons)
            {
                int maxBodies = GetMaxBodiesCount();
                Gizmos.matrix = transform.localToWorldMatrix;
                for (int n = 0; n < maxBodies; n++)
                {
                    RATKinectSkeleton skeleton = GetKinectSkeleton(n);
                    if (skeleton != null && (skeleton.valid))
                    {
                        //Draw body
                        for (int i = 0; i < skeleton.jointPositions3D.Length; i++)
                        {
                            RATKinectSkeleton.TrackingState state = skeleton.jointStates[i];
                            bool tracked = state != RATKinectSkeleton.TrackingState.NotTracked;
                            if (tracked)
                            {
                                Color cl = skeletonColor;
                                if (state != RATKinectSkeleton.TrackingState.Tracked)
                                {
                                    cl.a *= 0.3f;
                                }
                                Gizmos.color = cl;
                                Gizmos.DrawSphere(skeleton.jointPositions3D[i], jointRadius * HumanTopology.JOINT_DEBUG_WIDTHS[i]);
                            }
                        }
                        for (int i = 0; i < HumanTopology.BONE_CONNECTIONS.Length; i++)
                        {
                            BoneConnection bone   = HumanTopology.BONE_CONNECTIONS[i];
                            JointType      joint1 = bone.fromJoint;
                            JointType      joint2 = bone.toJoint;
                            RATKinectSkeleton.TrackingState state1 = skeleton.jointStates[(int)joint1];
                            RATKinectSkeleton.TrackingState state2 = skeleton.jointStates[(int)joint2];
                            bool tracked = state1 != RATKinectSkeleton.TrackingState.NotTracked && state2 != RATKinectSkeleton.TrackingState.NotTracked;
                            if (tracked)
                            {
                                Color cl = skeletonColor;
                                if (state1 != RATKinectSkeleton.TrackingState.Tracked || state2 != RATKinectSkeleton.TrackingState.Tracked)
                                {
                                    cl.a *= 0.3f;
                                }
                                Gizmos.color = cl;
                                Gizmos.DrawLine(skeleton.jointPositions3D[(int)joint1], skeleton.jointPositions3D[(int)joint2]);
                            }
                        }

                        //Draw face
                        drawEye(skeleton.leftEyePos, skeleton.leftEyeClosed, skeleton.faceOrientation);
                        drawEye(skeleton.rightEyePos, skeleton.rightEyeClosed, skeleton.faceOrientation);
                        Gizmos.color = faceColor;
                        Gizmos.DrawLine(skeleton.leftEyePos, skeleton.rightEyePos);
                        Gizmos.DrawSphere(skeleton.nosePos, noseRadius);
                        Gizmos.DrawSphere(skeleton.mouthLeftPos, mouthRadius);
                        Gizmos.DrawSphere(skeleton.mouthRightPos, mouthRadius);
                    }
                }

                Gizmos.matrix = Matrix4x4.identity;
            }
        }
Example #5
0
        public bool IsReady()
        {
            RATKinectSkeleton skel = GetSkeleton();

            return(skel != null && skel.valid);
        }