Example #1
0
        private static void EnforceTPoseLegs(ref HumanPose pose)
        {
            //Upper Leg
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftUpperLeg, HumanBodyBones.RightUpperLeg })
            {
                pose.muscles[GetMuscleFromBone(boneID, 0)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 1)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 0.56844866f;
            }

            //Lower Leg
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftLowerLeg, HumanBodyBones.RightLowerLeg })
            {
                pose.muscles[GetMuscleFromBone(boneID, 0)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 0.95906335f;
            }

            //Foot
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftFoot, HumanBodyBones.RightFoot })
            {
                pose.muscles[GetMuscleFromBone(boneID, 1)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = -0.03370474f;
            }

            //Toes
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftFoot, HumanBodyBones.RightFoot })
            {
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 0;
            }
        }
Example #2
0
    //   !!! Human Pose approach !!!
    void Start()
    {
        // https://forum.unity.com/threads/humanposehandler.430354/

        // get attached Animator controller
        anim = GetComponent <Animator>();

        // run this if you want the indexes to muscles on your character
        LookUpMuscleIndex();

        // TODO keeping body above plane
        //Vector3 current_position = transform.position;

        // get human pose handler
        humanPoseHandler = new HumanPoseHandler(anim.avatar, transform);
        // get human pose
        humanPose = new HumanPose();

        // TODO keeping body above plane
        //humanPose.bodyPosition = current_position;

        // reference pose to pose handler
        humanPoseHandler.GetHumanPose(ref humanPose);

        // set a specific musle; 9: Neck Nod Down-Up
        humanPose.muscles[9] = -20f;
        Debug.Log(humanPose.muscles[9]);

        // use pose information to actually set the pose; doesn't work so far
        humanPoseHandler.SetHumanPose(ref humanPose);
    }
    // Update is called once per frame
    void Update()
    {
        if (!isShowEditHandPose)
        {
            return;
        }
        if (animator == null)
        {
            return;
        }

        HumanPose pose    = new HumanPose();
        var       handler = new HumanPoseHandler(animator.avatar, animator.transform);

        handler.GetHumanPose(ref pose); //ポーズ取得

        //ハンドポーズを流し込む
        for (int i = 0; i < pose.muscles.Length; i++)
        {
            var muscle = HumanTrait.MuscleName[i];
            if (TraitLeftHandPropMap.ContainsKey(muscle)) //左手ポーズプロパティ
            {
                pose.muscles[i] = leftHandPoseValueMap[muscle];
            }
            else if (TraitRightHandPropMap.ContainsKey(muscle)) //右手ポーズプロパティ
            {
                pose.muscles[i] = rightHandPoseValueMap[muscle];
            }
        }

        handler.SetHumanPose(ref pose); //ポーズセット
    }
Example #4
0
        private static void EnforceTPoseArms(ref HumanPose pose)
        {
            //Shoulder
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftShoulder, HumanBodyBones.RightShoulder })
            {
                pose.muscles[GetMuscleFromBone(boneID, 1)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 0;
            }

            //Upper Arm
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftUpperArm, HumanBodyBones.RightUpperArm })
            {
                pose.muscles[GetMuscleFromBone(boneID, 0)] = 0;
                pose.muscles[GetMuscleFromBone(boneID, 1)] = 0.3f;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 0.4f;
            }

            //Lower Arm
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftLowerArm, HumanBodyBones.RightLowerArm })
            {
                pose.muscles[GetMuscleFromBone(boneID, 0)] = -0.06501173f;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = 1;
            }

            //Hand
            foreach (HumanBodyBones boneID in new HumanBodyBones[] { HumanBodyBones.LeftHand, HumanBodyBones.RightHand })
            {
                pose.muscles[GetMuscleFromBone(boneID, 1)] = 0.058751374f;
                pose.muscles[GetMuscleFromBone(boneID, 2)] = -0.042013716f;
            }
        }
        public virtual void ApplyAgentState()
        {
            AgentState _agentState;

            if (manualAnimation)
            {
                _agentState = manualAgentState;
            }
            else
            {
                _agentState = agentState;
            }

            for (int b = 0; b < _agentState.boneValues.Length; b++)
            {
                Quaternion newRotation = new Quaternion(
                    -_agentState.boneValues[b].r[0], // Same with order and sign of quat values
                    _agentState.boneValues[b].r[1],
                    _agentState.boneValues[b].r[2],
                    -_agentState.boneValues[b].r[3]);
                bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
            }

            if (retarget != null && poseHandler != null)
            {
                retarget.StorePose();
                HumanPose pose = retarget.GetPose();
                poseHandler.SetHumanPose(ref pose);
            }
        }
