コード例 #1
0
        // 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 System.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++;
        }
コード例 #2
0
        private static void SetHumanBoneTransformToHumanoidPoses(Animator animator, ref HumanoidPoses.SerializeHumanoidPose pose)
        {
            HumanBodyBones[] values = System.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);
                }
            }
        }