diff --git a/CHANGELOG.md b/CHANGELOG.md index 05a8c1b14..ffaf0840a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Added `PointAttachment`, additional method `newPointAttachment` in `AttachmentLoader` interface. * Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface. * `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 * Fixed renderer to work with 3.6 changes. diff --git a/spine-as3/spine-as3-example/lib/spine-as3.swc b/spine-as3/spine-as3-example/lib/spine-as3.swc index 29e0cccdd..73544b0ca 100644 Binary files a/spine-as3/spine-as3-example/lib/spine-as3.swc and b/spine-as3/spine-as3-example/lib/spine-as3.swc differ diff --git a/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs b/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs index ab3a5d9dd..059a93513 100644 --- a/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs +++ b/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs @@ -2,6 +2,8 @@ eclipse.preferences.version=1 encoding//src/spine/SkeletonClipping.as=UTF-8 encoding//src/spine/SkeletonJson.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/attachments/ClippingAttachment.as=UTF-8 encoding//src/spine/attachments/PointAttachment.as=UTF-8 diff --git a/spine-as3/spine-as3/src/spine/animation/Animation.as b/spine-as3/spine-as3/src/spine/animation/Animation.as index 4fbbbdc1e..96a541211 100644 --- a/spine-as3/spine-as3/src/spine/animation/Animation.as +++ b/spine-as3/spine-as3/src/spine/animation/Animation.as @@ -50,7 +50,7 @@ package spine.animation { } /** Poses the skeleton at the specified time for this animation. */ - public function apply(skeleton : Skeleton, lastTime : Number, time : Number, loop : Boolean, events : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, loop : Boolean, events : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { if (skeleton == null) throw new ArgumentError("skeleton cannot be null."); if (loop && duration != 0) { @@ -59,7 +59,7 @@ package spine.animation { } 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 { diff --git a/spine-as3/spine-as3/src/spine/animation/AnimationState.as b/spine-as3/spine-as3/src/spine/animation/AnimationState.as index 39ea40c4f..dc9d2effe 100644 --- a/spine-as3/spine-as3/src/spine/animation/AnimationState.as +++ b/spine-as3/spine-as3/src/spine/animation/AnimationState.as @@ -158,11 +158,12 @@ package spine.animation { var current : TrackEntry = tracks[i]; if (current == null || current.delay > 0) continue; applied = true; + var currentPose : MixPose = i == 0 ? MixPose.current : MixPose.currentLayered; // Apply mixing from entries first. var mix : Number = current.alpha; if (current.mixingFrom != null) - mix *= applyMixingFrom(current, skeleton); + mix *= applyMixingFrom(current, skeleton, currentPose); else if (current.trackTime >= current.trackEnd && current.next == null) mix = 0; @@ -173,7 +174,7 @@ package spine.animation { var ii : int = 0; if (mix == 1) { 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 { var timelineData : Vector. = current.timelineData; @@ -183,10 +184,11 @@ package spine.animation { for (ii = 0; ii < timelineCount; ii++) { var timeline : Timeline = timelines[ii]; + var pose : MixPose = timelineData[ii] >= AnimationState.FIRST ? MixPose.setup : currentPose; 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 - timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= FIRST, false); + timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, MixDirection.In); } } queueEvents(current, animationTime); @@ -199,9 +201,9 @@ package spine.animation { 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; - if (from.mixingFrom != null) applyMixingFrom(from, skeleton); + if (from.mixingFrom != null) applyMixingFrom(from, skeleton, currentPose); var mix : Number = 0; 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; var timelinesRotation : Vector. = from.timelinesRotation; - var first : Boolean = false; + var pose : MixPose; var alphaDip : Number = from.alpha * to.interruptAlpha; var alphaMix : Number = alphaDip * (1 - mix); var alpha : Number = 0; @@ -232,19 +234,21 @@ package spine.animation { var timeline : Timeline = timelines[i]; switch (timelineData[i]) { case SUBSEQUENT: - first = false; + if (!attachments && timeline is AttachmentTimeline) continue; + if (!drawOrder && timeline is DrawOrderTimeline) continue; + pose = currentPose; alpha = alphaMix; break; case FIRST: - first = true; + pose = MixPose.setup; alpha = alphaMix; break; case DIP: - first = true; + pose = MixPose.setup; alpha = alphaDip; break; default: - first = true; + pose = MixPose.setup; alpha = alphaDip; var dipMix : TrackEntry = timelineDipMix[i]; alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); @@ -252,13 +256,9 @@ package spine.animation { } from.totalAlpha += alpha; if (timeline is RotateTimeline) - applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); - else { - if (!first) { - if (!attachments && timeline is AttachmentTimeline) continue; - if (!drawOrder && timeline is DrawOrderTimeline) continue; - } - timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true); + applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame); + else { + timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, MixDirection.Out); } } @@ -270,11 +270,11 @@ package spine.animation { return mix; } - private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, setupPose : Boolean, timelinesRotation : Vector., i : int, firstFrame : Boolean) : void { + private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, pose : MixPose, timelinesRotation : Vector., i : int, firstFrame : Boolean) : void { if (firstFrame) timelinesRotation[i] = 0; if (alpha == 1) { - timeline.apply(skeleton, 0, time, null, 1, setupPose, false); + timeline.apply(skeleton, 0, time, null, 1, pose, MixDirection.In); return; } @@ -282,7 +282,7 @@ package spine.animation { var frames : Vector. = rotateTimeline.frames; var bone : Bone = skeleton.bones[rotateTimeline.boneIndex]; if (time < frames[0]) { - if (setupPose) bone.rotation = bone.data.rotation; + if (pose == MixPose.setup) bone.rotation = bone.data.rotation; 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. - 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; if (diff == 0) { total = timelinesRotation[i]; diff --git a/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as b/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as index d313e9d9c..6c2e75dde 100644 --- a/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as @@ -57,17 +57,17 @@ package spine.animation { attachmentNames[frameIndex] = attachmentName; } - public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var attachmentName : String; var slot : Slot = skeleton.slots[slotIndex]; - if (mixingOut && setupPose) { + if (direction == MixDirection.Out && pose == MixPose.setup) { attachmentName = slot.data.attachmentName; slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName); return; } var frames : Vector. = this.frames; if (time < frames[0]) { - if (setupPose) { + if (pose == MixPose.setup) { attachmentName = slot.data.attachmentName; slot.attachment = attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slotIndex, attachmentName); } diff --git a/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as b/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as index 8326a31fa..379998798 100644 --- a/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as @@ -29,6 +29,7 @@ *****************************************************************************/ package spine.animation { + import spine.Color; import spine.Event; import spine.Skeleton; import spine.Slot; @@ -59,13 +60,19 @@ package spine.animation { frames[int(frameIndex + A)] = a; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var slot : Slot = skeleton.slots[slotIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: 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; } @@ -95,7 +102,7 @@ package spine.animation { if (alpha == 1) { slot.color.setFrom(r, g, b, a); } else { - if (setupPose) { + if (pose == MixPose.setup) { slot.color.setFromColor(slot.data.color); } slot.color.r += (r - slot.color.r) * alpha; diff --git a/spine-as3/spine-as3/src/spine/animation/CurveTimeline.as b/spine-as3/spine-as3/src/spine/animation/CurveTimeline.as index 4fe581785..b88a354f8 100644 --- a/spine-as3/spine-as3/src/spine/animation/CurveTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/CurveTimeline.as @@ -45,7 +45,7 @@ package spine.animation { curves = new Vector.((frameCount - 1) * BEZIER_SIZE, true); } - public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { } public function getPropertyId() : int { diff --git a/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as b/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as index 03f653327..c903fa449 100644 --- a/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as @@ -48,7 +48,7 @@ package spine.animation { } 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. */ @@ -57,26 +57,34 @@ package spine.animation { frameVertices[frameIndex] = vertices; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var slot : Slot = skeleton.slots[slotIndex]; var slotAttachment : Attachment = slot.attachment; if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment)).applyDeform(attachment)) return; - - var frames : Vector. = this.frames; + var verticesArray : Vector. = slot.attachmentVertices; - if (time < frames[0]) { - if (setupPose) verticesArray.length = 0; - return; - } - var frameVertices : Vector.> = this.frameVertices; var vertexCount : int = frameVertices[0].length; - - if (verticesArray.length != vertexCount && !setupPose) alpha = 1; // Don't mix from uninitialized slot vertices. + if (verticesArray.length != vertexCount && pose != MixPose.setup) alpha = 1; // Don't mix from uninitialized slot vertices. verticesArray.length = vertexCount; var vertices : Vector. = verticesArray; - var i : int, n : int; + var frames : Vector. = 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 setupVertices : Vector.; var setup : Number, prev : Number; @@ -86,7 +94,7 @@ package spine.animation { // Vertex positions or deform offsets, no alpha. for (i = 0, n = vertexCount; i < n; i++) vertices[i] = lastVertices[i]; - } else if (setupPose) { + } else if (pose == MixPose.setup) { vertexAttachment = VertexAttachment(slotAttachment); if (vertexAttachment.bones == null) { // Unweighted vertex positions, with alpha. @@ -121,7 +129,7 @@ package spine.animation { prev = prevVertices[i]; vertices[i] = prev + (nextVertices[i] - prev) * percent; } - } else if (setupPose) { + } else if (pose == MixPose.setup) { vertexAttachment = VertexAttachment(slotAttachment); if (vertexAttachment.bones == null) { // Unweighted vertex positions, with alpha. diff --git a/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as b/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as index aa3371909..f46ff6896 100644 --- a/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as @@ -56,8 +56,8 @@ package spine.animation { drawOrders[frameIndex] = drawOrder; } - public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { - if (mixingOut && setupPose) { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + if (direction == MixDirection.Out && pose == MixPose.setup) { for (var ii : int = 0, n : int = skeleton.slots.length; ii < n; ii++) skeleton.drawOrder[ii] = skeleton.slots[ii]; return; @@ -68,7 +68,7 @@ package spine.animation { var slot : Slot; var i : int = 0; if (time < frames[0]) { - if (setupPose) { + if (pose == MixPose.setup) { for each (slot in slots) drawOrder[i++] = slot; } diff --git a/spine-as3/spine-as3/src/spine/animation/EventTimeline.as b/spine-as3/spine-as3/src/spine/animation/EventTimeline.as index 45f9141ee..b33b22c1b 100644 --- a/spine-as3/spine-as3/src/spine/animation/EventTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/EventTimeline.as @@ -56,11 +56,11 @@ package spine.animation { } /** Fires events for frames > lastTime and <= time. */ - public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { if (!firedEvents) return; 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; } else if (lastTime >= frames[int(frameCount - 1)]) // Last time is after last frame. return; diff --git a/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as b/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as index 62f5d9992..1449d6197 100644 --- a/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as @@ -57,23 +57,28 @@ package spine.animation { frames[int(frameIndex + BEND_DIRECTION)] = bendDirection; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var constraint : IkConstraint = skeleton.ikConstraints[ikConstraintIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: constraint.mix = constraint.data.mix; constraint.bendDirection = constraint.data.bendDirection; + return; + case MixPose.current: + constraint.mix += (constraint.data.mix - constraint.mix) * alpha; + constraint.bendDirection = constraint.data.bendDirection; } return; } 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.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 { 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; } @@ -84,12 +89,12 @@ package spine.animation { var frameTime : Number = frames[frame]; 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.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 { 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]); } } } diff --git a/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as b/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as index 5176b4d04..60ed68b82 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as @@ -57,12 +57,17 @@ package spine.animation { frames[frameIndex + TRANSLATE] = translateMix; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: constraint.rotateMix = constraint.data.rotateMix; 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; } @@ -83,7 +88,7 @@ package spine.animation { translate += (frames[frame + TRANSLATE] - translate) * percent; } - if (setupPose) { + if (pose == MixPose.setup) { constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; } else { diff --git a/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as b/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as index 1df6bdabd..fe8e3f8c4 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as @@ -56,10 +56,16 @@ package spine.animation { frames[frameIndex + VALUE] = value; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; 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; } @@ -75,7 +81,7 @@ package spine.animation { position += (frames[frame + VALUE] - position) * percent; } - if (setupPose) + if (pose == MixPose.setup) constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; else constraint.position += (position - constraint.position) * alpha; diff --git a/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as b/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as index 9b19645c0..d2671e029 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as @@ -42,10 +42,16 @@ package spine.animation { return (TimelineType.pathConstraintSpacing.ordinal << 24) + pathConstraintIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; 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; } @@ -62,7 +68,7 @@ package spine.animation { spacing += (frames[frame + VALUE] - spacing) * percent; } - if (setupPose) + if (pose == MixPose.setup) constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; else constraint.spacing += (spacing - constraint.spacing) * alpha; diff --git a/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as b/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as index f13ab9285..b50945685 100644 --- a/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as @@ -56,18 +56,26 @@ package spine.animation { frames[int(frameIndex + ROTATION)] = degrees; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; var r : Number; 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; } 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; else { r = bone.data.rotation + frames[frames.length + PREV_ROTATION] - bone.rotation; @@ -86,7 +94,7 @@ package spine.animation { r = frames[frame + ROTATION] - prevRotation; r -= (16384 - int((16384.499999999996 - r / 360))) * 360; r = prevRotation + r * percent; - if (setupPose) { + if (pose == MixPose.setup) { r -= (16384 - int((16384.499999999996 - r / 360))) * 360; bone.rotation = bone.data.rotation + r * alpha; } else { diff --git a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as index de4d379c3..05fdf7d32 100644 --- a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as @@ -43,14 +43,19 @@ package spine.animation { return (TimelineType.scale.ordinal << 24) + boneIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: bone.scaleX = bone.data.scaleX; 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; } @@ -75,7 +80,7 @@ package spine.animation { bone.scaleY = y; } else { var bx : Number, by : Number; - if (setupPose) { + if (pose == MixPose.setup) { bx = bone.data.scaleX; by = bone.data.scaleY; } else { @@ -83,7 +88,7 @@ package spine.animation { by = bone.scaleY; } // 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); y = Math.abs(y) * MathUtils.signum(by); } else { diff --git a/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as b/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as index ec64d34ba..d1cde5be1 100644 --- a/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as @@ -42,14 +42,19 @@ package spine.animation { return (TimelineType.shear.ordinal << 24) + boneIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: bone.shearX = bone.data.shearX; 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; } @@ -69,7 +74,7 @@ package spine.animation { x = x + (frames[frame + X] - x) * percent; y = y + (frames[frame + Y] - y) * percent; } - if (setupPose) { + if (pose == MixPose.setup) { bone.shearX = bone.data.shearX + x * alpha; bone.shearY = bone.data.shearY + y * alpha; } else { diff --git a/spine-as3/spine-as3/src/spine/animation/Timeline.as b/spine-as3/spine-as3/src/spine/animation/Timeline.as index 242dd9914..9673c7357 100644 --- a/spine-as3/spine-as3/src/spine/animation/Timeline.as +++ b/spine-as3/spine-as3/src/spine/animation/Timeline.as @@ -34,7 +34,7 @@ package spine.animation { public interface Timeline { /** Sets the value(s) for the specified time. */ - function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void; + function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void; function getPropertyId() : int; } diff --git a/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as b/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as index 2071910c6..39de58bda 100644 --- a/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as @@ -60,18 +60,25 @@ package spine.animation { frames[frameIndex + SHEAR] = shearMix; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var constraint : TransformConstraint = skeleton.transformConstraints[transformConstraintIndex]; var data : TransformConstraintData; if (time < frames[0]) { - if (setupPose) { - data = constraint.data; - constraint.rotateMix = constraint.data.rotateMix; - constraint.translateMix = constraint.data.translateMix; - constraint.scaleMix = constraint.data.scaleMix; - constraint.shearMix = constraint.data.shearMix; + data = constraint.data; + switch (pose) { + case MixPose.setup: + constraint.rotateMix = data.rotateMix; + constraint.translateMix = data.translateMix; + 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; } @@ -98,7 +105,7 @@ package spine.animation { scale += (frames[frame + SCALE] - scale) * percent; shear += (frames[frame + SHEAR] - shear) * percent; } - if (setupPose) { + if (pose == MixPose.setup) { data = constraint.data; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; diff --git a/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as b/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as index 109510532..61e5aef9d 100644 --- a/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as @@ -57,14 +57,19 @@ package spine.animation { frames[int(frameIndex + Y)] = y; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: bone.x = bone.data.x; 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; } @@ -84,7 +89,7 @@ package spine.animation { x += (frames[frame + X] - x) * percent; y += (frames[frame + Y] - y) * percent; } - if (setupPose) { + if (pose == MixPose.setup) { bone.x = bone.data.x + x * alpha; bone.y = bone.data.y + y * alpha; } else { diff --git a/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as b/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as index 86d094534..a947ef3d5 100644 --- a/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as @@ -64,14 +64,24 @@ package spine.animation { this.frames[frameIndex + TwoColorTimeline.B2] = b2; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, setupPose : Boolean, mixingOut : Boolean) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { var frames : Vector. = this.frames; var slot : Slot = skeleton.slots[slotIndex]; + var light : Color, dark : Color; if (time < frames[0]) { - if (setupPose) { + switch (pose) { + case MixPose.setup: slot.color.setFromColor(slot.data.color); 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; } @@ -111,9 +121,9 @@ package spine.animation { slot.color.setFrom(r, g, b, a); slot.darkColor.setFrom(r2, g2, b2, 1); } else { - var light : Color = slot.color; - var dark : Color = slot.darkColor; - if (setupPose) { + light = slot.color; + dark = slot.darkColor; + if (pose == MixPose.setup) { light.setFromColor(slot.data.color); dark.setFromColor(slot.data.darkColor); } diff --git a/spine-as3/spine-as3/src/spine/attachments/VertexAttachment.as b/spine-as3/spine-as3/src/spine/attachments/VertexAttachment.as index e34bd0df6..3731d84ca 100644 --- a/spine-as3/spine-as3/src/spine/attachments/VertexAttachment.as +++ b/spine-as3/spine-as3/src/spine/attachments/VertexAttachment.as @@ -34,9 +34,12 @@ package spine.attachments { import spine.Slot; public dynamic class VertexAttachment extends Attachment { + private static var nextID : int = 0; + public var bones : Vector.; public var vertices : Vector.; public var worldVerticesLength : int; + public var id : int = (nextID++ & 65535) << 11; public function VertexAttachment(name : String) { super(name); diff --git a/spine-starling/spine-starling-example/lib/spine-as3.swc b/spine-starling/spine-starling-example/lib/spine-as3.swc index 29e0cccdd..73544b0ca 100644 Binary files a/spine-starling/spine-starling-example/lib/spine-as3.swc and b/spine-starling/spine-starling-example/lib/spine-as3.swc differ diff --git a/spine-starling/spine-starling/lib/spine-as3.swc b/spine-starling/spine-starling/lib/spine-as3.swc index 29e0cccdd..73544b0ca 100644 Binary files a/spine-starling/spine-starling/lib/spine-as3.swc and b/spine-starling/spine-starling/lib/spine-as3.swc differ