From 5390d40093dbc22c8475a95e453efdf0d7b3decb Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 29 Sep 2013 22:15:25 +0200 Subject: [PATCH] Fixed spine-unity, spine-tk2d. --- spine-csharp/src/SkeletonJson.cs | 2 +- spine-tk2d/Assets/Spine/SkeletonAnimation.cs | 2 +- spine-tk2d/Assets/Spine/SkeletonComponent.cs | 30 ++++++++++++------- .../Spine/SpriteCollectionAttachmentLoader.cs | 8 ++++- spine-unity/Assets/Spine/SkeletonAnimation.cs | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index c3365a156..096c589b1 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -212,7 +212,7 @@ namespace Spine { List values = (List)map["vertices"]; float[] vertices = new float[values.Count]; for (int i = 0, n = values.Count; i < n; i++) - vertices[i] = (float)values[i] * scale; + vertices[i] = (float)values[i] * Scale; boundingBox.Vertices = vertices; } diff --git a/spine-tk2d/Assets/Spine/SkeletonAnimation.cs b/spine-tk2d/Assets/Spine/SkeletonAnimation.cs index 54b5d0e48..35ee6a1d7 100644 --- a/spine-tk2d/Assets/Spine/SkeletonAnimation.cs +++ b/spine-tk2d/Assets/Spine/SkeletonAnimation.cs @@ -56,7 +56,7 @@ public class SkeletonAnimation : SkeletonComponent { TrackEntry entry = state.GetCurrent(0); if (animationName == null || animationName.Length == 0) { if (entry != null && entry.Animation != null) - state.Clear(0); + state.ClearTrack(0); } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { Spine.Animation animation = skeleton.Data.FindAnimation(animationName); if (animation != null) diff --git a/spine-tk2d/Assets/Spine/SkeletonComponent.cs b/spine-tk2d/Assets/Spine/SkeletonComponent.cs index b4e3a7338..808430c08 100644 --- a/spine-tk2d/Assets/Spine/SkeletonComponent.cs +++ b/spine-tk2d/Assets/Spine/SkeletonComponent.cs @@ -72,7 +72,7 @@ public class SkeletonComponent : MonoBehaviour { mesh.name = "Skeleton Mesh"; mesh.hideFlags = HideFlags.HideAndDontSave; mesh.MarkDynamic(); - + vertices = new Vector3[0]; skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false)); @@ -89,10 +89,14 @@ public class SkeletonComponent : MonoBehaviour { } public virtual void Update () { + if (skeletonDataAsset == null) { + Clear(); + return; + } + SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); - // Clear fields if missing information to render. - if (skeletonDataAsset == null || skeletonData == null) { + if (skeletonData == null) { Clear(); return; } @@ -112,7 +116,7 @@ public class SkeletonComponent : MonoBehaviour { RegionAttachment regionAttachment = drawOrder[i].Attachment as RegionAttachment; if (regionAttachment == null) continue; - + // Add submesh when material changes. Material material = (Material)regionAttachment.RendererObject; if (lastMaterial != material && lastMaterial != null) { @@ -163,7 +167,7 @@ public class SkeletonComponent : MonoBehaviour { RegionAttachment regionAttachment = slot.Attachment as RegionAttachment; if (regionAttachment == null) continue; - + regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions); vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0); @@ -193,7 +197,7 @@ public class SkeletonComponent : MonoBehaviour { mesh.uv = uvs; mesh.subMeshCount = submeshMaterials.Count; - for (int i = 0; i < mesh.subMeshCount; ++i) + for (int i = 0, n = mesh.subMeshCount; i < n; ++i) mesh.SetTriangles(submeshIndexes[i], i); if (calculateNormals) { @@ -201,10 +205,11 @@ public class SkeletonComponent : MonoBehaviour { if (calculateTangents) { Vector4[] tangents = this.tangents; int count = mesh.normals.Length; - if (tangents.Length != count) + if (tangents.Length != count) { this.tangents = tangents = new Vector4[count]; - for (int i = 0; i < count; i++) - tangents[i] = new Vector4(1, 0, 0, 1); + for (int i = 0; i < count; i++) + tangents[i] = new Vector4(1, 0, 0, 1); + } mesh.tangents = tangents; } } @@ -230,7 +235,6 @@ public class SkeletonComponent : MonoBehaviour { } else { if (indexes.Length >= indexCount) { // Allow last submesh to have more indices than required. if (submeshFirstVertex[submeshIndex] == vertexIndex) return; - indexCount = indexes.Length; // Update vertices to the end. } else submeshIndexes[submeshIndex] = indexes = new int[indexCount]; } @@ -250,6 +254,12 @@ public class SkeletonComponent : MonoBehaviour { indexes[i + 4] = vertexIndex + 3; indexes[i + 5] = vertexIndex + 1; } + + if (lastSubmesh) { + // Update vertices to the end. + for (int i = indexCount, n = indexes.Length; i < n; i++) + indexes[i] = 0; + } } public virtual void OnEnable () { diff --git a/spine-tk2d/Assets/Spine/SpriteCollectionAttachmentLoader.cs b/spine-tk2d/Assets/Spine/SpriteCollectionAttachmentLoader.cs index 7caa94365..c0cd7b277 100644 --- a/spine-tk2d/Assets/Spine/SpriteCollectionAttachmentLoader.cs +++ b/spine-tk2d/Assets/Spine/SpriteCollectionAttachmentLoader.cs @@ -47,8 +47,14 @@ public class SpriteCollectionAttachmentLoader : AttachmentLoader { } public Attachment NewAttachment (Skin skin, AttachmentType type, String name) { - if (type != AttachmentType.region) + switch (type) { + case AttachmentType.region: + break; + case AttachmentType.boundingbox: + return new BoundingBoxAttachment(name); + default: throw new Exception("Unknown attachment type: " + type); + } // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); diff --git a/spine-unity/Assets/Spine/SkeletonAnimation.cs b/spine-unity/Assets/Spine/SkeletonAnimation.cs index 54b5d0e48..35ee6a1d7 100644 --- a/spine-unity/Assets/Spine/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/SkeletonAnimation.cs @@ -56,7 +56,7 @@ public class SkeletonAnimation : SkeletonComponent { TrackEntry entry = state.GetCurrent(0); if (animationName == null || animationName.Length == 0) { if (entry != null && entry.Animation != null) - state.Clear(0); + state.ClearTrack(0); } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { Spine.Animation animation = skeleton.Data.FindAnimation(animationName); if (animation != null)