Example #6
0
        void UpdateBodyPose(QueryResult queryResult)
        {
            if (!isActiveAndEnabled || m_Animator == null)
            {
                return;
            }

            m_AssignedBody = queryResult.ResolveValue(this);
            m_BodyPose     = m_AssignedBody.BodyPose;

            // We zero out the internal body position here - we let SetPose action handle that instead
            m_BodyPose.bodyPosition = Vector3.zero;
            m_BodyPose.bodyRotation = Quaternion.identity;

            m_PoseApplicator.SetHumanPose(ref m_BodyPose);

            if (queryResult.TryGetTrait(TraitNames.Pose, out Pose newPose))
            {
                transform.SetWorldPose(newPose);
            }

            if (m_ScaleToMatchHeight)
            {
                transform.localScale = Vector3.one * (m_AssignedBody.Height / m_RigHeight);
            }
        }
    /******************************
    ******************************/
    void mix_anim(ref HumanPose HumanPose_from, ref HumanPose HumanPose_to, ref HumanPose HumanPose_dst)
    {
        /********************
        ********************/
        for (int i = 0; i < HumanTrait.MuscleCount; i++)
        {
            HumanPose_dst.muscles[i] = Fader(HumanPose_from.muscles[i], HumanPose_to.muscles[i], Fade);
        }

        /********************
        *  https://docs.unity3d.com/ja/current/ScriptReference/Quaternion.html
        *       Slerp
        *               a と b の間を t で球状に補間します。パラメーター t は、[0, 1] の範囲です。
        *
        *       Lerp
        *               a と b の間を t で補間し、その後、その結果を正規化します。パラメーター t は、[0, 1] の範囲です。
        *               Slerp よりも高速ですが、回転が互いに離れている場合、見た目は劣ります。
        ********************/
        HumanPose_dst.bodyRotation = Quaternion.Slerp(HumanPose_from.bodyRotation, HumanPose_to.bodyRotation, Fade);
        // HumanPose_dst.bodyRotation = Quaternion.Lerp(HumanPose_from.bodyRotation, HumanPose_to.bodyRotation, Fade);

        /********************
        ********************/
        Vector3 pos_0 = HumanPose_from.bodyPosition;
        Vector3 pos_1 = HumanPose_to.bodyPosition;
        Vector3 pos_2 = Fader(pos_0, pos_1, Fade);

        HumanPose_dst.bodyPosition = pos_2;
    }
    void LateUpdate()
    {
        HumanPose m_humanPose = new HumanPose();

        m_srcPoseHandler.GetHumanPose(ref m_humanPose);
        m_destPoseHandler.SetHumanPose(ref m_humanPose);
    }
        /// <summary>
        /// Creates and returns a PosePreset based on humanoid muscle values
        /// </summary>
        public static PumkinsPosePreset CreatePreset(string poseName, HumanPose p)
        {
            PumkinsPosePreset pose = CreateInstance <PumkinsPosePreset>();

            pose.SetupPreset(poseName, p);
            return(pose);
        }
    void updatePose()
    {
        if (poseHandler == null || targetHandler == null)
        {
            return;
        }

        HumanPose pose = new HumanPose();

        // sensetime as source
        poseHandler.GetHumanPose(ref pose);

        // bone의 인덱스가 다른경우 직접 매핑함
        // Adjust finger spread with bending
        pose.muscles[56] = pose.muscles[55]; // Left thumb adjustment
        pose.muscles[60] = pose.muscles[59]; // Left index adjustment
        pose.muscles[64] = pose.muscles[63]; // Left middle adjustment
        pose.muscles[68] = pose.muscles[67]; // Left ring adjustment
        pose.muscles[72] = pose.muscles[71]; // Left little adjustment
        pose.muscles[76] = pose.muscles[75]; // Right thumb adjustment
        pose.muscles[80] = pose.muscles[79]; // Right index adjustment
        pose.muscles[84] = pose.muscles[83]; // Right middle adjustment
        pose.muscles[88] = pose.muscles[87]; // Right ring adjustment
        pose.muscles[92] = pose.muscles[91]; // Right little adjustment

        // zepeto as target
        targetHandler.SetHumanPose(ref pose);
    }
