diff --git a/spine-as3/spine-as3-example/lib/spine-as3.swc b/spine-as3/spine-as3-example/lib/spine-as3.swc index dc5ab4569..c9aeb03b4 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 bfbdea40e..bba54d7ec 100644 --- a/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs +++ b/spine-as3/spine-as3/.settings/org.eclipse.core.resources.prefs @@ -6,8 +6,32 @@ encoding//src/spine/SkeletonJson.as=UTF-8 encoding//src/spine/Triangulator.as=UTF-8 encoding//src/spine/Vertex.as=UTF-8 encoding//src/spine/VertexEffect.as=UTF-8 +encoding//src/spine/animation/Animation.as=UTF-8 +encoding//src/spine/animation/AnimationState.as=UTF-8 +encoding//src/spine/animation/AnimationStateData.as=UTF-8 +encoding//src/spine/animation/AttachmentTimeline.as=UTF-8 +encoding//src/spine/animation/ColorTimeline.as=UTF-8 +encoding//src/spine/animation/CurveTimeline.as=UTF-8 +encoding//src/spine/animation/DeformTimeline.as=UTF-8 +encoding//src/spine/animation/DrawOrderTimeline.as=UTF-8 +encoding//src/spine/animation/EventQueue.as=UTF-8 +encoding//src/spine/animation/EventTimeline.as=UTF-8 +encoding//src/spine/animation/EventType.as=UTF-8 +encoding//src/spine/animation/IkConstraintTimeline.as=UTF-8 +encoding//src/spine/animation/Listeners.as=UTF-8 +encoding//src/spine/animation/MixBlend.as=UTF-8 encoding//src/spine/animation/MixDirection.as=UTF-8 -encoding//src/spine/animation/MixPose.as=UTF-8 +encoding//src/spine/animation/PathConstraintMixTimeline.as=UTF-8 +encoding//src/spine/animation/PathConstraintPositionTimeline.as=UTF-8 +encoding//src/spine/animation/PathConstraintSpacingTimeline.as=UTF-8 +encoding//src/spine/animation/RotateTimeline.as=UTF-8 +encoding//src/spine/animation/ScaleTimeline.as=UTF-8 +encoding//src/spine/animation/ShearTimeline.as=UTF-8 +encoding//src/spine/animation/Timeline.as=UTF-8 +encoding//src/spine/animation/TimelineType.as=UTF-8 +encoding//src/spine/animation/TrackEntry.as=UTF-8 +encoding//src/spine/animation/TransformConstraintTimeline.as=UTF-8 +encoding//src/spine/animation/TranslateTimeline.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 96a541211..64ee7cb02 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, pose : MixPose, direction : MixDirection) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, loop : Boolean, events : Vector., alpha : Number, blend : MixBlend, 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, pose, direction); + timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, 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 97fb201a6..f677ec27b 100644 --- a/spine-as3/spine-as3/src/spine/animation/AnimationState.as +++ b/spine-as3/spine-as3/src/spine/animation/AnimationState.as @@ -159,12 +159,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; + var blend : MixBlend = i == 0 ? MixBlend.first : current.mixBlend; // Apply mixing from entries first. var mix : Number = current.alpha; if (current.mixingFrom != null) - mix *= applyMixingFrom(current, skeleton, currentPose); + mix *= applyMixingFrom(current, skeleton, blend); else if (current.trackTime >= current.trackEnd && current.next == null) mix = 0; @@ -173,9 +173,9 @@ package spine.animation { var timelineCount : int = current.animation.timelines.length; var timelines : Vector. = current.animation.timelines; var ii : int = 0; - if (mix == 1) { + if (mix == 1 || blend == MixBlend.add) { for (ii = 0; ii < timelineCount; ii++) - Timeline(timelines[ii]).apply(skeleton, animationLast, animationTime, events, 1, MixPose.setup, MixDirection.In); + Timeline(timelines[ii]).apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.In); } else { var timelineData : Vector. = current.timelineData; @@ -185,11 +185,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; + var timelineBlend : MixBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup; if (timeline is RotateTimeline) { - applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame); + applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); } else - timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, MixDirection.In); + timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection.In); } } queueEvents(current, animationTime); @@ -202,17 +202,18 @@ package spine.animation { return applied; } - private function applyMixingFrom(to : TrackEntry, skeleton : Skeleton, currentPose : MixPose) : Number { + private function applyMixingFrom(to : TrackEntry, skeleton : Skeleton, blend : MixBlend) : Number { var from : TrackEntry = to.mixingFrom; - if (from.mixingFrom != null) applyMixingFrom(from, skeleton, currentPose); + if (from.mixingFrom != null) applyMixingFrom(from, skeleton, blend); var mix : Number = 0; if (to.mixDuration == 0) { // Single frame mix to undo mixingFrom changes. mix = 1; - currentPose = MixPose.setup; + if (blend == MixBlend.first) blend = MixBlend.setup; } else { mix = to.mixTime / to.mixDuration; if (mix > 1) mix = 1; + if (blend != MixBlend.first) blend = from.mixBlend; } var events : Vector. = mix < from.eventThreshold ? this.events : null; @@ -220,49 +221,54 @@ package spine.animation { var animationLast : Number = from.animationLast, animationTime : Number = from.getAnimationTime(); var timelineCount : int = from.animation.timelines.length; var timelines : Vector. = from.animation.timelines; - var timelineData : Vector. = from.timelineData; - var timelineDipMix : Vector. = from.timelineDipMix; - - var firstFrame : Boolean = from.timelinesRotation.length == 0; - if (firstFrame) from.timelinesRotation.length = timelineCount << 1; - var timelinesRotation : Vector. = from.timelinesRotation; - - var pose : MixPose; var alphaDip : Number = from.alpha * to.interruptAlpha; var alphaMix : Number = alphaDip * (1 - mix); - var alpha : Number = 0; - from.totalAlpha = 0; - for (var i : int = 0; i < timelineCount; i++) { - var timeline : Timeline = timelines[i]; - switch (timelineData[i]) { - case SUBSEQUENT: - if (!attachments && timeline is AttachmentTimeline) continue; - if (!drawOrder && timeline is DrawOrderTimeline) continue; - pose = currentPose; - alpha = alphaMix; - break; - case FIRST: - pose = MixPose.setup; - alpha = alphaMix; - break; - case DIP: - pose = MixPose.setup; - alpha = alphaDip; - break; - default: - pose = MixPose.setup; - alpha = alphaDip; - var dipMix : TrackEntry = timelineDipMix[i]; - alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); - break; - } - from.totalAlpha += alpha; - if (timeline is RotateTimeline) - applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame); - else { - timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, MixDirection.Out); - } - } + var i : int = 0; + if (blend == MixBlend.add) { + for (i = 0; i < timelineCount; i++) + timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.Out); + } else { + var timelineData : Vector. = from.timelineData; + var timelineDipMix : Vector. = from.timelineDipMix; + + var firstFrame : Boolean = from.timelinesRotation.length == 0; + if (firstFrame) from.timelinesRotation.length = timelineCount << 1; + var timelinesRotation : Vector. = from.timelinesRotation; + + from.totalAlpha = 0; + for (i = 0; i < timelineCount; i++) { + var timeline : Timeline = timelines[i]; + var timelineBlend: MixBlend; + var alpha : Number = 0; + switch (timelineData[i]) { + case SUBSEQUENT: + if (!attachments && timeline is AttachmentTimeline) continue; + if (!drawOrder && timeline is DrawOrderTimeline) continue; + timelineBlend = blend; + alpha = alphaMix; + break; + case FIRST: + timelineBlend = MixBlend.setup; + alpha = alphaMix; + break; + case DIP: + timelineBlend = MixBlend.setup; + alpha = alphaDip; + break; + default: + timelineBlend = MixBlend.setup; + var dipMix : TrackEntry = timelineDipMix[i]; + alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); + break; + } + from.totalAlpha += alpha; + if (timeline is RotateTimeline) + applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame); + else { + timeline.apply(skeleton, animationLast, animationTime, events, alpha, timelineBlend, MixDirection.Out); + } + } + } if (to.mixDuration > 0) queueEvents(from, animationTime); this.events.length = 0; @@ -272,11 +278,11 @@ package spine.animation { return mix; } - private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, pose : MixPose, timelinesRotation : Vector., i : int, firstFrame : Boolean) : void { + private function applyRotateTimeline(timeline : Timeline, skeleton : Skeleton, time : Number, alpha : Number, blend : MixBlend, timelinesRotation : Vector., i : int, firstFrame : Boolean) : void { if (firstFrame) timelinesRotation[i] = 0; if (alpha == 1) { - timeline.apply(skeleton, 0, time, null, 1, pose, MixDirection.In); + timeline.apply(skeleton, 0, time, null, 1, blend, MixDirection.In); return; } @@ -284,7 +290,7 @@ package spine.animation { var frames : Vector. = rotateTimeline.frames; var bone : Bone = skeleton.bones[rotateTimeline.boneIndex]; if (time < frames[0]) { - if (pose == MixPose.setup) bone.rotation = bone.data.rotation; + if (blend == MixBlend.setup) bone.rotation = bone.data.rotation; return; } @@ -305,7 +311,7 @@ package spine.animation { } // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. - var r1 : Number = pose == MixPose.setup ? bone.data.rotation : bone.rotation; + var r1 : Number = blend == MixBlend.setup ? bone.data.rotation : bone.rotation; var total : Number, diff : Number = r2 - r1; if (diff == 0) { total = timelinesRotation[i]; @@ -559,7 +565,8 @@ package spine.animation { var mixingTo : Vector. = this.mixingTo; for (var i : int = 0, n : int = tracks.length; i < n; i++) { var entry : TrackEntry = tracks[i]; - if (entry != null) entry.setTimelineData(null, mixingTo, propertyIDs); + if (entry != null && (i == 0 || entry.mixBlend != MixBlend.add)) + entry.setTimelineData(null, mixingTo, propertyIDs); } } diff --git a/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as b/spine-as3/spine-as3/src/spine/animation/AttachmentTimeline.as index 6c2e75dde..842626015 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, pose : MixPose, direction : MixDirection) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var attachmentName : String; var slot : Slot = skeleton.slots[slotIndex]; - if (direction == MixDirection.Out && pose == MixPose.setup) { + if (direction == MixDirection.Out && blend == MixBlend.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 (pose == MixPose.setup) { + if (blend == MixBlend.setup || blend == MixBlend.first) { 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 379998798..675abd5a6 100644 --- a/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ColorTimeline.as @@ -60,16 +60,16 @@ package spine.animation { frames[int(frameIndex + A)] = a; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var slot : Slot = skeleton.slots[slotIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: slot.color.setFromColor(slot.data.color); return; - case MixPose.current: + case MixBlend.first: 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); @@ -102,7 +102,7 @@ package spine.animation { if (alpha == 1) { slot.color.setFrom(r, g, b, a); } else { - if (pose == MixPose.setup) { + if (blend == MixBlend.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 b88a354f8..7223f7486 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, pose : MixPose, direction : MixDirection) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, 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 5c04e8bd6..d8eaa8871 100644 --- a/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as @@ -57,7 +57,7 @@ package spine.animation { frameVertices[frameIndex] = vertices; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var vertexAttachment : VertexAttachment; var setupVertices : Vector.; var slot : Slot = skeleton.slots[slotIndex]; @@ -65,7 +65,7 @@ package spine.animation { if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment)).applyDeform(attachment)) return; var verticesArray : Vector. = slot.attachmentVertices; - if (verticesArray.length == 0) alpha = 1; + if (verticesArray.length == 0) blend = MixBlend.setup; var frameVertices : Vector.> = this.frameVertices; var vertexCount : int = frameVertices[0].length; @@ -75,11 +75,11 @@ package spine.animation { var i : int; if (time < frames[0]) { vertexAttachment = VertexAttachment(slotAttachment); - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: verticesArray.length = 0; return; - case MixPose.current: + case MixBlend.first: if (alpha == 1) { verticesArray.length = 0; return; @@ -108,27 +108,54 @@ package spine.animation { if (time >= frames[frames.length - 1]) { // Time is after last frame. var lastVertices : Vector. = frameVertices[frames.length - 1]; if (alpha == 1) { - // Vertex positions or deform offsets, no alpha. - for (i = 0, n = vertexCount; i < n; i++) - vertices[i] = lastVertices[i]; - } else if (pose == MixPose.setup) { - vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { - // Unweighted vertex positions, with alpha. - setupVertices = vertexAttachment.vertices; - for (i = 0; i < vertexCount; i++) { - setup = setupVertices[i]; - vertices[i] = setup + (lastVertices[i] - setup) * alpha; + if (blend == MixBlend.add) { + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + vertices[i] += lastVertices[i] - setupVertices[i]; + } + } else { + for (i = 0; i < vertexCount; i++) + vertices[i] += lastVertices[i]; } - } else { - // Weighted deform offsets, with alpha. - for (i = 0; i < vertexCount; i++) - vertices[i] = lastVertices[i] * alpha; + } else { + for (i = 0, n = vertexCount; i < n; i++) + vertices[i] = lastVertices[i]; } } else { - // Vertex positions or deform offsets, with alpha. - for (i = 0; i < vertexCount; i++) - vertices[i] += (lastVertices[i] - vertices[i]) * alpha; + switch (blend) { + case MixBlend.setup: + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + // Unweighted vertex positions, with alpha. + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + setup = setupVertices[i]; + vertices[i] = setup + (lastVertices[i] - setup) * alpha; + } + } else { + // Weighted deform offsets, with alpha. + for (i = 0; i < vertexCount; i++) + vertices[i] = lastVertices[i] * alpha; + } + break; + case MixBlend.first: + case MixBlend.replace: + for (i = 0; i < vertexCount; i++) + vertices[i] += (lastVertices[i] - vertices[i]) * alpha; + case MixBlend.add: + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + vertices[i] += (lastVertices[i] - setupVertices[i]) * alpha; + } + } else { + for (i = 0; i < vertexCount; i++) + vertices[i] += lastVertices[i] * alpha; + } + } } return; } @@ -141,34 +168,67 @@ package spine.animation { var percent : Number = getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime)); if (alpha == 1) { - // Vertex positions or deform offsets, no alpha. - for (i = 0; i < vertexCount; i++) { - prev = prevVertices[i]; - vertices[i] = prev + (nextVertices[i] - prev) * percent; - } - } else if (pose == MixPose.setup) { - vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { - // Unweighted vertex positions, with alpha. - setupVertices = vertexAttachment.vertices; - for (i = 0; i < vertexCount; i++) { - prev = prevVertices[i]; - setup = setupVertices[i]; - vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; + if (blend == MixBlend.add) { + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i]; + vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; + } + } else { + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i]; + vertices[i] += prev + (nextVertices[i] - prev) * percent; + } } - } else { - // Weighted deform offsets, with alpha. - for (i = 0; i < vertexCount; i++) { + } else { + for (i = 0; i < vertexCount; i++) { prev = prevVertices[i]; - vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; + vertices[i] = prev + (nextVertices[i] - prev) * percent; } } } else { - // Vertex positions or deform offsets, with alpha. - for (i = 0; i < vertexCount; i++) { - prev = prevVertices[i]; - vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; - } + switch (blend) { + case MixBlend.setup: + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + // Unweighted vertex positions, with alpha. + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i], setup = setupVertices[i]; + vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; + } + } else { + // Weighted deform offsets, with alpha. + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i]; + vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } + break; + case MixBlend.first: + case MixBlend.replace: + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i]; + vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; + } + break; + case MixBlend.add: + vertexAttachment = VertexAttachment(slotAttachment); + if (vertexAttachment.bones == null) { + setupVertices = vertexAttachment.vertices; + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i], setup = setupVertices[i]; + vertices[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; + } + } else { + for (i = 0; i < vertexCount; i++) { + prev = prevVertices[i]; + vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } + } } } } diff --git a/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as b/spine-as3/spine-as3/src/spine/animation/DrawOrderTimeline.as index f46ff6896..9ccb193a7 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, pose : MixPose, direction : MixDirection) : void { - if (direction == MixDirection.Out && pose == MixPose.setup) { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { + if (direction == MixDirection.Out && blend == MixBlend.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 (pose == MixPose.setup) { + if (blend == MixBlend.setup || blend == MixBlend.first) { 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 b33b22c1b..218a42533 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, pose : MixPose, direction : MixDirection) : void { + public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, 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, pose, direction); + apply(skeleton, lastTime, int.MAX_VALUE, firedEvents, alpha, blend, 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 1449d6197..f4078e98f 100644 --- a/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as @@ -57,15 +57,15 @@ package spine.animation { frames[int(frameIndex + BEND_DIRECTION)] = bendDirection; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var constraint : IkConstraint = skeleton.ikConstraints[ikConstraintIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: constraint.mix = constraint.data.mix; constraint.bendDirection = constraint.data.bendDirection; return; - case MixPose.current: + case MixBlend.first: constraint.mix += (constraint.data.mix - constraint.mix) * alpha; constraint.bendDirection = constraint.data.bendDirection; } @@ -73,7 +73,7 @@ package spine.animation { } if (time >= frames[int(frames.length - ENTRIES)]) { // Time is after last frame. - if (pose == MixPose.setup) { + if (blend == MixBlend.setup) { constraint.mix = constraint.data.mix + (frames[frames.length + PREV_MIX] - constraint.data.mix) * alpha; constraint.bendDirection = direction == MixDirection.Out ? constraint.data.bendDirection : int(frames[frames.length + PREV_BEND_DIRECTION]); } else { @@ -89,7 +89,7 @@ package spine.animation { var frameTime : Number = frames[frame]; var percent : Number = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); - if (pose == MixPose.setup) { + if (blend == MixBlend.setup) { constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha; constraint.bendDirection = direction == MixDirection.Out ? constraint.data.bendDirection : int(frames[frame + PREV_BEND_DIRECTION]); } else { diff --git a/spine-as3/spine-as3/src/spine/animation/MixPose.as b/spine-as3/spine-as3/src/spine/animation/MixBlend.as similarity index 84% rename from spine-as3/spine-as3/src/spine/animation/MixPose.as rename to spine-as3/spine-as3/src/spine/animation/MixBlend.as index 5be41fb78..d6d319a82 100644 --- a/spine-as3/spine-as3/src/spine/animation/MixPose.as +++ b/spine-as3/spine-as3/src/spine/animation/MixBlend.as @@ -29,15 +29,16 @@ *****************************************************************************/ package spine.animation { - public class MixPose { + public class MixBlend { public var ordinal : int; - public function MixPose(order : int) { + public function MixBlend(order : int) { this.ordinal = order; } - public static const setup : MixPose = new MixPose(0); - public static const current : MixPose = new MixPose(1); - public static const currentLayered : MixPose = new MixPose(2); + public static const setup : MixBlend = new MixBlend(0); + public static const first : MixBlend = new MixBlend(1); + public static const replace : MixBlend = new MixBlend(2); + public static const add : MixBlend = new MixBlend(3); } } \ No newline at end of file diff --git a/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as b/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as index 60ed68b82..50ed5d70f 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintMixTimeline.as @@ -57,15 +57,15 @@ package spine.animation { frames[frameIndex + TRANSLATE] = translateMix; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: constraint.rotateMix = constraint.data.rotateMix; constraint.translateMix = constraint.data.translateMix; return; - case MixPose.current: + case MixBlend.first: constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha; constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha; } @@ -88,7 +88,7 @@ package spine.animation { translate += (frames[frame + TRANSLATE] - translate) * percent; } - if (pose == MixPose.setup) { + if (blend == MixBlend.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 fe8e3f8c4..1ad9a166f 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintPositionTimeline.as @@ -56,14 +56,14 @@ package spine.animation { frames[frameIndex + VALUE] = value; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: constraint.position = constraint.data.position; return; - case MixPose.current: + case MixBlend.first: constraint.position += (constraint.data.position - constraint.position) * alpha; } return; @@ -81,7 +81,7 @@ package spine.animation { position += (frames[frame + VALUE] - position) * percent; } - if (pose == MixPose.setup) + if (blend == MixBlend.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 d2671e029..991a75bbb 100644 --- a/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/PathConstraintSpacingTimeline.as @@ -42,14 +42,14 @@ package spine.animation { return (TimelineType.pathConstraintSpacing.ordinal << 24) + pathConstraintIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var constraint : PathConstraint = skeleton.pathConstraints[pathConstraintIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: constraint.spacing = constraint.data.spacing; return; - case MixPose.current: + case MixBlend.first: constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha; } return; @@ -68,7 +68,7 @@ package spine.animation { spacing += (frames[frame + VALUE] - spacing) * percent; } - if (pose == MixPose.setup) + if (blend == MixBlend.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 b50945685..bad23fdb3 100644 --- a/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as @@ -56,32 +56,36 @@ package spine.animation { frames[int(frameIndex + ROTATION)] = degrees; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; var r : Number; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: bone.rotation = bone.data.rotation; return; - case MixPose.current: + case MixBlend.first: r = bone.data.rotation - bone.rotation; - r -= (16384 - int((16384.499999999996 - r / 360))) * 360; - bone.rotation += r * alpha; + bone.rotation += (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; } return; } if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame. - 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; - r -= (16384 - int((16384.499999999996 - r / 360))) * 360; // Wrap within -180 and 180. - bone.rotation += r * alpha; - } + r = frames[frames.length + PREV_ROTATION]; + switch (blend) { + case MixBlend.setup: + bone.rotation = bone.data.rotation + r * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + r += bone.data.rotation - bone.rotation; + r -= (16384 - int((16384.499999999996 - r / 360))) * 360; // Wrap within -180 and 180. + case MixBlend.add: + bone.rotation += r * alpha; + } return; } @@ -92,15 +96,16 @@ package spine.animation { var percent : Number = getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); r = frames[frame + ROTATION] - prevRotation; - r -= (16384 - int((16384.499999999996 - r / 360))) * 360; - r = prevRotation + r * percent; - if (pose == MixPose.setup) { - r -= (16384 - int((16384.499999999996 - r / 360))) * 360; - bone.rotation = bone.data.rotation + r * alpha; - } else { - r = bone.data.rotation + r - bone.rotation; - r -= (16384 - int((16384.499999999996 - r / 360))) * 360; - bone.rotation += r * alpha; + r = prevRotation + (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * percent; + switch (blend) { + case MixBlend.setup: + bone.rotation = bone.data.rotation + (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + r += bone.data.rotation - bone.rotation; + case MixBlend.add: + bone.rotation += (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; } } } diff --git a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as index 05fdf7d32..3e1f9cef8 100644 --- a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as @@ -43,17 +43,17 @@ package spine.animation { return (TimelineType.scale.ordinal << 24) + boneIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: bone.scaleX = bone.data.scaleX; bone.scaleY = bone.data.scaleY; return; - case MixPose.current: + case MixBlend.first: bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha; bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha; } @@ -76,27 +76,58 @@ package spine.animation { y = (y + (frames[frame + Y] - y) * percent) * bone.data.scaleY; } if (alpha == 1) { - bone.scaleX = x; - bone.scaleY = y; + if (blend == MixBlend.add) { + bone.scaleX += x - bone.data.scaleX; + bone.scaleY += y - bone.data.scaleY; + } else { + bone.scaleX = x; + bone.scaleY = y; + } } else { var bx : Number, by : Number; - if (pose == MixPose.setup) { - bx = bone.data.scaleX; - by = bone.data.scaleY; - } else { - bx = bone.scaleX; - by = bone.scaleY; - } - // Mixing out uses sign of setup or current pose, else use sign of key. if (direction == MixDirection.Out) { - x = Math.abs(x) * MathUtils.signum(bx); - y = Math.abs(y) * MathUtils.signum(by); + switch (blend) { + case MixBlend.setup: + bx = bone.data.scaleX; + by = bone.data.scaleY; + bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha; + bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + bx = bone.scaleX; + by = bone.scaleY; + bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha; + bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha; + break; + case MixBlend.add: + bx = bone.scaleX; + by = bone.scaleY; + bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bone.data.scaleX) * alpha; + bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - bone.data.scaleY) * alpha; + } } else { - bx = Math.abs(bx) * MathUtils.signum(x); - by = Math.abs(by) * MathUtils.signum(y); + switch (blend) { + case MixBlend.setup: + bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x); + by = Math.abs(bone.data.scaleY) * MathUtils.signum(y); + bone.scaleX = bx + (x - bx) * alpha; + bone.scaleY = by + (y - by) * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + bx = Math.abs(bone.scaleX) * MathUtils.signum(x); + by = Math.abs(bone.scaleY) * MathUtils.signum(y); + bone.scaleX = bx + (x - bx) * alpha; + bone.scaleY = by + (y - by) * alpha; + break; + case MixBlend.add: + bx = MathUtils.signum(x); + by = MathUtils.signum(y); + bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha; + bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha; + } } - bone.scaleX = bx + (x - bx) * alpha; - bone.scaleY = by + (y - by) * alpha; } } } diff --git a/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as b/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as index d1cde5be1..c4702ccb5 100644 --- a/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ShearTimeline.as @@ -42,17 +42,17 @@ package spine.animation { return (TimelineType.shear.ordinal << 24) + boneIndex; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: bone.shearX = bone.data.shearX; bone.shearY = bone.data.shearY; return; - case MixPose.current: + case MixBlend.first: bone.shearX += (bone.data.shearX - bone.shearX) * alpha; bone.shearY += (bone.data.shearY - bone.shearY) * alpha; } @@ -74,12 +74,19 @@ package spine.animation { x = x + (frames[frame + X] - x) * percent; y = y + (frames[frame + Y] - y) * percent; } - if (pose == MixPose.setup) { - bone.shearX = bone.data.shearX + x * alpha; - bone.shearY = bone.data.shearY + y * alpha; - } else { - bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha; - bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha; + switch (blend) { + case MixBlend.setup: + bone.shearX = bone.data.shearX + x * alpha; + bone.shearY = bone.data.shearY + y * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha; + bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha; + break; + case MixBlend.add: + bone.shearX += x * alpha; + bone.shearY += y * alpha; } } } diff --git a/spine-as3/spine-as3/src/spine/animation/Timeline.as b/spine-as3/spine-as3/src/spine/animation/Timeline.as index 9673c7357..dd7a6c811 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, pose : MixPose, direction : MixDirection) : void; + function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void; function getPropertyId() : int; } diff --git a/spine-as3/spine-as3/src/spine/animation/TrackEntry.as b/spine-as3/spine-as3/src/spine/animation/TrackEntry.as index aa6eb3661..506426130 100644 --- a/spine-as3/spine-as3/src/spine/animation/TrackEntry.as +++ b/spine-as3/spine-as3/src/spine/animation/TrackEntry.as @@ -47,6 +47,7 @@ package spine.animation { public var animationStart : Number, animationEnd : Number, animationLast : Number, nextAnimationLast : Number; public var delay : Number, trackTime : Number, trackLast : Number, nextTrackLast : Number, trackEnd : Number, timeScale : Number; public var alpha : Number, mixTime : Number, mixDuration : Number, interruptAlpha : Number, totalAlpha : Number = 0; + public var mixBlend: MixBlend = MixBlend.replace; public var timelineData : Vector. = new Vector.(); public var timelineDipMix : Vector. = new Vector.(); public var timelinesRotation : Vector. = new Vector.(); diff --git a/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as b/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as index 39de58bda..e7b2773e3 100644 --- a/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TransformConstraintTimeline.as @@ -60,21 +60,21 @@ package spine.animation { frames[frameIndex + SHEAR] = shearMix; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var constraint : TransformConstraint = skeleton.transformConstraints[transformConstraintIndex]; var data : TransformConstraintData; if (time < frames[0]) { data = constraint.data; - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: constraint.rotateMix = data.rotateMix; constraint.translateMix = data.translateMix; constraint.scaleMix = data.scaleMix; constraint.shearMix = data.shearMix; return; - case MixPose.current: + case MixBlend.first: constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha; constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha; constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha; @@ -105,7 +105,7 @@ package spine.animation { scale += (frames[frame + SCALE] - scale) * percent; shear += (frames[frame + SHEAR] - shear) * percent; } - if (pose == MixPose.setup) { + if (blend == MixBlend.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 61e5aef9d..1aa337688 100644 --- a/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TranslateTimeline.as @@ -57,17 +57,17 @@ package spine.animation { frames[int(frameIndex + Y)] = y; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var bone : Bone = skeleton.bones[boneIndex]; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: bone.x = bone.data.x; bone.y = bone.data.y; return; - case MixPose.current: + case MixBlend.first: bone.x += (bone.data.x - bone.x) * alpha; bone.y += (bone.data.y - bone.y) * alpha; } @@ -89,12 +89,19 @@ package spine.animation { x += (frames[frame + X] - x) * percent; y += (frames[frame + Y] - y) * percent; } - if (pose == MixPose.setup) { - bone.x = bone.data.x + x * alpha; - bone.y = bone.data.y + y * alpha; - } else { - bone.x += (bone.data.x + x - bone.x) * alpha; - bone.y += (bone.data.y + y - bone.y) * alpha; + switch (blend) { + case MixBlend.setup: + bone.x = bone.data.x + x * alpha; + bone.y = bone.data.y + y * alpha; + break; + case MixBlend.first: + case MixBlend.replace: + bone.x += (bone.data.x + x - bone.x) * alpha; + bone.y += (bone.data.y + y - bone.y) * alpha; + break; + case MixBlend.add: + bone.x += x * alpha; + bone.y += y * alpha; } } } diff --git a/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as b/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as index a947ef3d5..1ce1e8bc3 100644 --- a/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/TwoColorTimeline.as @@ -64,18 +64,18 @@ package spine.animation { this.frames[frameIndex + TwoColorTimeline.B2] = b2; } - override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, pose : MixPose, direction : MixDirection) : void { + override public function apply(skeleton : Skeleton, lastTime : Number, time : Number, firedEvents : Vector., alpha : Number, blend : MixBlend, direction : MixDirection) : void { var frames : Vector. = this.frames; var slot : Slot = skeleton.slots[slotIndex]; var light : Color, dark : Color; if (time < frames[0]) { - switch (pose) { - case MixPose.setup: + switch (blend) { + case MixBlend.setup: slot.color.setFromColor(slot.data.color); slot.darkColor.setFromColor(slot.data.darkColor); return; - case MixPose.current: + case MixBlend.first: light = slot.color; dark = slot.darkColor; var setupLight : Color = slot.data.color, setupDark : Color = slot.data.darkColor; @@ -123,7 +123,7 @@ package spine.animation { } else { light = slot.color; dark = slot.darkColor; - if (pose == MixPose.setup) { + if (blend == MixBlend.setup) { light.setFromColor(slot.data.color); dark.setFromColor(slot.data.darkColor); } diff --git a/spine-c/spine-c/src/spine/Animation.c b/spine-c/spine-c/src/spine/Animation.c index 7c385b281..df1043fcd 100644 --- a/spine-c/spine-c/src/spine/Animation.c +++ b/spine-c/spine-c/src/spine/Animation.c @@ -489,8 +489,10 @@ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f break; case SP_MIX_BLEND_FIRST: case SP_MIX_BLEND_REPLACE: - bone->scaleX += (x - bone->scaleX * SIGNUM(x)) * alpha; - bone->scaleY += (y - bone->scaleY * SIGNUM(y)) * alpha; + bx = ABS(bone->scaleX) * SIGNUM(x); + by = ABS(bone->scaleY) * SIGNUM(y); + bone->scaleX = bx + (x - bx) * alpha; + bone->scaleY = by + (y - by) * alpha; break; case SP_MIX_BLEND_ADD: bx = SIGNUM(x); diff --git a/spine-starling/spine-starling-example/lib/spine-as3.swc b/spine-starling/spine-starling-example/lib/spine-as3.swc index dc5ab4569..12937d9f9 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-example/src/spine/examples/Main.as b/spine-starling/spine-starling-example/src/spine/examples/Main.as index efc957784..418d37ac2 100644 --- a/spine-starling/spine-starling-example/src/spine/examples/Main.as +++ b/spine-starling/spine-starling-example/src/spine/examples/Main.as @@ -38,7 +38,7 @@ package spine.examples { private var _starling : Starling; public function Main() { - _starling = new Starling(SpineboyExample, stage); + _starling = new Starling(OwlExample, stage); _starling.enableErrorChecking = true; _starling.showStats = true; _starling.skipUnchangedFrames = false; diff --git a/spine-starling/spine-starling-example/src/spine/examples/OwlExample.as b/spine-starling/spine-starling-example/src/spine/examples/OwlExample.as new file mode 100644 index 000000000..8012c34b6 --- /dev/null +++ b/spine-starling/spine-starling-example/src/spine/examples/OwlExample.as @@ -0,0 +1,88 @@ +package spine.examples { + import spine.animation.MixBlend; + import spine.animation.TrackEntry; + import starling.display.DisplayObjectContainer; + import starling.events.Touch; + import starling.events.TouchPhase; + import starling.core.Starling; + import starling.events.TouchEvent; + import starling.display.Sprite; + + import spine.SkeletonData; + import spine.SkeletonJson; + import spine.attachments.AtlasAttachmentLoader; + import spine.starling.StarlingTextureLoader; + import spine.atlas.Atlas; + import spine.attachments.AttachmentLoader; + import spine.starling.SkeletonAnimation; + + public class OwlExample extends Sprite { + [Embed(source = "/owl-pro.json", mimeType = "application/octet-stream")] + static public const OwlJson : Class; + + [Embed(source = "/owl.atlas", mimeType = "application/octet-stream")] + static public const OwlAtlas : Class; + + [Embed(source = "/owl.png")] + static public const OwlAtlasTexture : Class; + private var skeleton : SkeletonAnimation; + + private var left: TrackEntry; + private var right: TrackEntry; + private var up: TrackEntry; + private var down: TrackEntry; + + public function OwlExample() { + var attachmentLoader : AttachmentLoader; + var spineAtlas : Atlas = new Atlas(new OwlAtlas(), new StarlingTextureLoader(new OwlAtlasTexture())); + attachmentLoader = new AtlasAttachmentLoader(spineAtlas); + + var json : SkeletonJson = new SkeletonJson(attachmentLoader); + json.scale = 0.5; + var skeletonData : SkeletonData = json.readSkeletonData(new OwlJson()); + + this.x = 400; + this.y = 400; + + skeleton = new SkeletonAnimation(skeletonData); + skeleton.state.setAnimationByName(0, "idle", true); + skeleton.state.setAnimationByName(1, "blink", true); + left = skeleton.state.setAnimationByName(2, "left", true); + right = skeleton.state.setAnimationByName(3, "right", true); + up = skeleton.state.setAnimationByName(4, "up", true); + down = skeleton.state.setAnimationByName(5, "down", true); + + left.alpha = right.alpha = up.alpha = down.alpha = 0; + left.mixBlend = right.mixBlend = up.mixBlend = down.mixBlend = MixBlend.add; + + skeleton.state.timeScale = 0.5; + skeleton.state.update(0.25); + skeleton.state.apply(skeleton.skeleton); + skeleton.skeleton.updateWorldTransform(); + + addChild(skeleton); + Starling.juggler.add(skeleton); + + addEventListener(TouchEvent.TOUCH, onTouch); + } + + private function onTouch(event : TouchEvent) : void { + var touch : Touch = event.getTouch(this); + if (touch && touch.phase == TouchPhase.ENDED) { + var parent : DisplayObjectContainer = this.parent; + this.removeFromParent(true); + parent.addChild(new SpineboyExample()); + } + + if (touch && touch.phase == TouchPhase.HOVER) { + var x : Number = touch.globalX / 800.0; + left.alpha = (Math.max(x, 0.5) - 0.5) * 2; + right.alpha = (0.5 - Math.min(x, 0.5)) * 2; + + var y : Number = touch.globalY / 600.0; + down.alpha = (Math.max(y, 0.5) - 0.5) * 2; + up.alpha = (0.5 - Math.min(y, 0.5)) * 2; + } + } + } +} \ No newline at end of file diff --git a/spine-starling/spine-starling/lib/spine-as3.swc b/spine-starling/spine-starling/lib/spine-as3.swc index dc5ab4569..12937d9f9 100644 Binary files a/spine-starling/spine-starling/lib/spine-as3.swc and b/spine-starling/spine-starling/lib/spine-as3.swc differ diff --git a/spine-ts/core/src/AnimationState.ts b/spine-ts/core/src/AnimationState.ts index f5b839f89..07e07c5fb 100644 --- a/spine-ts/core/src/AnimationState.ts +++ b/spine-ts/core/src/AnimationState.ts @@ -554,7 +554,8 @@ module spine { for (var i = 0, n = this.tracks.length; i < n; i++) { let entry = this.tracks[i]; - if (entry != null && (i == 0 || entry.mixBlend != MixBlend.add)) entry.setTimelineData(null, mixingTo, propertyIDs); + if (entry != null && (i == 0 || entry.mixBlend != MixBlend.add)) + entry.setTimelineData(null, mixingTo, propertyIDs); } }