mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Empty tracks shall not take effect (#9777)
* Empty tracks shall not take effect * Fix test * Fix test
This commit is contained in:
committed by
GitHub
parent
da2f73e096
commit
080053bc33
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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`, () => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user