mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
API improvements.
Before I get too many damned runtimes done. ;)
This commit is contained in:
parent
efff26ebc9
commit
c1c12677ba
@ -72,16 +72,10 @@ namespace Spine {
|
|||||||
: base(name) {
|
: 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 () {
|
public void UpdateUVs () {
|
||||||
float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
|
float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
|
||||||
float[] regionUVs = this.regionUVs;
|
float[] regionUVs = this.regionUVs;
|
||||||
|
if (this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length];
|
||||||
float[] uvs = this.uvs;
|
float[] uvs = this.uvs;
|
||||||
if (RegionRotate) {
|
if (RegionRotate) {
|
||||||
for (int i = 0, n = uvs.Length; i < n; i += 2) {
|
for (int i = 0, n = uvs.Length; i < n; i += 2) {
|
||||||
|
|||||||
@ -75,17 +75,10 @@ namespace Spine {
|
|||||||
: base(name) {
|
: 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 () {
|
public void UpdateUVs () {
|
||||||
float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
|
float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
|
||||||
float[] regionUVs = this.regionUVs;
|
float[] regionUVs = this.regionUVs;
|
||||||
|
if (this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length];
|
||||||
float[] uvs = this.uvs;
|
float[] uvs = this.uvs;
|
||||||
if (RegionRotate) {
|
if (RegionRotate) {
|
||||||
for (int i = 0, n = uvs.Length; i < n; i += 2) {
|
for (int i = 0, n = uvs.Length; i < n; i += 2) {
|
||||||
|
|||||||
@ -223,7 +223,9 @@ namespace Spine {
|
|||||||
float[] uvs = GetFloatArray(map, "uvs", 1);
|
float[] uvs = GetFloatArray(map, "uvs", 1);
|
||||||
int[] triangles = GetIntArray(map, "triangles");
|
int[] triangles = GetIntArray(map, "triangles");
|
||||||
float[] vertices = GetFloatArray(map, "vertices", Scale);
|
float[] vertices = GetFloatArray(map, "vertices", Scale);
|
||||||
mesh.SetMesh(vertices, triangles, uvs);
|
mesh.vertices = vertices;
|
||||||
|
mesh.triangles = triangles;
|
||||||
|
mesh.regionUVs = uvs;
|
||||||
mesh.UpdateUVs();
|
mesh.UpdateUVs();
|
||||||
|
|
||||||
if (map.ContainsKey("color")) {
|
if (map.ContainsKey("color")) {
|
||||||
@ -264,7 +266,10 @@ namespace Spine {
|
|||||||
i += 4;
|
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();
|
mesh.UpdateUVs();
|
||||||
|
|
||||||
if (map.ContainsKey("color")) {
|
if (map.ContainsKey("color")) {
|
||||||
|
|||||||
@ -229,7 +229,9 @@ public class SkeletonBinary {
|
|||||||
float[] uvs = readFloatArray(input, 1);
|
float[] uvs = readFloatArray(input, 1);
|
||||||
short[] triangles = readShortArray(input);
|
short[] triangles = readShortArray(input);
|
||||||
float[] vertices = readFloatArray(input, scale);
|
float[] vertices = readFloatArray(input, scale);
|
||||||
mesh.setMesh(vertices, triangles, uvs);
|
mesh.setVertices(vertices);
|
||||||
|
mesh.setTriangles(triangles);
|
||||||
|
mesh.setRegionUVs(uvs);
|
||||||
mesh.updateUVs();
|
mesh.updateUVs();
|
||||||
Color.rgba8888ToColor(mesh.getColor(), input.readInt());
|
Color.rgba8888ToColor(mesh.getColor(), input.readInt());
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
@ -262,7 +264,10 @@ public class SkeletonBinary {
|
|||||||
weights.add(input.readFloat());
|
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();
|
mesh.updateUVs();
|
||||||
Color.rgba8888ToColor(mesh.getColor(), input.readInt());
|
Color.rgba8888ToColor(mesh.getColor(), input.readInt());
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
|
|||||||
@ -213,7 +213,9 @@ public class SkeletonJson {
|
|||||||
for (int i = 0, n = vertices.length; i < n; i++)
|
for (int i = 0, n = vertices.length; i < n; i++)
|
||||||
vertices[i] *= scale;
|
vertices[i] *= scale;
|
||||||
}
|
}
|
||||||
mesh.setMesh(vertices, triangles, uvs);
|
mesh.setVertices(vertices);
|
||||||
|
mesh.setTriangles(triangles);
|
||||||
|
mesh.setRegionUVs(uvs);
|
||||||
mesh.updateUVs();
|
mesh.updateUVs();
|
||||||
|
|
||||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
||||||
@ -243,7 +245,10 @@ public class SkeletonJson {
|
|||||||
i += 4;
|
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();
|
mesh.updateUVs();
|
||||||
|
|
||||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
||||||
|
|||||||
@ -68,16 +68,11 @@ public class MeshAttachment extends Attachment {
|
|||||||
return region;
|
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 () {
|
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;
|
float u, v, width, height;
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
u = v = 0;
|
u = v = 0;
|
||||||
@ -90,12 +85,12 @@ public class MeshAttachment extends Attachment {
|
|||||||
}
|
}
|
||||||
float[] regionUVs = this.regionUVs;
|
float[] regionUVs = this.regionUVs;
|
||||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
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] = u + regionUVs[i + 1] * width;
|
||||||
worldVertices[w + 1] = v + height - regionUVs[i] * height;
|
worldVertices[w + 1] = v + height - regionUVs[i] * height;
|
||||||
}
|
}
|
||||||
} else {
|
} 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] = u + regionUVs[i] * width;
|
||||||
worldVertices[w + 1] = v + regionUVs[i + 1] * height;
|
worldVertices[w + 1] = v + regionUVs[i + 1] * height;
|
||||||
}
|
}
|
||||||
@ -139,10 +134,26 @@ public class MeshAttachment extends Attachment {
|
|||||||
return vertices;
|
return vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVertices (float[] vertices) {
|
||||||
|
this.vertices = vertices;
|
||||||
|
}
|
||||||
|
|
||||||
public short[] getTriangles () {
|
public short[] getTriangles () {
|
||||||
return triangles;
|
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 () {
|
public Color getColor () {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,24 +69,11 @@ public class SkinnedMeshAttachment extends Attachment {
|
|||||||
return region;
|
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 () {
|
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;
|
float u, v, width, height;
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
u = v = 0;
|
u = v = 0;
|
||||||
@ -99,12 +86,12 @@ public class SkinnedMeshAttachment extends Attachment {
|
|||||||
}
|
}
|
||||||
float[] regionUVs = this.regionUVs;
|
float[] regionUVs = this.regionUVs;
|
||||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
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] = u + regionUVs[i + 1] * width;
|
||||||
worldVertices[w + 1] = v + height - regionUVs[i] * height;
|
worldVertices[w + 1] = v + height - regionUVs[i] * height;
|
||||||
}
|
}
|
||||||
} else {
|
} 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] = u + regionUVs[i] * width;
|
||||||
worldVertices[w + 1] = v + regionUVs[i + 1] * height;
|
worldVertices[w + 1] = v + regionUVs[i + 1] * height;
|
||||||
}
|
}
|
||||||
@ -167,18 +154,43 @@ public class SkinnedMeshAttachment extends Attachment {
|
|||||||
return worldVertices;
|
return worldVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short[] getTriangles () {
|
|
||||||
return triangles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getBones () {
|
public int[] getBones () {
|
||||||
return bones;
|
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 () {
|
public float[] getWeights () {
|
||||||
return weights;
|
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 () {
|
public Color getColor () {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user