Esempio n. 1
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[this.boneIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    bone.rotation = bone.data.rotation;
                    return;
                }
                float num = bone.data.rotation - bone.rotation;
                num           -= (0x4000 - ((int)(16384.499999999996 - (num / 360f)))) * 360;
                bone.rotation += num * alpha;
            }
            else if (time >= frames[frames.Length - 2])
            {
                if (pose == MixPose.Setup)
                {
                    bone.rotation = bone.data.rotation + (frames[frames.Length + -1] * alpha);
                }
                else
                {
                    float num2 = (bone.data.rotation + frames[frames.Length + -1]) - bone.rotation;
                    num2          -= (0x4000 - ((int)(16384.499999999996 - (num2 / 360f)))) * 360;
                    bone.rotation += num2 * alpha;
                }
            }
            else
            {
                int   index        = Animation.BinarySearch(frames, time, 2);
                float num4         = frames[index + -1];
                float num5         = frames[index];
                float curvePercent = base.GetCurvePercent((index >> 1) - 1, 1f - ((time - num5) / (frames[index + -2] - num5)));
                float num7         = frames[index + 1] - num4;
                num7 -= (0x4000 - ((int)(16384.499999999996 - (num7 / 360f)))) * 360;
                num7  = num4 + (num7 * curvePercent);
                if (pose == MixPose.Setup)
                {
                    num7         -= (0x4000 - ((int)(16384.499999999996 - (num7 / 360f)))) * 360;
                    bone.rotation = bone.data.rotation + (num7 * alpha);
                }
                else
                {
                    num7           = (bone.data.rotation + num7) - bone.rotation;
                    num7          -= (0x4000 - ((int)(16384.499999999996 - (num7 / 360f)))) * 360;
                    bone.rotation += num7 * alpha;
                }
            }
        }
Esempio n. 2
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            PathConstraint constraint = skeleton.pathConstraints.Items[this.pathConstraintIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    constraint.rotateMix    = constraint.data.rotateMix;
                    constraint.translateMix = constraint.data.translateMix;
                    return;
                }
                constraint.rotateMix    += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
                constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
            }
            else
            {
                float num;
                float num2;
                if (time >= frames[frames.Length - 3])
                {
                    num  = frames[frames.Length + -2];
                    num2 = frames[frames.Length + -1];
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 3);
                    num  = frames[index + -2];
                    num2 = frames[index + -1];
                    float num4         = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 3) - 1, 1f - ((time - num4) / (frames[index + -3] - num4)));
                    num  += (frames[index + 1] - num) * curvePercent;
                    num2 += (frames[index + 2] - num2) * curvePercent;
                }
                if (pose == MixPose.Setup)
                {
                    constraint.rotateMix    = constraint.data.rotateMix + ((num - constraint.data.rotateMix) * alpha);
                    constraint.translateMix = constraint.data.translateMix + ((num2 - constraint.data.translateMix) * alpha);
                }
                else
                {
                    constraint.rotateMix    += (num - constraint.rotateMix) * alpha;
                    constraint.translateMix += (num2 - constraint.translateMix) * alpha;
                }
            }
        }
Esempio n. 3
0
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            ExposedList <Slot> drawOrder = skeleton.drawOrder;
            ExposedList <Slot> slots     = skeleton.slots;

            if (direction == MixDirection.Out && pose == MixPose.Setup)
            {
                Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
                return;
            }
            float[] array = frames;
            if (time < array[0])
            {
                if (pose == MixPose.Setup)
                {
                    Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
                }
                return;
            }
            int num = (!(time >= array[array.Length - 1])) ? (Animation.BinarySearch(array, time) - 1) : (array.Length - 1);

            int[] array2 = drawOrders[num];
            if (array2 == null)
            {
                drawOrder.Clear();
                int i = 0;
                for (int count = slots.Count; i < count; i++)
                {
                    drawOrder.Add(slots.Items[i]);
                }
                return;
            }
            Slot[] items  = drawOrder.Items;
            Slot[] items2 = slots.Items;
            int    j      = 0;

            for (int num2 = array2.Length; j < num2; j++)
            {
                items[j] = items2[array2[j]];
            }
        }
Esempio n. 4
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            TransformConstraint transformConstraint = skeleton.transformConstraints.Items[transformConstraintIndex];

            float[] array = frames;
            if (time < array[0])
            {
                TransformConstraintData data = transformConstraint.data;
                switch (pose)
                {
                case MixPose.Setup:
                    transformConstraint.rotateMix    = data.rotateMix;
                    transformConstraint.translateMix = data.translateMix;
                    transformConstraint.scaleMix     = data.scaleMix;
                    transformConstraint.shearMix     = data.shearMix;
                    break;

                case MixPose.Current:
                    transformConstraint.rotateMix    += (data.rotateMix - transformConstraint.rotateMix) * alpha;
                    transformConstraint.translateMix += (data.translateMix - transformConstraint.translateMix) * alpha;
                    transformConstraint.scaleMix     += (data.scaleMix - transformConstraint.scaleMix) * alpha;
                    transformConstraint.shearMix     += (data.shearMix - transformConstraint.shearMix) * alpha;
                    break;
                }
                return;
            }
            float num2;
            float num3;
            float num4;
            float num5;

            if (time >= array[array.Length - 5])
            {
                int num = array.Length;
                num2 = array[num + -4];
                num3 = array[num + -3];
                num4 = array[num + -2];
                num5 = array[num + -1];
            }
            else
            {
                int num6 = Animation.BinarySearch(array, time, 5);
                num2 = array[num6 + -4];
                num3 = array[num6 + -3];
                num4 = array[num6 + -2];
                num5 = array[num6 + -1];
                float num7         = array[num6];
                float curvePercent = GetCurvePercent(num6 / 5 - 1, 1f - (time - num7) / (array[num6 + -5] - num7));
                num2 += (array[num6 + 1] - num2) * curvePercent;
                num3 += (array[num6 + 2] - num3) * curvePercent;
                num4 += (array[num6 + 3] - num4) * curvePercent;
                num5 += (array[num6 + 4] - num5) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                TransformConstraintData data2 = transformConstraint.data;
                transformConstraint.rotateMix    = data2.rotateMix + (num2 - data2.rotateMix) * alpha;
                transformConstraint.translateMix = data2.translateMix + (num3 - data2.translateMix) * alpha;
                transformConstraint.scaleMix     = data2.scaleMix + (num4 - data2.scaleMix) * alpha;
                transformConstraint.shearMix     = data2.shearMix + (num5 - data2.shearMix) * alpha;
            }
            else
            {
                transformConstraint.rotateMix    += (num2 - transformConstraint.rotateMix) * alpha;
                transformConstraint.translateMix += (num3 - transformConstraint.translateMix) * alpha;
                transformConstraint.scaleMix     += (num4 - transformConstraint.scaleMix) * alpha;
                transformConstraint.shearMix     += (num5 - transformConstraint.shearMix) * alpha;
            }
        }