Example #11
0
    private IEnumerator RecordRoutine()
    {
        Debug.Log("Started recording ...");
        yield return(new WaitForEndOfFrame());

        float t0    = -1.0f;
        var   poses = new Dictionary <float, HumanPose>();

        while (m_Recording)
        {
            float tn = Time.time;

            // Capture the start time.
            if (t0 < 0)
            {
                t0 = tn;
            }

            // Pose time stored relative to first pose.
            tn = tn - t0;

            HumanPose pose = new HumanPose();
            m_SourcePoseHandler.GetHumanPose(ref pose);

            poses.Add(tn, pose);

            yield return(new WaitForEndOfFrame());
        }

        Debug.Log("Stopped recording, adding to database ...");

        // Build an animation clip from our time/pose pairs
        StageDive.AnimClip clip = new StageDive.AnimClip();
        foreach (var time_pose in poses)
        {
            var time = time_pose.Key;
            var pose = time_pose.Value;
            clip.frames.Add(new StageDive.AnimFrame
            {
                time = time,
                pose = new StageDive.HumanPose
                {
                    px      = pose.bodyPosition.x,
                    py      = pose.bodyPosition.y,
                    pz      = pose.bodyPosition.z,
                    rx      = pose.bodyRotation.x,
                    ry      = pose.bodyRotation.y,
                    rz      = pose.bodyRotation.z,
                    rw      = pose.bodyRotation.w,
                    muscles = pose.muscles
                }
            });
        }

        // Store in database
        var name = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH'h'mm'm'ss's'");

        m_AnimClipDatabase.AddAnimClip(name, clip);
    }
    private void Start()
    {
        Debug.Assert(source != null);

        SetTarget(_target);

        _currentPose = new UnityEngine.HumanPose();
    }
 // Use this for initialization
 void Start()
 {
     hph         = new HumanPoseHandler(GetComponent <Animator>().avatar, root);
     currentPose = new HumanPose();
     hph.GetHumanPose(ref currentPose);
     poseModified = false;
     poseStep     = 0;
 }
        /// <summary>
        /// Creates and returns a PosePreset based on humanoid muscle values
        /// </summary>
        public static PumkinsPosePreset CreatePreset(string poseName, Animator anim)
        {
            HumanPose        hp  = new HumanPose();
            HumanPoseHandler hph = new HumanPoseHandler(anim.avatar, anim.transform);

            hph.GetHumanPose(ref hp);

            return(CreatePreset(poseName, hp));
        }
        public bool SetupPreset(string poseName, GameObject avatar, PosePresetMode mode)
        {
            if (!avatar)
            {
                return(false);
            }

            if (mode == PosePresetMode.TransformRotations)
            {
                Transform[] trans = avatar.GetComponentsInChildren <Transform>();

                transformPaths     = new List <string>(trans.Length);
                transformRotations = new List <Vector3>(trans.Length);

                for (int i = 0; i < trans.Length; i++)
                {
                    var    t    = trans[i];
                    string path = Helpers.GetTransformPath(t, avatar.transform, true);

                    if (t && !string.IsNullOrEmpty(path))
                    {
                        transformPaths.Add(path);
                        transformRotations.Add(t.localEulerAngles);
                    }
                }
                return(true);
            }
            else
            {
                Animator anim = avatar.GetComponent <Animator>();

                if (!anim)
                {
                    return(false);
                }

                SerialTransform tr = avatar.transform;
                avatar.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
                HumanPose hp = new HumanPose();
                try
                {
                    HumanPoseHandler hph = new HumanPoseHandler(anim.avatar, anim.transform);
                    hph.GetHumanPose(ref hp);
                }
                catch
                {
                    avatar.transform.SetPositionAndRotation(tr.position, tr.rotation);
                    return(false);
                }
                finally
                {
                    avatar.transform.SetPositionAndRotation(tr.position, tr.rotation);
                    SetupPreset(poseName, hp);
                }
                return(true);
            }
        }
Example #16
0
 private void StartPlaying()
 {
     isPlaying    = true;
     currentFrame = 0;
     currentTime  = 0f;
     Debug.Log("===STARTED PLAYING ANIMATION===");
     currentPose = poseDict[sortedKeys[currentFrame++]];
     poseHandler.SetHumanPose(ref currentPose);
 }
