import { EventDispatcher, Object3D } from 'three'; import { Tween } from 'three/examples/jsm/libs/tween.module.js'; import { default as animation } from './index'; import { IClipAnimation, IClipAnimationFrame, IClipAnimationPlayerEventMap, IClipTransform, IClipTweenSource } from '../Interface'; /** * 剪辑动画播放器 * * @remarks * SDK 内部实现。业务侧推荐使用 {@link SoonSpace.playClipAnimation} 等高层方法, * 不需要直接构造该类。 * * 行为: * - 接收一组关键帧({@link IClipAnimationFrame}),按数组顺序串行播放 * - 每段为一次 `ssp.animation()` 补间,覆盖目标的 position / rotation / scale * - 通过 `update` / `start` 事件暴露每帧的 tween 数据,便于上层做 UI 同步 * * 生命周期: * - {@link initTransform} —— 记录初始姿态(首次 `play` 前自动调用) * - {@link play} —— 顺序播放所有 frame,被 {@link stop} 中断时优雅退出 * - {@link reset} —— 把目标 transform 还原到 `initTransform` 时的快照 * - {@link dispose} —— `stop + reset + 移除初始姿态标记` */ export declare class ClipAnimationPlayer extends EventDispatcher { /** SoonSpace 实例 —— 仅用 `animation()` 调度补间 + `render()` 触发重绘 */ readonly ssp: { animation: typeof animation; render: () => void; }; /** 被动画的目标对象(每帧的 position / rotation / scale 会写到这里) */ readonly target: Object3D; /** 当前 in-flight 的 tween 集合,{@link stop} 时统一打断 */ readonly tweenSet: Set>; /** 是否仍有 tween 在执行 */ get isPlaying(): boolean; constructor( /** SoonSpace 实例 —— 仅用 `animation()` 调度补间 + `render()` 触发重绘 */ ssp: { animation: typeof animation; render: () => void; }, /** 被动画的目标对象(每帧的 position / rotation / scale 会写到这里) */ target: Object3D); /** * 把当前 target.position / rotation / scale 作为初始快照记录到 target 上的 Symbol 槽 * * @remarks * 通常无需手动调用 —— {@link play} 会在首次执行前惰性调用一次。 * 多次调用不会覆盖(除非显式传入 `defaultTransform`)。 * * @param defaultTransform - 显式指定初始姿态(覆盖目标当前 transform 的快照) */ initTransform(defaultTransform?: IClipTransform): IClipTransform; /** 取出 {@link initTransform} 记录的初始姿态;未记录时返回 `undefined` */ getInitialTransform(): IClipTransform | undefined; /** * 按数组顺序播放关键帧 * * @remarks * - 首次调用时会通过 {@link initTransform} 记录初始姿态 * - 第 0 帧的"起点"为初始姿态;后续帧的"起点"为前一帧的 target 值 * - 被 {@link stop} 打断时立即结束剩余帧的播放并 resolve * * @param frames - 关键帧数组(**调用方需自行排序**;高层方法 `playClipAnimation` 会按 `index` 排序后再传入) */ play(frames: IClipAnimationFrame[]): Promise; /** 停止所有 in-flight tween;{@link play} 会随之 resolve */ stop(): void; /** * 把 target 还原到 {@link initTransform} 时的初始姿态并触发一次重绘 * * @remarks 未调用过 {@link initTransform} 时(无快照)此方法为 no-op */ reset(): void; /** * 一站式清理:{@link stop} → {@link reset} → 移除 target 上的初始姿态 Symbol 槽 * @remarks 释放后再次 {@link play} 会重新捕获当前 target 状态作为新的初始姿态 */ dispose(): void; } export type { IClipAnimation, IClipAnimationFrame, IClipTransform, IClipTweenSource, IClipAnimationPlayerEventMap, };