Skip to content

Commit

Permalink
Optimize-2
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit committed Jul 21, 2021
1 parent dfdce41 commit 74a9857
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cocos/3d/skeletal-animation/skeletal-animation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export class SkeletalAnimationState extends AnimationState {
}
}

private _sampleCurvesBaked (ratio: number) {
private _sampleCurvesBaked (time: number) {
const ratio = time / this.duration;
const info = this._animInfo!;
const curFrame = (ratio * this._frames + 0.5) | 0;
if (curFrame === info.data[0]) { return; }
Expand Down
18 changes: 10 additions & 8 deletions cocos/core/animation/animation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class AnimationState extends Playable {

public sample () {
const info = this.getWrappedInfo(this.time, this._wrappedInfo);
this._sampleCurves(info.ratio);
this._sampleCurves(info.time);
if (!EDITOR || legacyCC.GAME_VIEW) {
this._sampleEvents(info);
}
Expand Down Expand Up @@ -510,12 +510,13 @@ export class AnimationState extends Playable {
this.emit(EventType.PAUSE, this);
}

protected _sampleCurves (ratio: number) {
if (this._poseOutput) {
this._poseOutput.weight = this.weight;
protected _sampleCurves (time: number) {
const { _poseOutput: poseOutput, _clipEval: clipEval } = this;
if (poseOutput) {
poseOutput.weight = this.weight;
}
if (this._clipEval) {
this._clipEval.evaluate(this.current);
if (clipEval) {
clipEval.evaluate(time);
}
}

Expand Down Expand Up @@ -558,8 +559,9 @@ export class AnimationState extends Playable {

let time = this.time % playbackDuration;
if (time < 0.0) { time += playbackDuration; }
const ratio = (playbackStart + time) * this._invDuration;
this._sampleCurves(ratio);
const realTime = playbackStart + time;
const ratio = realTime * this._invDuration;
this._sampleCurves(playbackStart + time);

if (!EDITOR || legacyCC.GAME_VIEW) {
this._sampleEvents(this.getWrappedInfo(this.time, this._wrappedInfo));
Expand Down
13 changes: 10 additions & 3 deletions cocos/core/animation/tracks/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,22 @@ export abstract class SingleChannelTrack<TCurve extends Curve> extends Track {

public [createEvalSymbol] (_runtimeBinding: RuntimeBinding): TrackEval {
const { curve } = this._channel;
return {
evaluate: (time) => curve.evaluate(time),
};
return new SingleChannelTrackEval(curve);
}

@serializable
private _channel: Channel<TCurve>;
}

class SingleChannelTrackEval<TCurve extends Curve> implements TrackEval {
constructor (private _curve: TCurve) {
}

public evaluate (time: number) {
return this._curve.evaluate(time);
}
}

export type RuntimeBinding = {
setValue(value: unknown): void;

Expand Down

0 comments on commit 74a9857

Please sign in to comment.