Example #17
0
        private static void ReloadPoseVariables(GameObject newAvatar)
        {
            if (newAvatar)
            {
                _avatarAnimator = newAvatar.GetComponent <Animator>();
            }
            else
            {
                _avatarAnimator = null;
            }

            if (bones == null)
            {
                bones = new List <PoseEditorBone>();
            }
            bones.Clear();

            if (newAvatar && AvatarAnimator && AvatarAnimator.isHuman)
            {
                avatarPose = new HumanPose();

                SerialTransform st = newAvatar.transform;
                Vector3         avatarPos;

                avatarPoseHandler = new HumanPoseHandler(AvatarAnimator.avatar, AvatarAnimator.transform);
                avatarPoseHandler.GetHumanPose(ref avatarPose);

                avatarPos = st.position;
                newAvatar.transform.position = avatarPos;

                //Human bone transforms to compare against
                HashSet <Transform> humanBoneTransforms = new HashSet <Transform>();
                for (int i = 0; i < HumanTrait.BoneCount; i++)
                {
                    humanBoneTransforms.Add(AvatarAnimator.GetBoneTransform((HumanBodyBones)i));
                }

                //Get bone human bone root and tip positions
                for (int i = 0; i < HumanTrait.BoneCount; i++)
                {
                    Transform bone = AvatarAnimator.GetBoneTransform((HumanBodyBones)i);
                    if (!bone || bone.childCount == 0)
                    {
                        continue;
                    }
                    for (int j = 0; j < bone.childCount; j++)
                    {
                        Transform child = bone.GetChild(j);
                        if (humanBoneTransforms.Contains(child))
                        {
                            bones.Add(new PoseEditorBone(bone, child));
                        }
                    }
                }
            }
        }
    private HumanPose MusclesToPose(ref float[] muscles_array)
    {
        HumanPose pose = new HumanPose();

        pose.bodyPosition = currentPose.bodyPosition;
        pose.bodyRotation = currentPose.bodyRotation;
        pose.muscles      = new float[currentPose.muscles.Length];
        System.Array.Copy(muscles_array, pose.muscles, muscles_array.Length);
        return(pose);
    }
Example #19
0
        public static void EnforceTPose(this Animator animator)
        {
            HumanPoseHandler poseHandler = new HumanPoseHandler(animator.avatar, animator.transform);

            HumanPose pose = new HumanPose();

            poseHandler.GetHumanPose(ref pose);

            pose.bodyPosition = new Vector3(0.0023505474f, 0.97386265f, -0.015300978f);
            pose.bodyRotation = Quaternion.identity;

            EnforceTPoseSpine(ref pose);
            EnforceTPoseLegs(ref pose);
            EnforceTPoseArms(ref pose);
            EnforceTPoseFingers(ref pose);
            EnforceTPoseFace(ref pose);

            poseHandler.SetHumanPose(ref pose);

            //RuntimeAnimatorController tmp = animator.runtimeAnimatorController;
            //animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animations/TPose");
            //animator.Update(0);
            //animator.runtimeAnimatorController = tmp;

            //Enforce the TPose of the Spine
            //animator.EnforceTPose(QuickHumanBodyBones.Hips, QuickHumanBodyBones.Head, animator.transform.up);

            ////Enforce the TPose of the LeftArm
            //animator.EnforceTPose(QuickHumanBodyBones.LeftUpperArm, QuickHumanBodyBones.LeftLowerArm, -animator.transform.right);
            //animator.EnforceTPose(QuickHumanBodyBones.LeftLowerArm, QuickHumanBodyBones.LeftHand, -animator.transform.right);

            ////Enforce the TPose of the RightArm
            //animator.EnforceTPose(QuickHumanBodyBones.RightUpperArm, QuickHumanBodyBones.RightLowerArm, animator.transform.right);
            //animator.EnforceTPose(QuickHumanBodyBones.RightLowerArm, QuickHumanBodyBones.RightHand, animator.transform.right);

            ////Enforce the TPose of the Hands
            //animator.EnforceTPoseHand(true);
            //animator.EnforceTPoseHand(false);

            ////Enforce the TPose of the Fingers
            //animator.EnforceTPoseFingers(true);
            //animator.EnforceTPoseFingers(false);

            ////Enforce the TPose of the LeftLeg
            //animator.EnforceTPose(QuickHumanBodyBones.LeftUpperLeg, QuickHumanBodyBones.LeftLowerLeg, -animator.transform.up);
            //animator.EnforceTPose(QuickHumanBodyBones.LeftLowerLeg, QuickHumanBodyBones.LeftFoot, -animator.transform.up);

            ////Enforce the TPose of the RightLeg
            //animator.EnforceTPose(QuickHumanBodyBones.RightUpperLeg, QuickHumanBodyBones.RightLowerLeg, -animator.transform.up);
            //animator.EnforceTPose(QuickHumanBodyBones.RightLowerLeg, QuickHumanBodyBones.RightFoot, -animator.transform.up);
        }
