This commit is contained in:
badlogic 2017-06-21 16:08:24 +02:00
commit df4fb90402

View File

@ -862,6 +862,8 @@ public class Animation {
/** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */ /** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */
static public class DeformTimeline extends CurveTimeline { static public class DeformTimeline extends CurveTimeline {
static private float[] zeros = new float[64];
int slotIndex; int slotIndex;
VertexAttachment attachment; VertexAttachment attachment;
private final float[] frames; // time, ... private final float[] frames; // time, ...
@ -923,20 +925,43 @@ public class Animation {
FloatArray verticesArray = slot.getAttachmentVertices(); FloatArray verticesArray = slot.getAttachmentVertices();
float[][] frameVertices = this.frameVertices; float[][] frameVertices = this.frameVertices;
int vertexCount = frameVertices[0].length; int vertexCount = frameVertices[0].length;
if (verticesArray.size != vertexCount && pose != setup) alpha = 1; // Don't mix from uninitialized slot vertices.
float[] vertices = verticesArray.setSize(vertexCount); float[] vertices = verticesArray.setSize(vertexCount);
float[] frames = this.frames; float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame. if (time < frames[0]) { // Time is before first frame.
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
switch (pose) { switch (pose) {
case setup: case setup:
verticesArray.size = 0; break;
return;
case current: case current:
if (alpha == 1) break;
if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions.
float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++)
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
} else {
// Weighted deform offsets.
alpha = 1 - alpha; alpha = 1 - alpha;
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] *= alpha; vertices[i] *= alpha;
} }
// Fall thru.
default:
return;
}
float[] zeroVertices;
if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions (setup pose).
zeroVertices = vertexAttachment.getVertices();
} else {
// Weighted deform offsets (zeros).
zeroVertices = zeros;
if (zeroVertices.length < vertexCount) zeros = zeroVertices = new float[vertexCount];
}
System.arraycopy(zeroVertices, 0, vertices, 0, vertexCount);
return; return;
} }