Deform timeline additive

This commit is contained in:
Nathan Sweet 2017-10-28 20:14:08 +02:00
parent 5a4da17e7d
commit 72d18eefd4
2 changed files with 106 additions and 38 deletions

View File

@ -173,10 +173,14 @@ public class Animation {
* <code>first</code> is intended for the first animations applied, not for animations layered on top of those. */ * <code>first</code> is intended for the first animations applied, not for animations layered on top of those. */
first, first,
/** Transitions from the current value to the timeline value. No change is made before the first key (the current value is /** Transitions from the current value to the timeline value. No change is made before the first key (the current value is
* kept until the first key). */ * kept until the first key).
* <p>
* <code>replace</code> is intended for animations layered on top of others, not for the first animations applied. */
replace, replace,
/** Transitions from the current value to the current value plus the timeline value. No change is made before the first key /** Transitions from the current value to the current value plus the timeline value. No change is made before the first key
* (the current value is kept until the first key). */ * (the current value is kept until the first key).
* <p>
* <code>add</code> is intended for animations layered on top of others, not for the first animations applied. */
add add
} }
@ -1016,26 +1020,49 @@ public class Animation {
if (time >= frames[frames.length - 1]) { // Time is after last frame. if (time >= frames[frames.length - 1]) { // Time is after last frame.
float[] lastVertices = frameVertices[frames.length - 1]; float[] lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
// Vertex positions or deform offsets, no alpha. if (blend == add) {
System.arraycopy(lastVertices, 0, vertices, 0, vertexCount); VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
} else if (blend == setup) { if (vertexAttachment.getBones() == null) {
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment; // Unweighted vertex positions, no alpha.
if (vertexAttachment.getBones() == null) { float[] setupVertices = vertexAttachment.getVertices();
// Unweighted vertex positions, with alpha. for (int i = 0; i < vertexCount; i++)
float[] setupVertices = vertexAttachment.getVertices(); vertices[i] += lastVertices[i] - setupVertices[i];
for (int i = 0; i < vertexCount; i++) { } else {
float setup = setupVertices[i]; // Weighted deform offsets, no alpha.
vertices[i] = setup + (lastVertices[i] - setup) * alpha; for (int i = 0; i < vertexCount; i++)
vertices[i] += lastVertices[i];
} }
} else { } else {
// Weighted deform offsets, with alpha. // Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) System.arraycopy(lastVertices, 0, vertices, 0, vertexCount);
vertices[i] = lastVertices[i] * alpha;
} }
} else { } else {
// Vertex positions or deform offsets, with alpha. switch (blend) {
for (int i = 0; i < vertexCount; i++) case setup:
vertices[i] += (lastVertices[i] - vertices[i]) * alpha; VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions, with alpha.
float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) {
float setup = setupVertices[i];
vertices[i] = setup + (lastVertices[i] - setup) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++)
vertices[i] = lastVertices[i] * alpha;
}
break;
case first:
case replace:
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++)
vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
break;
case add:
for (int i = 0; i < vertexCount; i++)
vertices[i] += lastVertices[i] * alpha;
}
} }
return; return;
} }
@ -1048,32 +1075,73 @@ public class Animation {
float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime)); float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
if (alpha == 1) { if (alpha == 1) {
// Vertex positions or deform offsets, no alpha. if (blend == add) {
for (int i = 0; i < vertexCount; i++) { VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
float prev = prevVertices[i]; if (vertexAttachment.getBones() == null) {
vertices[i] = prev + (nextVertices[i] - prev) * percent; // Unweighted vertex positions, no alpha.
} float[] setupVertices = vertexAttachment.getVertices();
} else if (blend == setup) { for (int i = 0; i < vertexCount; i++) {
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment; float prev = prevVertices[i];
if (vertexAttachment.getBones() == null) { vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
// Unweighted vertex positions, with alpha. }
float[] setupVertices = vertexAttachment.getVertices(); } else {
for (int i = 0; i < vertexCount; i++) { // Weighted deform offsets, no alpha.
float prev = prevVertices[i], setup = setupVertices[i]; for (int i = 0; i < vertexCount; i++) {
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; float prev = prevVertices[i];
vertices[i] += prev + (nextVertices[i] - prev) * percent;
}
} }
} else { } else {
// Weighted deform offsets, with alpha. // Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
} else { } else {
// Vertex positions or deform offsets, with alpha. switch (blend) {
for (int i = 0; i < vertexCount; i++) { case setup: {
float prev = prevVertices[i]; VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions, with alpha.
float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i], setup = setupVertices[i];
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
break;
}
case first:
case replace:
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
}
break;
case add:
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions, with alpha.
float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
} }
} }
} }

View File

@ -224,7 +224,7 @@ public class AnimationState {
for (int ii = 0; ii < timelineCount; ii++) { for (int ii = 0; ii < timelineCount; ii++) {
Timeline timeline = (Timeline)timelines[ii]; Timeline timeline = (Timeline)timelines[ii];
MixBlend timelineBlend = timelineData[ii] >= FIRST ? MixBlend.setup : blend; MixBlend timelineBlend = timelineData[ii] == SUBSEQUENT ? blend : MixBlend.setup;
if (timeline instanceof RotateTimeline) { if (timeline instanceof RotateTimeline) {
applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1,
firstFrame); firstFrame);