// Update is called once per frame
        private void LateUpdate()
        {
            if (!_recording)
            {
                return;
            }


            RecordedTime += Time.deltaTime;
            //現在のフレームのHumanoidの姿勢を取得
            _poseHandler.GetHumanPose(ref _currentPose);
            //posesに取得した姿勢を書き込む
            var serializedPose = new HumanoidPoses.SerializeHumanoidPose();

            switch (_rootBoneSystem)
            {
            case MotionDataSettings.Rootbonesystem.Objectroot:
                serializedPose.BodyRootPosition = _animator.transform.localPosition;
                serializedPose.BodyRootRotation = _animator.transform.localRotation;
                break;

            case MotionDataSettings.Rootbonesystem.Hipbone:
                serializedPose.BodyRootPosition = _animator.GetBoneTransform(_targetRootBone).position;
                serializedPose.BodyRootRotation = _animator.GetBoneTransform(_targetRootBone).rotation;
                Debug.LogWarning(_animator.GetBoneTransform(_targetRootBone).position);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            var bodyTQ      = new TQ(_currentPose.bodyPosition, _currentPose.bodyRotation);
            var LeftFootTQ  = new TQ(_animator.GetBoneTransform(IK_LeftFootBone).position, _animator.GetBoneTransform(IK_LeftFootBone).rotation);
            var RightFootTQ = new TQ(_animator.GetBoneTransform(IK_RightFootBone).position, _animator.GetBoneTransform(IK_RightFootBone).rotation);

            LeftFootTQ  = AvatarUtility.GetIKGoalTQ(_animator.avatar, _animator.humanScale, AvatarIKGoal.LeftFoot, bodyTQ, LeftFootTQ);
            RightFootTQ = AvatarUtility.GetIKGoalTQ(_animator.avatar, _animator.humanScale, AvatarIKGoal.RightFoot, bodyTQ, RightFootTQ);

            serializedPose.BodyPosition    = bodyTQ.t;
            serializedPose.BodyRotation    = bodyTQ.q;
            serializedPose.LeftfootIK_Pos  = LeftFootTQ.t;
            serializedPose.LeftfootIK_Rot  = LeftFootTQ.q;
            serializedPose.RightfootIK_Pos = RightFootTQ.t;
            serializedPose.RightfootIK_Rot = RightFootTQ.q;



            serializedPose.FrameCount = FrameIndex;
            serializedPose.Muscles    = new float[_currentPose.muscles.Length];
            serializedPose.Time       = RecordedTime;
            for (int i = 0; i < serializedPose.Muscles.Length; i++)
            {
                serializedPose.Muscles[i] = _currentPose.muscles[i];
            }

            SetHumanBoneTransformToHumanoidPoses(_animator, ref serializedPose);

            Poses.Poses.Add(serializedPose);
            FrameIndex++;
        }
 void SetHumanBoneTransformToHumanoidPoses(Animator animator, ref HumanoidPoses.SerializeHumanoidPose pose)
 {
     HumanBodyBones[] values = HumanBodyBones.GetValues(typeof(HumanBodyBones)) as HumanBodyBones[];
     foreach (HumanBodyBones b in values)
     {
         Transform t = animator.GetBoneTransform(b);
         if (t != null)
         {
             var bone = new HumanoidPoses.SerializeHumanoidPose.HumanoidBone();
             bone.Set(animator.transform, t);
             pose.humanoidBones.Add(bone);
         }
     }
 }
Exemplo n.º 3
0
        //CSVから_recordedMotionDataを作る
        private void LoadCSVData(string motionDataPath)
        {
            //ファイルが存在しなければ終了
            if (!File.Exists(motionDataPath))
            {
                return;
            }


            RecordedMotionData = ScriptableObject.CreateInstance <HumanoidPoses>();

            FileStream   fs = null;
            StreamReader sr = null;

            //ファイル読み込み
            try
            {
                fs = new FileStream(motionDataPath, FileMode.Open);
                sr = new StreamReader(fs);

                while (sr.Peek() > -1)
                {
                    string line          = sr.ReadLine();
                    var    seriHumanPose = new HumanoidPoses.SerializeHumanoidPose();
                    if (line != "")
                    {
                        seriHumanPose.DeserializeCSV(line);
                        RecordedMotionData.Poses.Add(seriHumanPose);
                    }
                }
                sr.Close();
                fs.Close();
                sr = null;
                fs = null;
            }
            catch (System.Exception e)
            {
                Debug.LogError("ファイル読み込み失敗!" + e.Message + e.StackTrace);
            }

            if (sr != null)
            {
                sr.Close();
            }

            if (fs != null)
            {
                fs.Close();
            }
        }
        //CSVから_recordedMotionDataを作る
        public void LoadCSVData(string motionDataPath)
        {
            //ファイルが存在しなければ終了
            if (!File.Exists(motionDataPath))
            {
                return;
            }

            _recordedMotionData = new HumanoidPoses();

            FileStream   fs = null;
            StreamReader sr = null;

            //ファイル読み込み
            try
            {
                fs = new FileStream(motionDataPath, FileMode.Open);
                sr = new StreamReader(fs);
                string[] tickString = sr.ReadLine().Split(',');

                while (sr.Peek() > -1)
                {
                    string line = sr.ReadLine();
                    HumanoidPoses.SerializeHumanoidPose seriHumanPose = new HumanoidPoses.SerializeHumanoidPose();
                    if (line != "")
                    {
                        seriHumanPose.DeserializeCSV(line);
                        _recordedMotionData.Poses.Add(seriHumanPose);
                    }
                }
                sr.Close();
                fs.Close();
                sr = null;
                fs = null;
            }
            catch (System.Exception e)
            {
                Debug.LogError("ファイル読み込み失敗!" + e.Message + e.StackTrace);
            }
            if (sr != null)
            {
                sr.Close();
            }
            if (fs != null)
            {
                fs.Close();
            }
        }
        // Update is called once per frame
        private void LateUpdate()
        {
            if (!_recording)
            {
                return;
            }


            RecordedTime += Time.realtimeSinceStartup - _recordStartTime;
            //現在のフレームのHumanoidの姿勢を取得
            _poseHandler.GetHumanPose(ref _currentPose);
            //posesに取得した姿勢を書き込む
            var serializedPose = new HumanoidPoses.SerializeHumanoidPose();

            switch (_rootBoneSystem)
            {
            case MotionDataSettings.Rootbonesystem.Objectroot:
                serializedPose.BodyRootPosition = _animator.transform.localPosition;
                serializedPose.BodyRootRotation = _animator.transform.localRotation;
                break;

            case MotionDataSettings.Rootbonesystem.Hipbone:
                serializedPose.BodyRootPosition = _animator.GetBoneTransform(_targetRootBone).position;
                serializedPose.BodyRootRotation = _animator.GetBoneTransform(_targetRootBone).rotation;
                Debug.LogWarning(_animator.GetBoneTransform(_targetRootBone).position);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            serializedPose.BodyPosition = _currentPose.bodyPosition;
            serializedPose.BodyRotation = _currentPose.bodyRotation;
            serializedPose.FrameCount   = FrameIndex;
            serializedPose.Muscles      = new float[_currentPose.muscles.Length];
            serializedPose.Time         = RecordedTime;
            for (int i = 0; i < serializedPose.Muscles.Length; i++)
            {
                serializedPose.Muscles[i] = _currentPose.muscles[i];
            }

            SetHumanBoneTransformToHumanoidPoses(_animator, ref serializedPose);

            Poses.Poses.Add(serializedPose);
            FrameIndex++;
        }
        // Update is called once per frame
        void LateUpdate()
        {
            if (_recording)
            {
                _recordedTime += Time.deltaTime;
                //現在のフレームのHumanoidの姿勢を取得
                _poseHandler.GetHumanPose(ref _currentPose);
                //posesに取得した姿勢を書き込む
                var serializedPose = new HumanoidPoses.SerializeHumanoidPose();

                if (_rootBoneSystem == MotionDataSettings.Rootbonesystem.Objectroot)
                {
                    serializedPose.BodyRootPosition = _animator.transform.localPosition;
                    serializedPose.BodyRootRotation = _animator.transform.localRotation;
                }
                else if (_rootBoneSystem == MotionDataSettings.Rootbonesystem.Hipbone)
                {
                    serializedPose.BodyRootPosition = _animator.GetBoneTransform(_targetRootBone).position;
                    serializedPose.BodyRootRotation = _animator.GetBoneTransform(_targetRootBone).rotation;
                    Debug.LogWarning(_animator.GetBoneTransform(_targetRootBone).position);
                }
                else
                {
                    Debug.LogWarning("enum not set");
                }

                serializedPose.BodyPosition = _currentPose.bodyPosition;
                serializedPose.BodyRotation = _currentPose.bodyRotation;
                serializedPose.FrameCount   = _frameIndex;
                serializedPose.Muscles      = new float[_currentPose.muscles.Length];
                serializedPose.FrameCount   = _frameIndex;
                serializedPose.Time         = _recordedTime;
                for (int i = 0; i < serializedPose.Muscles.Length; i++)
                {
                    serializedPose.Muscles[i] = _currentPose.muscles[i];
                }


                SetHumanBoneTransformToHumanoidPoses(_animator, ref serializedPose);


                _poses.Poses.Add(serializedPose);
                _frameIndex++;
            }
        }
Exemplo n.º 7
0
        private static void SetHumanBoneTransformToHumanoidPoses(Animator animator, ref HumanoidPoses.SerializeHumanoidPose pose)
        {
            HumanBodyBones[] values = Enum.GetValues(typeof(HumanBodyBones)) as HumanBodyBones[];
            foreach (HumanBodyBones b in values)
            {
                if (b < 0 || b >= HumanBodyBones.LastBone)
                {
                    continue;
                }

                Transform t = animator.GetBoneTransform(b);
                if (t != null)
                {
                    var bone = new HumanoidPoses.SerializeHumanoidPose.HumanoidBone();
                    bone.Set(animator.transform, t);
                    pose.HumanoidBones.Add(bone);
                }
            }
        }