mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
JSON and binary loading for sequences.
This commit is contained in:
parent
eb5e19036d
commit
515d238886
@ -63,6 +63,7 @@ import com.esotericsoftware.spine.Animation.RotateTimeline;
|
|||||||
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ScaleXTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleXTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ScaleYTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleYTimeline;
|
||||||
|
import com.esotericsoftware.spine.Animation.SequenceTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearTimeline;
|
import com.esotericsoftware.spine.Animation.ShearTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearXTimeline;
|
import com.esotericsoftware.spine.Animation.ShearXTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearYTimeline;
|
import com.esotericsoftware.spine.Animation.ShearYTimeline;
|
||||||
@ -85,6 +86,8 @@ import com.esotericsoftware.spine.attachments.MeshAttachment;
|
|||||||
import com.esotericsoftware.spine.attachments.PathAttachment;
|
import com.esotericsoftware.spine.attachments.PathAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.PointAttachment;
|
import com.esotericsoftware.spine.attachments.PointAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||||
|
import com.esotericsoftware.spine.attachments.Sequence;
|
||||||
|
import com.esotericsoftware.spine.attachments.Sequence.SequenceMode;
|
||||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||||
|
|
||||||
/** Loads skeleton data in the Spine binary format.
|
/** Loads skeleton data in the Spine binary format.
|
||||||
@ -111,6 +114,9 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
static public final int SLOT_RGB2 = 4;
|
static public final int SLOT_RGB2 = 4;
|
||||||
static public final int SLOT_ALPHA = 5;
|
static public final int SLOT_ALPHA = 5;
|
||||||
|
|
||||||
|
static public final int ATTACHMENT_DEFORM = 0;
|
||||||
|
static public final int ATTACHMENT_SEQUENCE = 1;
|
||||||
|
|
||||||
static public final int PATH_POSITION = 0;
|
static public final int PATH_POSITION = 0;
|
||||||
static public final int PATH_SPACING = 1;
|
static public final int PATH_SPACING = 1;
|
||||||
static public final int PATH_MIX = 2;
|
static public final int PATH_MIX = 2;
|
||||||
@ -302,7 +308,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent);
|
if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent);
|
||||||
linkedMesh.mesh.setTimelineAttachment(linkedMesh.inheritTimelines ? (VertexAttachment)parent : linkedMesh.mesh);
|
linkedMesh.mesh.setTimelineAttachment(linkedMesh.inheritTimelines ? (VertexAttachment)parent : linkedMesh.mesh);
|
||||||
linkedMesh.mesh.setParentMesh((MeshAttachment)parent);
|
linkedMesh.mesh.setParentMesh((MeshAttachment)parent);
|
||||||
linkedMesh.mesh.updateRegion();
|
if (linkedMesh.mesh.getSequence() == null) linkedMesh.mesh.updateRegion();
|
||||||
}
|
}
|
||||||
linkedMeshes.clear();
|
linkedMeshes.clear();
|
||||||
|
|
||||||
@ -395,11 +401,10 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
float width = input.readFloat();
|
float width = input.readFloat();
|
||||||
float height = input.readFloat();
|
float height = input.readFloat();
|
||||||
int color = input.readInt();
|
int color = input.readInt();
|
||||||
|
Sequence sequence = readSequence(input);
|
||||||
// BOZO! - Read sequence.
|
|
||||||
|
|
||||||
if (path == null) path = name;
|
if (path == null) path = name;
|
||||||
RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path, null);
|
RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path, sequence);
|
||||||
if (region == null) return null;
|
if (region == null) return null;
|
||||||
region.setPath(path);
|
region.setPath(path);
|
||||||
region.setX(x * scale);
|
region.setX(x * scale);
|
||||||
@ -410,7 +415,8 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
region.setWidth(width * scale);
|
region.setWidth(width * scale);
|
||||||
region.setHeight(height * scale);
|
region.setHeight(height * scale);
|
||||||
Color.rgba8888ToColor(region.getColor(), color);
|
Color.rgba8888ToColor(region.getColor(), color);
|
||||||
region.updateRegion();
|
region.setSequence(sequence);
|
||||||
|
if (sequence == null) region.updateRegion();
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
case boundingbox: {
|
case boundingbox: {
|
||||||
@ -434,6 +440,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
short[] triangles = readShortArray(input);
|
short[] triangles = readShortArray(input);
|
||||||
Vertices vertices = readVertices(input, vertexCount);
|
Vertices vertices = readVertices(input, vertexCount);
|
||||||
int hullLength = input.readInt(true);
|
int hullLength = input.readInt(true);
|
||||||
|
Sequence sequence = readSequence(input);
|
||||||
short[] edges = null;
|
short[] edges = null;
|
||||||
float width = 0, height = 0;
|
float width = 0, height = 0;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
@ -442,10 +449,8 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
height = input.readFloat();
|
height = input.readFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BOZO! - Read sequence.
|
|
||||||
|
|
||||||
if (path == null) path = name;
|
if (path == null) path = name;
|
||||||
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, null);
|
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, sequence);
|
||||||
if (mesh == null) return null;
|
if (mesh == null) return null;
|
||||||
mesh.setPath(path);
|
mesh.setPath(path);
|
||||||
Color.rgba8888ToColor(mesh.getColor(), color);
|
Color.rgba8888ToColor(mesh.getColor(), color);
|
||||||
@ -454,8 +459,9 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
mesh.setWorldVerticesLength(vertexCount << 1);
|
mesh.setWorldVerticesLength(vertexCount << 1);
|
||||||
mesh.setTriangles(triangles);
|
mesh.setTriangles(triangles);
|
||||||
mesh.setRegionUVs(uvs);
|
mesh.setRegionUVs(uvs);
|
||||||
mesh.updateRegion();
|
if (sequence == null) mesh.updateRegion();
|
||||||
mesh.setHullLength(hullLength << 1);
|
mesh.setHullLength(hullLength << 1);
|
||||||
|
mesh.setSequence(sequence);
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
mesh.setEdges(edges);
|
mesh.setEdges(edges);
|
||||||
mesh.setWidth(width * scale);
|
mesh.setWidth(width * scale);
|
||||||
@ -469,19 +475,19 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
String skinName = input.readStringRef();
|
String skinName = input.readStringRef();
|
||||||
String parent = input.readStringRef();
|
String parent = input.readStringRef();
|
||||||
boolean inheritTimelines = input.readBoolean();
|
boolean inheritTimelines = input.readBoolean();
|
||||||
|
Sequence sequence = readSequence(input);
|
||||||
float width = 0, height = 0;
|
float width = 0, height = 0;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
width = input.readFloat();
|
width = input.readFloat();
|
||||||
height = input.readFloat();
|
height = input.readFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BOZO! - Read sequence.
|
|
||||||
|
|
||||||
if (path == null) path = name;
|
if (path == null) path = name;
|
||||||
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, null);
|
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, sequence);
|
||||||
if (mesh == null) return null;
|
if (mesh == null) return null;
|
||||||
mesh.setPath(path);
|
mesh.setPath(path);
|
||||||
Color.rgba8888ToColor(mesh.getColor(), color);
|
Color.rgba8888ToColor(mesh.getColor(), color);
|
||||||
|
mesh.setSequence(sequence);
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
mesh.setWidth(width * scale);
|
mesh.setWidth(width * scale);
|
||||||
mesh.setHeight(height * scale);
|
mesh.setHeight(height * scale);
|
||||||
@ -542,6 +548,15 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Sequence readSequence (SkeletonInput input) throws IOException {
|
||||||
|
if (!input.readBoolean()) return null;
|
||||||
|
Sequence sequence = new Sequence(input.readInt(true));
|
||||||
|
sequence.setStart(input.readInt(true));
|
||||||
|
sequence.setDigits(input.readInt(true));
|
||||||
|
sequence.setSetupIndex(input.readInt(true));
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
|
||||||
private Vertices readVertices (SkeletonInput input, int vertexCount) throws IOException {
|
private Vertices readVertices (SkeletonInput input, int vertexCount) throws IOException {
|
||||||
float scale = this.scale;
|
float scale = this.scale;
|
||||||
int verticesLength = vertexCount << 1;
|
int verticesLength = vertexCount << 1;
|
||||||
@ -751,7 +766,6 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
a = a2;
|
a = a2;
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -897,57 +911,73 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deform timelines.
|
// Attachment timelines.
|
||||||
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||||
Skin skin = skeletonData.skins.get(input.readInt(true));
|
Skin skin = skeletonData.skins.get(input.readInt(true));
|
||||||
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
|
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
|
||||||
int slotIndex = input.readInt(true);
|
int slotIndex = input.readInt(true);
|
||||||
for (int iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
|
for (int iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
|
||||||
String attachmentName = input.readStringRef();
|
String attachmentName = input.readStringRef();
|
||||||
VertexAttachment attachment = (VertexAttachment)skin.getAttachment(slotIndex, attachmentName);
|
Attachment attachment = skin.getAttachment(slotIndex, attachmentName);
|
||||||
if (attachment == null) throw new SerializationException("Vertex attachment not found: " + attachmentName);
|
if (attachment == null) throw new SerializationException("Timeline attachment not found: " + attachmentName);
|
||||||
boolean weighted = attachment.getBones() != null;
|
|
||||||
float[] vertices = attachment.getVertices();
|
|
||||||
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length;
|
|
||||||
|
|
||||||
int frameCount = input.readInt(true), frameLast = frameCount - 1;
|
int timelineType = input.readByte(), frameCount = input.readInt(true), frameLast = frameCount - 1;
|
||||||
DeformTimeline timeline = new DeformTimeline(frameCount, input.readInt(true), slotIndex, attachment);
|
switch (timelineType) {
|
||||||
|
case ATTACHMENT_DEFORM: {
|
||||||
|
VertexAttachment vertexAttachment = (VertexAttachment)attachment;
|
||||||
|
boolean weighted = vertexAttachment.getBones() != null;
|
||||||
|
float[] vertices = vertexAttachment.getVertices();
|
||||||
|
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length;
|
||||||
|
|
||||||
float time = input.readFloat();
|
DeformTimeline timeline = new DeformTimeline(frameCount, input.readInt(true), slotIndex, vertexAttachment);
|
||||||
for (int frame = 0, bezier = 0;; frame++) {
|
|
||||||
float[] deform;
|
float time = input.readFloat();
|
||||||
int end = input.readInt(true);
|
for (int frame = 0, bezier = 0;; frame++) {
|
||||||
if (end == 0)
|
float[] deform;
|
||||||
deform = weighted ? new float[deformLength] : vertices;
|
int end = input.readInt(true);
|
||||||
else {
|
if (end == 0)
|
||||||
deform = new float[deformLength];
|
deform = weighted ? new float[deformLength] : vertices;
|
||||||
int start = input.readInt(true);
|
else {
|
||||||
end += start;
|
deform = new float[deformLength];
|
||||||
if (scale == 1) {
|
int start = input.readInt(true);
|
||||||
for (int v = start; v < end; v++)
|
end += start;
|
||||||
deform[v] = input.readFloat();
|
if (scale == 1) {
|
||||||
} else {
|
for (int v = start; v < end; v++)
|
||||||
for (int v = start; v < end; v++)
|
deform[v] = input.readFloat();
|
||||||
deform[v] = input.readFloat() * scale;
|
} else {
|
||||||
|
for (int v = start; v < end; v++)
|
||||||
|
deform[v] = input.readFloat() * scale;
|
||||||
|
}
|
||||||
|
if (!weighted) {
|
||||||
|
for (int v = 0, vn = deform.length; v < vn; v++)
|
||||||
|
deform[v] += vertices[v];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!weighted) {
|
timeline.setFrame(frame, time, deform);
|
||||||
for (int v = 0, vn = deform.length; v < vn; v++)
|
if (frame == frameLast) break;
|
||||||
deform[v] += vertices[v];
|
float time2 = input.readFloat();
|
||||||
|
switch (input.readByte()) {
|
||||||
|
case CURVE_STEPPED:
|
||||||
|
timeline.setStepped(frame);
|
||||||
|
break;
|
||||||
|
case CURVE_BEZIER:
|
||||||
|
setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
|
||||||
}
|
}
|
||||||
|
time = time2;
|
||||||
}
|
}
|
||||||
timeline.setFrame(frame, time, deform);
|
timelines.add(timeline);
|
||||||
if (frame == frameLast) break;
|
break;
|
||||||
float time2 = input.readFloat();
|
}
|
||||||
switch (input.readByte()) {
|
case ATTACHMENT_SEQUENCE:
|
||||||
case CURVE_STEPPED:
|
SequenceTimeline timeline = new SequenceTimeline(frameCount, slotIndex, attachment);
|
||||||
timeline.setStepped(frame);
|
for (int frame = 0; frame < frameCount; frame++) {
|
||||||
break;
|
float time = input.readFloat();
|
||||||
case CURVE_BEZIER:
|
int modeAndIndex = input.readInt();
|
||||||
setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
|
timeline.setFrame(frame, time, SequenceMode.values[modeAndIndex & 0xf], modeAndIndex >> 4,
|
||||||
}
|
input.readFloat());
|
||||||
time = time2;
|
}
|
||||||
|
timelines.add(timeline);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import com.badlogic.gdx.utils.FloatArray;
|
|||||||
import com.badlogic.gdx.utils.IntArray;
|
import com.badlogic.gdx.utils.IntArray;
|
||||||
import com.badlogic.gdx.utils.JsonReader;
|
import com.badlogic.gdx.utils.JsonReader;
|
||||||
import com.badlogic.gdx.utils.JsonValue;
|
import com.badlogic.gdx.utils.JsonValue;
|
||||||
|
import com.badlogic.gdx.utils.Null;
|
||||||
import com.badlogic.gdx.utils.SerializationException;
|
import com.badlogic.gdx.utils.SerializationException;
|
||||||
|
|
||||||
import com.esotericsoftware.spine.Animation.AlphaTimeline;
|
import com.esotericsoftware.spine.Animation.AlphaTimeline;
|
||||||
@ -63,6 +64,7 @@ import com.esotericsoftware.spine.Animation.RotateTimeline;
|
|||||||
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ScaleXTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleXTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ScaleYTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleYTimeline;
|
||||||
|
import com.esotericsoftware.spine.Animation.SequenceTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearTimeline;
|
import com.esotericsoftware.spine.Animation.ShearTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearXTimeline;
|
import com.esotericsoftware.spine.Animation.ShearXTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.ShearYTimeline;
|
import com.esotericsoftware.spine.Animation.ShearYTimeline;
|
||||||
@ -84,6 +86,8 @@ import com.esotericsoftware.spine.attachments.MeshAttachment;
|
|||||||
import com.esotericsoftware.spine.attachments.PathAttachment;
|
import com.esotericsoftware.spine.attachments.PathAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.PointAttachment;
|
import com.esotericsoftware.spine.attachments.PointAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||||
|
import com.esotericsoftware.spine.attachments.Sequence;
|
||||||
|
import com.esotericsoftware.spine.attachments.Sequence.SequenceMode;
|
||||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||||
|
|
||||||
/** Loads skeleton data in the Spine JSON format.
|
/** Loads skeleton data in the Spine JSON format.
|
||||||
@ -323,7 +327,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent);
|
if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent);
|
||||||
linkedMesh.mesh.setTimelineAttachment(linkedMesh.inheritTimelines ? (VertexAttachment)parent : linkedMesh.mesh);
|
linkedMesh.mesh.setTimelineAttachment(linkedMesh.inheritTimelines ? (VertexAttachment)parent : linkedMesh.mesh);
|
||||||
linkedMesh.mesh.setParentMesh((MeshAttachment)parent);
|
linkedMesh.mesh.setParentMesh((MeshAttachment)parent);
|
||||||
linkedMesh.mesh.updateRegion();
|
if (linkedMesh.mesh.getSequence() == null) linkedMesh.mesh.updateRegion();
|
||||||
}
|
}
|
||||||
linkedMeshes.clear();
|
linkedMeshes.clear();
|
||||||
|
|
||||||
@ -366,8 +370,8 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) {
|
switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) {
|
||||||
case region: {
|
case region: {
|
||||||
String path = map.getString("path", name);
|
String path = map.getString("path", name);
|
||||||
// BOZO! - Read sequence.
|
Sequence sequence = readSequence(map.get("sequence"));
|
||||||
RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path, null);
|
RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path, sequence);
|
||||||
if (region == null) return null;
|
if (region == null) return null;
|
||||||
region.setPath(path);
|
region.setPath(path);
|
||||||
region.setX(map.getFloat("x", 0) * scale);
|
region.setX(map.getFloat("x", 0) * scale);
|
||||||
@ -377,11 +381,12 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
region.setRotation(map.getFloat("rotation", 0));
|
region.setRotation(map.getFloat("rotation", 0));
|
||||||
region.setWidth(map.getFloat("width") * scale);
|
region.setWidth(map.getFloat("width") * scale);
|
||||||
region.setHeight(map.getFloat("height") * scale);
|
region.setHeight(map.getFloat("height") * scale);
|
||||||
|
region.setSequence(sequence);
|
||||||
|
|
||||||
String color = map.getString("color", null);
|
String color = map.getString("color", null);
|
||||||
if (color != null) Color.valueOf(color, region.getColor());
|
if (color != null) Color.valueOf(color, region.getColor());
|
||||||
|
|
||||||
region.updateRegion();
|
if (region.getSequence() == null) region.updateRegion();
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
case boundingbox: {
|
case boundingbox: {
|
||||||
@ -396,8 +401,8 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
case mesh:
|
case mesh:
|
||||||
case linkedmesh: {
|
case linkedmesh: {
|
||||||
String path = map.getString("path", name);
|
String path = map.getString("path", name);
|
||||||
// BOZO! - Read sequence.
|
Sequence sequence = readSequence(map.get("sequence"));
|
||||||
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, null);
|
MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path, sequence);
|
||||||
if (mesh == null) return null;
|
if (mesh == null) return null;
|
||||||
mesh.setPath(path);
|
mesh.setPath(path);
|
||||||
|
|
||||||
@ -406,6 +411,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
|
|
||||||
mesh.setWidth(map.getFloat("width", 0) * scale);
|
mesh.setWidth(map.getFloat("width", 0) * scale);
|
||||||
mesh.setHeight(map.getFloat("height", 0) * scale);
|
mesh.setHeight(map.getFloat("height", 0) * scale);
|
||||||
|
mesh.setSequence(sequence);
|
||||||
|
|
||||||
String parent = map.getString("parent", null);
|
String parent = map.getString("parent", null);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
@ -418,7 +424,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
readVertices(map, mesh, uvs.length);
|
readVertices(map, mesh, uvs.length);
|
||||||
mesh.setTriangles(map.require("triangles").asShortArray());
|
mesh.setTriangles(map.require("triangles").asShortArray());
|
||||||
mesh.setRegionUVs(uvs);
|
mesh.setRegionUVs(uvs);
|
||||||
mesh.updateRegion();
|
if (mesh.getSequence() == null) mesh.updateRegion();
|
||||||
|
|
||||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() << 1);
|
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() << 1);
|
||||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asShortArray());
|
if (map.has("edges")) mesh.setEdges(map.require("edges").asShortArray());
|
||||||
@ -474,6 +480,15 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Sequence readSequence (@Null JsonValue map) {
|
||||||
|
if (map == null) return null;
|
||||||
|
Sequence sequence = new Sequence(map.getInt("count"));
|
||||||
|
sequence.setStart(map.getInt("start", 1));
|
||||||
|
sequence.setDigits(map.getInt("digits", 0));
|
||||||
|
sequence.setSetupIndex(map.getInt("setup", 0));
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
|
||||||
private void readVertices (JsonValue map, VertexAttachment attachment, int verticesLength) {
|
private void readVertices (JsonValue map, VertexAttachment attachment, int verticesLength) {
|
||||||
attachment.setWorldVerticesLength(verticesLength);
|
attachment.setWorldVerticesLength(verticesLength);
|
||||||
float[] vertices = map.require("vertices").asFloatArray();
|
float[] vertices = map.require("vertices").asFloatArray();
|
||||||
@ -862,8 +877,8 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deform timelines.
|
// Attachment timelines.
|
||||||
for (JsonValue deformMap = map.getChild("deform"); deformMap != null; deformMap = deformMap.next) {
|
for (JsonValue deformMap = map.getChild("attachments"); deformMap != null; deformMap = deformMap.next) {
|
||||||
Skin skin = skeletonData.findSkin(deformMap.name);
|
Skin skin = skeletonData.findSkin(deformMap.name);
|
||||||
if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name);
|
if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name);
|
||||||
for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) {
|
for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) {
|
||||||
@ -873,46 +888,63 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
JsonValue keyMap = timelineMap.child;
|
JsonValue keyMap = timelineMap.child;
|
||||||
if (keyMap == null) continue;
|
if (keyMap == null) continue;
|
||||||
|
|
||||||
VertexAttachment attachment = (VertexAttachment)skin.getAttachment(slot.index, timelineMap.name);
|
Attachment attachment = skin.getAttachment(slot.index, timelineMap.name);
|
||||||
if (attachment == null) throw new SerializationException("Deform attachment not found: " + timelineMap.name);
|
if (attachment == null) throw new SerializationException("Timeline attachment not found: " + timelineMap.name);
|
||||||
boolean weighted = attachment.getBones() != null;
|
|
||||||
float[] vertices = attachment.getVertices();
|
|
||||||
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length;
|
|
||||||
|
|
||||||
DeformTimeline timeline = new DeformTimeline(timelineMap.size, timelineMap.size, slot.index, attachment);
|
int frames = keyMap.size;
|
||||||
float time = keyMap.getFloat("time", 0);
|
String timelineName = keyMap.name;
|
||||||
for (int frame = 0, bezier = 0;; frame++) {
|
keyMap = keyMap.child;
|
||||||
float[] deform;
|
if (timelineName.equals("deform")) {
|
||||||
JsonValue verticesValue = keyMap.get("vertices");
|
VertexAttachment vertexAttachment = (VertexAttachment)attachment;
|
||||||
if (verticesValue == null)
|
boolean weighted = vertexAttachment.getBones() != null;
|
||||||
deform = weighted ? new float[deformLength] : vertices;
|
float[] vertices = vertexAttachment.getVertices();
|
||||||
else {
|
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length;
|
||||||
deform = new float[deformLength];
|
|
||||||
int start = keyMap.getInt("offset", 0);
|
|
||||||
arraycopy(verticesValue.asFloatArray(), 0, deform, start, verticesValue.size);
|
|
||||||
if (scale != 1) {
|
|
||||||
for (int i = start, n = i + verticesValue.size; i < n; i++)
|
|
||||||
deform[i] *= scale;
|
|
||||||
}
|
|
||||||
if (!weighted) {
|
|
||||||
for (int i = 0; i < deformLength; i++)
|
|
||||||
deform[i] += vertices[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timeline.setFrame(frame, time, deform);
|
DeformTimeline timeline = new DeformTimeline(frames, frames, slot.index, vertexAttachment);
|
||||||
JsonValue nextMap = keyMap.next;
|
float time = keyMap.getFloat("time", 0);
|
||||||
if (nextMap == null) {
|
for (int frame = 0, bezier = 0;; frame++) {
|
||||||
timeline.shrink(bezier);
|
float[] deform;
|
||||||
break;
|
JsonValue verticesValue = keyMap.get("vertices");
|
||||||
|
if (verticesValue == null)
|
||||||
|
deform = weighted ? new float[deformLength] : vertices;
|
||||||
|
else {
|
||||||
|
deform = new float[deformLength];
|
||||||
|
int start = keyMap.getInt("offset", 0);
|
||||||
|
arraycopy(verticesValue.asFloatArray(), 0, deform, start, verticesValue.size);
|
||||||
|
if (scale != 1) {
|
||||||
|
for (int i = start, n = i + verticesValue.size; i < n; i++)
|
||||||
|
deform[i] *= scale;
|
||||||
|
}
|
||||||
|
if (!weighted) {
|
||||||
|
for (int i = 0; i < deformLength; i++)
|
||||||
|
deform[i] += vertices[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timeline.setFrame(frame, time, deform);
|
||||||
|
JsonValue nextMap = keyMap.next;
|
||||||
|
if (nextMap == null) {
|
||||||
|
timeline.shrink(bezier);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
float time2 = nextMap.getFloat("time", 0);
|
||||||
|
JsonValue curve = keyMap.get("curve");
|
||||||
|
if (curve != null) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
|
||||||
|
time = time2;
|
||||||
|
keyMap = nextMap;
|
||||||
}
|
}
|
||||||
float time2 = nextMap.getFloat("time", 0);
|
timelines.add(timeline);
|
||||||
JsonValue curve = keyMap.get("curve");
|
} else if (timelineName.equals("sequence")) {
|
||||||
if (curve != null) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
|
SequenceTimeline timeline = new SequenceTimeline(frames, slot.index, attachment);
|
||||||
time = time2;
|
float lastDelay = 0;
|
||||||
keyMap = nextMap;
|
for (int frame = 0; keyMap != null; keyMap = keyMap.next, frame++) {
|
||||||
|
float delay = keyMap.getFloat("delay", lastDelay);
|
||||||
|
timeline.setFrame(frame, keyMap.getFloat("time", 0), SequenceMode.valueOf(keyMap.getString("mode", "stop")),
|
||||||
|
keyMap.getInt("index", 0), delay);
|
||||||
|
delay = lastDelay;
|
||||||
|
}
|
||||||
|
timelines.add(timeline);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,8 +95,7 @@ public class MeshAttachment extends VertexAttachment implements HasTextureRegion
|
|||||||
this.region = region;
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureRegion getRegion () {
|
public @Null TextureRegion getRegion () {
|
||||||
if (region == null) throw new IllegalStateException("Region has not been set: " + this);
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -156,8 +156,7 @@ public class RegionAttachment extends Attachment implements HasTextureRegion {
|
|||||||
this.region = region;
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureRegion getRegion () {
|
public @Null TextureRegion getRegion () {
|
||||||
if (region == null) throw new IllegalStateException("Region has not been set: " + name);
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user