mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
Changed binary format for 3.1.05.
* String encoding simplified for reading by using number of bytes rather than number of UTF-8 characters. * Parent bone index is no longer minus 1 and omitted for root. * Mesh and weighted mesh vertices array is no longer preceeded by a length. UVs array length is vertex count, not vertex array length. Edges changed to short. * Bounding box vertices array length is vertex count, not vertex array length.
This commit is contained in:
parent
f62f2bc7df
commit
3a06b829cc
@ -104,7 +104,47 @@ public class SkeletonBinary {
|
||||
SkeletonData skeletonData = new SkeletonData();
|
||||
skeletonData.name = file.nameWithoutExtension();
|
||||
|
||||
DataInput input = new DataInput(file.read(512));
|
||||
DataInput input = new DataInput(file.read(512)) {
|
||||
private char[] chars = new char[32];
|
||||
|
||||
public String readString () throws IOException {
|
||||
int byteCount = readInt(true);
|
||||
switch (byteCount) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return "";
|
||||
}
|
||||
byteCount--;
|
||||
if (chars.length < byteCount) chars = new char[byteCount];
|
||||
int charCount = 0;
|
||||
for (int i = 0; i < byteCount; i++, charCount++) {
|
||||
int b = read();
|
||||
switch (b >> 4) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
chars[charCount] = (char)b;
|
||||
break;
|
||||
case 12:
|
||||
case 13:
|
||||
chars[charCount] = (char)((b & 0x1F) << 6 | read() & 0x3F);
|
||||
i++;
|
||||
break;
|
||||
case 14:
|
||||
chars[charCount] = (char)((b & 0x0F) << 12 | (read() & 0x3F) << 6 | read() & 0x3F);
|
||||
i += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new String(chars, 0, charCount);
|
||||
}
|
||||
};
|
||||
try {
|
||||
skeletonData.hash = input.readString();
|
||||
if (skeletonData.hash.isEmpty()) skeletonData.hash = null;
|
||||
@ -123,9 +163,7 @@ public class SkeletonBinary {
|
||||
// Bones.
|
||||
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||
String name = input.readString();
|
||||
BoneData parent = null;
|
||||
int parentIndex = input.readInt(true) - 1;
|
||||
if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex);
|
||||
BoneData parent = i == 0 ? null : skeletonData.bones.get(input.readInt(true));
|
||||
BoneData boneData = new BoneData(name, parent);
|
||||
boneData.x = input.readFloat() * scale;
|
||||
boneData.y = input.readFloat() * scale;
|
||||
@ -284,7 +322,7 @@ public class SkeletonBinary {
|
||||
return region;
|
||||
}
|
||||
case boundingbox: {
|
||||
float[] vertices = readFloatArray(input, scale);
|
||||
float[] vertices = readFloatArray(input, input.readInt(true) * 2, scale);
|
||||
BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name);
|
||||
if (box == null) return null;
|
||||
box.setVertices(vertices);
|
||||
@ -294,14 +332,15 @@ public class SkeletonBinary {
|
||||
String path = input.readString();
|
||||
int color = input.readInt();
|
||||
int hullLength = 0;
|
||||
float[] uvs = readFloatArray(input, 1);
|
||||
int verticesLength = input.readInt(true) * 2;
|
||||
float[] uvs = readFloatArray(input, verticesLength, 1);
|
||||
short[] triangles = readShortArray(input);
|
||||
float[] vertices = readFloatArray(input, scale);
|
||||
float[] vertices = readFloatArray(input, verticesLength, scale);
|
||||
hullLength = input.readInt(true);
|
||||
int[] edges = null;
|
||||
short[] edges = null;
|
||||
float width = 0, height = 0;
|
||||
if (nonessential) {
|
||||
edges = readIntArray(input);
|
||||
edges = readShortArray(input);
|
||||
width = input.readFloat();
|
||||
height = input.readFloat();
|
||||
}
|
||||
@ -351,15 +390,15 @@ public class SkeletonBinary {
|
||||
case weightedmesh: {
|
||||
String path = input.readString();
|
||||
int color = input.readInt();
|
||||
float[] uvs = readFloatArray(input, 1);
|
||||
short[] triangles = readShortArray(input);
|
||||
int vertexCount = input.readInt(true);
|
||||
float[] uvs = readFloatArray(input, vertexCount * 2, 1);
|
||||
short[] triangles = readShortArray(input);
|
||||
FloatArray weights = new FloatArray(uvs.length * 3 * 3);
|
||||
IntArray bones = new IntArray(uvs.length * 3);
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
int boneCount = (int)input.readFloat();
|
||||
bones.add(boneCount);
|
||||
for (int nn = i + boneCount * 4; i < nn; i += 4) {
|
||||
for (int ii = 0, nn = boneCount; ii < nn; ii++) {
|
||||
bones.add((int)input.readFloat());
|
||||
weights.add(input.readFloat() * scale);
|
||||
weights.add(input.readFloat() * scale);
|
||||
@ -367,10 +406,10 @@ public class SkeletonBinary {
|
||||
}
|
||||
}
|
||||
int hullLength = input.readInt(true);
|
||||
int[] edges = null;
|
||||
short[] edges = null;
|
||||
float width = 0, height = 0;
|
||||
if (nonessential) {
|
||||
edges = readIntArray(input);
|
||||
edges = readShortArray(input);
|
||||
width = input.readFloat();
|
||||
height = input.readFloat();
|
||||
}
|
||||
@ -422,8 +461,7 @@ public class SkeletonBinary {
|
||||
return null;
|
||||
}
|
||||
|
||||
private float[] readFloatArray (DataInput input, float scale) throws IOException {
|
||||
int n = input.readInt(true);
|
||||
private float[] readFloatArray (DataInput input, int n, float scale) throws IOException {
|
||||
float[] array = new float[n];
|
||||
if (scale == 1) {
|
||||
for (int i = 0; i < n; i++)
|
||||
@ -443,14 +481,6 @@ public class SkeletonBinary {
|
||||
return array;
|
||||
}
|
||||
|
||||
private int[] readIntArray (DataInput input) throws IOException {
|
||||
int n = input.readInt(true);
|
||||
int[] array = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
array[i] = input.readInt(true);
|
||||
return array;
|
||||
}
|
||||
|
||||
private void readAnimation (String name, DataInput input, SkeletonData skeletonData) {
|
||||
Array<Timeline> timelines = new Array();
|
||||
float scale = this.scale;
|
||||
|
||||
@ -300,7 +300,7 @@ public class SkeletonJson {
|
||||
mesh.updateUVs();
|
||||
|
||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray());
|
||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asShortArray());
|
||||
} else {
|
||||
mesh.setInheritFFD(map.getBoolean("ffd", true));
|
||||
linkedMeshes.add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent));
|
||||
@ -343,7 +343,7 @@ public class SkeletonJson {
|
||||
mesh.updateUVs();
|
||||
|
||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray());
|
||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asShortArray());
|
||||
} else {
|
||||
mesh.setInheritFFD(map.getBoolean("ffd", true));
|
||||
linkedMeshes.add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent));
|
||||
|
||||
@ -53,7 +53,7 @@ public class MeshAttachment extends Attachment implements FfdAttachment {
|
||||
private boolean inheritFFD;
|
||||
|
||||
// Nonessential.
|
||||
private int[] edges;
|
||||
private short[] edges;
|
||||
private float width, height;
|
||||
|
||||
public MeshAttachment (String name) {
|
||||
@ -182,11 +182,11 @@ public class MeshAttachment extends Attachment implements FfdAttachment {
|
||||
this.hullLength = hullLength;
|
||||
}
|
||||
|
||||
public int[] getEdges () {
|
||||
public short[] getEdges () {
|
||||
return edges;
|
||||
}
|
||||
|
||||
public void setEdges (int[] edges) {
|
||||
public void setEdges (short[] edges) {
|
||||
this.edges = edges;
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ public class WeightedMeshAttachment extends Attachment implements FfdAttachment
|
||||
private boolean inheritFFD;
|
||||
|
||||
// Nonessential.
|
||||
private int[] edges;
|
||||
private short[] edges;
|
||||
private float width, height;
|
||||
|
||||
public WeightedMeshAttachment (String name) {
|
||||
@ -220,11 +220,11 @@ public class WeightedMeshAttachment extends Attachment implements FfdAttachment
|
||||
this.hullLength = hullLength;
|
||||
}
|
||||
|
||||
public void setEdges (int[] edges) {
|
||||
public void setEdges (short[] edges) {
|
||||
this.edges = edges;
|
||||
}
|
||||
|
||||
public int[] getEdges () {
|
||||
public short[] getEdges () {
|
||||
return edges;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user