Sequence attachment fixes.

This commit is contained in:
Nathan Sweet 2021-10-04 20:48:58 -10:00
parent f7ae127115
commit d798334a5e
2 changed files with 58 additions and 60 deletions

View File

@ -878,72 +878,70 @@ public class SkeletonJson extends SkeletonLoader {
} }
// Attachment timelines. // Attachment timelines.
for (JsonValue deformMap = map.getChild("attachments"); deformMap != null; deformMap = deformMap.next) { for (JsonValue attachmentsMap = map.getChild("attachments"); attachmentsMap != null; attachmentsMap = attachmentsMap.next) {
Skin skin = skeletonData.findSkin(deformMap.name); Skin skin = skeletonData.findSkin(attachmentsMap.name);
if (skin == null) throw new SerializationException("Skin not found: " + deformMap.name); if (skin == null) throw new SerializationException("Skin not found: " + attachmentsMap.name);
for (JsonValue slotMap = deformMap.child; slotMap != null; slotMap = slotMap.next) { for (JsonValue slotMap = attachmentsMap.child; slotMap != null; slotMap = slotMap.next) {
SlotData slot = skeletonData.findSlot(slotMap.name); SlotData slot = skeletonData.findSlot(slotMap.name);
if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name); if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) { for (JsonValue attachmentMap = slotMap.child; attachmentMap != null; attachmentMap = attachmentMap.next) {
JsonValue keyMap = timelineMap.child; Attachment attachment = skin.getAttachment(slot.index, attachmentMap.name);
if (keyMap == null) continue; if (attachment == null) throw new SerializationException("Timeline attachment not found: " + attachmentMap.name);
for (JsonValue timelineMap = attachmentMap.child; timelineMap != null; timelineMap = timelineMap.next) {
JsonValue keyMap = timelineMap.child;
int frames = timelineMap.size;
String timelineName = timelineMap.name;
if (timelineName.equals("deform")) {
VertexAttachment vertexAttachment = (VertexAttachment)attachment;
boolean weighted = vertexAttachment.getBones() != null;
float[] vertices = vertexAttachment.getVertices();
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length;
Attachment attachment = skin.getAttachment(slot.index, timelineMap.name); DeformTimeline timeline = new DeformTimeline(frames, frames, slot.index, vertexAttachment);
if (attachment == null) throw new SerializationException("Timeline attachment not found: " + timelineMap.name); float time = keyMap.getFloat("time", 0);
for (int frame = 0, bezier = 0;; frame++) {
int frames = keyMap.size; float[] deform;
String timelineName = keyMap.name; JsonValue verticesValue = keyMap.get("vertices");
keyMap = keyMap.child; if (verticesValue == null)
if (timelineName.equals("deform")) { deform = weighted ? new float[deformLength] : vertices;
VertexAttachment vertexAttachment = (VertexAttachment)attachment; else {
boolean weighted = vertexAttachment.getBones() != null; deform = new float[deformLength];
float[] vertices = vertexAttachment.getVertices(); int start = keyMap.getInt("offset", 0);
int deformLength = weighted ? (vertices.length / 3) << 1 : vertices.length; arraycopy(verticesValue.asFloatArray(), 0, deform, start, verticesValue.size);
if (scale != 1) {
DeformTimeline timeline = new DeformTimeline(frames, frames, slot.index, vertexAttachment); for (int i = start, n = i + verticesValue.size; i < n; i++)
float time = keyMap.getFloat("time", 0); deform[i] *= scale;
for (int frame = 0, bezier = 0;; frame++) { }
float[] deform; if (!weighted) {
JsonValue verticesValue = keyMap.get("vertices"); for (int i = 0; i < deformLength; i++)
if (verticesValue == null) deform[i] += vertices[i];
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); timeline.setFrame(frame, time, deform);
JsonValue nextMap = keyMap.next; JsonValue nextMap = keyMap.next;
if (nextMap == null) { if (nextMap == null) {
timeline.shrink(bezier); timeline.shrink(bezier);
break; 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);
lastDelay = delay;
}
timelines.add(timeline);
} }
timelines.add(timeline);
} else if (timelineName.equals("sequence")) {
SequenceTimeline timeline = new SequenceTimeline(frames, slot.index, attachment);
float lastDelay = 0;
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);
} }
} }
} }

View File

@ -286,7 +286,7 @@ public class MeshAttachment extends VertexAttachment implements HasTextureRegion
mesh.path = path; mesh.path = path;
mesh.color.set(color); mesh.color.set(color);
mesh.setParentMesh(parentMesh != null ? parentMesh : this); mesh.setParentMesh(parentMesh != null ? parentMesh : this);
mesh.updateRegion(); if (mesh.getRegion() != null) mesh.updateRegion();
return mesh; return mesh;
} }