예제 #1
0
    public static SQT Lerp(SQT from, SQT to, float t)
    {
        if (from.Position_Weight == 0 || to.Position_Weight == 0)
        {
            if (from.Position_Weight == 0)
            {
                result.Position        = to.Position;
                result.Position_Weight = to.Position_Weight;
            }
            else
            {
                result.Position        = from.Position;
                result.Position_Weight = from.Position_Weight;
            }
        }
        else
        {
            result.Position        = Vector3.Lerp(from.Position, to.Position, t);
            result.Position_Weight = 1;
        }

        if (from.Rotation_Weight == 0 || to.Rotation_Weight == 0)
        {
            if (from.Rotation_Weight == 0)
            {
                result.Rotation        = to.Rotation;
                result.Rotation_Weight = to.Rotation_Weight;
            }
            else
            {
                result.Rotation        = from.Rotation;
                result.Rotation_Weight = from.Rotation_Weight;
            }
        }
        else
        {
            result.Rotation        = Quaternion.Slerp(from.Rotation, to.Rotation, t);
            result.Rotation_Weight = 1;
        }

        if (from.Scale_Weight == 0 || to.Scale_Weight == 0)
        {
            if (from.Scale_Weight == 0)
            {
                result.Scale        = to.Scale;
                result.Scale_Weight = to.Scale_Weight;
            }
            else
            {
                result.Scale        = from.Scale;
                result.Scale_Weight = from.Scale_Weight;
            }
        }
        else
        {
            result.Scale        = Vector3.Lerp(from.Scale, to.Scale, t);
            result.Scale_Weight = 1;
        }
        return(result);
    }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if (currentAAnimation != null)
     {
         //更新动画的局部时间.
         currentAAnimation.Update(Time.deltaTime * Speed);
         if (targetAAnimation != null)
         {
             targetAAnimation.Update(Time.deltaTime * Speed);
             transitionWight += Time.deltaTime * 5;
             //过渡结束.
             if (transitionWight >= 1)
             {
                 transitionWight   = 0;
                 currentAAnimation = targetAAnimation;
                 targetAAnimation  = null;
                 reallySQT         = targetSQT;
             }
         }
         //更新动画数据.
         int JointsCount = JointsList.Count;
         for (int i = 0; i < JointsCount; i++)
         {
             jointName = JointsList[i];
             //如果设置了骨骼遮罩,则直接返回.
             if (JointMaskDic.ContainsKey(jointName) && JointMaskDic[jointName])
             {
                 continue;
             }
             currentJointTransform = GetJointsByName(jointName);
             if (currentJointTransform == null)
             {
                 continue;
             }
             Transform joint = DrawJoints(jointName);
             if (joint != null)
             {
                 joint.parent        = currentJointTransform;
                 joint.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                 joint.localPosition = Vector3.zero;
                 joint.localRotation = Quaternion.identity;
                 joint.gameObject.SetActive(drawJoints);
             }
             currentSQT = currentAAnimation.UpdateSQT(jointName);
             if (targetAAnimation != null)
             {
                 targetSQT = targetAAnimation.UpdateSQT(jointName);
             }
             else
             {
                 targetSQT.SetAllWeight(0);
             }
             reallySQT = ToolSQT.Lerp(currentSQT, targetSQT, transitionWight);
             if (reallySQT.Position_Weight != 0)
             {
                 currentJointTransform.localPosition = reallySQT.Position;
             }
             if (reallySQT.Rotation_Weight != 0)
             {
                 currentJointTransform.localRotation = reallySQT.Rotation;
             }
             if (reallySQT.Scale_Weight != 0)
             {
                 currentJointTransform.localScale = reallySQT.Scale;
             }
         }
     }
 }