Example #20
0
        private void LateUpdate()
        {
            if (_SrcPose == null || _DstPose == null)
            {
                return;
            }
            _SrcPose.GetHumanPose(ref _Pose);
            //ワールド座標系での値になっている模様
            //Debug.Log($"bodyPosition : {_Pose.bodyPosition} / bodyRotation : {_Pose.bodyRotation}");
            WriteInformation("Source", _Source);

            //this.gameObject.transform.position = Vector3.zero;
            //this.gameObject.transform.rotation = Quaternion.identity;
            //this.gameObject.transform.localPosition = Vector3.zero;
            //this.gameObject.transform.localRotation = Quaternion.identity;

            HumanPose oldPose = new HumanPose();

            //HumanPose newPose = new HumanPose();
            _DstPose.GetHumanPose(ref oldPose);

            //重心、および、腰と両肩の中点からの向きであるため、正確に処理するには問題がありそう
            //_Pose.bodyPosition -= _Source.transform.position;
            //_Pose.bodyRotation *= Quaternion.Inverse(_Source.transform.rotation);


            _DstPose.SetHumanPose(ref _Pose);
            //_DstPose.GetHumanPose(ref newPose);

            //Debug.Log($"localPosition : {this.transform.localPosition} / position : {this.transform.position} / localRotation : {this.transform.localRotation} / rotation : {this.transform.rotation}");
            WriteInformation("VRM", this.GetComponent <Animator>());

            //Debug.Log($"{oldPose.bodyPosition} -> {_Pose.bodyPosition} -> {newPose.bodyPosition}");
            //Debug.Log($"{oldPose.bodyRotation} -> {_Pose.bodyRotation} -> {newPose.bodyRotation}");

            //return;

            //_SrcPose = null;

            //https://forum.unity.com/threads/humanpose-issue-continued.484128/
            //ポーズの同期で位置も変わってしまう?
            //  Craftopiaのプレーヤーでは問題なさそう
            //
            //なお、テスト的にユニティちゃんのプロジェクトで同期させようとした場合、上手く動かなかった
            //ユニティちゃん自体のCharacter1_Hipsの配置が正規化?されたおらず、回転がかかった状態であるためと考えられます。

            //this.gameObject.transform.localPosition = this.gameObject.transform.right;// Vector3.zero;
            //this.gameObject.transform.localPosition = Vector3.zero;
            //this.gameObject.transform.localRotation = Quaternion.identity;
            //Debug.Log($"LateUpdate {this.gameObject.transform.localPosition} / {this.gameObject.transform.position}");
        }
