Fixed spine-unity, spine-tk2d.

This commit is contained in:
NathanSweet 2013-09-29 22:15:25 +02:00
parent 8e4f1e5f49
commit 5390d40093
5 changed files with 30 additions and 14 deletions

View File

@ -212,7 +212,7 @@ namespace Spine {
List<Object> values = (List<Object>)map["vertices"]; List<Object> values = (List<Object>)map["vertices"];
float[] vertices = new float[values.Count]; float[] vertices = new float[values.Count];
for (int i = 0, n = values.Count; i < n; i++) 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; boundingBox.Vertices = vertices;
} }

View File

@ -56,7 +56,7 @@ public class SkeletonAnimation : SkeletonComponent {
TrackEntry entry = state.GetCurrent(0); TrackEntry entry = state.GetCurrent(0);
if (animationName == null || animationName.Length == 0) { if (animationName == null || animationName.Length == 0) {
if (entry != null && entry.Animation != null) if (entry != null && entry.Animation != null)
state.Clear(0); state.ClearTrack(0);
} else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) {
Spine.Animation animation = skeleton.Data.FindAnimation(animationName); Spine.Animation animation = skeleton.Data.FindAnimation(animationName);
if (animation != null) if (animation != null)

View File

@ -72,7 +72,7 @@ public class SkeletonComponent : MonoBehaviour {
mesh.name = "Skeleton Mesh"; mesh.name = "Skeleton Mesh";
mesh.hideFlags = HideFlags.HideAndDontSave; mesh.hideFlags = HideFlags.HideAndDontSave;
mesh.MarkDynamic(); mesh.MarkDynamic();
vertices = new Vector3[0]; vertices = new Vector3[0];
skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false)); skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false));
@ -89,10 +89,14 @@ public class SkeletonComponent : MonoBehaviour {
} }
public virtual void Update () { public virtual void Update () {
if (skeletonDataAsset == null) {
Clear();
return;
}
SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);
// Clear fields if missing information to render. if (skeletonData == null) {
if (skeletonDataAsset == null || skeletonData == null) {
Clear(); Clear();
return; return;
} }
@ -112,7 +116,7 @@ public class SkeletonComponent : MonoBehaviour {
RegionAttachment regionAttachment = drawOrder[i].Attachment as RegionAttachment; RegionAttachment regionAttachment = drawOrder[i].Attachment as RegionAttachment;
if (regionAttachment == null) if (regionAttachment == null)
continue; continue;
// Add submesh when material changes. // Add submesh when material changes.
Material material = (Material)regionAttachment.RendererObject; Material material = (Material)regionAttachment.RendererObject;
if (lastMaterial != material && lastMaterial != null) { if (lastMaterial != material && lastMaterial != null) {
@ -163,7 +167,7 @@ public class SkeletonComponent : MonoBehaviour {
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment; RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
if (regionAttachment == null) if (regionAttachment == null)
continue; continue;
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions); regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0); vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0);
@ -193,7 +197,7 @@ public class SkeletonComponent : MonoBehaviour {
mesh.uv = uvs; mesh.uv = uvs;
mesh.subMeshCount = submeshMaterials.Count; 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); mesh.SetTriangles(submeshIndexes[i], i);
if (calculateNormals) { if (calculateNormals) {
@ -201,10 +205,11 @@ public class SkeletonComponent : MonoBehaviour {
if (calculateTangents) { if (calculateTangents) {
Vector4[] tangents = this.tangents; Vector4[] tangents = this.tangents;
int count = mesh.normals.Length; int count = mesh.normals.Length;
if (tangents.Length != count) if (tangents.Length != count) {
this.tangents = tangents = new Vector4[count]; this.tangents = tangents = new Vector4[count];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
tangents[i] = new Vector4(1, 0, 0, 1); tangents[i] = new Vector4(1, 0, 0, 1);
}
mesh.tangents = tangents; mesh.tangents = tangents;
} }
} }
@ -230,7 +235,6 @@ public class SkeletonComponent : MonoBehaviour {
} else { } else {
if (indexes.Length >= indexCount) { // Allow last submesh to have more indices than required. if (indexes.Length >= indexCount) { // Allow last submesh to have more indices than required.
if (submeshFirstVertex[submeshIndex] == vertexIndex) return; if (submeshFirstVertex[submeshIndex] == vertexIndex) return;
indexCount = indexes.Length; // Update vertices to the end.
} else } else
submeshIndexes[submeshIndex] = indexes = new int[indexCount]; submeshIndexes[submeshIndex] = indexes = new int[indexCount];
} }
@ -250,6 +254,12 @@ public class SkeletonComponent : MonoBehaviour {
indexes[i + 4] = vertexIndex + 3; indexes[i + 4] = vertexIndex + 3;
indexes[i + 5] = vertexIndex + 1; 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 () { public virtual void OnEnable () {

View File

@ -47,8 +47,14 @@ public class SpriteCollectionAttachmentLoader : AttachmentLoader {
} }
public Attachment NewAttachment (Skin skin, AttachmentType type, String name) { 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); throw new Exception("Unknown attachment type: " + type);
}
// Strip folder names. // Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'}); int index = name.LastIndexOfAny(new char[] {'/', '\\'});

View File

@ -56,7 +56,7 @@ public class SkeletonAnimation : SkeletonComponent {
TrackEntry entry = state.GetCurrent(0); TrackEntry entry = state.GetCurrent(0);
if (animationName == null || animationName.Length == 0) { if (animationName == null || animationName.Length == 0) {
if (entry != null && entry.Animation != null) if (entry != null && entry.Animation != null)
state.Clear(0); state.ClearTrack(0);
} else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) {
Spine.Animation animation = skeleton.Data.FindAnimation(animationName); Spine.Animation animation = skeleton.Data.FindAnimation(animationName);
if (animation != null) if (animation != null)