Esempio n. 5
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot slot = skeleton.slots.Items[slotIndex];

            float[] array = frames;
            if (time < array[0])
            {
                SlotData data = slot.data;
                switch (pose)
                {
                case MixPose.Setup:
                    slot.r = data.r;
                    slot.g = data.g;
                    slot.b = data.b;
                    slot.a = data.a;
                    break;

                case MixPose.Current:
                    slot.r += (slot.r - data.r) * alpha;
                    slot.g += (slot.g - data.g) * alpha;
                    slot.b += (slot.b - data.b) * alpha;
                    slot.a += (slot.a - data.a) * alpha;
                    break;
                }
                return;
            }
            float num2;
            float num3;
            float num4;
            float num5;

            if (time >= array[array.Length - 5])
            {
                int num = array.Length;
                num2 = array[num + -4];
                num3 = array[num + -3];
                num4 = array[num + -2];
                num5 = array[num + -1];
            }
            else
            {
                int num6 = Animation.BinarySearch(array, time, 5);
                num2 = array[num6 + -4];
                num3 = array[num6 + -3];
                num4 = array[num6 + -2];
                num5 = array[num6 + -1];
                float num7         = array[num6];
                float curvePercent = GetCurvePercent(num6 / 5 - 1, 1f - (time - num7) / (array[num6 + -5] - num7));
                num2 += (array[num6 + 1] - num2) * curvePercent;
                num3 += (array[num6 + 2] - num3) * curvePercent;
                num4 += (array[num6 + 3] - num4) * curvePercent;
                num5 += (array[num6 + 4] - num5) * curvePercent;
            }
            if (alpha == 1f)
            {
                slot.r = num2;
                slot.g = num3;
                slot.b = num4;
                slot.a = num5;
                return;
            }
            float r;
            float g;
            float b;
            float a;

            if (pose == MixPose.Setup)
            {
                r = slot.data.r;
                g = slot.data.g;
                b = slot.data.b;
                a = slot.data.a;
            }
            else
            {
                r = slot.r;
                g = slot.g;
                b = slot.b;
                a = slot.a;
            }
            slot.r = r + (num2 - r) * alpha;
            slot.g = g + (num3 - g) * alpha;
            slot.b = b + (num4 - b) * alpha;
            slot.a = a + (num5 - a) * alpha;
        }
Esempio n. 6
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            PathConstraint pathConstraint = skeleton.pathConstraints.Items[pathConstraintIndex];

            float[] frames = base.frames;
            if (time < frames[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    pathConstraint.spacing = pathConstraint.data.spacing;
                    break;

                case MixPose.Current:
                    pathConstraint.spacing += (pathConstraint.data.spacing - pathConstraint.spacing) * alpha;
                    break;
                }
                return;
            }
            float num;

            if (time >= frames[frames.Length - 2])
            {
                num = frames[frames.Length + -1];
            }
            else
            {
                int num2 = Animation.BinarySearch(frames, time, 2);
                num = frames[num2 + -1];
                float num3         = frames[num2];
                float curvePercent = GetCurvePercent(num2 / 2 - 1, 1f - (time - num3) / (frames[num2 + -2] - num3));
                num += (frames[num2 + 1] - num) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                pathConstraint.spacing = pathConstraint.data.spacing + (num - pathConstraint.data.spacing) * alpha;
            }
            else
            {
                pathConstraint.spacing += (num - pathConstraint.spacing) * alpha;
            }
        }
Esempio n. 7
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            IkConstraint constraint = skeleton.ikConstraints.Items[this.ikConstraintIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    constraint.mix           = constraint.data.mix;
                    constraint.bendDirection = constraint.data.bendDirection;
                    return;
                }
                constraint.mix          += (constraint.data.mix - constraint.mix) * alpha;
                constraint.bendDirection = constraint.data.bendDirection;
            }
            else if (time >= frames[frames.Length - 3])
            {
                if (pose == MixPose.Setup)
                {
                    constraint.mix           = constraint.data.mix + ((frames[frames.Length + -2] - constraint.data.mix) * alpha);
                    constraint.bendDirection = (direction != MixDirection.Out) ? ((int)frames[frames.Length + -1]) : constraint.data.bendDirection;
                }
                else
                {
                    constraint.mix += (frames[frames.Length + -2] - constraint.mix) * alpha;
                    if (direction == MixDirection.In)
                    {
                        constraint.bendDirection = (int)frames[frames.Length + -1];
                    }
                }
            }
            else
            {
                int   index        = Animation.BinarySearch(frames, time, 3);
                float num2         = frames[index + -2];
                float num3         = frames[index];
                float curvePercent = base.GetCurvePercent((index / 3) - 1, 1f - ((time - num3) / (frames[index + -3] - num3)));
                if (pose == MixPose.Setup)
                {
                    constraint.mix           = constraint.data.mix + (((num2 + ((frames[index + 1] - num2) * curvePercent)) - constraint.data.mix) * alpha);
                    constraint.bendDirection = (direction != MixDirection.Out) ? ((int)frames[index + -1]) : constraint.data.bendDirection;
                }
                else
                {
                    constraint.mix += ((num2 + ((frames[index + 1] - num2) * curvePercent)) - constraint.mix) * alpha;
                    if (direction == MixDirection.In)
                    {
                        constraint.bendDirection = (int)frames[index + -1];
                    }
                }
            }
        }
