[as3] Ported VertexAttachment id and Timeline/Animation#apply changes

This commit is contained in:
badlogic 2017-06-12 17:27:14 +02:00
parent a797534476
commit ba409c8f3b
25 changed files with 178 additions and 95 deletions

View File

@ -16,6 +16,7 @@
* Added `PointAttachment`, additional method `newPointAttachment` in `AttachmentLoader` interface. * Added `PointAttachment`, additional method `newPointAttachment` in `AttachmentLoader` interface.
* Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface. * Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface.
* `AnimationState#apply` returns boolean indicating if any timeline was applied or not. * `AnimationState#apply` returns boolean indicating if any timeline was applied or not.
* `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans
### Starling ### Starling
* Fixed renderer to work with 3.6 changes. * Fixed renderer to work with 3.6 changes.

View File

@ -2,6 +2,8 @@ eclipse.preferences.version=1
encoding//src/spine/SkeletonClipping.as=UTF-8 encoding//src/spine/SkeletonClipping.as=UTF-8
encoding//src/spine/SkeletonJson.as=UTF-8 encoding//src/spine/SkeletonJson.as=UTF-8
encoding//src/spine/Triangulator.as=UTF-8 encoding//src/spine/Triangulator.as=UTF-8
encoding//src/spine/animation/MixDirection.as=UTF-8
encoding//src/spine/animation/MixPose.as=UTF-8
encoding//src/spine/animation/TwoColorTimeline.as=UTF-8 encoding//src/spine/animation/TwoColorTimeline.as=UTF-8
encoding//src/spine/attachments/ClippingAttachment.as=UTF-8 encoding//src/spine/attachments/ClippingAttachment.as=UTF-8
encoding//src/spine/attachments/PointAttachment.as=UTF-8 encoding//src/spine/attachments/PointAttachment.as=UTF-8

View File

@ -50,7 +50,7 @@ package spine.animation {
} }
/** Poses the skeleton at the specified time for this animation. */ /** Poses the skeleton at the specified time for this animation. */
public function apply(skeleton : Skeleton, lastTime : Number, time : Number, loop : Boolean, events : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { public function apply(skeleton : Skeleton, lastTime : Number, time : Number, loop : Boolean, events : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
if (skeleton == null) throw new ArgumentError("skeleton cannot be null."); if (skeleton == null) throw new ArgumentError("skeleton cannot be null.");
if (loop && duration != 0) { if (loop && duration != 0) {
@ -59,7 +59,7 @@ package spine.animation {
} }
for (var i : int = 0, n : int = timelines.length; i < n; i++) for (var i : int = 0, n : int = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
} }
public function get name() : String { public function get name() : String {

View File

@ -158,11 +158,12 @@ package spine.animation {
var current : TrackEntry = tracks[i]; var current : TrackEntry = tracks[i];
if (current == null || current.delay > 0) continue; if (current == null || current.delay > 0) continue;
applied = true; applied = true;
var currentPose : MixPose = i == 0 ? MixPose.current : MixPose.currentLayered;
// Apply mixing from entries first. // Apply mixing from entries first.
var mix : Number = current.alpha; var mix : Number = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= applyMixingFrom(current, skeleton); mix *= applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
@ -173,7 +174,7 @@ package spine.animation {
var ii : int = 0; var ii : int = 0;
if (mix == 1) { if (mix == 1) {
for (ii = 0; ii < timelineCount; ii++) for (ii = 0; ii < timelineCount; ii++)
Timeline(timelines[ii]).apply(skeleton, animationLast, animationTime, events, 1, true, false); Timeline(timelines[ii]).apply(skeleton, animationLast, animationTime, events, 1, MixPose.setup, MixDirection.In);
} else { } else {
var timelineData : Vector.<int> = current.timelineData; var timelineData : Vector.<int> = current.timelineData;
@ -183,10 +184,11 @@ package spine.animation {
for (ii = 0; ii < timelineCount; ii++) { for (ii = 0; ii < timelineCount; ii++) {
var timeline : Timeline = timelines[ii]; var timeline : Timeline = timelines[ii];
var pose : MixPose = timelineData[ii] >= AnimationState.FIRST ? MixPose.setup : currentPose;
if (timeline is RotateTimeline) { if (timeline is RotateTimeline) {
applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= FIRST, timelinesRotation, ii << 1, firstFrame); applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} else } else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, MixDirection.In);
} }
} }
queueEvents(current, animationTime); queueEvents(current, animationTime);
@ -199,9 +201,9 @@ package spine.animation {
return applied; return applied;
} }
private function applyMixingFrom(to : TrackEntry, skeleton : Skeleton) : Number { private function applyMixingFrom(to : TrackEntry, skeleton : Skeleton, currentPose : MixPose) : Number {
var from : TrackEntry = to.mixingFrom; var from : TrackEntry = to.mixingFrom;
if (from.mixingFrom != null) applyMixingFrom(from, skeleton); if (from.mixingFrom != null) applyMixingFrom(from, skeleton, currentPose);
var mix : Number = 0; var mix : Number = 0;
if (to.mixDuration == 0) // Single frame mix to undo mixingFrom changes. if (to.mixDuration == 0) // Single frame mix to undo mixingFrom changes.
@ -223,7 +225,7 @@ package spine.animation {
if (firstFrame) from.timelinesRotation.length = timelineCount << 1; if (firstFrame) from.timelinesRotation.length = timelineCount << 1;
var timelinesRotation : Vector.<Number> = from.timelinesRotation; var timelinesRotation : Vector.<Number> = from.timelinesRotation;
var first : Boolean = false; var pose : MixPose;
var alphaDip : Number = from.alpha * to.interruptAlpha; var alphaDip : Number = from.alpha * to.interruptAlpha;
var alphaMix : Number = alphaDip * (1 - mix); var alphaMix : Number = alphaDip * (1 - mix);
var alpha : Number = 0; var alpha : Number = 0;
@ -232,19 +234,21 @@ package spine.animation {
var timeline : Timeline = timelines[i]; var timeline : Timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case SUBSEQUENT: case SUBSEQUENT:
first = false; if (!attachments && timeline is AttachmentTimeline) continue;
if (!drawOrder && timeline is DrawOrderTimeline) continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case FIRST: case FIRST:
first = true; pose = MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case DIP: case DIP:
first = true; pose = MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix : TrackEntry = timelineDipMix[i]; var dipMix : TrackEntry = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -252,13 +256,9 @@ package spine.animation {
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline is RotateTimeline) if (timeline is RotateTimeline)
applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, MixDirection.Out);
if (!attachments && timeline is AttachmentTimeline) continue;
if (!drawOrder && timeline is DrawOrderTimeline) continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
@ -270,11 +270,11 @@ package spine.animation {
return mix; return mix;
} }
private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, setupPose : Boolean, timelinesRotation : Vector.<Number>, i : int, firstFrame : Boolean) : void { private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, pose : MixPose, timelinesRotation : Vector.<Number>, i : int, firstFrame : Boolean) : void {
if (firstFrame) timelinesRotation[i] = 0; if (firstFrame) timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, MixDirection.In);
return; return;
} }
@ -282,7 +282,7 @@ package spine.animation {
var frames : Vector.<Number> = rotateTimeline.frames; var frames : Vector.<Number> = rotateTimeline.frames;
var bone : Bone = skeleton.bones[rotateTimeline.boneIndex]; var bone : Bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) bone.rotation = bone.data.rotation; if (pose == MixPose.setup) bone.rotation = bone.data.rotation;
return; return;
} }
@ -303,7 +303,7 @@ package spine.animation {
} }
// Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
var r1 : Number = setupPose ? bone.data.rotation : bone.rotation; var r1 : Number = pose == MixPose.setup ? bone.data.rotation : bone.rotation;
var total : Number, diff : Number = r2 - r1; var total : Number, diff : Number = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];

View File

@ -57,17 +57,17 @@ package spine.animation {
attachmentNames[frameIndex] = attachmentName; attachmentNames[frameIndex] = attachmentName;
} }
public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var attachmentName : String; var attachmentName : String;
var slot : Slot = skeleton.slots[slotIndex]; var slot : Slot = skeleton.slots[slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.Out && pose == MixPose.setup) {
attachmentName = slot.data.attachmentName; attachmentName = slot.data.attachmentName;
slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName); slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName);
return; return;
} }
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
attachmentName = slot.data.attachmentName; attachmentName = slot.data.attachmentName;
slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName); slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName);
} }

View File

@ -29,6 +29,7 @@
*****************************************************************************/ *****************************************************************************/
package spine.animation { package spine.animation {
import spine.Color;
import spine.Event; import spine.Event;
import spine.Skeleton; import spine.Skeleton;
import spine.Slot; import spine.Slot;
@ -59,13 +60,19 @@ package spine.animation {
frames[int(frameIndex + A)] = a; frames[int(frameIndex + A)] = a;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var slot : Slot = skeleton.slots[slotIndex]; var slot : Slot = skeleton.slots[slotIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
slot.color.setFromColor(slot.data.color); slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color : Color = slot.color, setup : Color = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
(setup.a - color.a) * alpha);
} }
return; return;
} }
@ -95,7 +102,7 @@ package spine.animation {
if (alpha == 1) { if (alpha == 1) {
slot.color.setFrom(r, g, b, a); slot.color.setFrom(r, g, b, a);
} else { } else {
if (setupPose) { if (pose == MixPose.setup) {
slot.color.setFromColor(slot.data.color); slot.color.setFromColor(slot.data.color);
} }
slot.color.r += (r - slot.color.r) * alpha; slot.color.r += (r - slot.color.r) * alpha;

View File

@ -45,7 +45,7 @@ package spine.animation {
curves = new Vector.<Number>((frameCount - 1) * BEZIER_SIZE, true); curves = new Vector.<Number>((frameCount - 1) * BEZIER_SIZE, true);
} }
public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
} }
public function getPropertyId() : int { public function getPropertyId() : int {

View File

@ -48,7 +48,7 @@ package spine.animation {
} }
override public function getPropertyId() : int { override public function getPropertyId() : int {
return (TimelineType.deform.ordinal << 24) + slotIndex; return (TimelineType.deform.ordinal << 27) + attachment.id + slotIndex;
} }
/** Sets the time and value of the specified keyframe. */ /** Sets the time and value of the specified keyframe. */
@ -57,26 +57,34 @@ package spine.animation {
frameVertices[frameIndex] = vertices; frameVertices[frameIndex] = vertices;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var slot : Slot = skeleton.slots[slotIndex]; var slot : Slot = skeleton.slots[slotIndex];
var slotAttachment : Attachment = slot.attachment; var slotAttachment : Attachment = slot.attachment;
if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment)).applyDeform(attachment)) return; if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment)).applyDeform(attachment)) return;
var frames : Vector.<Number> = this.frames;
var verticesArray : Vector.<Number> = slot.attachmentVertices; var verticesArray : Vector.<Number> = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose) verticesArray.length = 0;
return;
}
var frameVertices : Vector.<Vector.<Number>> = this.frameVertices; var frameVertices : Vector.<Vector.<Number>> = this.frameVertices;
var vertexCount : int = frameVertices[0].length; var vertexCount : int = frameVertices[0].length;
if (verticesArray.length != vertexCount && pose != MixPose.setup) alpha = 1; // Don't mix from uninitialized slot vertices.
if (verticesArray.length != vertexCount && !setupPose) alpha = 1; // Don't mix from uninitialized slot vertices.
verticesArray.length = vertexCount; verticesArray.length = vertexCount;
var vertices : Vector.<Number> = verticesArray; var vertices : Vector.<Number> = verticesArray;
var i : int, n : int; var frames : Vector.<Number> = this.frames;
var i : int;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
var n : int;
var vertexAttachment : VertexAttachment; var vertexAttachment : VertexAttachment;
var setupVertices : Vector.<Number>; var setupVertices : Vector.<Number>;
var setup : Number, prev : Number; var setup : Number, prev : Number;
@ -86,7 +94,7 @@ package spine.animation {
// Vertex positions or deform offsets, no alpha. // Vertex positions or deform offsets, no alpha.
for (i = 0, n = vertexCount; i < n; i++) for (i = 0, n = vertexCount; i < n; i++)
vertices[i] = lastVertices[i]; vertices[i] = lastVertices[i];
} else if (setupPose) { } else if (pose == MixPose.setup) {
vertexAttachment = VertexAttachment(slotAttachment); vertexAttachment = VertexAttachment(slotAttachment);
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
// Unweighted vertex positions, with alpha. // Unweighted vertex positions, with alpha.
@ -121,7 +129,7 @@ package spine.animation {
prev = prevVertices[i]; prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} else if (setupPose) { } else if (pose == MixPose.setup) {
vertexAttachment = VertexAttachment(slotAttachment); vertexAttachment = VertexAttachment(slotAttachment);
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
// Unweighted vertex positions, with alpha. // Unweighted vertex positions, with alpha.

View File

@ -56,8 +56,8 @@ package spine.animation {
drawOrders[frameIndex] = drawOrder; drawOrders[frameIndex] = drawOrder;
} }
public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
if (mixingOut && setupPose) { if (direction == MixDirection.Out && pose == MixPose.setup) {
for (var ii : int = 0, n : int = skeleton.slots.length; ii < n; ii++) for (var ii : int = 0, n : int = skeleton.slots.length; ii < n; ii++)
skeleton.drawOrder[ii] = skeleton.slots[ii]; skeleton.drawOrder[ii] = skeleton.slots[ii];
return; return;
@ -68,7 +68,7 @@ package spine.animation {
var slot : Slot; var slot : Slot;
var i : int = 0; var i : int = 0;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
for each (slot in slots) for each (slot in slots)
drawOrder[i++] = slot; drawOrder[i++] = slot;
} }

View File

@ -56,11 +56,11 @@ package spine.animation {
} }
/** Fires events for frames > lastTime and <= time. */ /** Fires events for frames > lastTime and <= time. */
public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
if (!firedEvents) return; if (!firedEvents) return;
if (lastTime > time) { // Fire events after last time for looped animations. if (lastTime > time) { // Fire events after last time for looped animations.
apply(skeleton, lastTime, int.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); apply(skeleton, lastTime, int.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} else if (lastTime >= frames[int(frameCount - 1)]) // Last time is after last frame. } else if (lastTime >= frames[int(frameCount - 1)]) // Last time is after last frame.
return; return;

View File

@ -57,23 +57,28 @@ package spine.animation {
frames[int(frameIndex + BEND_DIRECTION)] = bendDirection; frames[int(frameIndex + BEND_DIRECTION)] = bendDirection;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var constraint : IkConstraint = skeleton.ikConstraints[ikConstraintIndex]; var constraint : IkConstraint = skeleton.ikConstraints[ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
constraint.mix = constraint.data.mix; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection; constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[int(frames.length - ENTRIES)]) { // Time is after last frame. if (time >= frames[int(frames.length - ENTRIES)]) { // Time is after last frame.
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection : int(frames[frames.length + PREV_BEND_DIRECTION]); constraint.bendDirection = direction == MixDirection.Out ? constraint.data.bendDirection : int(frames[frames.length + PREV_BEND_DIRECTION]);
} else { } else {
constraint.mix += (frames[frames.length + PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) constraint.bendDirection = int(frames[frames.length + PREV_BEND_DIRECTION]); if (direction == MixDirection.In) constraint.bendDirection = int(frames[frames.length + PREV_BEND_DIRECTION]);
} }
return; return;
} }
@ -84,12 +89,12 @@ package spine.animation {
var frameTime : Number = frames[frame]; var frameTime : Number = frames[frame];
var percent : Number = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); var percent : Number = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection : int(frames[frame + PREV_BEND_DIRECTION]); constraint.bendDirection = direction == MixDirection.Out ? constraint.data.bendDirection : int(frames[frame + PREV_BEND_DIRECTION]);
} else { } else {
constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) constraint.bendDirection = int(frames[frame + PREV_BEND_DIRECTION]); if (direction == MixDirection.In) constraint.bendDirection = int(frames[frame + PREV_BEND_DIRECTION]);
} }
} }
} }

View File

@ -57,12 +57,17 @@ package spine.animation {
frames[frameIndex + TRANSLATE] = translateMix; frames[frameIndex + TRANSLATE] = translateMix;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
constraint.rotateMix = constraint.data.rotateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix; constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -83,7 +88,7 @@ package spine.animation {
translate += (frames[frame + TRANSLATE] - translate) * percent; translate += (frames[frame + TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} else { } else {

View File

@ -56,10 +56,16 @@ package spine.animation {
frames[frameIndex + VALUE] = value; frames[frameIndex + VALUE] = value;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) constraint.position = constraint.data.position; switch (pose) {
case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
@ -75,7 +81,7 @@ package spine.animation {
position += (frames[frame + VALUE] - position) * percent; position += (frames[frame + VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;

View File

@ -42,10 +42,16 @@ package spine.animation {
return (TimelineType.pathConstraintSpacing.ordinal << 24) + pathConstraintIndex; return (TimelineType.pathConstraintSpacing.ordinal << 24) + pathConstraintIndex;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) constraint.spacing = constraint.data.spacing; switch (pose) {
case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
@ -62,7 +68,7 @@ package spine.animation {
spacing += (frames[frame + VALUE] - spacing) * percent; spacing += (frames[frame + VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;

View File

@ -56,18 +56,26 @@ package spine.animation {
frames[int(frameIndex + ROTATION)] = degrees; frames[int(frameIndex + ROTATION)] = degrees;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var bone : Bone = skeleton.bones[boneIndex]; var bone : Bone = skeleton.bones[boneIndex];
var r : Number; var r : Number;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) bone.rotation = bone.data.rotation; switch (pose) {
case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
r = bone.data.rotation - bone.rotation;
r -= (16384 - int((16384.499999999996 - r / 360))) * 360;
bone.rotation += r * alpha;
}
return; return;
} }
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame. if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + PREV_ROTATION] * alpha;
else { else {
r = bone.data.rotation + frames[frames.length + PREV_ROTATION] - bone.rotation; r = bone.data.rotation + frames[frames.length + PREV_ROTATION] - bone.rotation;
@ -86,7 +94,7 @@ package spine.animation {
r = frames[frame + ROTATION] - prevRotation; r = frames[frame + ROTATION] - prevRotation;
r -= (16384 - int((16384.499999999996 - r / 360))) * 360; r -= (16384 - int((16384.499999999996 - r / 360))) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - int((16384.499999999996 - r / 360))) * 360; r -= (16384 - int((16384.499999999996 - r / 360))) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} else { } else {

View File

@ -43,14 +43,19 @@ package spine.animation {
return (TimelineType.scale.ordinal << 24) + boneIndex; return (TimelineType.scale.ordinal << 24) + boneIndex;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var bone : Bone = skeleton.bones[boneIndex]; var bone : Bone = skeleton.bones[boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.scaleX = bone.data.scaleX; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY; bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -75,7 +80,7 @@ package spine.animation {
bone.scaleY = y; bone.scaleY = y;
} else { } else {
var bx : Number, by : Number; var bx : Number, by : Number;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} else { } else {
@ -83,7 +88,7 @@ package spine.animation {
by = bone.scaleY; by = bone.scaleY;
} }
// Mixing out uses sign of setup or current pose, else use sign of key. // Mixing out uses sign of setup or current pose, else use sign of key.
if (mixingOut) { if (direction == MixDirection.Out) {
x = Math.abs(x) * MathUtils.signum(bx); x = Math.abs(x) * MathUtils.signum(bx);
y = Math.abs(y) * MathUtils.signum(by); y = Math.abs(y) * MathUtils.signum(by);
} else { } else {

View File

@ -42,14 +42,19 @@ package spine.animation {
return (TimelineType.shear.ordinal << 24) + boneIndex; return (TimelineType.shear.ordinal << 24) + boneIndex;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var bone : Bone = skeleton.bones[boneIndex]; var bone : Bone = skeleton.bones[boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.shearX = bone.data.shearX; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY; bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -69,7 +74,7 @@ package spine.animation {
x = x + (frames[frame + X] - x) * percent; x = x + (frames[frame + X] - x) * percent;
y = y + (frames[frame + Y] - y) * percent; y = y + (frames[frame + Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} else { } else {

View File

@ -34,7 +34,7 @@ package spine.animation {
public interface Timeline { public interface Timeline {
/** Sets the value(s) for the specified time. */ /** Sets the value(s) for the specified time. */
function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void; function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void;
function getPropertyId() : int; function getPropertyId() : int;
} }

View File

@ -60,18 +60,25 @@ package spine.animation {
frames[frameIndex + SHEAR] = shearMix; frames[frameIndex + SHEAR] = shearMix;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var constraint : TransformConstraint = skeleton.transformConstraints[transformConstraintIndex]; var constraint : TransformConstraint = skeleton.transformConstraints[transformConstraintIndex];
var data : TransformConstraintData; var data : TransformConstraintData;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { data = constraint.data;
data = constraint.data; switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = constraint.data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = constraint.data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -98,7 +105,7 @@ package spine.animation {
scale += (frames[frame + SCALE] - scale) * percent; scale += (frames[frame + SCALE] - scale) * percent;
shear += (frames[frame + SHEAR] - shear) * percent; shear += (frames[frame + SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
data = constraint.data; data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;

View File

@ -57,14 +57,19 @@ package spine.animation {
frames[int(frameIndex + Y)] = y; frames[int(frameIndex + Y)] = y;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var bone : Bone = skeleton.bones[boneIndex]; var bone : Bone = skeleton.bones[boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.x = bone.data.x; bone.x = bone.data.x;
bone.y = bone.data.y; bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -84,7 +89,7 @@ package spine.animation {
x += (frames[frame + X] - x) * percent; x += (frames[frame + X] - x) * percent;
y += (frames[frame + Y] - y) * percent; y += (frames[frame + Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} else { } else {

View File

@ -64,14 +64,24 @@ package spine.animation {
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
} }
override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector.<Event>, alpha : Number, pose : MixPose, direction : MixDirection) : void {
var frames : Vector.<Number> = this.frames; var frames : Vector.<Number> = this.frames;
var slot : Slot = skeleton.slots[slotIndex]; var slot : Slot = skeleton.slots[slotIndex];
var light : Color, dark : Color;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
slot.color.setFromColor(slot.data.color); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor); slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
light = slot.color;
dark = slot.darkColor;
var setupLight : Color = slot.data.color, setupDark : Color = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha,
(setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -111,9 +121,9 @@ package spine.animation {
slot.color.setFrom(r, g, b, a); slot.color.setFrom(r, g, b, a);
slot.darkColor.setFrom(r2, g2, b2, 1); slot.darkColor.setFrom(r2, g2, b2, 1);
} else { } else {
var light : Color = slot.color; light = slot.color;
var dark : Color = slot.darkColor; dark = slot.darkColor;
if (setupPose) { if (pose == MixPose.setup) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }

View File

@ -34,9 +34,12 @@ package spine.attachments {
import spine.Slot; import spine.Slot;
public dynamic class VertexAttachment extends Attachment { public dynamic class VertexAttachment extends Attachment {
private static var nextID : int = 0;
public var bones : Vector.<int>; public var bones : Vector.<int>;
public var vertices : Vector.<Number>; public var vertices : Vector.<Number>;
public var worldVerticesLength : int; public var worldVerticesLength : int;
public var id : int = (nextID++ & 65535) << 11;
public function VertexAttachment(name : String) { public function VertexAttachment(name : String) {
super(name); super(name);