ApplyDeform() public method

Returns true if a deform originally applied to the specified attachment should be applied to this attachment.
public ApplyDeform ( VertexAttachment sourceAttachment ) : bool
sourceAttachment VertexAttachment
return bool
Exemplo n.º 1
0
        override public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha)
        {
            Slot             slot           = skeleton.slots.Items[slotIndex];
            VertexAttachment slotAttachment = slot.attachment as VertexAttachment;

            if (slotAttachment == null || !slotAttachment.ApplyDeform(attachment))
            {
                return;
            }

            float[] frames = this.frames;
            if (time < frames[0])
            {
                return;                               // Time is before first frame.
            }
            float[][] frameVertices = this.frameVertices;
            int       vertexCount   = frameVertices[0].Length;

            var verticesArray = slot.attachmentVertices;

            if (verticesArray.Count != vertexCount)
            {
                alpha = 1;                                                 // Don't mix from uninitialized slot vertices.
            }
            // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count.
            if (verticesArray.Capacity < vertexCount)
            {
                verticesArray.Capacity = vertexCount;
            }
            verticesArray.Count = vertexCount;
            float[] vertices = verticesArray.Items;

            if (time >= frames[frames.Length - 1])               // Time is after last frame.
            {
                float[] lastVertices = frameVertices[frames.Length - 1];
                if (alpha < 1)
                {
                    for (int i = 0; i < vertexCount; i++)
                    {
                        float vertex = vertices[i];
                        vertices[i] = vertex + (lastVertices[i] - vertex) * alpha;
                    }
                }
                else
                {
                    Array.Copy(lastVertices, 0, vertices, 0, vertexCount);
                }
                return;
            }

            // Interpolate between the previous frame and the current frame.
            int frame = Animation.binarySearch(frames, time);

            float[] prevVertices = frameVertices[frame - 1];
            float[] nextVertices = frameVertices[frame];
            float   frameTime    = frames[frame];
            float   percent      = GetCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));

            if (alpha < 1)
            {
                for (int i = 0; i < vertexCount; i++)
                {
                    float prev   = prevVertices[i];
                    float vertex = vertices[i];
                    vertices[i] = vertex + (prev + (nextVertices[i] - prev) * percent - vertex) * alpha;
                }
            }
            else
            {
                for (int i = 0; i < vertexCount; i++)
                {
                    float prev = prevVertices[i];
                    vertices[i] = prev + (nextVertices[i] - prev) * percent;
                }
            }
        }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
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;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha)
        {
            Slot             slot             = skeleton.slots.Items[this.slotIndex];
            VertexAttachment vertexAttachment = slot.attachment as VertexAttachment;

            if (vertexAttachment == null || !vertexAttachment.ApplyDeform(this.attachment))
            {
                return;
            }
            float[] array = this.frames;
            if (time < array[0])
            {
                return;
            }
            float[][]           array2             = this.frameVertices;
            int                 num                = array2[0].Length;
            ExposedList <float> attachmentVertices = slot.attachmentVertices;

            if (attachmentVertices.Count != num)
            {
                alpha = 1f;
            }
            if (attachmentVertices.Capacity < num)
            {
                attachmentVertices.Capacity = num;
            }
            attachmentVertices.Count = num;
            float[] items = attachmentVertices.Items;
            if (time >= array[array.Length - 1])
            {
                float[] array3 = array2[array.Length - 1];
                if (alpha < 1f)
                {
                    for (int i = 0; i < num; i++)
                    {
                        float num2 = items[i];
                        items[i] = num2 + (array3[i] - num2) * alpha;
                    }
                }
                else
                {
                    Array.Copy(array3, 0, items, 0, num);
                }
                return;
            }
            int num3 = Animation.binarySearch(array, time);

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

            if (alpha < 1f)
            {
                for (int j = 0; j < num; j++)
                {
                    float num5 = array4[j];
                    float num6 = items[j];
                    items[j] = num6 + (num5 + (array5[j] - num5) * curvePercent - num6) * alpha;
                }
            }
            else
            {
                for (int k = 0; k < num; k++)
                {
                    float num7 = array4[k];
                    items[k] = num7 + (array5[k] - num7) * curvePercent;
                }
            }
        }