// gets the current avatar pose private void GetAvatarPose(float fCurrentTime, bool isMirrored) { KinectManager kinectManager = KinectManager.Instance; if (kinectManager == null || avatarModel == null || poseJoints == null) { return; } poseAvatar.fTime = fCurrentTime; if (poseAvatar.avBoneDirs == null) { poseAvatar.avBoneDirs = new Vector3[poseJoints.Count]; } for (int i = 0; i < poseJoints.Count; i++) { KinectInterop.JointType joint = poseJoints[i]; KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); int jointCount = kinectManager.GetJointCount(); if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) { Transform avatarTransform1 = avatarModel.GetBoneTransform(avatarModel.GetBoneIndexByJoint(joint, isMirrored)); Transform avatarTransform2 = avatarModel.GetBoneTransform(avatarModel.GetBoneIndexByJoint(nextJoint, isMirrored)); if (avatarTransform1 != null && avatarTransform2 != null) { poseAvatar.avBoneDirs[i] = (avatarTransform2.position - avatarTransform1.position).normalized; } } } }
// gets the current User pose private void GetUserPose(float fCurrentTime, bool isMirrored) { KinectManager kinectManager = KinectManager.Instance; if (kinectManager == null || User == null || poseJoints == null) { return; } //poseUser.fTime = fCurrentTime; if (poseUser.avBoneDirs == null) { poseUser.avBoneDirs = new Vector3[poseJoints.Count]; } // Gets real-time joint pose data of the user with respect to the next joints for (int i = 0; i < poseJoints.Count; i++) { KinectInterop.JointType joint = poseJoints[i]; KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); int jointCount = kinectManager.GetJointCount(); if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) { Transform avatarTransform1 = User.GetBoneTransform(User.GetBoneIndexByJoint(joint, isMirrored)); Transform avatarTransform2 = User.GetBoneTransform(User.GetBoneIndexByJoint(nextJoint, isMirrored)); if (avatarTransform1 != null && avatarTransform2 != null) { poseUser.avBoneDirs[i] = (avatarTransform2.position - avatarTransform1.position).normalized; //Debug.Log(poseUser.avBoneDirs[i]); } } } }
// adds current pose of poseModel to the saved poses list private void AddCurrentPoseToSaved(float fCurrentTime, bool isMirrored) { KinectManager kinectManager = KinectManager.Instance; if (kinectManager == null || poseModel == null || poseJoints == null) { return; } PoseModelData pose = new PoseModelData(); pose.fTime = fCurrentTime; pose.avBoneDirs = new Vector3[poseJoints.Count]; // save model rotation Quaternion poseModelRotation = poseModel.transform.rotation; if (avatarController) { ulong avatarUserId = avatarController.playerId; bool isAvatarMirrored = avatarController.mirroredMovement; Quaternion userRotation = kinectManager.GetUserOrientation(avatarUserId, !isAvatarMirrored); poseModel.transform.rotation = initialPoseRotation * userRotation; } int jointCount = kinectManager.GetJointCount(); for (int i = 0; i < poseJoints.Count; i++) { KinectInterop.JointType joint = poseJoints[i]; KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) { Transform poseTransform1 = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(joint, isMirrored)); Transform poseTransform2 = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(nextJoint, isMirrored)); if (poseTransform1 != null && poseTransform2 != null) { pose.avBoneDirs[i] = (poseTransform2.position - poseTransform1.position).normalized; } } } // add pose to the list alSavedPoses.Add(pose); // restore model rotation poseModel.transform.rotation = poseModelRotation; }
/* * // adds current pose of poseModel to the saved poses list * private void AddCurrentPoseToSaved(float fCurrentTime, bool isMirrored) * { * * PoseModelData pose = new PoseModelData(); * pose.fTime = fCurrentTime; * pose.avBoneDirs = new Vector3[poseJoints.Count]; * * // save model rotation * Quaternion poseModelRotation = poseModel.transform.rotation; * * * for (int i = 0; i < poseJoints.Count; i++) * { * HumanBodyBones joint = poseJoints[i]; * HumanBodyBones nextJoint = HumanBodyBones.GetNextJoint(joint); * * if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) * { * Transform poseTransform1 = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(joint, isMirrored)); * Transform poseTransform2 = poseModel.GetBoneTransfsorm(poseModel.GetBoneIndexByJoint(nextJoint, isMirrored)); * * if (poseTransform1 != null && poseTransform2 != null) * { * pose.avBoneDirs[i] = (poseTransform2.position - poseTransform1.position).normalized; * } * } * } * * // add pose to the list * alSavedPoses.Add(pose); * * // restore model rotation * poseModel.transform.rotation = poseModelRotation; * }*/ private Transform[] GetBoneData(PoseModelHelper ModelData) { for (int j = 0; j < ModelData.GetBoneTransformCount(); j++) { bone_data[j] = ModelData.GetBoneTransform(j); Debug.Log(bone_data[j].position); } return(bone_data); }
// Update is called once per frame void Update() { KinectManager kinectManager = KinectManager.Instance; if (!flag && char_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1) { /**************************This is one way of storing pose data******************************/ /* * for (int i = 0; i < poseJoints.Count; i++) * { * savePose[i] = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(poseJoints[i], false)).position; * } * * PoseArchive.ArraySavedPoses[Exercise_index] = savePose; * PoseArchive.saveCounter++; * flag = true; * //Debug.Log("Exercise number " + Exercise_index + " has one of its bone transform value as " + savePose[4]); */ ///Using Head as reference point and calculating joint positions with respect to head ///Save them in the array to be referenced later for comparision with user motion data /* * Transform headTransform = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(Head, false)); * * for (int i = 0; i < poseJoints.Count; i++) * { * KinectInterop.JointType joint = poseJoints[i]; * * Transform jointTransform = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(joint, false)); * * if(jointTransform != null && headTransform != null) * { * savePose[i] = (headTransform.position - jointTransform.position).normalized; * } * }*/ /****************************This is another way of storing joint data of a pose************************/ ///Get joint data wrt the next joints for (int i = 0; i < poseJoints.Count; i++) { KinectInterop.JointType joint = poseJoints[i]; KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); int jointCount = kinectManager.GetJointCount(); if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) { Transform avatarTransform1 = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(joint, false)); Transform avatarTransform2 = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(nextJoint, false)); if (avatarTransform1 != null && avatarTransform2 != null) { savePose[i] = (avatarTransform2.position - avatarTransform1.position).normalized; //Debug.Log(savePose[i]); } } } //Store the poses captured in an array to be referenced later PoseArchive.ArraySavedPoses[Exercise_index] = savePose; PoseArchive.saveCounter++; flag = true; //Debug.Log("Exercise number " + Exercise_index + " has one of its bone transform value as " + savePose[4]); } }
// Update is called once per frame void Update() { //for (int i = 0; i < ExerPoses.Length; i++) //{ /* * for(int i = 0; i < poseModel.GetBoneTransformCount(); i++) * { * Debug.Log(poseModel.GetBoneTransform(i)); * }*/ //Every exercise has 2 states Concentric and Eccentric state //bool check = char_animator.GetAnimatorTransitionInfo(0).IsName("Entry -> Shoulder start"); // The initial transition happens with a delay, always ensure that the delay is accouted for, to be on safer side give the time delay as 1 and then find the bone transitions to get the exact positions if (!flag && char_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1) { int numAnims = char_animator.runtimeAnimatorController.animationClips.Length; foreach (int i in animChange) { } for (int i = 0; i < 2 * Exercises; i++) { //animatorOverrideController["Test"] = exerciseClips[i]; for (int j = 0; j < poseJoints.Count; j++) { Save_pose_data[i, j] = poseModel.GetBoneTransform(poseModel.GetBoneIndexByJoint(poseJoints[j], false)); //Debug.Log(Save_pose_data[i,j].position); test.anim = i; test.b_index = j; test.BonePos = Save_pose_data[0, j].position; //Debug.Log() Debug.Log("Animation num " + i + " Bone number " + j + " Bone position " + Save_pose_data[i, j].position); //Debug.Log(new PoseModelData(i, j, Save_pose_data[i, j].position)); } if (i < 5) { char_animator.SetInteger("changeAnim", i + 1); Debug.Log("THIS IS INSANEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); } else { char_animator.SetInteger("changeAnim", 0); } } flag = true; } /* * for(int i = 0; i < Save_pose_data.Length; i++) * { * Save_pose_data[i,] = GetBoneData(poseModel); * if(Save_pose_data[i,] != null) * { * if (i != 5) * char_animator.SetInteger("changeAnim", i + 1); * else * char_animator.SetInteger("changeAnim", 0); * } * Debug.Log(Save_pose_data[i,]); * * }*/ //Debug.Log(char_animator.GetBoneTransform(HumanBodyBones.LeftHand).position); //Debug.Log(poseModel.GetBoneTransform(8).position); //Debug.Log(Save_pose_data); }
// gets the current User pose private void GetUserPose(float fCurrentTime, bool isMirrored) { KinectManager kinectManager = KinectManager.Instance; if (kinectManager == null || User == null || poseJoints == null) { return; } //poseUser.fTime = fCurrentTime; if (poseUser.avBoneDirs == null) { poseUser.avBoneDirs = new Vector3[poseJoints.Count]; } //Use User not poseModel /* * for (int i = 0; i < poseJoints.Count; i++) * { * poseUser.avBoneDirs[i] = User.GetBoneTransform(User.GetBoneIndexByJoint(poseJoints[i], false)).position; * }*/ /* * Transform headTransform = User.GetBoneTransform(User.GetBoneIndexByJoint(Head, isMirrored)); * for (int i = 0; i < poseJoints.Count; i++) * { * KinectInterop.JointType joint = poseJoints[i]; * //KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); * * int jointCount = kinectManager.GetJointCount(); * * if(Head != joint) * { * Transform userJointTransform = User.GetBoneTransform(User.GetBoneIndexByJoint(joint, isMirrored)); * * if (userJointTransform != null && headTransform != null) * { * poseUser.avBoneDirs[i] = (headTransform.position - userJointTransform.position).normalized; * } * } * }*/ for (int i = 0; i < poseJoints.Count; i++) { KinectInterop.JointType joint = poseJoints[i]; KinectInterop.JointType nextJoint = kinectManager.GetNextJoint(joint); int jointCount = kinectManager.GetJointCount(); if (nextJoint != joint && (int)nextJoint >= 0 && (int)nextJoint < jointCount) { Transform avatarTransform1 = User.GetBoneTransform(User.GetBoneIndexByJoint(joint, isMirrored)); Transform avatarTransform2 = User.GetBoneTransform(User.GetBoneIndexByJoint(nextJoint, isMirrored)); if (avatarTransform1 != null && avatarTransform2 != null) { poseUser.avBoneDirs[i] = (avatarTransform2.position - avatarTransform1.position).normalized; //Debug.Log(poseUser.avBoneDirs[i]); } } } }