Esempio n. 8
0
 public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
 {
     if (firedEvents != null)
     {
         float[] frames = this.frames;
         int     length = frames.Length;
         if (lastTime > time)
         {
             this.Apply(skeleton, lastTime, 2.147484E+09f, firedEvents, alpha, pose, direction);
             lastTime = -1f;
         }
         else if (lastTime >= frames[length - 1])
         {
             return;
         }
         if (time >= frames[0])
         {
             int num2;
             if (lastTime < frames[0])
             {
                 num2 = 0;
             }
             else
             {
                 num2 = Animation.BinarySearch(frames, lastTime);
                 float num3 = frames[num2];
                 while (num2 > 0)
                 {
                     if (frames[num2 - 1] != num3)
                     {
                         break;
                     }
                     num2--;
                 }
             }
             while ((num2 < length) && (time >= frames[num2]))
             {
                 firedEvents.Add(this.events[num2]);
                 num2++;
             }
         }
     }
 }
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            ExposedList <Slot> drawOrder = skeleton.drawOrder;
            ExposedList <Slot> slots     = skeleton.slots;

            if ((direction == MixDirection.Out) && (pose == MixPose.Setup))
            {
                Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
            }
            else
            {
                float[] frames = this.frames;
                if (time < frames[0])
                {
                    if (pose == MixPose.Setup)
                    {
                        Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
                    }
                }
                else
                {
                    int num;
                    if (time >= frames[frames.Length - 1])
                    {
                        num = frames.Length - 1;
                    }
                    else
                    {
                        num = Animation.BinarySearch(frames, time) - 1;
                    }
                    int[] numArray2 = this.drawOrders[num];
                    if (numArray2 == null)
                    {
                        drawOrder.Clear(true);
                        int index = 0;
                        int count = slots.Count;
                        while (index < count)
                        {
                            drawOrder.Add(slots.Items[index]);
                            index++;
                        }
                    }
                    else
                    {
                        Slot[] items      = drawOrder.Items;
                        Slot[] slotArray2 = slots.Items;
                        int    index      = 0;
                        int    length     = numArray2.Length;
                        while (index < length)
                        {
                            items[index] = slotArray2[numArray2[index]];
                            index++;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot slot = skeleton.slots.Items[slotIndex];

            if (direction == MixDirection.Out && pose == MixPose.Setup)
            {
                string attachmentName = slot.data.attachmentName;
                slot.Attachment = ((attachmentName != null) ? skeleton.GetAttachment(slotIndex, attachmentName) : null);
                return;
            }
            float[] array = frames;
            if (time < array[0])
            {
                if (pose == MixPose.Setup)
                {
                    string attachmentName = slot.data.attachmentName;
                    slot.Attachment = ((attachmentName != null) ? skeleton.GetAttachment(slotIndex, attachmentName) : null);
                }
            }
            else
            {
                int    num            = (!(time >= array[array.Length - 1])) ? (Animation.BinarySearch(array, time, 1) - 1) : (array.Length - 1);
                string attachmentName = attachmentNames[num];
                slot.Attachment = ((attachmentName != null) ? skeleton.GetAttachment(slotIndex, attachmentName) : null);
            }
        }
        // NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties.
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            trackBindingSkeletonAnimation = playerData as SkeletonAnimation;
            if (!trackBindingSkeletonAnimation)
            {
                return;
            }

            int inputCount = playable.GetInputCount();

            if (trackBindingSkeleton == null)
            {
                trackBindingSkeleton = trackBindingSkeletonAnimation.Skeleton;
            }

            //trackBindingSkeleton.SetToSetupPose();
            for (int i = 0; i < inputCount; i++)
            {
                var inputPlayable     = (ScriptPlayable <SpineAnimationBehaviour>)playable.GetInput(i); // The clip
                var clipBehaviourData = inputPlayable.GetBehaviour();                                   // the stateless data

                clipBehaviourData.EnsureInitialize(trackBindingSkeleton.Data);
                var animation = clipBehaviourData.animation;
                if (animation != null)
                {
                    animation.SetKeyedItemsToSetupPose(trackBindingSkeleton);
                }
            }

            float totalWeight   = 0f;
            int   currentInputs = 0;

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight       = playable.GetInputWeight(i);
                var   inputPlayable     = (ScriptPlayable <SpineAnimationBehaviour>)playable.GetInput(i); // The clip
                var   clipBehaviourData = inputPlayable.GetBehaviour();                                   // the stateless data

                float time = (float)inputPlayable.GetTime();                                              // clip time.

                totalWeight += inputWeight;
//				clipBehaviourData.EnsureInitialize(trackBindingSkeleton.Data);
                var animation = clipBehaviourData.animation;
                if (animation != null)
                {
                    if (!Mathf.Approximately(inputWeight, 0f))
                    {
                        MixPose      mixPose      = currentInputs == 0 ? MixPose.Setup : MixPose.Current;
                        MixDirection mixDirection = MixDirection.In;

                        if (inputWeight < 1 && currentInputs > 1)
                        {
                            mixDirection = MixDirection.Out;
                        }

                        animation.Apply(trackBindingSkeleton, 0f, time, clipBehaviourData.loop, null, inputWeight, mixPose, mixDirection);
                        Debug.LogFormat("Applying {0} at {1} as input [{2}] using {3} {4}", animation.Name, inputWeight, i, mixPose, mixDirection);

                        currentInputs++;
                    }
                    else
                    {
                        //animation.Apply(trackBindingSkeleton, 0f, time, clipBehaviourData.loop, null, 0, MixPose.Current, MixDirection.Out);
                        continue;
                    }
                }
                // SPINETODO: Translate AnimationState into MixerBehaviour for robustness.
            }
        }
Esempio n. 12
0
        public void Apply(Skeleton skeleton, float lastTime, float time, bool loop, ExposedList <Event> events, float alpha, MixPose pose, MixDirection direction)
        {
            if (skeleton == null)
            {
                throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
            }
            if (loop && (this.duration != 0f))
            {
                time = time % this.duration;
                if (lastTime > 0f)
                {
                    lastTime = lastTime % this.duration;
                }
            }
            ExposedList <Timeline> timelines = this.timelines;
            int index = 0;
            int count = timelines.Count;

            while (index < count)
            {
                timelines.Items[index].Apply(skeleton, lastTime, time, events, alpha, pose, direction);
                index++;
            }
        }
Esempio n. 13
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[boneIndex];

            float[] frames = base.frames;
            if (time < frames[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    bone.scaleX = bone.data.scaleX;
                    bone.scaleY = bone.data.scaleY;
                    break;

                case MixPose.Current:
                    bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
                    bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
                    break;
                }
                return;
            }
            float num;
            float num2;

            if (time >= frames[frames.Length - 3])
            {
                num  = frames[frames.Length + -2] * bone.data.scaleX;
                num2 = frames[frames.Length + -1] * bone.data.scaleY;
            }
            else
            {
                int num3 = Animation.BinarySearch(frames, time, 3);
                num  = frames[num3 + -2];
                num2 = frames[num3 + -1];
                float num4         = frames[num3];
                float curvePercent = GetCurvePercent(num3 / 3 - 1, 1f - (time - num4) / (frames[num3 + -3] - num4));
                num  = (num + (frames[num3 + 1] - num) * curvePercent) * bone.data.scaleX;
                num2 = (num2 + (frames[num3 + 2] - num2) * curvePercent) * bone.data.scaleY;
            }
            if (alpha == 1f)
            {
                bone.scaleX = num;
                bone.scaleY = num2;
                return;
            }
            float num5;
            float num6;

            if (pose == MixPose.Setup)
            {
                num5 = bone.data.scaleX;
                num6 = bone.data.scaleY;
            }
            else
            {
                num5 = bone.scaleX;
                num6 = bone.scaleY;
            }
            if (direction == MixDirection.Out)
            {
                num  = ((!(num >= 0f)) ? (0f - num) : num) * (float)((num5 >= 0f) ? 1 : (-1));
                num2 = ((!(num2 >= 0f)) ? (0f - num2) : num2) * (float)((num6 >= 0f) ? 1 : (-1));
            }
            else
            {
                num5 = ((!(num5 >= 0f)) ? (0f - num5) : num5) * (float)((num >= 0f) ? 1 : (-1));
                num6 = ((!(num6 >= 0f)) ? (0f - num6) : num6) * (float)((num2 >= 0f) ? 1 : (-1));
            }
            bone.scaleX = num5 + (num - num5) * alpha;
            bone.scaleY = num6 + (num2 - num6) * alpha;
        }
Esempio n. 14
0
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            if (firedEvents == null)
            {
                return;
            }
            float[] array = frames;
            int     num   = array.Length;

            if (lastTime > time)
            {
                Apply(skeleton, lastTime, 2.14748365E+09f, firedEvents, alpha, pose, direction);
                lastTime = -1f;
            }
            else if (lastTime >= array[num - 1])
            {
                return;
            }
            if (time < array[0])
            {
                return;
            }
            int i;

            if (lastTime < array[0])
            {
                i = 0;
            }
            else
            {
                i = Animation.BinarySearch(array, lastTime);
                float num2 = array[i];
                while (i > 0 && array[i - 1] == num2)
                {
                    i--;
                }
            }
            for (; i < num && time >= array[i]; i++)
            {
                firedEvents.Add(events[i]);
            }
        }
