mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts] Port of commit 29bf262: Fix track 0 dip mixing to animation with key > frame 0.
This commit is contained in:
parent
556509adc8
commit
e1ea92aad7
@ -154,8 +154,8 @@ export class AnimationState {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the
|
/** Poses the skeleton using the track entry animations. The animation state is not changed, so can be applied to multiple
|
||||||
* animation state can be applied to multiple skeletons to pose them identically.
|
* skeletons to pose them identically.
|
||||||
* @returns True if any animations were applied. */
|
* @returns True if any animations were applied. */
|
||||||
apply (skeleton: Skeleton): boolean {
|
apply (skeleton: Skeleton): boolean {
|
||||||
if (!skeleton) throw new Error("skeleton cannot be null.");
|
if (!skeleton) throw new Error("skeleton cannot be null.");
|
||||||
@ -169,12 +169,14 @@ export class AnimationState {
|
|||||||
const current = tracks[i];
|
const current = tracks[i];
|
||||||
if (!current || current.delay > 0) continue;
|
if (!current || current.delay > 0) continue;
|
||||||
applied = true;
|
applied = true;
|
||||||
|
|
||||||
|
// Track 0 animations aren't for layering, so never use current values before the first key.
|
||||||
const blend: MixBlend = i === 0 ? MixBlend.first : current.mixBlend;
|
const blend: MixBlend = i === 0 ? MixBlend.first : current.mixBlend;
|
||||||
|
|
||||||
// Apply mixing from entries first.
|
// Apply mixing from entries first.
|
||||||
let alpha = current.alpha;
|
let alpha = current.alpha;
|
||||||
if (current.mixingFrom)
|
if (current.mixingFrom)
|
||||||
alpha *= this.applyMixingFrom(current, skeleton, blend);
|
alpha *= this.applyMixingFrom(current, skeleton);
|
||||||
else if (current.trackTime >= current.trackEnd && !current.next)
|
else if (current.trackTime >= current.trackEnd && !current.next)
|
||||||
alpha = 0;
|
alpha = 0;
|
||||||
let attachments = alpha >= current.alphaAttachmentThreshold;
|
let attachments = alpha >= current.alphaAttachmentThreshold;
|
||||||
@ -211,7 +213,7 @@ export class AnimationState {
|
|||||||
|
|
||||||
for (let ii = 0; ii < timelineCount; ii++) {
|
for (let ii = 0; ii < timelineCount; ii++) {
|
||||||
const timeline = timelines[ii];
|
const timeline = timelines[ii];
|
||||||
const timelineBlend = timelineMode[ii] === SUBSEQUENT ? blend : MixBlend.setup;
|
const timelineBlend = timelineMode[ii] === SUBSEQUENT ? current.mixBlend : MixBlend.setup;
|
||||||
if (!shortestRotation && timeline instanceof RotateTimeline) {
|
if (!shortestRotation && timeline instanceof RotateTimeline) {
|
||||||
this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, current.timelinesRotation, ii << 1, firstFrame);
|
this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, current.timelinesRotation, ii << 1, firstFrame);
|
||||||
} else if (timeline instanceof AttachmentTimeline) {
|
} else if (timeline instanceof AttachmentTimeline) {
|
||||||
@ -247,18 +249,16 @@ export class AnimationState {
|
|||||||
return applied;
|
return applied;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyMixingFrom (to: TrackEntry, skeleton: Skeleton, blend: MixBlend) {
|
applyMixingFrom (to: TrackEntry, skeleton: Skeleton) {
|
||||||
const from = to.mixingFrom!;
|
const from = to.mixingFrom!;
|
||||||
if (from.mixingFrom) this.applyMixingFrom(from, skeleton, blend);
|
if (from.mixingFrom) this.applyMixingFrom(from, skeleton);
|
||||||
|
|
||||||
let mix = 0;
|
let mix = 0;
|
||||||
if (to.mixDuration === 0) { // Single frame mix to undo mixingFrom changes.
|
if (to.mixDuration === 0) // Single frame mix to undo mixingFrom changes.
|
||||||
mix = 1;
|
mix = 1;
|
||||||
if (blend === MixBlend.first) blend = MixBlend.setup;
|
else {
|
||||||
} else {
|
|
||||||
mix = to.mixTime / to.mixDuration;
|
mix = to.mixTime / to.mixDuration;
|
||||||
if (mix > 1) mix = 1;
|
if (mix > 1) mix = 1;
|
||||||
if (blend !== MixBlend.first) blend = from.mixBlend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachments = mix < from.mixAttachmentThreshold, drawOrder = mix < from.mixDrawOrderThreshold;
|
const attachments = mix < from.mixAttachmentThreshold, drawOrder = mix < from.mixDrawOrderThreshold;
|
||||||
@ -272,6 +272,7 @@ export class AnimationState {
|
|||||||
else if (mix < from.eventThreshold)
|
else if (mix < from.eventThreshold)
|
||||||
events = this.events;
|
events = this.events;
|
||||||
|
|
||||||
|
const blend = from.mixBlend;
|
||||||
if (blend === MixBlend.add) {
|
if (blend === MixBlend.add) {
|
||||||
for (let i = 0; i < timelineCount; i++)
|
for (let i = 0; i < timelineCount; i++)
|
||||||
timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, MixDirection.out, false);
|
timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, MixDirection.out, false);
|
||||||
@ -1011,9 +1012,7 @@ export class TrackEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}, which
|
/** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}.
|
||||||
* replaces the values from the lower tracks with the animation values. {@link MixBlend#add} adds the animation values to
|
|
||||||
* the values from the lower tracks.
|
|
||||||
*
|
*
|
||||||
* The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is next
|
* The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is next
|
||||||
* called. */
|
* called. */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user