API improvements.

Before I get too many damned runtimes done. ;)
This commit is contained in:
NathanSweet 2014-04-28 16:49:20 +02:00
parent efff26ebc9
commit c1c12677ba
7 changed files with 80 additions and 55 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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")) {

View File

@ -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) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}