Esempio n. 15
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[base.boneIndex];

            float[] frames = base.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    bone.shearX = bone.data.shearX;
                    bone.shearY = bone.data.shearY;
                    return;
                }
                bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
                bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
            }
            else
            {
                float num;
                float num2;
                if (time >= frames[frames.Length - 3])
                {
                    num  = frames[frames.Length + -2];
                    num2 = frames[frames.Length + -1];
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 3);
                    num  = frames[index + -2];
                    num2 = frames[index + -1];
                    float num4         = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 3) - 1, 1f - ((time - num4) / (frames[index + -3] - num4)));
                    num  += (frames[index + 1] - num) * curvePercent;
                    num2 += (frames[index + 2] - num2) * curvePercent;
                }
                if (pose == MixPose.Setup)
                {
                    bone.shearX = bone.data.shearX + (num * alpha);
                    bone.shearY = bone.data.shearY + (num2 * alpha);
                }
                else
                {
                    bone.shearX += ((bone.data.shearX + num) - bone.shearX) * alpha;
                    bone.shearY += ((bone.data.shearY + num2) - bone.shearY) * alpha;
                }
            }
        }
Esempio n. 16
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot slot = skeleton.slots.Items[slotIndex];

            float[] array = frames;
            if (time < array[0])
            {
                SlotData data = slot.data;
                switch (pose)
                {
                case MixPose.Setup:
                    slot.r  = data.r;
                    slot.g  = data.g;
                    slot.b  = data.b;
                    slot.a  = data.a;
                    slot.r2 = data.r2;
                    slot.g2 = data.g2;
                    slot.b2 = data.b2;
                    break;

                case MixPose.Current:
                    slot.r  += (slot.r - data.r) * alpha;
                    slot.g  += (slot.g - data.g) * alpha;
                    slot.b  += (slot.b - data.b) * alpha;
                    slot.a  += (slot.a - data.a) * alpha;
                    slot.r2 += (slot.r2 - data.r2) * alpha;
                    slot.g2 += (slot.g2 - data.g2) * alpha;
                    slot.b2 += (slot.b2 - data.b2) * alpha;
                    break;
                }
                return;
            }
            float num2;
            float num3;
            float num4;
            float num5;
            float num6;
            float num7;
            float num8;

            if (time >= array[array.Length - 8])
            {
                int num = array.Length;
                num2 = array[num + -7];
                num3 = array[num + -6];
                num4 = array[num + -5];
                num5 = array[num + -4];
                num6 = array[num + -3];
                num7 = array[num + -2];
                num8 = array[num + -1];
            }
            else
            {
                int num9 = Animation.BinarySearch(array, time, 8);
                num2 = array[num9 + -7];
                num3 = array[num9 + -6];
                num4 = array[num9 + -5];
                num5 = array[num9 + -4];
                num6 = array[num9 + -3];
                num7 = array[num9 + -2];
                num8 = array[num9 + -1];
                float num10        = array[num9];
                float curvePercent = GetCurvePercent(num9 / 8 - 1, 1f - (time - num10) / (array[num9 + -8] - num10));
                num2 += (array[num9 + 1] - num2) * curvePercent;
                num3 += (array[num9 + 2] - num3) * curvePercent;
                num4 += (array[num9 + 3] - num4) * curvePercent;
                num5 += (array[num9 + 4] - num5) * curvePercent;
                num6 += (array[num9 + 5] - num6) * curvePercent;
                num7 += (array[num9 + 6] - num7) * curvePercent;
                num8 += (array[num9 + 7] - num8) * curvePercent;
            }
            if (alpha == 1f)
            {
                slot.r  = num2;
                slot.g  = num3;
                slot.b  = num4;
                slot.a  = num5;
                slot.r2 = num6;
                slot.g2 = num7;
                slot.b2 = num8;
                return;
            }
            float r;
            float g;
            float b;
            float a;
            float r2;
            float g2;
            float b2;

            if (pose == MixPose.Setup)
            {
                r  = slot.data.r;
                g  = slot.data.g;
                b  = slot.data.b;
                a  = slot.data.a;
                r2 = slot.data.r2;
                g2 = slot.data.g2;
                b2 = slot.data.b2;
            }
            else
            {
                r  = slot.r;
                g  = slot.g;
                b  = slot.b;
                a  = slot.a;
                r2 = slot.r2;
                g2 = slot.g2;
                b2 = slot.b2;
            }
            slot.r  = r + (num2 - r) * alpha;
            slot.g  = g + (num3 - g) * alpha;
            slot.b  = b + (num4 - b) * alpha;
            slot.a  = a + (num5 - a) * alpha;
            slot.r2 = r2 + (num6 - r2) * alpha;
            slot.g2 = g2 + (num7 - g2) * alpha;
            slot.b2 = b2 + (num8 - b2) * alpha;
        }
Esempio n. 17
0
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            string attachmentName;
            Slot   slot = skeleton.slots.Items[this.slotIndex];

            if ((direction == MixDirection.Out) && (pose == MixPose.Setup))
            {
                attachmentName  = slot.data.attachmentName;
                slot.Attachment = (attachmentName != null) ? skeleton.GetAttachment(this.slotIndex, attachmentName) : null;
            }
            else
            {
                float[] frames = this.frames;
                if (time < frames[0])
                {
                    if (pose == MixPose.Setup)
                    {
                        attachmentName  = slot.data.attachmentName;
                        slot.Attachment = (attachmentName != null) ? skeleton.GetAttachment(this.slotIndex, attachmentName) : null;
                    }
                }
                else
                {
                    int num;
                    if (time >= frames[frames.Length - 1])
                    {
                        num = frames.Length - 1;
                    }
                    else
                    {
                        num = Animation.BinarySearch(frames, time, 1) - 1;
                    }
                    attachmentName  = this.attachmentNames[num];
                    slot.Attachment = (attachmentName != null) ? skeleton.GetAttachment(this.slotIndex, attachmentName) : null;
                }
            }
        }
Esempio n. 18
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            PathConstraint pathConstraint = skeleton.pathConstraints.Items[pathConstraintIndex];

            float[] array = frames;
            if (time < array[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    pathConstraint.rotateMix    = pathConstraint.data.rotateMix;
                    pathConstraint.translateMix = pathConstraint.data.translateMix;
                    break;

                case MixPose.Current:
                    pathConstraint.rotateMix    += (pathConstraint.data.rotateMix - pathConstraint.rotateMix) * alpha;
                    pathConstraint.translateMix += (pathConstraint.data.translateMix - pathConstraint.translateMix) * alpha;
                    break;
                }
                return;
            }
            float num;
            float num2;

            if (time >= array[array.Length - 3])
            {
                num  = array[array.Length + -2];
                num2 = array[array.Length + -1];
            }
            else
            {
                int num3 = Animation.BinarySearch(array, time, 3);
                num  = array[num3 + -2];
                num2 = array[num3 + -1];
                float num4         = array[num3];
                float curvePercent = GetCurvePercent(num3 / 3 - 1, 1f - (time - num4) / (array[num3 + -3] - num4));
                num  += (array[num3 + 1] - num) * curvePercent;
                num2 += (array[num3 + 2] - num2) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                pathConstraint.rotateMix    = pathConstraint.data.rotateMix + (num - pathConstraint.data.rotateMix) * alpha;
                pathConstraint.translateMix = pathConstraint.data.translateMix + (num2 - pathConstraint.data.translateMix) * alpha;
            }
            else
            {
                pathConstraint.rotateMix    += (num - pathConstraint.rotateMix) * alpha;
                pathConstraint.translateMix += (num2 - pathConstraint.translateMix) * alpha;
            }
        }
