A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(cocos): the importer converts Animation clips (.anim) to timelines: position, scale, rotation, sprite and label colour, opacity and active tracks, and plays model-file clips on the node
yhhc541d5d1f4d5
diff --git a/pipeline/src/import/cocos/animationClip.ts b/pipeline/src/import/cocos/animationClip.tsnew file mode 100644index 000000000..5742127aa--- /dev/null+++ b/pipeline/src/import/cocos/animationClip.ts@@ -0,0 +1,214 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A Cocos `.anim` as an engine `.estimeline`.+ *+ * A clip is a list of tracks. Each names what it animates by a path (the nodes below the animated one, then a component, then a property) and+ * carries curves of keyframes. The timeline says the same: a track addresses a node by `childPath`, a component and a property, with a channel of+ * keys per number. A node's position, scale and a sprite's colour are numbers on both sides; a rotation is keyed as euler angles in Cocos and as a+ * quaternion here, so it is sampled; an `active` track becomes the ranges the node is active in. A track on something the timeline cannot reach is+ * counted, not dropped silently.+ */+type Raw = Record<string, unknown>;+const isObj = (v: unknown): v is Raw => typeof v === 'object' && v !== null && !Array.isArray(v);+const num = (v: unknown, d: number): number => (typeof v === 'number' && Number.isFinite(v) ? v : d);++export interface Key { time: number; value: number; inTangent: number; outTangent: number; interpolation: string }++export interface ConvertedClip {+ document: {+ version: string; type: 'timeline'; duration: number; wrapMode: 'once' | 'loop' | 'pingPong'; tracks: Raw[];+ };+ /** Tracks that could not be carried, by what they animated, with how many. */+ skipped: Map<string, number>;+ /** Whether the clip had events, which a timeline does not take from here. */+ events: number;+}++/** Cocos's `AnimationClip.WrapMode`: Loop (2, 22) and PingPong (36) are themselves, the rest play once. */+function wrapModeOf(mode: unknown): 'once' | 'loop' | 'pingPong' {+ return mode === 2 || mode === 22 ? 'loop' : mode === 36 ? 'pingPong' : 'once';+}++const INTERPOLATION = ['linear', 'step', 'hermite'];++/** One curve as keys. A value that is not an object (an older file) is a number on a straight line. */+function curveKeys(d: unknown[], curveRef: unknown, scale = 1): Key[] {+ const curve = deref(d, curveRef);+ if (!isObj(curve)) return [];+ const times = Array.isArray(curve._times) ? (curve._times as unknown[]) : [];+ const values = Array.isArray(curve._values) ? (curve._values as unknown[]) : [];+ const keys: Key[] = [];+ for (let i = 0; i < Math.min(times.length, values.length); i++) {+ const v = deref(d, values[i]);+ const time = num(times[i], 0);+ if (isObj(v)) {+ keys.push({+ time, value: num(v.value, 0) * scale, inTangent: num(v.leftTangent, 0) * scale, outTangent: num(v.rightTangent, 0) * scale,+ interpolation: INTERPOLATION[num(v.interpolationMode, 0)] ?? 'linear',+ });+ } else if (typeof v === 'number') {+ keys.push({ time, value: v * scale, inTangent: 0, outTangent: 0, interpolation: 'linear' });+ }+ }+ return keys;+}++function deref(d: unknown[], v: unknown): unknown {+ return isObj(v) && typeof v.__id__ === 'number' ? d[v.__id__] : v;+}++/** A curve's value at @p t, straight between keys and held by a step key. */+function sample(keys: Key[], t: number): number {+ if (keys.length === 0) return 0;+ if (t <= keys[0]!.time) return keys[0]!.value;+ const last = keys[keys.length - 1]!;+ if (t >= last.time) return last.value;+ for (let i = 1; i < keys.length; i++) {+ const b = keys[i]!;+ if (t <= b.time) {+ const a = keys[i - 1]!;+ if (a.interpolation === 'step') return a.value;+ const f = b.time === a.time ? 0 : (t - a.time) / (b.time - a.time);+ return a.value + (b.value - a.value) * f;+ }+ }+ return last.value;+}++/** Euler degrees as a quaternion (x, y, z, w), by Cocos's own `Quat.fromEuler`. */+function quatFromEuler(xDeg: number, yDeg: number, zDeg: number): [number, number, number, number] {+ const r = Math.PI / 360;+ const x = xDeg * r, y = yDeg * r, z = zDeg * r;+ const sx = Math.sin(x), cx = Math.cos(x), sy = Math.sin(y), cy = Math.cos(y), sz = Math.sin(z), cz = Math.cos(z);+ return [sx * cy * cz + cx * sy * sz, cx * sy * cz + sx * cy * sz, cx * cy * sz - sx * sy * cz, cx * cy * cz - sx * sy * sz];+}++/** The times to sample a rotation at: every key of any axis, and a step between them so a turn is not cut across by a straight line. */+function sampleTimes(curves: Key[][], duration: number): number[] {+ const times = new Set<number>();+ for (const keys of curves) for (const k of keys) times.add(k.time);+ const sorted = [...times].sort((a, b) => a - b);+ const out = new Set<number>(sorted);+ for (let i = 1; i < sorted.length; i++) {+ const span = sorted[i]! - sorted[i - 1]!;+ const steps = Math.min(30, Math.ceil(span * 30));+ for (let s = 1; s < steps; s++) out.add(sorted[i - 1]! + (span * s) / steps);+ }+ if (sorted.length === 0 && duration > 0) out.add(0);+ return [...out].sort((a, b) => a - b);+}++interface Target {+ /** Names of the nodes below the animated one, joined by `/`. */+ childPath: string;+ /** The component the property is on (`cc.Sprite`), or null for the node itself. */+ component: string | null;+ property: string;+}++function targetOf(d: unknown[], binding: unknown): Target | null {+ const b = deref(d, binding);+ if (!isObj(b)) return null;+ const path = deref(d, b.path);+ if (!isObj(path) || !Array.isArray(path._paths)) return null;+ const names: string[] = [];+ let component: string | null = null;+ let property = '';+ for (const raw of path._paths as unknown[]) {+ const p = deref(d, raw);+ if (typeof p === 'string') {+ property = p;+ } else if (isObj(p) && typeof p.path === 'string') {+ names.push(...p.path.split('/').filter(Boolean)); // a HierarchyPath+ } else if (isObj(p) && typeof p.component === 'string') {+ component = p.component;+ }+ }+ return property ? { childPath: names.join('/'), component, property } : null;+}++const COMPONENT_OF: Record<string, { component: string; property: string; scale: number } | undefined> = {+ 'cc.Sprite.color': { component: 'Sprite', property: 'color', scale: 1 / 255 },+ 'cc.Label.color': { component: 'Text', property: 'color', scale: 1 / 255 },+ 'cc.UIOpacity.opacity': { component: 'GroupOpacity', property: 'opacity', scale: 1 / 255 },+};++const channelNames = (property: string, n: number): string[] => ['x', 'y', 'z', 'w'].slice(0, n).map((c) => `${property}.${c}`);++/** Convert the objects of a `.anim` file. */+export function convertAnimationClip(objects: unknown): ConvertedClip {+ const skipped = new Map<string, number>();+ const skip = (what: string): void => { skipped.set(what, (skipped.get(what) ?? 0) + 1); };+ const empty: ConvertedClip = { document: { version: '1.3', type: 'timeline', duration: 0, wrapMode: 'once', tracks: [] }, skipped, events: 0 };+ const d = Array.isArray(objects) ? objects : [objects];+ const clip = d[0];+ if (!isObj(clip)) return empty;+ const duration = num(clip._duration, 0);+ const tracks: Raw[] = [];+ for (const ref of Array.isArray(clip._tracks) ? (clip._tracks as unknown[]) : []) {+ const track = deref(d, ref);+ if (!isObj(track)) continue;+ const target = targetOf(d, track._binding);+ if (!target) { skip('unreadable'); continue; }+ const channels = (Array.isArray(track._channels) ? (track._channels as unknown[]) : track._channel ? [track._channel] : [])+ .map((c) => { const ch = deref(d, c); return isObj(ch) ? ch._curve : undefined; });+ const name = target.childPath.split('/').pop() ?? '';+ const kind = String(track.__type__ ?? '');++ if (target.component === null && (target.property === 'position' || target.property === 'scale') && kind.endsWith('VectorTrack')) {+ const props = channelNames(target.property, 3);+ const out = props.map((property, i) => ({ property, keyframes: curveKeys(d, channels[i]) })).filter((c) => c.keyframes.length > 0);+ if (out.length > 0) tracks.push({ type: 'property', name, childPath: target.childPath, component: 'Transform', channels: out });+ continue;+ }+ if (target.component === null && target.property === 'eulerAngles' && kind.endsWith('VectorTrack')) {+ const curves = [0, 1, 2].map((i) => curveKeys(d, channels[i]));+ const times = sampleTimes(curves, duration);+ if (times.length === 0) continue;+ const quats = times.map((t) => quatFromEuler(sample(curves[0]!, t), sample(curves[1]!, t), sample(curves[2]!, t)));+ const out = channelNames('rotation', 4).map((property, i) => ({+ property, keyframes: times.map((time, k) => ({ time, value: quats[k]![i]!, inTangent: 0, outTangent: 0, interpolation: 'linear' })),+ }));+ tracks.push({ type: 'property', name, childPath: target.childPath, component: 'Transform', channels: out });+ continue;+ }+ if (target.component === null && target.property === 'rotation' && kind.endsWith('QuatTrack')) {+ const out = channelNames('rotation', 4).map((property, i) => ({ property, keyframes: curveKeys(d, channels[i]) })).filter((c) => c.keyframes.length > 0);+ if (out.length > 0) tracks.push({ type: 'property', name, childPath: target.childPath, component: 'Transform', channels: out });+ continue;+ }+ const mapped = target.component ? COMPONENT_OF[`${target.component}.${target.property}`] : undefined;+ if (mapped && kind.endsWith('ColorTrack')) {+ const out = ['r', 'g', 'b', 'a'].map((c, i) => ({ property: `${mapped.property}.${c}`, keyframes: curveKeys(d, channels[i], mapped.scale) })).filter((c) => c.keyframes.length > 0);+ if (out.length > 0) tracks.push({ type: 'property', name, childPath: target.childPath, component: mapped.component, channels: out });+ continue;+ }+ if (mapped && kind.endsWith('RealTrack')) {+ const keyframes = curveKeys(d, channels[0], mapped.scale);+ if (keyframes.length > 0) tracks.push({ type: 'property', name, childPath: target.childPath, component: mapped.component, channels: [{ property: mapped.property, keyframes }] });+ continue;+ }+ if (target.component === null && target.property === 'active' && kind.endsWith('ObjectTrack')) {+ const curve = deref(d, channels[0]);+ const times = isObj(curve) && Array.isArray(curve._times) ? (curve._times as number[]) : [];+ const values = isObj(curve) && Array.isArray(curve._values) ? (curve._values as unknown[]) : [];+ const ranges: Array<{ start: number; end: number }> = [];+ let from: number | null = null;+ for (let i = 0; i < Math.min(times.length, values.length); i++) {+ const on = deref(d, values[i]) === true;+ if (on && from === null) from = times[i]!;+ if (!on && from !== null) { ranges.push({ start: from, end: times[i]! }); from = null; }+ }+ if (from !== null) ranges.push({ start: from, end: Math.max(duration, from) });+ if (ranges.length > 0) tracks.push({ type: 'activation', name, childPath: target.childPath, ranges });+ continue;+ }+ skip(`${target.component ?? 'node'}.${target.property}`);+ }+ return {+ document: { version: '1.3', type: 'timeline', duration, wrapMode: wrapModeOf(clip.wrapMode), tracks },+ skipped,+ events: Array.isArray(clip._events) ? clip._events.length : 0,+ };+}diff --git a/pipeline/src/import/cocos/components.ts b/pipeline/src/import/cocos/components.tsindex 81cac6c63..ab9455be9 100644--- a/pipeline/src/import/cocos/components.ts+++ b/pipeline/src/import/cocos/components.ts@@ -65,6 +65,8 @@ export interface ComponentContext {* the part was picked because the model draws only one.*/modelMesh?(uuid: string): { components: Record<string, unknown>[]; exact: boolean } | null;+ /** The timeline a Cocos `.anim` clip is converted to (project-relative), or null when the clip is not one of the project's. */+ animationClip?(clipUuid: string, where: string): string | null;/** The joints, by name, a skinned part of a model is bound to, in the order its vertices index them. */modelSkin?(meshUuid: string): string[] | null;/**@@ -501,6 +503,18 @@ function skinnedMeshRenderer(c: CocosComponent, ctx: ComponentContext, where: streturn { component: mesh.component, extra: [{ type: 'MeshSkin', data: { joints } }] };}+/** `cc.Animation`: the clip it plays by default, as a timeline that plays on the node, from the start if the node asks. */+function animation(c: CocosComponent, node: CocosNode, ctx: ComponentContext, where: string): ComponentData | null {+ const clips = (Array.isArray(c.data._clips) ? c.data._clips : []).map(uuidOf).filter(Boolean);+ const wanted = uuidOf(c.data._defaultClip) || clips[0] || '';+ // a clip of the project's own, or one that lives in a model file and animates the bones below this node+ const ref = wanted ? ctx.animationClip?.(wanted, where) ?? ctx.clipOn?.(wanted, namePaths(node), where) : null;+ if (!ref) return null;+ if (clips.length > 1) ctx.report.note('animation-several-clips', where);+ ctx.report.component('cc.Animation', clips.length > 1 ? 'partial' : 'mapped');+ return { type: 'TimelinePlayer', data: { timeline: ref, playing: c.data.playOnLoad === true, speed: 1, wrapMode: '' } };+}+/** `cc.SkeletalAnimation`: the clip it plays by default, copied onto this node's own bones, played from the start if the node asks. */function skeletalAnimation(c: CocosComponent, node: CocosNode, ctx: ComponentContext, where: string): ComponentData | null {const clips = (Array.isArray(c.data._clips) ? c.data._clips : []).map(uuidOf).filter(Boolean);@@ -711,6 +725,9 @@ export function convertNode(node: CocosNode, ctx: ComponentContext, where: strinif (skinned) extra.push(...skinned.extra);break;}+ case 'cc.Animation':+ out = animation(c, node, ctx, where);+ break;case 'cc.SkeletalAnimation':out = skeletalAnimation(c, node, ctx, where);break;diff --git a/pipeline/src/import/cocos/importProject.ts b/pipeline/src/import/cocos/importProject.tsindex 801f94d29..ca5eff23d 100644--- a/pipeline/src/import/cocos/importProject.ts+++ b/pipeline/src/import/cocos/importProject.ts@@ -18,7 +18,8 @@ import type { AssetHints, SliceBorder } from './components';import { convertPrefab, convertScene, type ConvertContext } from './convert';import { parseCocosDocument, type CocosDocument } from './document';import { ImportReport, type ImportReportData } from './report';-import { CocosModels, clipOf, clipPlayOf, retargetClip } from './models';+import { CocosModels, clipOf, clipPlayOf, mintSidecar, retargetClip } from './models';+import { convertAnimationClip } from './animationClip';import type { MaterialInfo } from './components';export interface CocosImportOptions {@@ -130,6 +131,7 @@ export async function importCocosProject(opts: CocosImportOptions): Promise<Impo};const models = new CocosModels(index, out, into, opts.dryRun === true);+ const clips = new Map<string, string | null>();const scripts = buildScriptIndex(index);/** The scripts a converted document refers to, which the project has to bundle for those components to exist. */const usedScripts = new Set<string>();@@ -173,6 +175,25 @@ export async function importCocosProject(opts: CocosImportOptions): Promise<Impoif (own) return own;return m.use.skin.size === 1 ? [...m.use.skin.values()][0]! : null;},+ animationClip(clipUuid, where) {+ const entry = index.byUuid.get(clipUuid.split('@')[0]!);+ if (!entry || !entry.rel.endsWith('.anim')) return null;+ const rel = outRef(esRel(entry.rel, '.estimeline'));+ if (clips.has(entry.file)) return clips.get(entry.file) ?? null;+ let ref: string | null = null;+ try {+ const converted = convertAnimationClip(JSON.parse(readFileSync(entry.file, 'utf8')));+ for (const [what, count] of converted.skipped) report.note('animation-track-unsupported', `${entry.rel}: ${what} ×${count}`);+ if (converted.events > 0) report.note('animation-events-dropped', `${entry.rel}: ${converted.events}`);+ write(rel, converted.document);+ if (!opts.dryRun) mintSidecar(path.join(out, rel));+ ref = rel;+ } catch (err) {+ report.note('animation-clip-unreadable', `${where}: ${entry.rel}: ${(err as Error).message}`);+ }+ clips.set(entry.file, ref);+ return ref;+ },clipOn(clipUuid, paths, where) {const clip = models.use(clipUuid);if (!clip) return null;diff --git a/pipeline/src/import/cocos/models.ts b/pipeline/src/import/cocos/models.tsindex 6115150f6..4877d8d4f 100644--- a/pipeline/src/import/cocos/models.ts+++ b/pipeline/src/import/cocos/models.ts@@ -161,6 +161,12 @@ function readUse(prefabAbs: string, prefab: string, absDir: string, stem: stringreturn { prefab: hasPrefab ? prefab : '', rootId: (doc as { rootEntityId?: string }).rootEntityId ?? 'n1', byEntity, clips, paths, skin };}+/** Give a generated asset the `.meta` an export needs to ship it, unless it has one. */+export function mintSidecar(file: string): void {+ const type = metaTypeFor(file);+ if (type && !existsSync(`${file}.meta`)) writeFileSync(`${file}.meta`, `${JSON.stringify(mintMeta(type), null, 2)}\n`);+}+/** How a Cocos clip plays, from the sub-asset the scene names: the part of the animation it is, and what it does at its end. */export interface ClipPlay {span?: { from: number; to: number };@@ -228,7 +234,6 @@ export function retargetClip(out: string, clipRef: string, paths: Map<string, stmkdirSync(path.dirname(file), { recursive: true });const copy = { ...doc, tracks, duration: span ? span.to - span.from : doc.duration, ...(play.wrapMode ? { wrapMode: play.wrapMode } : {}) };writeFileSync(file, `${JSON.stringify(copy, null, 2)}\n`);- const type = metaTypeFor(file);- if (type && !existsSync(`${file}.meta`)) writeFileSync(`${file}.meta`, `${JSON.stringify(mintMeta(type), null, 2)}\n`);+ mintSidecar(file);return { ref, dropped };}diff --git a/pipeline/tests/cocos-animation-clip.test.ts b/pipeline/tests/cocos-animation-clip.test.tsnew file mode 100644index 000000000..54546e70f--- /dev/null+++ b/pipeline/tests/cocos-animation-clip.test.ts@@ -0,0 +1,118 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A Cocos `.anim` as an engine timeline: what each kind of track becomes, and what is counted instead of lost.+ */+import { describe, expect, it } from 'vitest';+import { convertAnimationClip } from '../src/import/cocos/animationClip';++/** Build a `.anim`'s object list from tracks written as [binding path parts, track kind, curves]; ids are assigned as the list grows. */+function anim(tracks: Array<{ kind: string; path: unknown[]; curves: Array<{ times: number[]; values: unknown[] }> }>, over: Record<string, unknown> = {}): unknown[] {+ const objects: unknown[] = [];+ const add = (o: unknown): { __id__: number } => { objects.push(o); return { __id__: objects.length - 1 }; };+ const clip: Record<string, unknown> = { __type__: 'cc.AnimationClip', _name: 'clip', wrapMode: 1, _duration: 1, _tracks: [], _events: [], ...over };+ add(clip);+ const refs = tracks.map((t) => {+ const path = add({ __type__: 'cc.animation.TrackPath', _paths: t.path.map((p) => (typeof p === 'string' ? p : add(p))) });+ const channels = t.curves.map((c) => add({ __type__: 'cc.animation.Channel', _curve: add({ __type__: 'cc.RealCurve', _times: c.times, _values: c.values }) }));+ return add({ __type__: t.kind, _binding: { __type__: 'cc.animation.TrackBinding', path }, _channels: channels });+ });+ clip._tracks = refs;+ return objects;+}+const real = (value: number, extra: object = {}) => ({ __type__: 'cc.RealKeyframeValue', interpolationMode: 0, value, leftTangent: 0, rightTangent: 0, ...extra });+const hierarchy = (path: string) => ({ __type__: 'cc.animation.HierarchyPath', path });+const component = (name: string) => ({ __type__: 'cc.animation.ComponentPath', component: name });++describe('a Cocos animation clip', () => {+ it('moves a child node: position becomes the transform\'s three channels, under the child\'s path', () => {+ const { document } = convertAnimationClip(anim([{+ kind: 'cc.animation.VectorTrack', path: [hierarchy('body/arm'), 'position'],+ curves: [+ { times: [0, 1], values: [real(0), real(10)] }, { times: [0, 1], values: [real(5), real(5)] }, { times: [0, 1], values: [real(0), real(0)] },+ ],+ }]));+ expect(document.tracks).toHaveLength(1);+ const t = document.tracks[0] as any;+ expect([t.type, t.childPath, t.component]).toEqual(['property', 'body/arm', 'Transform']);+ expect(t.channels.map((c: any) => c.property)).toEqual(['position.x', 'position.y', 'position.z']);+ expect(t.channels[0].keyframes.map((k: any) => k.value)).toEqual([0, 10]);+ });++ it('fades a sprite: its colour keyed 0..255 becomes 0..1 on the Sprite', () => {+ const key = (v: number) => real(v);+ const curve = (a: number, b: number) => ({ times: [0, 1], values: [key(a), key(b)] });+ const { document } = convertAnimationClip(anim([{+ kind: 'cc.animation.ColorTrack', path: [component('cc.Sprite'), 'color'], curves: [curve(255, 255), curve(255, 255), curve(255, 255), curve(255, 0)],+ }]));+ const t = document.tracks[0] as any;+ expect([t.component, t.childPath]).toEqual(['Sprite', '']);+ expect(t.channels.map((c: any) => c.property)).toEqual(['color.r', 'color.g', 'color.b', 'color.a']);+ expect(t.channels[3].keyframes.map((k: any) => k.value)).toEqual([1, 0]);+ });++ it('turns a node about its Z: euler angles become the quaternion channels, sampled finely enough to follow the turn', () => {+ const { document } = convertAnimationClip(anim([{+ kind: 'cc.animation.VectorTrack', path: [hierarchy('wheel'), 'eulerAngles'],+ curves: [{ times: [0, 1], values: [real(0), real(0)] }, { times: [0, 1], values: [real(0), real(0)] }, { times: [0, 1], values: [real(0), real(180)] }],+ }]));+ const t = document.tracks[0] as any;+ expect(t.channels.map((c: any) => c.property)).toEqual(['rotation.x', 'rotation.y', 'rotation.z', 'rotation.w']);+ const z = t.channels[2].keyframes;+ const w = t.channels[3].keyframes;+ expect(z.length).toBeGreaterThan(10);+ expect(z[0].value).toBeCloseTo(0, 5);+ expect(z[z.length - 1].value).toBeCloseTo(1, 5); // 180 degrees about Z: (0, 0, 1, 0)+ expect(w[w.length - 1].value).toBeCloseTo(0, 5);+ const mid = Math.floor(z.length / 2);+ expect(Math.hypot(z[mid].value, w[mid].value)).toBeCloseTo(1, 2); // still a rotation half-way+ });++ it('turns an active track into the ranges the node is on in', () => {+ const { document } = convertAnimationClip(anim([{+ kind: 'cc.animation.ObjectTrack', path: [hierarchy('flash'), 'active'], curves: [{ times: [0, 0.25, 0.5], values: [false, true, false] }],+ }]));+ expect(document.tracks[0]).toMatchObject({ type: 'activation', childPath: 'flash', ranges: [{ start: 0.25, end: 0.5 }] });+ });++ it('keeps the key\'s curve: held, straight, or with its tangents', () => {+ const { document } = convertAnimationClip(anim([{+ kind: 'cc.animation.VectorTrack', path: ['scale'],+ curves: [{ times: [0, 1, 2], values: [real(1, { interpolationMode: 1 }), real(2, { interpolationMode: 2, leftTangent: 3, rightTangent: 4 }), real(3)] },+ { times: [0], values: [real(1)] }, { times: [0], values: [real(1)] }],+ }], { _duration: 2 }));+ const keys = (document.tracks[0] as any).channels[0].keyframes;+ expect(keys.map((k: any) => k.interpolation)).toEqual(['step', 'hermite', 'linear']);+ expect([keys[1].inTangent, keys[1].outTangent]).toEqual([3, 4]);+ });++ it('plays once, loops or ping-pongs as the clip says, and counts what it cannot carry', () => {+ expect(convertAnimationClip(anim([], { wrapMode: 2 })).document.wrapMode).toBe('loop');+ expect(convertAnimationClip(anim([], { wrapMode: 36 })).document.wrapMode).toBe('pingPong');+ expect(convertAnimationClip(anim([], { wrapMode: 1 })).document.wrapMode).toBe('once');+ const clip = convertAnimationClip(anim([{+ kind: 'cc.animation.RealTrack', path: [component('cc.ParticleSystem'), 'material'], curves: [{ times: [0], values: [real(1)] }],+ }], { _events: [{}, {}] }));+ expect(clip.document.tracks).toEqual([]);+ expect(clip.skipped.get('cc.ParticleSystem.material')).toBe(1);+ expect(clip.events).toBe(2);+ });+});++describe('what the engine reads of it', () => {+ it('parses every kind of track written here with the timeline loader the runtime uses', async () => {+ const path = await import('node:path');+ const { parseTimelineAsset } = await import(/* @vite-ignore */ path.resolve(__dirname, '../../sdk/src/timeline/TimelineLoader.ts'));+ const curve = (v: number[]) => ({ times: v.map((_, i) => i), values: v.map((x) => real(x)) });+ const clip = convertAnimationClip(anim([+ { kind: 'cc.animation.VectorTrack', path: [hierarchy('a'), 'position'], curves: [curve([0, 1]), curve([0, 1]), curve([0, 0])] },+ { kind: 'cc.animation.VectorTrack', path: [hierarchy('a'), 'eulerAngles'], curves: [curve([0, 0]), curve([0, 0]), curve([0, 90])] },+ { kind: 'cc.animation.ColorTrack', path: [component('cc.Sprite'), 'color'], curves: [curve([255, 0]), curve([255, 0]), curve([255, 0]), curve([255, 0])] },+ { kind: 'cc.animation.RealTrack', path: [component('cc.UIOpacity'), 'opacity'], curves: [curve([255, 0])] },+ { kind: 'cc.animation.ObjectTrack', path: [hierarchy('b'), 'active'], curves: [{ times: [0, 1], values: [true, false] }] },+ ], { wrapMode: 2 }));+ const asset = parseTimelineAsset(clip.document);+ expect(asset.tracks.map((t: any) => t.type)).toEqual(['property', 'property', 'property', 'property', 'activation']);+ expect(asset.wrapMode).toBeDefined();+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex b0efbccd8..046bd35a6 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'feat(cocos): the importer converts Animation clips (.anim) to timelines: position, scale, rotation, sprite and label colour, opacity and active tracks, and plays model-file clips on the node':+ {"internal":"The Cocos Creator compatibility layer and importer have not shipped; nothing a creator reaches without opting in."},'feat(cocos): a MeshRenderer wears the Cocos material it was given (image, tint, blending, culling, lighting), and a mesh is found by its place in the model when its name is not readable':{"internal":"The Cocos Creator compatibility layer and importer have not shipped; nothing a creator reaches without opting in."},'feat(cocos): the importer binds SkinnedMeshRenderer to the model skin and plays SkeletalAnimation clips on the skeleton they are put on, cut to the span and wrap mode Cocos names':