Example #21
0
        public void Modify(ref HumanPose pose)
        {
            if (LeftHandPose != null)
            {
                pose.muscles[this.LeftThumb1Stretched]  = LeftHandPose.ThumbStretch;
                pose.muscles[this.LeftThumb2Stretched]  = LeftHandPose.ThumbStretch;
                pose.muscles[this.LeftThumb3Stretched]  = LeftHandPose.ThumbStretch;
                pose.muscles[this.LeftIndex1Stretched]  = LeftHandPose.IndexStretch;
                pose.muscles[this.LeftIndex2Stretched]  = LeftHandPose.IndexStretch;
                pose.muscles[this.LeftIndex3Stretched]  = LeftHandPose.IndexStretch;
                pose.muscles[this.LeftMiddle1Stretched] = LeftHandPose.MiddleStretch;
                pose.muscles[this.LeftMiddle2Stretched] = LeftHandPose.MiddleStretch;
                pose.muscles[this.LeftMiddle3Stretched] = LeftHandPose.MiddleStretch;
                pose.muscles[this.LeftRing1Stretched]   = LeftHandPose.RingStretch;
                pose.muscles[this.LeftRing2Stretched]   = LeftHandPose.RingStretch;
                pose.muscles[this.LeftRing3Stretched]   = LeftHandPose.RingStretch;
                pose.muscles[this.LeftLittle1Stretched] = LeftHandPose.LittleStretch;
                pose.muscles[this.LeftLittle2Stretched] = LeftHandPose.LittleStretch;
                pose.muscles[this.LeftLittle3Stretched] = LeftHandPose.LittleStretch;
                pose.muscles[this.LeftThumbSpread]      = LeftHandPose.ThumbSpread;
                pose.muscles[this.LeftIndexSpread]      = LeftHandPose.IndexSpread;
                pose.muscles[this.LeftMiddleSpread]     = LeftHandPose.MiddleSpread;
                pose.muscles[this.LeftRingSpread]       = LeftHandPose.RingSpread;
                pose.muscles[this.LeftLittleSpread]     = LeftHandPose.LittleSpread;
            }

            if (RightHandPose != null)
            {
                pose.muscles[this.RightThumb1Stretched]  = RightHandPose.ThumbStretch;
                pose.muscles[this.RightThumb2Stretched]  = RightHandPose.ThumbStretch;
                pose.muscles[this.RightThumb3Stretched]  = RightHandPose.ThumbStretch;
                pose.muscles[this.RightIndex1Stretched]  = RightHandPose.IndexStretch;
                pose.muscles[this.RightIndex2Stretched]  = RightHandPose.IndexStretch;
                pose.muscles[this.RightIndex3Stretched]  = RightHandPose.IndexStretch;
                pose.muscles[this.RightMiddle1Stretched] = RightHandPose.MiddleStretch;
                pose.muscles[this.RightMiddle2Stretched] = RightHandPose.MiddleStretch;
                pose.muscles[this.RightMiddle3Stretched] = RightHandPose.MiddleStretch;
                pose.muscles[this.RightRing1Stretched]   = RightHandPose.RingStretch;
                pose.muscles[this.RightRing2Stretched]   = RightHandPose.RingStretch;
                pose.muscles[this.RightRing3Stretched]   = RightHandPose.RingStretch;
                pose.muscles[this.RightLittle1Stretched] = RightHandPose.LittleStretch;
                pose.muscles[this.RightLittle2Stretched] = RightHandPose.LittleStretch;
                pose.muscles[this.RightLittle3Stretched] = RightHandPose.LittleStretch;
                pose.muscles[this.RightThumbSpread]      = RightHandPose.ThumbSpread;
                pose.muscles[this.RightIndexSpread]      = RightHandPose.IndexSpread;
                pose.muscles[this.RightMiddleSpread]     = RightHandPose.MiddleSpread;
                pose.muscles[this.RightRingSpread]       = RightHandPose.RingSpread;
                pose.muscles[this.RightLittleSpread]     = RightHandPose.LittleSpread;
            }
        }
Example #22
0
 private static void EnforceTPoseSpine(ref HumanPose pose)
 {
     for (HumanBodyBones boneID = HumanBodyBones.Spine; boneID <= HumanBodyBones.Head; boneID++)
     {
         for (int i = 0; i < 3; i++)
         {
             int muscleID = GetMuscleFromBone(boneID, i);
             if (muscleID >= 0)
             {
                 pose.muscles[muscleID] = 0;
             }
         }
     }
 }
        /// <summary>
        /// Puts objToApplyPoseTo into the selected pose, or resets the pose if bodyData is null.
        /// </summary>
        /// <param name="objToApplyPoseTo">The humanoid animator to pose</param>
        /// <param name="bodyData">(Optional) The pose to use. If null, animator will take on the default 'reset' pose</param>
        /// <param name="overrideRelevantMuscles">If true, all muscles will be posed, including those marked non-relevant (eg. lacking platform tracking support).</param>
        internal static void LoadBodyPose(Animator objToApplyPoseTo, BodyPoseData bodyData = null, bool overrideRelevantMuscles = false)
        {
            StopTimelineIfNecessary();

            var animTransform = objToApplyPoseTo.transform;
            // if we don't set the transform to 0,0,0 then loading pose will offset the body from the transform root
            var originalPos = animTransform.localPosition;
            var originalRot = animTransform.localRotation;

            animTransform.localRotation = Quaternion.identity;
            animTransform.localPosition = Vector3.zero;

            var avatar = objToApplyPoseTo.avatar;

            if (!avatar.isHuman)
            {
                Debug.LogError("LoadBodyPose can only be used on humanoid avatars.");
                return;
            }

            var humanPoseHandler = new HumanPoseHandler(avatar, animTransform);
            var humanPose        = new HumanPose();

            humanPoseHandler.GetHumanPose(ref humanPose);

            if (bodyData == null)
            {
                for (var i = 0; i < humanPose.muscles.Length; i++)
                {
                    humanPose.muscles[i] = 0;
                }
            }
            else
            {
                humanPose.bodyRotation = Quaternion.identity;

                for (var i = 0; i < bodyData.Muscles.Length; i++)
                {
                    if (overrideRelevantMuscles || bodyData.MuscleRelevantData[i]) // Only set muscles with relevant data
                    {
                        humanPose.muscles[i] = bodyData.Muscles[i];
                    }
                }
            }

            humanPoseHandler.SetHumanPose(ref humanPose);

            animTransform.localRotation = originalRot;
            animTransform.localPosition = originalPos;
        }