Esempio n. 19
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot             slot       = skeleton.slots.Items[this.slotIndex];
            VertexAttachment attachment = slot.attachment as VertexAttachment;

            if ((attachment != null) && attachment.ApplyDeform(this.attachment))
            {
                float[]             items;
                ExposedList <float> attachmentVertices = slot.attachmentVertices;
                if (attachmentVertices.Count == 0)
                {
                    alpha = 1f;
                }
                float[][] frameVertices = this.frameVertices;
                int       length        = frameVertices[0].Length;
                float[]   frames        = this.frames;
                if (time < frames[0])
                {
                    if (pose != MixPose.Setup)
                    {
                        if (pose != MixPose.Current)
                        {
                            return;
                        }
                    }
                    else
                    {
                        attachmentVertices.Clear(true);
                        return;
                    }
                    if (alpha == 1f)
                    {
                        attachmentVertices.Clear(true);
                    }
                    else
                    {
                        if (attachmentVertices.Capacity < length)
                        {
                            attachmentVertices.Capacity = length;
                        }
                        attachmentVertices.Count = length;
                        items = attachmentVertices.Items;
                        if (attachment.bones == null)
                        {
                            float[] vertices = attachment.vertices;
                            for (int i = 0; i < length; i++)
                            {
                                items[i] += (vertices[i] - items[i]) * alpha;
                            }
                        }
                        else
                        {
                            alpha = 1f - alpha;
                            for (int i = 0; i < length; i++)
                            {
                                items[i] *= alpha;
                            }
                        }
                    }
                }
                else
                {
                    if (attachmentVertices.Capacity < length)
                    {
                        attachmentVertices.Capacity = length;
                    }
                    attachmentVertices.Count = length;
                    items = attachmentVertices.Items;
                    if (time >= frames[frames.Length - 1])
                    {
                        float[] sourceArray = frameVertices[frames.Length - 1];
                        if (alpha == 1f)
                        {
                            Array.Copy(sourceArray, 0, items, 0, length);
                        }
                        else if (pose == MixPose.Setup)
                        {
                            if (attachment.bones == null)
                            {
                                float[] vertices = attachment.vertices;
                                for (int i = 0; i < length; i++)
                                {
                                    float num5 = vertices[i];
                                    items[i] = num5 + ((sourceArray[i] - num5) * alpha);
                                }
                            }
                            else
                            {
                                for (int i = 0; i < length; i++)
                                {
                                    items[i] = sourceArray[i] * alpha;
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < length; i++)
                            {
                                items[i] += (sourceArray[i] - items[i]) * alpha;
                            }
                        }
                    }
                    else
                    {
                        int     index        = Animation.BinarySearch(frames, time);
                        float[] numArray7    = frameVertices[index - 1];
                        float[] numArray8    = frameVertices[index];
                        float   num9         = frames[index];
                        float   curvePercent = base.GetCurvePercent(index - 1, 1f - ((time - num9) / (frames[index - 1] - num9)));
                        if (alpha == 1f)
                        {
                            for (int i = 0; i < length; i++)
                            {
                                float num12 = numArray7[i];
                                items[i] = num12 + ((numArray8[i] - num12) * curvePercent);
                            }
                        }
                        else if (pose == MixPose.Setup)
                        {
                            if (attachment.bones == null)
                            {
                                float[] vertices = attachment.vertices;
                                for (int i = 0; i < length; i++)
                                {
                                    float num14 = numArray7[i];
                                    float num15 = vertices[i];
                                    items[i] = num15 + (((num14 + ((numArray8[i] - num14) * curvePercent)) - num15) * alpha);
                                }
                            }
                            else
                            {
                                for (int i = 0; i < length; i++)
                                {
                                    float num17 = numArray7[i];
                                    items[i] = (num17 + ((numArray8[i] - num17) * curvePercent)) * alpha;
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < length; i++)
                            {
                                float num19 = numArray7[i];
                                items[i] += ((num19 + ((numArray8[i] - num19) * curvePercent)) - items[i]) * alpha;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[boneIndex];

            float[] frames = base.frames;
            if (time < frames[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    bone.shearX = bone.data.shearX;
                    bone.shearY = bone.data.shearY;
                    break;

                case MixPose.Current:
                    bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
                    bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
                    break;
                }
                return;
            }
            float num;
            float num2;

            if (time >= frames[frames.Length - 3])
            {
                num  = frames[frames.Length + -2];
                num2 = frames[frames.Length + -1];
            }
            else
            {
                int num3 = Animation.BinarySearch(frames, time, 3);
                num  = frames[num3 + -2];
                num2 = frames[num3 + -1];
                float num4         = frames[num3];
                float curvePercent = GetCurvePercent(num3 / 3 - 1, 1f - (time - num4) / (frames[num3 + -3] - num4));
                num  += (frames[num3 + 1] - num) * curvePercent;
                num2 += (frames[num3 + 2] - num2) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                bone.shearX = bone.data.shearX + num * alpha;
                bone.shearY = bone.data.shearY + num2 * alpha;
            }
            else
            {
                bone.shearX += (bone.data.shearX + num - bone.shearX) * alpha;
                bone.shearY += (bone.data.shearY + num2 - bone.shearY) * alpha;
            }
        }
Esempio n. 21
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            IkConstraint ikConstraint = skeleton.ikConstraints.Items[ikConstraintIndex];

            float[] array = frames;
            if (time < array[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    ikConstraint.mix           = ikConstraint.data.mix;
                    ikConstraint.bendDirection = ikConstraint.data.bendDirection;
                    break;

                case MixPose.Current:
                    ikConstraint.mix          += (ikConstraint.data.mix - ikConstraint.mix) * alpha;
                    ikConstraint.bendDirection = ikConstraint.data.bendDirection;
                    break;
                }
                return;
            }
            if (time >= array[array.Length - 3])
            {
                if (pose == MixPose.Setup)
                {
                    ikConstraint.mix           = ikConstraint.data.mix + (array[array.Length + -2] - ikConstraint.data.mix) * alpha;
                    ikConstraint.bendDirection = ((direction != MixDirection.Out) ? ((int)array[array.Length + -1]) : ikConstraint.data.bendDirection);
                    return;
                }
                ikConstraint.mix += (array[array.Length + -2] - ikConstraint.mix) * alpha;
                if (direction == MixDirection.In)
                {
                    ikConstraint.bendDirection = (int)array[array.Length + -1];
                }
                return;
            }
            int   num          = Animation.BinarySearch(array, time, 3);
            float num2         = array[num + -2];
            float num3         = array[num];
            float curvePercent = GetCurvePercent(num / 3 - 1, 1f - (time - num3) / (array[num + -3] - num3));

            if (pose == MixPose.Setup)
            {
                ikConstraint.mix           = ikConstraint.data.mix + (num2 + (array[num + 1] - num2) * curvePercent - ikConstraint.data.mix) * alpha;
                ikConstraint.bendDirection = ((direction != MixDirection.Out) ? ((int)array[num + -1]) : ikConstraint.data.bendDirection);
                return;
            }
            ikConstraint.mix += (num2 + (array[num + 1] - num2) * curvePercent - ikConstraint.mix) * alpha;
            if (direction == MixDirection.In)
            {
                ikConstraint.bendDirection = (int)array[num + -1];
            }
        }
Esempio n. 22
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[base.boneIndex];

            float[] frames = base.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    bone.scaleX = bone.data.scaleX;
                    bone.scaleY = bone.data.scaleY;
                    return;
                }
                bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
                bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
            }
            else
            {
                float num;
                float num2;
                if (time >= frames[frames.Length - 3])
                {
                    num  = frames[frames.Length + -2] * bone.data.scaleX;
                    num2 = frames[frames.Length + -1] * bone.data.scaleY;
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 3);
                    num  = frames[index + -2];
                    num2 = frames[index + -1];
                    float num4         = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 3) - 1, 1f - ((time - num4) / (frames[index + -3] - num4)));
                    num  = (num + ((frames[index + 1] - num) * curvePercent)) * bone.data.scaleX;
                    num2 = (num2 + ((frames[index + 2] - num2) * curvePercent)) * bone.data.scaleY;
                }
                if (alpha == 1f)
                {
                    bone.scaleX = num;
                    bone.scaleY = num2;
                }
                else
                {
                    float scaleX;
                    float scaleY;
                    if (pose == MixPose.Setup)
                    {
                        scaleX = bone.data.scaleX;
                        scaleY = bone.data.scaleY;
                    }
                    else
                    {
                        scaleX = bone.scaleX;
                        scaleY = bone.scaleY;
                    }
                    if (direction == MixDirection.Out)
                    {
                        num  = ((num < 0f) ? -num : num) * ((scaleX < 0f) ? ((float)(-1)) : ((float)1));
                        num2 = ((num2 < 0f) ? -num2 : num2) * ((scaleY < 0f) ? ((float)(-1)) : ((float)1));
                    }
                    else
                    {
                        scaleX = ((scaleX < 0f) ? -scaleX : scaleX) * ((num < 0f) ? ((float)(-1)) : ((float)1));
                        scaleY = ((scaleY < 0f) ? -scaleY : scaleY) * ((num2 < 0f) ? ((float)(-1)) : ((float)1));
                    }
                    bone.scaleX = scaleX + ((num - scaleX) * alpha);
                    bone.scaleY = scaleY + ((num2 - scaleY) * alpha);
                }
            }
        }
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            PathConstraint constraint = skeleton.pathConstraints.Items[this.pathConstraintIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    constraint.position = constraint.data.position;
                    return;
                }
                constraint.position += (constraint.data.position - constraint.position) * alpha;
            }
            else
            {
                float num;
                if (time >= frames[frames.Length - 2])
                {
                    num = frames[frames.Length + -1];
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 2);
                    num = frames[index + -1];
                    float num3         = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 2) - 1, 1f - ((time - num3) / (frames[index + -2] - num3)));
                    num += (frames[index + 1] - num) * curvePercent;
                }
                if (pose == MixPose.Setup)
                {
                    constraint.position = constraint.data.position + ((num - constraint.data.position) * alpha);
                }
                else
                {
                    constraint.position += (num - constraint.position) * alpha;
                }
            }
        }
