示例#1
0
    public void ProcessAnimation(AnimationStream stream)
    {
        float weight;

        if (m_UseAnimatorProperty)
        {
            weight  = m_AnimatorWeight.GetFloat(stream);
            weight += m_AnimatorWeightOffset.GetFloat(stream);
            weight  = Mathf.Clamp01(weight);
            m_WeightHandle.SetFloat(stream, weight);
        }
        else
        {
            weight = m_WeightHandle.GetFloat(stream);
        }

        weight = 1f;

        Vector3    effectorPosition;
        Quaternion effectorRotation;

        if (m_UseStreamEffector)
        {
            effectorPosition = m_EffectorStreamHandle.GetPosition(stream);
            effectorRotation = m_EffectorStreamHandle.GetRotation(stream);
        }
        else
        {
            effectorPosition = m_EffectorSceneHandle.GetPosition(stream);
            effectorRotation = m_EffectorSceneHandle.GetRotation(stream);
        }

        effectorRotation *= Quaternion.Euler(m_TargetOffset);

        if (m_IkType == IkType.Generic)
        {
            AnimJobUtilities.SolveTwoBoneIK(stream, m_StartHandle, m_MidHandle, m_EndHandle, effectorPosition, effectorRotation, weight, weight);
        }

        else if (m_IkType == IkType.Humanoid)
        {
            if (stream.isHumanStream)
            {
                var humanStream = stream.AsHuman();

                humanStream.SetGoalPosition(m_HumanLimb, effectorPosition);
                humanStream.SetGoalRotation(m_HumanLimb, effectorRotation);
                humanStream.SetGoalWeightPosition(m_HumanLimb, weight);
                humanStream.SetGoalWeightRotation(m_HumanLimb, weight);
                humanStream.SolveIK();
            }
        }
    }
示例#2
0
    public void ProcessAnimation(AnimationStream stream)
    {
        float weight;

        if (m_UseAnimatorProperty)
        {
            weight  = m_AnimatorWeight.GetFloat(stream);
            weight += m_AnimatorWeightOffset.GetFloat(stream);
            weight  = Mathf.Clamp01(weight);
            m_WeightHandle.SetFloat(stream, weight);
        }
        else
        {
            weight = m_WeightHandle.GetFloat(stream);
        }

        weight = 1f;

        Vector3    effectorPosition;
        Quaternion effectorRotation;

        if (m_UseStreamEffector)
        {
            effectorPosition = m_EffectorStreamHandle.GetPosition(stream);
            effectorRotation = m_EffectorStreamHandle.GetRotation(stream);
        }
        else
        {
            effectorPosition = m_EffectorSceneHandle.GetPosition(stream);
            effectorRotation = m_EffectorSceneHandle.GetRotation(stream);
        }

        effectorRotation *= Quaternion.Euler(m_TargetOffset);

        // Changes to the stream seems to kill the foot ik data in the stream.
        // TODO: (sunek) Get rid of this workaround once fixed in release
        if (stream.isHumanStream)
        {
            var humanStream = stream.AsHuman();
            humanStream.SetGoalPosition(AvatarIKGoal.LeftFoot, humanStream.GetGoalPosition(AvatarIKGoal.LeftFoot));
            humanStream.SetGoalRotation(AvatarIKGoal.LeftFoot, humanStream.GetGoalRotation(AvatarIKGoal.LeftFoot));
            humanStream.SetGoalPosition(AvatarIKGoal.RightFoot, humanStream.GetGoalPosition(AvatarIKGoal.RightFoot));
            humanStream.SetGoalRotation(AvatarIKGoal.RightFoot, humanStream.GetGoalRotation(AvatarIKGoal.RightFoot));
        }


        if (m_IkType == IkType.Generic)
        {
            AnimJobUtilities.SolveTwoBoneIK(stream, m_StartHandle, m_MidHandle, m_EndHandle, effectorPosition, effectorRotation, weight, weight);
        }

        else if (m_IkType == IkType.Humanoid)
        {
            if (stream.isHumanStream)
            {
                var humanStream = stream.AsHuman();

                humanStream.SetGoalPosition(m_HumanLimb, effectorPosition);
                humanStream.SetGoalRotation(m_HumanLimb, effectorRotation);
                humanStream.SetGoalWeightPosition(m_HumanLimb, weight);
                humanStream.SetGoalWeightRotation(m_HumanLimb, weight);
                humanStream.SolveIK();
            }
        }
    }