Spine.VertexAttachment.ApplyDeform C# (CSharp) Method

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
		virtual public bool ApplyDeform (VertexAttachment sourceAttachment) {
			return this == sourceAttachment;
		}			
	}

Usage Example

Esempio 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;
                }
            }
        }
All Usage Examples Of Spine.VertexAttachment::ApplyDeform