diff --git a/cocos/core/animation/animation-clip.ts b/cocos/core/animation/animation-clip.ts index 1c72b4ba49..ebb736ec63 100644 --- a/cocos/core/animation/animation-clip.ts +++ b/cocos/core/animation/animation-clip.ts @@ -600,6 +600,9 @@ export class AnimationClip extends Asset { if (rootMotionTrackExcludes.includes(track)) { continue; } + if (Array.from(track.channels()).every(({ curve }) => curve.keyFramesCount === 0)) { + continue; + } const trackTarget = binder(track[trackBindingTag]); if (!trackTarget) { continue; diff --git a/cocos/core/animation/tracks/track.ts b/cocos/core/animation/tracks/track.ts index c2087acb8e..19a826df89 100644 --- a/cocos/core/animation/tracks/track.ts +++ b/cocos/core/animation/tracks/track.ts @@ -270,7 +270,7 @@ export { TrackPath }; * It's the basic unit of animation clip. */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}Track`) -export class Track { +export abstract class Track { get path () { return this._binding.path; } @@ -304,9 +304,7 @@ export class Track { return range; } - public [createEvalSymbol] (runtimeBinding: RuntimeBinding): TrackEval { - throw new Error(`No Impl`); - } + public abstract [createEvalSymbol] (runtimeBinding: RuntimeBinding): TrackEval; @serializable private _binding = new TrackBinding(); diff --git a/tests/animation/animation-clip-3.x.test.ts b/tests/animation/animation-clip-3.x.test.ts index 65bf97b889..f792da2cd6 100644 --- a/tests/animation/animation-clip-3.x.test.ts +++ b/tests/animation/animation-clip-3.x.test.ts @@ -1,5 +1,5 @@ -import { Node, RealKeyframeValue, Vec3 } from '../../cocos/core'; -import { ColorTrack, RealTrack, SizeTrack, TrackPath, VectorTrack } from '../../cocos/core/animation/animation'; +import { Color, Component, Node, Quat, RealKeyframeValue, Size, Vec3 } from '../../cocos/core'; +import { ColorTrack, ObjectTrack, QuatTrack, RealTrack, SizeTrack, TrackPath, VectorTrack } from '../../cocos/core/animation/animation'; import { AnimationClip, searchForRootBonePathSymbol } from '../../cocos/core/animation/animation-clip'; import { TargetPath } from '../../cocos/core/animation/target-path'; @@ -122,6 +122,35 @@ describe('Animation Clip', () => { expect(Vec3.equals(dummyRootJointNode.position, new Vec3(1.4))).toBe(true); }); }); + + test('Empty track does not take effect', () => { + const trackAndInitValues = [ + [new RealTrack(), 6.6, (a: number, b: number) => a === b], + [new ObjectTrack(), true, (a: boolean, b: boolean) => a === b], + [new VectorTrack(), new Vec3(6.6, 6.6, 6.6), Vec3.equals], + [new ColorTrack(), new Color(66, 66, 66, 66), Color.equals], + [new SizeTrack(), new Size(6.6, 6.6), (a: Size, b: Size) => a.equals(b)], + [new QuatTrack(), new Quat(6.6, 6.6, 6.6, 6.6), Quat.equals], + ] as const; + + class TestComp extends Component { + public properties: unknown[] = []; + } + + const node = new Node(); + const component = node.addComponent(TestComp) as TestComp; + const clip = new AnimationClip(); + trackAndInitValues.forEach(([track, value], index) => { + component.properties.push(value); + track.path.toComponent(TestComp).toProperty('properties').toElement(index); + }); + const evaluator = clip.createEvaluator({ target: node }); + evaluator.evaluate(0.0); + trackAndInitValues.forEach(([, value, equals], index) => { + expect((equals as (a: unknown, b: unknown) => boolean)( + component.properties[index], value)).toBeTruthy(); + }); + }); }); describe(`Tracks`, () => { diff --git a/tests/animation/animation-clip.test.ts b/tests/animation/animation-clip.test.ts index ee7d7c0255..e441444595 100644 --- a/tests/animation/animation-clip.test.ts +++ b/tests/animation/animation-clip.test.ts @@ -160,29 +160,15 @@ describe('Custom track setter', () => { expect(mockSetValue).toBeCalled(); }); - test('get() got called if any of channels is empty', () => { - const target = new Target(); - const mockGetValue = target.getValue = jest.fn(target.getValue); - const mockSetValue = target.setValue = jest.fn(target.setValue); - - const track = new VectorTrack(); - track.proxy = valueProxyWithGetSet; - const clip = new AnimationClip(); - clip.addTrack(track); - const clipEval = clip.createEvaluator({ - target, - }); - clipEval.evaluate(0.0); - expect(mockGetValue).toBeCalled(); - expect(mockSetValue).toBeCalled(); - }); - test('If get() is not defined, the default channel value would be used', () => { const target = new Target(); const mockSetValue = target.setValue = jest.fn(target.setValue); const track = new VectorTrack(); track.proxy = valueProxyWithOnlySet; + track.channels().forEach(({ curve }) => { + curve.assignSorted([[0.0, ({ value: 2.0 })]]); + }); const clip = new AnimationClip(); clip.addTrack(track); const clipEval = clip.createEvaluator({