Example #24
0
        private void LoadPoseData()
        {
            if (!Application.isPlaying && !loadInEditor)
            {
                return;
            }
            if (loadPath == null)
            {
                Debug.LogError("***NO LOAD PATH SET ON " + gameObject.name + "***");
                return;
            }
            string[] splitPath = loadPath.Split('/');
            string   filename  = splitPath[splitPath.Length - 1];

            Debug.Log("===LOADING POSE: " + filename.ToUpper() + "===");

            BinaryFormatter                  formatter         = new BinaryFormatter();
            SurrogateSelector                surrogateSelector = new SurrogateSelector();
            Vector3SerializationSurrogate    vector3SS         = new Vector3SerializationSurrogate();
            QuaternionSerializationSurrogate quatSS            = new QuaternionSerializationSurrogate();

            surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3SS);
            surrogateSelector.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), quatSS);
            formatter.SurrogateSelector = surrogateSelector;

            FileStream file = File.Open(loadPath, FileMode.Open);

            Dictionary <float, RecordablePose> recordablePoseData = (Dictionary <float, RecordablePose>)formatter.Deserialize(file);

            file.Close();
            poseDict = new Dictionary <float, HumanPose>(recordablePoseData.Keys.Count);
            foreach (var key in recordablePoseData.Keys)
            {
                RecordablePose rPose = recordablePoseData[key];
                HumanPose      pose  = new HumanPose();
                pose.bodyPosition = rPose.bodyPosition;
                pose.bodyRotation = rPose.bodyRotation;
                pose.muscles      = rPose.muscles;
                poseDict.Add(key, pose);
            }
            sortedKeys = new List <float>(recordablePoseData.Keys);
            sortedKeys.Sort();
            totalFrames = recordablePoseData.Keys.Count;
            Debug.Log("===SUCCESSFULLY LOADED " + filename.ToUpper() + "===");
            if (playOnAwake)
            {
                StartPlaying();
            }
        }
