Permalink
Browse files

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.
  • Loading branch information...
NathanSweet committed Apr 8, 2016
1 parent f62f2bc commit 3a06b829cc81203ebeec996efad33e4bef6cc8c7
@@ -104,7 +104,47 @@ public SkeletonData readSkeletonData (FileHandle file) {
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 SkeletonData readSkeletonData (FileHandle file) {
// 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 @@ private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, St
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 @@ private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, St
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,26 +390,26 @@ private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, St
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);
weights.add(input.readFloat());
}
}
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 @@ private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, St
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 @@ private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, St
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 @@ private Attachment readAttachment (Skin skin, int slotIndex, String name, JsonVa
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 @@ private Attachment readAttachment (Skin skin, int slotIndex, String name, JsonVa
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 @@
private boolean inheritFFD;
// Nonessential.
private int[] edges;
private short[] edges;
private float width, height;
public MeshAttachment (String name) {
@@ -182,11 +182,11 @@ public void setHullLength (int hullLength) {
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 @@
private boolean inheritFFD;
// Nonessential.
private int[] edges;
private short[] edges;
private float width, height;
public WeightedMeshAttachment (String name) {
@@ -220,11 +220,11 @@ public void setHullLength (int hullLength) {
this.hullLength = hullLength;
}
public void setEdges (int[] edges) {
public void setEdges (short[] edges) {
this.edges = edges;
}
public int[] getEdges () {
public short[] getEdges () {
return edges;
}

0 comments on commit 3a06b82

Please sign in to comment.