Skip to content

Commit

Permalink
[libgdx] Fixed mixing unweighted meshes that aren't keyed on frame zero.
Browse files Browse the repository at this point in the history
closes #925
  • Loading branch information
NathanSweet committed Jun 21, 2017
1 parent 37f555a commit a8e1faf
Showing 1 changed file with 31 additions and 6 deletions.
Expand Up @@ -862,6 +862,8 @@ public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> e

/** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */
static public class DeformTimeline extends CurveTimeline {
static private float[] zeros = new float[64];

int slotIndex;
VertexAttachment attachment;
private final float[] frames; // time, ...
Expand Down Expand Up @@ -923,20 +925,43 @@ public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> e
FloatArray verticesArray = slot.getAttachmentVertices();
float[][] frameVertices = this.frameVertices;
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[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;

switch (pose) {
case setup:
verticesArray.size = 0;
return;
break;
case current:
alpha = 1 - alpha;
for (int i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
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;
for (int i = 0; i < vertexCount; i++)
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;
}

Expand Down

0 comments on commit a8e1faf

Please sign in to comment.