Exemplo n.º 1
0
    private static void Solve(AnimationStream stream, TransformStreamHandle topHandle, TransformStreamHandle midHandle, TransformStreamHandle lowHandle, TransformSceneHandle effectorHandle)
    {
        Quaternion aRotation = topHandle.GetRotation(stream);
        Quaternion bRotation = midHandle.GetRotation(stream);
        Quaternion eRotation = effectorHandle.GetRotation(stream);

        Vector3 aPosition = topHandle.GetPosition(stream);
        Vector3 bPosition = midHandle.GetPosition(stream);
        Vector3 cPosition = lowHandle.GetPosition(stream);
        Vector3 ePosition = effectorHandle.GetPosition(stream);

        Vector3 ab = bPosition - aPosition;
        Vector3 bc = cPosition - bPosition;
        Vector3 ac = cPosition - aPosition;
        Vector3 ae = ePosition - aPosition;

        float   abcAngle = TriangleAngle(ac.magnitude, ab, bc);
        float   abeAngle = TriangleAngle(ae.magnitude, ab, bc);
        float   angle    = (abcAngle - abeAngle) * Mathf.Rad2Deg;
        Vector3 axis     = Vector3.Cross(ab, bc).normalized;

        Quaternion fromToRotation = Quaternion.AngleAxis(angle, axis);

        Quaternion worldQ = fromToRotation * bRotation;

        midHandle.SetRotation(stream, worldQ);

        cPosition = lowHandle.GetPosition(stream);
        ac        = cPosition - aPosition;
        Quaternion fromTo = Quaternion.FromToRotation(ac, ae);

        topHandle.SetRotation(stream, fromTo * aRotation);

        //lowHandle.SetRotation(stream, eRotation);
    }
Exemplo n.º 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);

            if (m_IkType == IkType.Generic)
            {
                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();
                }
            }
        }
Exemplo n.º 3
0
        private static void Solve(AnimationStream stream, TransformStreamHandle topHandle, TransformStreamHandle midHandle, TransformStreamHandle lowHandle,
                                  TransformSceneHandle effectorHandle)
        {
            var aRotation = topHandle.GetRotation(stream);
            var bRotation = midHandle.GetRotation(stream);
            var eRotation = effectorHandle.GetRotation(stream);

            var aPosition = topHandle.GetPosition(stream);
            var bPosition = midHandle.GetPosition(stream);
            var cPosition = lowHandle.GetPosition(stream);
            var ePosition = effectorHandle.GetPosition(stream);

            var ab = bPosition - aPosition;
            var bc = cPosition - bPosition;
            var ac = cPosition - aPosition;
            var ae = ePosition - aPosition;

            var abcAngle = TriangleAngle(ac.magnitude, ab, bc);
            var abeAngle = TriangleAngle(ae.magnitude, ab, bc);
            var angle    = (abcAngle - abeAngle) * Mathf.Rad2Deg;
            var axis     = Vector3.Cross(ab, bc).normalized;

            var fromToRotation = Quaternion.AngleAxis(angle, axis);

            var worldQ = fromToRotation * bRotation;

            midHandle.SetRotation(stream, worldQ);

            cPosition = lowHandle.GetPosition(stream);
            ac        = cPosition - aPosition;
            var fromTo = Quaternion.FromToRotation(ac, ae);

            topHandle.SetRotation(stream, fromTo * aRotation);

            lowHandle.SetRotation(stream, eRotation);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the rotation of the transform in world space.
 /// </summary>
 /// <param name="stream">The AnimationStream that holds the animated values.</param>
 /// <returns>The rotation of the transform in world space.</returns>
 public Quaternion GetRotation(AnimationStream stream) =>
 m_InStream == 1 ? m_StreamHandle.GetRotation(stream) : m_SceneHandle.GetRotation(stream);
Exemplo n.º 5
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();
            }
        }
    }