Example #1
0
    void OnEnable()
    {
        m_Animator = GetComponent <Animator>();

        // Setting to Always animate because on the first frame the renderer can be not visible which break syncGoal on start up
        m_Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

        if (!m_Animator.avatar.isHuman)
        {
            throw new InvalidOperationException("Avatar must be a humanoid.");
        }

        m_Graph = PlayableGraph.Create();
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var output = AnimationPlayableOutput.Create(m_Graph, "output", m_Animator);

        var clip         = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Humanoid", "Idle");
        var clipPlayable = AnimationClipPlayable.Create(m_Graph, clip);

        clipPlayable.SetApplyFootIK(false);
        clipPlayable.SetApplyPlayableIK(false);

        var job = new FullBodyIKJob();

        job.stiffness        = stiffness;
        job.maxPullIteration = maxPullIteration;

        SetupIKLimbHandle(ref job.leftArm, HumanBodyBones.LeftUpperArm, HumanBodyBones.LeftLowerArm, HumanBodyBones.LeftHand);
        SetupIKLimbHandle(ref job.rightArm, HumanBodyBones.RightUpperArm, HumanBodyBones.RightLowerArm, HumanBodyBones.RightHand);
        SetupIKLimbHandle(ref job.leftLeg, HumanBodyBones.LeftUpperLeg, HumanBodyBones.LeftLowerLeg, HumanBodyBones.LeftFoot);
        SetupIKLimbHandle(ref job.rightLeg, HumanBodyBones.RightUpperLeg, HumanBodyBones.RightLowerLeg, HumanBodyBones.RightFoot);

        m_LeftFootEffector  = SetupEffector(ref job.leftFootEffector, "LeftFootEffector");
        m_RightFootEffector = SetupEffector(ref job.rightFootEffector, "RightFootEffector");
        m_LeftHandEffector  = SetupEffector(ref job.leftHandEffector, "LeftHandEffector");
        m_RightHandEffector = SetupEffector(ref job.rightHandEffector, "RightHandEffector");

        m_LeftKneeHintEffector   = SetupHintEffector(ref job.leftKneeHintEffector, "LeftKneeHintEffector");
        m_RightKneeHintEffector  = SetupHintEffector(ref job.rightKneeHintEffector, "RightKneeHintEffector");
        m_LeftElbowHintEffector  = SetupHintEffector(ref job.leftElbowHintEffector, "LeftElbowHintEffector");
        m_RightElbowHintEffector = SetupHintEffector(ref job.rightElbowHintEffector, "RightElbowHintEffector");

        m_LookAtEffector = SetupLookAtEffector(ref job.lookAtEffector, "LookAtEffector");

        m_BodyRotationEffector = SetupBodyEffector(ref job.bodyEffector, "BodyEffector");



        m_IKPlayable = AnimationScriptPlayable.Create <FullBodyIKJob>(m_Graph, job, 1);
        m_IKPlayable.ConnectInput(0, clipPlayable, 0, 1.0f);

        output.SetSourcePlayable(m_IKPlayable);

        m_Graph.Play();
        m_Graph.Evaluate(0);
        SyncIKFromPose();

        ResetIKWeight();
    }
Example #2
0
    void OnEnable()
    {
        animator = GetComponent <Animator>();

        if (!animator.avatar.isHuman)
        {
            throw new InvalidOperationException("Avatar must be a humanoid.");
        }

        graph = PlayableGraph.Create();
        var output = AnimationPlayableOutput.Create(graph, "output", animator);

        var job = new FullBodyIKJob();

        leftFootEffector  = SetupEffector(ref job.leftFootEffector, "leftFootEffector");
        rightFootEffector = SetupEffector(ref job.rightFootEffector, "rightFootEffector");
        leftHandEffector  = SetupEffector(ref job.leftHandEffector, "leftHandEffector");
        rightHandEffector = SetupEffector(ref job.rightHandEffector, "rightHandEffector");

        leftKneeHintEffector   = SetupHintEffector(ref job.leftKneeHintEffector, "leftKneeHintEffector");
        rightKneeHintEffector  = SetupHintEffector(ref job.rightKneeHintEffector, "rightKneeHintEffector");
        leftElbowHintEffector  = SetupHintEffector(ref job.leftElbowHintEffector, "leftElbowHintEffector");
        rightElbowHintEffector = SetupHintEffector(ref job.rightElbowHintEffector, "rightElbowHintEffector");

        lookAtEffector = SetupLookAtEffector(ref job.lookAtEffector, "lookAtEffector");

        bodyRotationEffector = SetupBodyEffector(ref job.bodyEffector, "bodyEffector");

        ikPlayable = AnimationScriptPlayable.Create <FullBodyIKJob>(graph, job);

        output.SetSourcePlayable(ikPlayable);

        // Sync IK goal on original pose and activate ik weight
        SyncIKFromPose();
        ResetIKWeight();

        graph.Play();
    }