- 删除从未显示的 idle 手势帧(小程序包内 png 和视频用高清帧),训练分包减少 17KB - 删除骨架连线 BONES、镜像函数 mirrorPose(骨架已去掉)和未使用的 Bgm 类型 - 只给单测用的 sampleMotion 移到测试目录 - 删除训练菜单里未使用的 .menu-icon-text 样式 - 补全 history 单测数据缺少的 adviceKind 字段(严格类型检查报错)
82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
/**
|
|
* 教练“小甄”帧资源
|
|
*
|
|
* 动作帧是 AI 画的原图加少量插帧(由 training-videos/scripts 生成并对齐),内置在 training/static/coach。
|
|
* 每个动作的一侧 10~24 帧,出自同一张设定稿并统一了脸(前后帧一致,不会闪);
|
|
* 每帧带实测的动作幅度,按幅度查帧,帧间距不均匀时播放速度仍然均匀。
|
|
*/
|
|
import type { MoveId, Side } from './motions.ts'
|
|
import { COACH_HD, COACH_SEQUENCES, type CoachSequence } from './coachSequences.ts'
|
|
|
|
export type Gesture = 'wave' | 'cheer' | 'thumbs'
|
|
|
|
const MOVE_SEQUENCE: Record<MoveId, Record<Side, string>> = {
|
|
squat: { L: 'squat', R: 'squat' },
|
|
march: { L: 'march_l', R: 'march_r' },
|
|
jack: { L: 'jack_l', R: 'jack_r' },
|
|
raise: { L: 'raise', R: 'raise' },
|
|
}
|
|
|
|
/** 错误示范帧(示范视频对比用) */
|
|
export const MISTAKE_FRAMES: Record<MoveId, string> = {
|
|
squat: 'wrong_squat',
|
|
march: 'wrong_march',
|
|
jack: 'wrong_jack',
|
|
raise: 'wrong_raise',
|
|
}
|
|
|
|
function seqOf(move: MoveId, side: Side): CoachSequence {
|
|
return COACH_SEQUENCES[MOVE_SEQUENCE[move][side]]
|
|
}
|
|
|
|
export function sequenceOf(move: MoveId, side: Side): string[] {
|
|
return seqOf(move, side).frames
|
|
}
|
|
|
|
/** 动作到位的那一帧(封面、错误示范对比用) */
|
|
export function peakFrame(move: MoveId): string {
|
|
const frames = sequenceOf(move, 'L')
|
|
return frames[frames.length - 1]
|
|
}
|
|
|
|
export function frameUrl(name: string): string {
|
|
return `/training/static/coach/${name}.png`
|
|
}
|
|
|
|
/** 高清帧地址(COS):带内容版本号,重新上传同名文件后缓存自动刷新 */
|
|
export function hdFrameUrl(base: string, name: string): string {
|
|
return `${base}/${name}.webp?v=${COACH_HD.version}`
|
|
}
|
|
|
|
/** 高清帧的裁切框:在整张画布上的比例 [左, 上, 右, 下],用来把裁过的图放回原位 */
|
|
export function hdCropOf(move: MoveId): [number, number, number, number] {
|
|
return COACH_HD.crops[move]
|
|
}
|
|
|
|
/** 播放某个动作需要加载的全部帧 */
|
|
export function framesToLoad(move: MoveId): string[] {
|
|
return [...new Set([...sequenceOf(move, 'L'), ...sequenceOf(move, 'R')])]
|
|
}
|
|
|
|
export type FramePair = { a: string; b: string; w: number }
|
|
|
|
/** 动作幅度 → 相邻两帧与两帧之间的位置(0~1),按每帧的实测幅度插值 */
|
|
export function framePair(move: MoveId, amount: number, side: Side): FramePair {
|
|
const { frames, amounts } = seqOf(move, side)
|
|
const x = Math.min(1, Math.max(0, amount))
|
|
let i = 0
|
|
while (i < frames.length - 2 && amounts[i + 1] <= x) i += 1
|
|
const span = amounts[i + 1] - amounts[i]
|
|
const w = span > 0 ? Math.min(1, Math.max(0, (x - amounts[i]) / span)) : 1
|
|
return { a: frames[i], b: frames[i + 1], w }
|
|
}
|
|
|
|
/**
|
|
* 播放时的混合权重:大部分时间显示单张清晰帧,只在换帧的瞬间短暂过渡。
|
|
* 相邻两帧一直按比例混合的话,移动中的手臂会出现半透明的双影。
|
|
*/
|
|
export function crispBlend(w: number): number {
|
|
const t = Math.min(1, Math.max(0, (w - 0.44) / 0.12))
|
|
return t * t * (3 - 2 * t)
|
|
}
|