Esempio n. 24
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Bone bone = skeleton.bones.Items[boneIndex];

            float[] array = frames;
            if (time < array[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                    bone.x = bone.data.x;
                    bone.y = bone.data.y;
                    break;

                case MixPose.Current:
                    bone.x += (bone.data.x - bone.x) * alpha;
                    bone.y += (bone.data.y - bone.y) * alpha;
                    break;
                }
                return;
            }
            float num;
            float num2;

            if (time >= array[array.Length - 3])
            {
                num  = array[array.Length + -2];
                num2 = array[array.Length + -1];
            }
            else
            {
                int num3 = Animation.BinarySearch(array, time, 3);
                num  = array[num3 + -2];
                num2 = array[num3 + -1];
                float num4         = array[num3];
                float curvePercent = GetCurvePercent(num3 / 3 - 1, 1f - (time - num4) / (array[num3 + -3] - num4));
                num  += (array[num3 + 1] - num) * curvePercent;
                num2 += (array[num3 + 2] - num2) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                bone.x = bone.data.x + num * alpha;
                bone.y = bone.data.y + num2 * alpha;
            }
            else
            {
                bone.x += (bone.data.x + num - bone.x) * alpha;
                bone.y += (bone.data.y + num2 - bone.y) * alpha;
            }
        }
Esempio n. 25
0
        public void Apply(Skeleton skeleton, float lastTime, float time, bool loop, ExposedList <Event> events, float alpha, MixPose pose, MixDirection direction)
        {
            if (skeleton == null)
            {
                throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
            }
            if (loop && duration != 0f)
            {
                time %= duration;
                if (lastTime > 0f)
                {
                    lastTime %= duration;
                }
            }
            ExposedList <Timeline> exposedList = timelines;
            int i = 0;

            for (int count = exposedList.Count; i < count; i++)
            {
                exposedList.Items[i].Apply(skeleton, lastTime, time, events, alpha, pose, direction);
            }
        }
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot slot = skeleton.slots.Items[this.slotIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                SlotData data = slot.data;
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    slot.r  = data.r;
                    slot.g  = data.g;
                    slot.b  = data.b;
                    slot.a  = data.a;
                    slot.r2 = data.r2;
                    slot.g2 = data.g2;
                    slot.b2 = data.b2;
                    return;
                }
                slot.r  += (slot.r - data.r) * alpha;
                slot.g  += (slot.g - data.g) * alpha;
                slot.b  += (slot.b - data.b) * alpha;
                slot.a  += (slot.a - data.a) * alpha;
                slot.r2 += (slot.r2 - data.r2) * alpha;
                slot.g2 += (slot.g2 - data.g2) * alpha;
                slot.b2 += (slot.b2 - data.b2) * alpha;
            }
            else
            {
                float num;
                float num2;
                float num3;
                float num4;
                float num5;
                float num6;
                float num7;
                if (time >= frames[frames.Length - 8])
                {
                    int length = frames.Length;
                    num  = frames[length + -7];
                    num2 = frames[length + -6];
                    num3 = frames[length + -5];
                    num4 = frames[length + -4];
                    num5 = frames[length + -3];
                    num6 = frames[length + -2];
                    num7 = frames[length + -1];
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 8);
                    num  = frames[index + -7];
                    num2 = frames[index + -6];
                    num3 = frames[index + -5];
                    num4 = frames[index + -4];
                    num5 = frames[index + -3];
                    num6 = frames[index + -2];
                    num7 = frames[index + -1];
                    float num10        = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 8) - 1, 1f - ((time - num10) / (frames[index + -8] - num10)));
                    num  += (frames[index + 1] - num) * curvePercent;
                    num2 += (frames[index + 2] - num2) * curvePercent;
                    num3 += (frames[index + 3] - num3) * curvePercent;
                    num4 += (frames[index + 4] - num4) * curvePercent;
                    num5 += (frames[index + 5] - num5) * curvePercent;
                    num6 += (frames[index + 6] - num6) * curvePercent;
                    num7 += (frames[index + 7] - num7) * curvePercent;
                }
                if (alpha == 1f)
                {
                    slot.r  = num;
                    slot.g  = num2;
                    slot.b  = num3;
                    slot.a  = num4;
                    slot.r2 = num5;
                    slot.g2 = num6;
                    slot.b2 = num7;
                }
                else
                {
                    float r;
                    float g;
                    float b;
                    float a;
                    float num16;
                    float num17;
                    float num18;
                    if (pose == MixPose.Setup)
                    {
                        r     = slot.data.r;
                        g     = slot.data.g;
                        b     = slot.data.b;
                        a     = slot.data.a;
                        num16 = slot.data.r2;
                        num17 = slot.data.g2;
                        num18 = slot.data.b2;
                    }
                    else
                    {
                        r     = slot.r;
                        g     = slot.g;
                        b     = slot.b;
                        a     = slot.a;
                        num16 = slot.r2;
                        num17 = slot.g2;
                        num18 = slot.b2;
                    }
                    slot.r  = r + ((num - r) * alpha);
                    slot.g  = g + ((num2 - g) * alpha);
                    slot.b  = b + ((num3 - b) * alpha);
                    slot.a  = a + ((num4 - a) * alpha);
                    slot.r2 = num16 + ((num5 - num16) * alpha);
                    slot.g2 = num17 + ((num6 - num17) * alpha);
                    slot.b2 = num18 + ((num7 - num18) * alpha);
                }
            }
        }