Example #25
0
 public override void OnInspectorGUI()
 {
     if (_RecordPose == null)
     {
         _RecordPose = (RecordPose)target;
     }
     if (_RecordPose.targetAvatar == null)
     {
         _RecordPose.animator     = ((RecordPose)target).gameObject.GetComponent <Animator>();
         _RecordPose.targetAvatar = _RecordPose.animator.avatar;
         _RecordPose._gameObject  = ((RecordPose)target).gameObject;
     }
     if (GUILayout.Button("Create humanoid animation"))
     {
         Vector3 originalPos = _RecordPose.animator.gameObject.transform.position;
         _RecordPose.animator.gameObject.transform.position = Vector3.zero;
         HumanPose _humanPose = _RecordPose.Record();
         _RecordPose.animator.gameObject.transform.position = originalPos;
         float frameRate = 60f;
         float length    = 1 / frameRate;
         var   clip      = new AnimationClip {
             frameRate = frameRate
         };
         AnimationUtility.SetAnimationClipSettings(clip, new AnimationClipSettings {
             loopTime = false
         });
         //set muscle values
         for (int i = 0; i < HumanTrait.MuscleCount; i++)
         {
             var muscle = GetCurveName(HumanTrait.MuscleName[i]);
             clip.SetCurve("", typeof(Animator), muscle, CreateCurve(_humanPose.muscles[i], length));
         }
         Vector3    Position = _humanPose.bodyPosition;
         Quaternion Rotation = _humanPose.bodyRotation;// _RecordPose.animator.bodyRotation;
         //set root pos/rot
         clip.SetCurve("", typeof(Animator), "RootT.x", CreateCurve(Position.x, length));
         clip.SetCurve("", typeof(Animator), "RootT.y", CreateCurve(Position.y, length));
         clip.SetCurve("", typeof(Animator), "RootT.z", CreateCurve(Position.z, length));
         clip.SetCurve("", typeof(Animator), "RootQ.x", CreateCurve(Rotation.x, length));
         clip.SetCurve("", typeof(Animator), "RootQ.y", CreateCurve(Rotation.y, length));
         clip.SetCurve("", typeof(Animator), "RootQ.z", CreateCurve(Rotation.z, length));
         clip.SetCurve("", typeof(Animator), "RootQ.w", CreateCurve(Rotation.w, length));
         clip.EnsureQuaternionContinuity();
         var path            = string.Format("Assets/Recorded_{0}_{1:yyyy_MM_dd_HH_mm_ss}_Humanoid.anim", _RecordPose._gameObject.name, DateTime.Now);
         var uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(path);
         AssetDatabase.CreateAsset(clip, uniqueAssetPath);
         AssetDatabase.SaveAssets();
     }
 }
Example #26
0
        public void GetHumanPose()
        {
            PoseHandler = new HumanPoseHandler(animator.avatar, animator.transform);

            _pose = new HumanPose();

            PoseHandler.GetHumanPose(ref _pose);

            for (int i = 0; i < _pose.muscles.Length; i++)
            {
                _pose.muscles[i] = 0;
            }
            Position = new Vector3(0, 1, 0);
            Rotation = Quaternion.identity;
        }
Example #27
0
        public MuscleTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, HumanPose humanPose,
                              HumanPoseHandler humanPoseHandler) : base(state, multiColumnHeader)
        {
            this.rowHeight = 20;
            this.showAlternatingRowBackgrounds = true;
            this.showBorder = true;

            this.humanPose        = humanPose;
            this.humanPoseHandler = humanPoseHandler;

            this.initialHumanPoseValues = humanPose.muscles.ToArray();

            multiColumnHeader.ResizeToFit();
            this.Reload();
        }
Example #28
0
        /// <summary>
        /// animatorのAvatarを更新する
        /// </summary>
        public static void UpdateAnimatorAvatar(Animator animator, HumanDescription humanDescription, ICollection <SkeletonInfo> HumanSkeletonInfos, string avatarName = "customAvater")
        {
            Avatar avater = GenerateAvatar(animator.transform, humanDescription, HumanSkeletonInfos);

            avater.name     = avatarName;
            animator.avatar = avater;

            // 一度ポーズを更新しないとおかしなポーズになる。
            // たぶん更新前のavatarにおいての位置・回転情報が残ったままなので変になる?
            var PoseHandler = new HumanPoseHandler(animator.avatar, animator.transform);
            var pose        = new HumanPose();

            PoseHandler.GetHumanPose(ref pose);
            PoseHandler.SetHumanPose(ref pose);
        }
Example #29
0
        public virtual void EvaluateHumanPose(float time, ref HumanPose pose)
        {
            if (_animator.isHuman)
            {
                pose.bodyPosition = GetAnimationCurve(CURVE_BODY_POSITION).EvaluateVector3(time);
                pose.bodyRotation = GetAnimationCurve(CURVE_BODY_ROTATION).EvaluateQuaternion(time);

                List <float> muscles = new List <float>();
                for (int i = 0; i < QuickHumanTrait.GetNumMuscles(); i++)
                {
                    muscles.Add(_curves[QuickHumanTrait.GetMuscleName(i)].Evaluate(time));
                }

                pose.muscles = muscles.ToArray();
            }
        }
        public HumanPose GetHumanPose(Animator anim)
        {
            if (!anim || !anim.isHuman)
            {
                return(default(HumanPose));
            }

            HumanPose hp = new HumanPose
            {
                bodyPosition = anim.bodyPosition,
                bodyRotation = anim.bodyRotation,
                muscles      = muscles
            };

            return(hp);
        }