From 9deb3be61c855e4dcd14d53751a9bfdd7d890cf4 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 19 Mar 2019 17:16:57 +0100 Subject: [PATCH] [csharp] Ported AnimationState and Animation changes of commit bd306d4. See #1303. --- spine-csharp/src/Animation.cs | 64 +++++++++---------- .../src/Attachments/VertexAttachment.cs | 13 +++- spine-csharp/src/Slot.cs | 15 +++-- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index d47588324..cd174da92 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -987,7 +987,7 @@ namespace Spine { } } - /// Changes a slot's to deform a . + /// Changes a slot's to deform a . public class DeformTimeline : CurveTimeline, ISlotTimeline { internal int slotIndex; internal VertexAttachment attachment; @@ -1037,41 +1037,41 @@ namespace Spine { VertexAttachment vertexAttachment = slot.attachment as VertexAttachment; if (vertexAttachment == null || !vertexAttachment.ApplyDeform(attachment)) return; - var verticesArray = slot.attachmentVertices; - if (verticesArray.Count == 0) blend = MixBlend.Setup; + var deformArray = slot.Deform; + if (deformArray.Count == 0) blend = MixBlend.Setup; float[][] frameVertices = this.frameVertices; int vertexCount = frameVertices[0].Length; float[] frames = this.frames; - float[] vertices; + float[] deform; if (time < frames[0]) { // Time is before first frame. switch (blend) { case MixBlend.Setup: - verticesArray.Clear(); + deformArray.Clear(); return; case MixBlend.Replace: if (alpha == 1) { - verticesArray.Clear(); + deformArray.Clear(); return; } - // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. - if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; - verticesArray.Count = vertexCount; - vertices = verticesArray.Items; + // deformArray.SetSize(vertexCount) // Ensure size and preemptively set count. + if (deformArray.Capacity < vertexCount) deformArray.Capacity = vertexCount; + deformArray.Count = vertexCount; + deform = deformArray.Items; if (vertexAttachment.bones == null) { // Unweighted vertex positions. float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) - vertices[i] += (setupVertices[i] - vertices[i]) * alpha; + deform[i] += (setupVertices[i] - deform[i]) * alpha; } else { // Weighted deform offsets. alpha = 1 - alpha; for (int i = 0; i < vertexCount; i++) - vertices[i] *= alpha; + deform[i] *= alpha; } return; default: @@ -1080,10 +1080,10 @@ namespace Spine { } - // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. - if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; - verticesArray.Count = vertexCount; - vertices = verticesArray.Items; + // deformArray.SetSize(vertexCount) // Ensure size and preemptively set count. + if (deformArray.Capacity < vertexCount) deformArray.Capacity = vertexCount; + deformArray.Count = vertexCount; + deform = deformArray.Items; if (time >= frames[frames.Length - 1]) { // Time is after last frame. @@ -1094,15 +1094,15 @@ namespace Spine { // Unweighted vertex positions, no alpha. float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) - vertices[i] += lastVertices[i] - setupVertices[i]; + deform[i] += lastVertices[i] - setupVertices[i]; } else { // Weighted deform offsets, no alpha. for (int i = 0; i < vertexCount; i++) - vertices[i] += lastVertices[i]; + deform[i] += lastVertices[i]; } } else { // Vertex positions or deform offsets, no alpha. - Array.Copy(lastVertices, 0, vertices, 0, vertexCount); + Array.Copy(lastVertices, 0, deform, 0, vertexCount); } } else { switch (blend) { @@ -1112,12 +1112,12 @@ namespace Spine { float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) { float setup = setupVertices[i]; - vertices[i] = setup + (lastVertices[i] - setup) * alpha; + deform[i] = setup + (lastVertices[i] - setup) * alpha; } } else { // Weighted deform offsets, with alpha. for (int i = 0; i < vertexCount; i++) - vertices[i] = lastVertices[i] * alpha; + deform[i] = lastVertices[i] * alpha; } break; } @@ -1125,18 +1125,18 @@ namespace Spine { case MixBlend.Replace: // Vertex positions or deform offsets, with alpha. for (int i = 0; i < vertexCount; i++) - vertices[i] += (lastVertices[i] - vertices[i]) * alpha; + deform[i] += (lastVertices[i] - deform[i]) * alpha; break; case MixBlend.Add: if (vertexAttachment.bones == null) { // Unweighted vertex positions, no alpha. float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) - vertices[i] += (lastVertices[i] - setupVertices[i]) * alpha; + deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; } else { // Weighted deform offsets, alpha. for (int i = 0; i < vertexCount; i++) - vertices[i] += lastVertices[i] * alpha; + deform[i] += lastVertices[i] * alpha; } break; } @@ -1158,20 +1158,20 @@ namespace Spine { float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; + deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; } } else { // Weighted deform offsets, no alpha. for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] += prev + (nextVertices[i] - prev) * percent; + deform[i] += prev + (nextVertices[i] - prev) * percent; } } } else { // Vertex positions or deform offsets, no alpha. for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] = prev + (nextVertices[i] - prev) * percent; + deform[i] = prev + (nextVertices[i] - prev) * percent; } } } else { @@ -1182,13 +1182,13 @@ namespace Spine { float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i], setup = setupVertices[i]; - vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; + deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; } } else { // Weighted deform offsets, with alpha. for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; + deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; } } break; @@ -1198,7 +1198,7 @@ namespace Spine { // Vertex positions or deform offsets, with alpha. for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; + deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha; } break; } @@ -1208,13 +1208,13 @@ namespace Spine { float[] setupVertices = vertexAttachment.vertices; for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; + deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; } } else { // Weighted deform offsets, with alpha. for (int i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; + deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; } } break; diff --git a/spine-csharp/src/Attachments/VertexAttachment.cs b/spine-csharp/src/Attachments/VertexAttachment.cs index 16b9b0e45..09b9d2b69 100644 --- a/spine-csharp/src/Attachments/VertexAttachment.cs +++ b/spine-csharp/src/Attachments/VertexAttachment.cs @@ -31,7 +31,8 @@ using System; namespace Spine { - /// >An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. + /// >An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's + /// . public class VertexAttachment : Attachment { static int nextID = 0; static readonly Object nextIdLock = new Object(); @@ -59,7 +60,13 @@ namespace Spine { ComputeWorldVertices(slot, 0, worldVerticesLength, worldVertices, 0); } - /// Transforms local vertices to world coordinates. + /// + /// Transforms the attachment's local to world coordinates. If the slot has , + /// they are used to deform the vertices. + /// + /// See World transforms in the Spine + /// Runtimes Guide. + /// /// The index of the first value to transform. Each vertex has 2 values, x and y. /// The number of world vertex values to output. Must be less than or equal to - start. /// The output world vertices. Must have a length greater than or equal to + . @@ -68,7 +75,7 @@ namespace Spine { public void ComputeWorldVertices (Slot slot, int start, int count, float[] worldVertices, int offset, int stride = 2) { count = offset + (count >> 1) * stride; Skeleton skeleton = slot.bone.skeleton; - var deformArray = slot.attachmentVertices; + var deformArray = slot.deform; float[] vertices = this.vertices; int[] bones = this.bones; if (bones == null) { diff --git a/spine-csharp/src/Slot.cs b/spine-csharp/src/Slot.cs index 52660d06a..7cbda1da4 100644 --- a/spine-csharp/src/Slot.cs +++ b/spine-csharp/src/Slot.cs @@ -45,7 +45,7 @@ namespace Spine { internal bool hasSecondColor; internal Attachment attachment; internal float attachmentTime; - internal ExposedList attachmentVertices = new ExposedList(); + internal ExposedList deform = new ExposedList(); public Slot (SlotData data, Bone bone) { if (data == null) throw new ArgumentNullException("data", "data cannot be null."); @@ -84,6 +84,7 @@ namespace Spine { attachment = slot.attachment; attachmentTime = slot.attachmentTime; + deform.AddRange(slot.deform); } /// The slot's setup pose data. @@ -128,7 +129,7 @@ namespace Spine { if (attachment == value) return; attachment = value; attachmentTime = bone.skeleton.time; - attachmentVertices .Clear(false); + deform.Clear(false); } } @@ -139,17 +140,17 @@ namespace Spine { set { attachmentTime = bone.skeleton.time - value; } } - /// Vertices to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a + /// Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a /// weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions. /// /// See and . - public ExposedList AttachmentVertices { + public ExposedList Deform { get { - return attachmentVertices ; + return deform; } set { - if (attachmentVertices == null) throw new ArgumentNullException("attachmentVertices", "attachmentVertices cannot be null."); - attachmentVertices = value; + if (deform == null) throw new ArgumentNullException("deform", "deform cannot be null."); + deform = value; } }