Esempio n. 27
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            TransformConstraint constraint = skeleton.transformConstraints.Items[this.transformConstraintIndex];

            float[] frames = this.frames;
            if (time < frames[0])
            {
                TransformConstraintData data = constraint.data;
                if (pose != MixPose.Setup)
                {
                    if (pose != MixPose.Current)
                    {
                        return;
                    }
                }
                else
                {
                    constraint.rotateMix    = data.rotateMix;
                    constraint.translateMix = data.translateMix;
                    constraint.scaleMix     = data.scaleMix;
                    constraint.shearMix     = data.shearMix;
                    return;
                }
                constraint.rotateMix    += (data.rotateMix - constraint.rotateMix) * alpha;
                constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
                constraint.scaleMix     += (data.scaleMix - constraint.scaleMix) * alpha;
                constraint.shearMix     += (data.shearMix - constraint.shearMix) * alpha;
            }
            else
            {
                float num;
                float num2;
                float num3;
                float num4;
                if (time >= frames[frames.Length - 5])
                {
                    int length = frames.Length;
                    num  = frames[length + -4];
                    num2 = frames[length + -3];
                    num3 = frames[length + -2];
                    num4 = frames[length + -1];
                }
                else
                {
                    int index = Animation.BinarySearch(frames, time, 5);
                    num  = frames[index + -4];
                    num2 = frames[index + -3];
                    num3 = frames[index + -2];
                    num4 = frames[index + -1];
                    float num7         = frames[index];
                    float curvePercent = base.GetCurvePercent((index / 5) - 1, 1f - ((time - num7) / (frames[index + -5] - num7)));
                    num  += (frames[index + 1] - num) * curvePercent;
                    num2 += (frames[index + 2] - num2) * curvePercent;
                    num3 += (frames[index + 3] - num3) * curvePercent;
                    num4 += (frames[index + 4] - num4) * curvePercent;
                }
                if (pose == MixPose.Setup)
                {
                    TransformConstraintData data = constraint.data;
                    constraint.rotateMix    = data.rotateMix + ((num - data.rotateMix) * alpha);
                    constraint.translateMix = data.translateMix + ((num2 - data.translateMix) * alpha);
                    constraint.scaleMix     = data.scaleMix + ((num3 - data.scaleMix) * alpha);
                    constraint.shearMix     = data.shearMix + ((num4 - data.shearMix) * alpha);
                }
                else
                {
                    constraint.rotateMix    += (num - constraint.rotateMix) * alpha;
                    constraint.translateMix += (num2 - constraint.translateMix) * alpha;
                    constraint.scaleMix     += (num3 - constraint.scaleMix) * alpha;
                    constraint.shearMix     += (num4 - constraint.shearMix) * alpha;
                }
            }
        }
Esempio n. 28
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            Slot             slot             = skeleton.slots.Items[slotIndex];
            VertexAttachment vertexAttachment = slot.attachment as VertexAttachment;

            if (vertexAttachment == null || !vertexAttachment.ApplyDeform(attachment))
            {
                return;
            }
            ExposedList <float> attachmentVertices = slot.attachmentVertices;

            float[][] array = frameVertices;
            int       num   = array[0].Length;

            if (attachmentVertices.Capacity < num)
            {
                attachmentVertices.Capacity = num;
            }
            attachmentVertices.Count = num;
            float[] items  = attachmentVertices.Items;
            float[] array2 = frames;
            if (time < array2[0])
            {
                switch (pose)
                {
                case MixPose.Setup:
                {
                    float[] array3;
                    if (vertexAttachment.bones == null)
                    {
                        array3 = vertexAttachment.vertices;
                    }
                    else
                    {
                        array3 = zeros;
                        if (array3.Length < num)
                        {
                            array3 = (zeros = new float[num]);
                        }
                    }
                    Array.Copy(array3, 0, items, 0, num);
                    break;
                }

                case MixPose.Current:
                    if (alpha == 1f)
                    {
                        break;
                    }
                    if (vertexAttachment.bones == null)
                    {
                        float[] vertices = vertexAttachment.vertices;
                        for (int i = 0; i < num; i++)
                        {
                            items[i] += (vertices[i] - items[i]) * alpha;
                        }
                    }
                    else
                    {
                        alpha = 1f - alpha;
                        for (int j = 0; j < num; j++)
                        {
                            items[j] *= alpha;
                        }
                    }
                    break;
                }
                return;
            }
            if (time >= array2[array2.Length - 1])
            {
                float[] array4 = array[array2.Length - 1];
                if (alpha == 1f)
                {
                    Array.Copy(array4, 0, items, 0, num);
                }
                else if (pose == MixPose.Setup)
                {
                    if (vertexAttachment.bones == null)
                    {
                        float[] vertices2 = vertexAttachment.vertices;
                        for (int k = 0; k < num; k++)
                        {
                            float num2 = vertices2[k];
                            items[k] = num2 + (array4[k] - num2) * alpha;
                        }
                    }
                    else
                    {
                        for (int l = 0; l < num; l++)
                        {
                            items[l] = array4[l] * alpha;
                        }
                    }
                }
                else
                {
                    for (int m = 0; m < num; m++)
                    {
                        items[m] += (array4[m] - items[m]) * alpha;
                    }
                }
                return;
            }
            int num3 = Animation.BinarySearch(array2, time);

            float[] array5       = array[num3 - 1];
            float[] array6       = array[num3];
            float   num4         = array2[num3];
            float   curvePercent = GetCurvePercent(num3 - 1, 1f - (time - num4) / (array2[num3 - 1] - num4));

            if (alpha == 1f)
            {
                for (int n = 0; n < num; n++)
                {
                    float num5 = array5[n];
                    items[n] = num5 + (array6[n] - num5) * curvePercent;
                }
            }
            else if (pose == MixPose.Setup)
            {
                if (vertexAttachment.bones == null)
                {
                    float[] vertices3 = vertexAttachment.vertices;
                    for (int num6 = 0; num6 < num; num6++)
                    {
                        float num7 = array5[num6];
                        float num8 = vertices3[num6];
                        items[num6] = num8 + (num7 + (array6[num6] - num7) * curvePercent - num8) * alpha;
                    }
                }
                else
                {
                    for (int num9 = 0; num9 < num; num9++)
                    {
                        float num10 = array5[num9];
                        items[num9] = (num10 + (array6[num9] - num10) * curvePercent) * alpha;
                    }
                }
            }
            else
            {
                for (int num11 = 0; num11 < num; num11++)
                {
                    float num12 = array5[num11];
                    items[num11] += (num12 + (array6[num11] - num12) * curvePercent - items[num11]) * alpha;
                }
            }
        }
