From c1c12677bad2353f6471eaa087e2eaccced9427f Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Mon, 28 Apr 2014 16:49:20 +0200 Subject: [PATCH] API improvements. Before I get too many damned runtimes done. ;) --- .../src/Attachments/MeshAttachment.cs | 8 +-- .../src/Attachments/SkinnedMeshAttachment.cs | 9 +-- spine-csharp/src/SkeletonJson.cs | 9 ++- .../spine/SkeletonBinary.java | 9 ++- .../esotericsoftware/spine/SkeletonJson.java | 9 ++- .../spine/attachments/MeshAttachment.java | 33 +++++++---- .../attachments/SkinnedMeshAttachment.java | 58 +++++++++++-------- 7 files changed, 80 insertions(+), 55 deletions(-) diff --git a/spine-csharp/src/Attachments/MeshAttachment.cs b/spine-csharp/src/Attachments/MeshAttachment.cs index bf5d1cf87..d640ff9e8 100644 --- a/spine-csharp/src/Attachments/MeshAttachment.cs +++ b/spine-csharp/src/Attachments/MeshAttachment.cs @@ -72,16 +72,10 @@ namespace Spine { : base(name) { } - public void SetMesh (float[] vertices, int[] triangles, float[] regionUVs) { - this.vertices = vertices; - this.triangles = triangles; - this.regionUVs = regionUVs; - this.uvs = new float[regionUVs.Length]; - } - public void UpdateUVs () { float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV; float[] regionUVs = this.regionUVs; + if (this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length]; float[] uvs = this.uvs; if (RegionRotate) { for (int i = 0, n = uvs.Length; i < n; i += 2) { diff --git a/spine-csharp/src/Attachments/SkinnedMeshAttachment.cs b/spine-csharp/src/Attachments/SkinnedMeshAttachment.cs index cb32cfa54..c685eaa2a 100644 --- a/spine-csharp/src/Attachments/SkinnedMeshAttachment.cs +++ b/spine-csharp/src/Attachments/SkinnedMeshAttachment.cs @@ -75,17 +75,10 @@ namespace Spine { : base(name) { } - public void SetMesh (int[] bones, float[] weights, int[] triangles, float[] regionUVs) { - this.bones = bones; - this.weights = weights; - this.triangles = triangles; - this.regionUVs = regionUVs; - this.uvs = new float[regionUVs.Length]; - } - public void UpdateUVs () { float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV; float[] regionUVs = this.regionUVs; + if (this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length]; float[] uvs = this.uvs; if (RegionRotate) { for (int i = 0, n = uvs.Length; i < n; i += 2) { diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index cd44b4cbb..4face533e 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -223,7 +223,9 @@ namespace Spine { float[] uvs = GetFloatArray(map, "uvs", 1); int[] triangles = GetIntArray(map, "triangles"); float[] vertices = GetFloatArray(map, "vertices", Scale); - mesh.SetMesh(vertices, triangles, uvs); + mesh.vertices = vertices; + mesh.triangles = triangles; + mesh.regionUVs = uvs; mesh.UpdateUVs(); if (map.ContainsKey("color")) { @@ -264,7 +266,10 @@ namespace Spine { i += 4; } } - mesh.SetMesh(bones.ToArray(), weights.ToArray(), triangles, uvs); + mesh.bones = bones.ToArray(); + mesh.weights = weights.ToArray(); + mesh.triangles = triangles; + mesh.regionUVs = uvs; mesh.UpdateUVs(); if (map.ContainsKey("color")) { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index c89892cca..7c9c3ace2 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -229,7 +229,9 @@ public class SkeletonBinary { float[] uvs = readFloatArray(input, 1); short[] triangles = readShortArray(input); float[] vertices = readFloatArray(input, scale); - mesh.setMesh(vertices, triangles, uvs); + mesh.setVertices(vertices); + mesh.setTriangles(triangles); + mesh.setRegionUVs(uvs); mesh.updateUVs(); Color.rgba8888ToColor(mesh.getColor(), input.readInt()); if (nonessential) { @@ -262,7 +264,10 @@ public class SkeletonBinary { weights.add(input.readFloat()); } } - mesh.setMesh(bones.toArray(), weights.toArray(), triangles, uvs); + mesh.setBones(bones.toArray()); + mesh.setWeights(weights.toArray()); + mesh.setTriangles(triangles); + mesh.setRegionUVs(uvs); mesh.updateUVs(); Color.rgba8888ToColor(mesh.getColor(), input.readInt()); if (nonessential) { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index 9c46e066d..ff3a31cb3 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -213,7 +213,9 @@ public class SkeletonJson { for (int i = 0, n = vertices.length; i < n; i++) vertices[i] *= scale; } - mesh.setMesh(vertices, triangles, uvs); + mesh.setVertices(vertices); + mesh.setTriangles(triangles); + mesh.setRegionUVs(uvs); mesh.updateUVs(); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); @@ -243,7 +245,10 @@ public class SkeletonJson { i += 4; } } - mesh.setMesh(bones.toArray(), weights.toArray(), triangles, uvs); + mesh.setBones(bones.toArray()); + mesh.setWeights(weights.toArray()); + mesh.setTriangles(triangles); + mesh.setRegionUVs(uvs); mesh.updateUVs(); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java index 94e59ab3f..ad5ebe422 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java @@ -68,16 +68,11 @@ public class MeshAttachment extends Attachment { return region; } - public void setMesh (float[] vertices, short[] triangles, float[] regionUVs) { - this.vertices = vertices; - this.triangles = triangles; - this.regionUVs = regionUVs; - - int worldVerticesLength = vertices.length / 2 * 5; - if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength]; - } - public void updateUVs () { + int verticesLength = vertices.length; + int worldVerticesLength = verticesLength / 2 * 5; + if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength]; + float u, v, width, height; if (region == null) { u = v = 0; @@ -90,12 +85,12 @@ public class MeshAttachment extends Attachment { } float[] regionUVs = this.regionUVs; if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { - for (int i = 0, w = 3, n = vertices.length; i < n; i += 2, w += 5) { + for (int i = 0, w = 3; i < verticesLength; i += 2, w += 5) { worldVertices[w] = u + regionUVs[i + 1] * width; worldVertices[w + 1] = v + height - regionUVs[i] * height; } } else { - for (int i = 0, w = 3, n = vertices.length; i < n; i += 2, w += 5) { + for (int i = 0, w = 3; i < verticesLength; i += 2, w += 5) { worldVertices[w] = u + regionUVs[i] * width; worldVertices[w + 1] = v + regionUVs[i + 1] * height; } @@ -139,10 +134,26 @@ public class MeshAttachment extends Attachment { return vertices; } + public void setVertices (float[] vertices) { + this.vertices = vertices; + } + public short[] getTriangles () { return triangles; } + public void setTriangles (short[] triangles) { + this.triangles = triangles; + } + + public float[] getRegionUVs () { + return regionUVs; + } + + public void setRegionUVs (float[] regionUVs) { + this.regionUVs = regionUVs; + } + public Color getColor () { return color; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java index 0aa89dbc9..a9dcfa9c7 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java @@ -69,24 +69,11 @@ public class SkinnedMeshAttachment extends Attachment { return region; } - /** @param bones For each vertex, the number of bones affecting the vertex followed by that many bone indices. Ie: count, - * boneIndex, ... - * @param weights For each bone affecting the vertex, the vertex position in the bone's coordinate system and the weight for - * the bone's influence. Ie: x, y, weight, ... - * @param regionUVs For each vertex, a texure coordinate pair. Ie: u, v, ... - * @param triangles Vertex number triplets which describe the mesh's triangulation. */ - public void setMesh (int[] bones, float[] weights, short[] triangles, float[] regionUVs) { - this.bones = bones; - this.weights = weights; - this.triangles = triangles; - this.regionUVs = regionUVs; - - int uvsLength = regionUVs.length; - int worldVerticesLength = uvsLength / 2 * 5; - if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength]; - } - public void updateUVs () { + int verticesLength = regionUVs.length; + int worldVerticesLength = verticesLength / 2 * 5; + if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength]; + float u, v, width, height; if (region == null) { u = v = 0; @@ -99,12 +86,12 @@ public class SkinnedMeshAttachment extends Attachment { } float[] regionUVs = this.regionUVs; if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { - for (int i = 0, w = 3, n = regionUVs.length; i < n; i += 2, w += 5) { + for (int i = 0, w = 3; i < verticesLength; i += 2, w += 5) { worldVertices[w] = u + regionUVs[i + 1] * width; worldVertices[w + 1] = v + height - regionUVs[i] * height; } } else { - for (int i = 0, w = 3, n = regionUVs.length; i < n; i += 2, w += 5) { + for (int i = 0, w = 3; i < verticesLength; i += 2, w += 5) { worldVertices[w] = u + regionUVs[i] * width; worldVertices[w + 1] = v + regionUVs[i + 1] * height; } @@ -167,18 +154,43 @@ public class SkinnedMeshAttachment extends Attachment { return worldVertices; } - public short[] getTriangles () { - return triangles; - } - public int[] getBones () { return bones; } + /** For each vertex, the number of bones affecting the vertex followed by that many bone indices. Ie: count, boneIndex, ... */ + public void setBones (int[] bones) { + this.bones = bones; + } + public float[] getWeights () { return weights; } + /** For each bone affecting the vertex, the vertex position in the bone's coordinate system and the weight for the bone's + * influence. Ie: x, y, weight, ... */ + public void setWeights (float[] weights) { + this.weights = weights; + } + + public short[] getTriangles () { + return triangles; + } + + /** Vertex number triplets which describe the mesh's triangulation. */ + public void setTriangles (short[] triangles) { + this.triangles = triangles; + } + + public float[] getRegionUVs () { + return regionUVs; + } + + /** For each vertex, a texure coordinate pair. Ie: u, v, ... */ + public void setRegionUVs (float[] regionUVs) { + this.regionUVs = regionUVs; + } + public Color getColor () { return color; }