Esempio n. 29
0
 public abstract void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction);
Esempio n. 30
0
        /// <summary>Applies the Playable ScriptPlayable(SpineAnimationBehaviour) to a skeleton.</summary>
        /// <returns>The number of actual applied clips (inputs with weight greater than 0) in the current frame.</returns>
        internal int ApplyPlayableFrame(Playable playable, Skeleton skeleton, HashSet <int> frameAppliedProperties, int trackIndex)
        {
            int  inputCount   = playable.GetInputCount();
            bool isUpperTrack = trackIndex > 0;

            // Prepare lastTimes and lastInputWeights array
            if (this.lastTimes == null || this.lastTimes.Length < inputCount)
            {
                this.lastInputWeights = new float[inputCount];
                this.lastTimes        = new float[inputCount];

                for (int i = 0; i < inputCount; i++)
                {
                    this.lastInputWeights[i] = 0f;
                    this.lastTimes[i]        = 0f;
                }
            }

            var lastInputWeights = this.lastInputWeights;
            var lastTimes        = this.lastTimes;
            //var frameAppliedProperties = this.frameAppliedProperties;

            int currentInputs = 0;
            //frameAppliedProperties.Clear();

            // foreach (clip)
            var eventBuffer = this.eventBuffer;

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight       = playable.GetInputWeight(i);
                var   inputPlayableClip = (ScriptPlayable <SpineAnimationBehaviour>)playable.GetInput(i); // The clip. Returns a handle struct.
                SpineAnimationBehaviour clipBehaviourData = inputPlayableClip.GetBehaviour();             // the stateless data

                float clipTime     = (float)inputPlayableClip.GetTime();                                  // stateful: clip time.
                float applyTime    = clipTime;
                float clipLastTime = lastTimes[i];
                //bool backwardsPlayback = clipLastTime > applyTime;

                Animation spineAnimation  = clipBehaviourData.animation;
                bool      loop            = clipBehaviourData.loop;
                var       clipEventBuffer = inputWeight > clipBehaviourData.eventThreshold ? eventBuffer : null;
                bool      skipAttachments = inputWeight < clipBehaviourData.attachmentThreshold;
                bool      skipDrawOrder   = inputWeight < clipBehaviourData.drawOrderThreshold;


                if (spineAnimation != null)
                {
                    //Debug.LogFormat("{0} - {1}", i, animation.name);

                    if (Mathf.Approximately(inputWeight, 0))
                    {
                        if (lastInputWeights[i] > 0)
                        {
                            if (isUpperTrack)
                            {
                                foreach (var spineTimeline in spineAnimation.timelines)
                                {
                                    if (!frameAppliedProperties.Contains(spineTimeline.PropertyId))
                                    {
                                        spineTimeline.Apply(skeleton, 0, 0, null, 0, MixPose.Setup, MixDirection.Out);
                                    }
                                    frameAppliedProperties.Add(spineTimeline.PropertyId);
                                }
                                //Debug.Log("conditionally remove " + spineAnimation.name);
                            }
                            else
                            {
                                spineAnimation.SetKeyedItemsToSetupPose(skeleton);                                 // Animation last apply.
                                //Debug.Log("setkeyeditemstosetuppose " + spineAnimation.name);
                            }

                            inputWeight = 0f;
                        }
                        applyTime = lastTimes[i];
                        // Don't do else if input weight is <= 0. This is part of the Unity reference implementation.
                    }
                    else
                    {
//						if (isUpperTrack) {
//							Debug.Log(trackIndex + " applying " + spineAnimation.name + " " + Time.frameCount + " " + inputWeight);
//						}

                        float duration = spineAnimation.duration;
                        if (loop && duration != 0)
                        {
                            applyTime %= duration;
                            if (clipLastTime > 0)
                            {
                                clipLastTime %= duration;
                            }
                        }

                        // EXPERIMENTAL: Allow first animation to mix-in rather than do a flat Setup Pose override.
                        bool    isFirstOnLowestTrack = !isUpperTrack && i == 0 && (inputCount == 1 || playable.GetInputWeight(1) == 0);
                        MixPose animationPose        = MixPose.Setup;
                        MixPose trackCurrentMixType  = isUpperTrack ? MixPose.CurrentLayered : MixPose.Current;

                        //Animation.Apply();
                        foreach (var spineTimeline in spineAnimation.Timelines)
                        {
                            int pid = spineTimeline.PropertyId;

                            MixPose pose = animationPose;
                            if (isFirstOnLowestTrack)
                            {
                                pose = MixPose.CurrentLayered;
                            }
                            else if (currentInputs > 0 || isUpperTrack)
                            {
                                if (frameAppliedProperties.Contains(pid))
                                {
                                    pose = trackCurrentMixType;
                                }
                            }

                            MixDirection direction = MixDirection.In;
                            if (inputWeight < lastInputWeights[i])
                            {
                                direction = MixDirection.Out;
                            }

                            if (direction == MixDirection.In)
                            {
                                if (skipAttachments && spineTimeline is AttachmentTimeline)
                                {
                                    continue;
                                }
                                if (skipDrawOrder && spineTimeline is DrawOrderTimeline)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (skipAttachments && spineTimeline is AttachmentTimeline)
                                {
                                    pose      = MixPose.Setup;
                                    direction = MixDirection.Out;
                                }
                                if (skipDrawOrder && spineTimeline is DrawOrderTimeline)
                                {
                                    pose      = MixPose.Setup;
                                    direction = MixDirection.Out;
                                }
                            }

//							var rot = spineTimeline as RotateTimeline;
//							if (rot != null) {
//								var bone = skeleton.bones.Items[rot.boneIndex];
//								if (bone.data.name == "rear-upper-arm") {
//									Debug.Log(bone.rotation + " " + pose);
//									Debug.Log(frameAppliedProperties.Contains(pid));
//								}
//							}

                            // TODO: Handle RotateTimeline like AnimationState.
                            spineTimeline.Apply(skeleton, lastTimes[i], applyTime, clipEventBuffer, inputWeight, pose, direction);
                            frameAppliedProperties.Add(spineTimeline.PropertyId);
                        }

                        //Debug.LogFormat("Applying {0} at {1} as input [{2}] using {3} {4}", animation.Name, inputWeight, i, mixPose, mixDirection);

                        currentInputs++;
                    }
                }

                lastInputWeights[i] = inputWeight;
                lastTimes[i]        = applyTime;
            }

            return(currentInputs);
        }