dsh-game-material-master 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -27,7 +27,9 @@ window.__ModuleLoader__.load({
27
27
  const GAME_STUDIO_PANEL_ID = "gameStudio";
28
28
  // ── 远程贡献 ─────────────────────────────────────────────────────────
29
29
  // 与宿主 src/wire.ts 的 METHODS 必须一一对应;那份是唯一的真源。
30
- const codec = (symbol) => ({ mode: "strict", typeSymbol: symbol, schema: { parse: (value) => value } });
30
+ // 宿主校验在服务端;浏览器半区只声明同一套 strict codec。
31
+ // DSH 的 typert 要求 create() 工厂,运行时走 codec.create().parse()。
32
+ const codec = (symbol) => ({ mode: "strict", typeSymbol: symbol, create: () => ({ parse: (value) => value }) });
31
33
  const REMOTE_METHODS = [
32
34
  ["getConfig", false],
33
35
  ["saveConfig", true],
@@ -58,6 +60,10 @@ window.__ModuleLoader__.load({
58
60
  ["pollVideos", true],
59
61
  ["clearVideos", true],
60
62
  ["runFrames", true],
63
+ ["prepareFramePick", true],
64
+ ["setFramePick", true],
65
+ ["setFramePicks", true],
66
+ ["resetFramePicks", true],
61
67
  ["rekey", true],
62
68
  ["compose", true],
63
69
  // 模块②:图片生成
@@ -224,7 +230,7 @@ window.__ModuleLoader__.load({
224
230
  const STAGES = [
225
231
  { key: "images", title: "① 八方向绿幕图", hint: "以源图为基准,按依赖顺序生成八个方位的纯绿幕全身图" },
226
232
  { key: "videos", title: "② 行走动作视频", hint: "固定镜头、固定背景,让角色朝原方位原地走三步" },
227
- { key: "frames", title: "③ 提取序列帧", hint: "每段视频按时长平均抽帧,逐帧核对动作连贯性" },
233
+ { key: "frames", title: "③ 提取序列帧", hint: "可整批等分抽帧,也可对每一段视频手动选帧" },
228
234
  { key: "sheet", title: "④ 抠绿幕合成整图", hint: "剔除绿幕并按行序拼成一张精灵图" },
229
235
  { key: "preview", title: "⑤ 行走预览", hint: "用 WASD 或方向键操控角色,看看八方向接起来顺不顺" }
230
236
  ];
@@ -510,6 +516,8 @@ window.__ModuleLoader__.load({
510
516
  .SPR_axisDotIndex{font-size:10px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}
511
517
  .SPR_axisRuler{display:flex;align-items:center;justify-content:space-between;gap:10px;font-size:11px;color:var(--dsw-alias-label-tertiary);margin-top:6px}
512
518
  .SPR_axisRulerMid{text-align:center}
519
+ .SPR_pickPanel{grid-column:1 / -1;border:1px solid var(--dsw-alias-border-l2);border-radius:12px;padding:12px;background:var(--dsw-alias-bg-layer-1)}
520
+ .SPR_pickHead{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:8px;flex-wrap:wrap}
513
521
  .SPR_modules{display:flex;gap:8px;padding:10px 18px;border-bottom:1px solid var(--dsw-alias-border-l2);flex:none;flex-wrap:wrap}
514
522
  .SPR_module{font:inherit;cursor:pointer;text-align:left;display:flex;flex-direction:column;gap:1px;padding:6px 12px;border-radius:10px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary)}
515
523
  .SPR_module:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}
@@ -1879,19 +1887,181 @@ window.__ModuleLoader__.load({
1879
1887
  }, video?.approved === true ? "已通过" : "通过")));
1880
1888
  })));
1881
1889
  }
1890
+ /**
1891
+ * 某一段行走视频的选帧轴。圆圈个数 = 输出帧数,拖到候选条带的哪一格,
1892
+ * 那一张输出帧就用那一格。松手才提交,和转圈截帧的八圆圈是同一套交互。
1893
+ */
1894
+ function FramePickAxis({ project, directionKey, total, duration, picks, api, start, busy }) {
1895
+ const trackRef = React.useRef(null);
1896
+ const [drag, setDrag] = React.useState(null);
1897
+ const pickOf = (slot) => {
1898
+ if (drag !== null && drag.slot === slot)
1899
+ return drag.index;
1900
+ return Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0)));
1901
+ };
1902
+ const indexFromEvent = (event) => {
1903
+ const node = trackRef.current;
1904
+ if (node === null || total <= 0)
1905
+ return 0;
1906
+ const rect = node.getBoundingClientRect();
1907
+ if (rect.width <= 0)
1908
+ return 0;
1909
+ const fraction = clamp01((event.clientX - rect.left) / rect.width);
1910
+ return Math.min(total - 1, Math.max(0, Math.round(fraction * total - 0.5)));
1911
+ };
1912
+ const commit = (slot, index) => {
1913
+ const current = Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0)));
1914
+ if (index === current)
1915
+ return;
1916
+ void start(() => api.setFramePick({ projectId: project.id, key: directionKey, slot, index }), { reload: true }, { key: `frames:slot:${directionKey}:${slot}`, label: `正在切出第 ${slot + 1} 帧…` });
1917
+ };
1918
+ const nudge = (slot, delta) => {
1919
+ const next = Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0) + delta));
1920
+ commit(slot, next);
1921
+ };
1922
+ const lanes = {};
1923
+ const used = [];
1924
+ picks.forEach((_, slot) => {
1925
+ const index = pickOf(slot);
1926
+ let lane = 0;
1927
+ while (used.some((item) => item.lane === lane && Math.abs(item.index - index) < 2))
1928
+ lane++;
1929
+ used.push({ lane, index });
1930
+ lanes[slot] = lane;
1931
+ });
1932
+ const candidates = project.frames?.[directionKey]?.candidates ?? {};
1933
+ return h("div", { className: "SPR_axisWrap" }, h("div", {
1934
+ className: "SPR_axis",
1935
+ ref: trackRef,
1936
+ "data-dragging": drag === null ? undefined : "true",
1937
+ onPointerMove: (event) => {
1938
+ if (drag === null)
1939
+ return;
1940
+ const index = indexFromEvent(event);
1941
+ if (index !== drag.index)
1942
+ setDrag({ slot: drag.slot, index });
1943
+ },
1944
+ onPointerUp: (event) => {
1945
+ if (drag === null)
1946
+ return;
1947
+ const index = indexFromEvent(event);
1948
+ const slot = drag.slot;
1949
+ setDrag(null);
1950
+ commit(slot, index);
1951
+ },
1952
+ onPointerLeave: () => {
1953
+ if (drag === null)
1954
+ return;
1955
+ setDrag(null);
1956
+ }
1957
+ }, h("img", {
1958
+ className: "SPR_axisStrip",
1959
+ src: assetUrl(project, candidates.strip, candidates.updatedAt),
1960
+ alt: "候选帧",
1961
+ draggable: false
1962
+ }), picks.map((_, slot) => {
1963
+ const index = pickOf(slot);
1964
+ const active = drag !== null && drag.slot === slot;
1965
+ const time = duration > 0 && total > 0 ? (index * duration) / total : 0;
1966
+ return h("button", {
1967
+ key: slot,
1968
+ type: "button",
1969
+ className: "SPR_axisDot",
1970
+ "data-active": active ? "true" : "false",
1971
+ "data-testid": `frame-dot-${directionKey}-${slot}`,
1972
+ style: { left: `${((index + 0.5) / Math.max(1, total)) * 100}%`, top: `${6 + (lanes[slot] ?? 0) * 26}px` },
1973
+ title: `第 ${slot + 1} 帧:候选第 ${index + 1}/${total}(${time.toFixed(2)} 秒)— 拖动改位置,←/→ 微调`,
1974
+ "aria-label": `第 ${slot + 1} 帧,候选第 ${index + 1}`,
1975
+ onPointerDown: (event) => {
1976
+ if (busy === true)
1977
+ return;
1978
+ event.preventDefault();
1979
+ setDrag({ slot, index });
1980
+ try {
1981
+ event.currentTarget.setPointerCapture?.(event.pointerId);
1982
+ }
1983
+ catch {
1984
+ /* 指针捕获失败不影响拖动 */
1985
+ }
1986
+ },
1987
+ onKeyDown: (event) => {
1988
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
1989
+ return;
1990
+ event.preventDefault();
1991
+ nudge(slot, event.key === "ArrowLeft" ? -1 : 1);
1992
+ }
1993
+ }, h("span", { className: "SPR_axisDotLabel" }, String(slot + 1)), h("span", { className: "SPR_axisDotIndex" }, String(index + 1)));
1994
+ })), h("div", { className: "SPR_axisRuler" }, h("span", null, "0 秒"), h("span", { className: "SPR_axisRulerMid" }, `共 ${total} 张候选帧 · ${picks.length} 个圆圈 —— 拖动圆圈决定每一张输出帧截在哪`), h("span", null, `${duration.toFixed(2)} 秒`)));
1995
+ }
1996
+ function FramePickPanel({ project, direction, api, start, tasks, countDraft, setCountDraft }) {
1997
+ const node = project.frames?.[direction.key] ?? {};
1998
+ const candidates = node.candidates ?? {};
1999
+ const total = Array.isArray(candidates.frames) ? candidates.frames.length : 0;
2000
+ const duration = Number(candidates.duration ?? node.duration ?? 0);
2001
+ const picks = Array.isArray(candidates.picks) ? candidates.picks : [];
2002
+ const frameCount = Number(countDraft ?? candidates.rawFrameCount ?? 32);
2003
+ const taskKey = `frames:pick:${direction.key}`;
2004
+ const hostPick = hostJob(project, taskKey);
2005
+ const cutting = candidates.status === "running" || tasks.has(taskKey) || hostPick !== undefined;
2006
+ const video = project.videos?.[direction.key];
2007
+ return h("div", { className: "SPR_pickPanel", "data-testid": `frame-pick-${direction.key}` }, h("div", { className: "SPR_pickHead" }, h("span", { className: "SPR_nodeTitle" }, `手动选帧 · ${direction.label}`), h("span", { className: "SPR_refRow" }, "只影响这一段视频。圆圈个数跟「每段视频抽帧数」走,拖到哪一格就截哪一格。")), video?.file !== undefined
2008
+ ? h("video", {
2009
+ className: "SPR_video",
2010
+ src: assetUrl(project, video.file, video.updatedAt),
2011
+ controls: true,
2012
+ preload: "metadata"
2013
+ })
2014
+ : null, h("div", { className: "SPR_toolbar" }, h(NumField, {
2015
+ label: "候选帧数(8~64)",
2016
+ value: frameCount,
2017
+ min: TURN_FRAME_MIN,
2018
+ max: TURN_FRAME_MAX,
2019
+ onChange: (value) => setCountDraft(value)
2020
+ }), h(BusyBtn, {
2021
+ busy: tasks.has(taskKey),
2022
+ busyText: "正在抽候选帧…",
2023
+ disabled: cutting && !tasks.has(taskKey),
2024
+ onClick: () => void start(() => api.prepareFramePick({ projectId: project.id, key: direction.key, count: frameCount }), { reload: true, notice: `已按 ${frameCount} 张候选帧重抽「${direction.label}」`, noticeKind: "ok" }, { key: taskKey, label: `正在抽取「${direction.label}」的候选帧…` })
2025
+ }, total > 0 ? "重新抽取候选帧" : "抽取候选帧"), h(BusyBtn, {
2026
+ busy: tasks.has(`frames:slot:${direction.key}:reset`),
2027
+ busyText: "正在重置…",
2028
+ disabled: total === 0 || cutting,
2029
+ onClick: () => void start(() => api.resetFramePicks({ projectId: project.id, key: direction.key }), { reload: true, notice: "圆圈已回到等分位置", noticeKind: "ok" }, { key: `frames:slot:${direction.key}:reset`, label: `正在重置「${direction.label}」的选帧…` })
2030
+ }, "重置为等分"), h(BusyBadge, { show: cutting, text: tasks.label(taskKey) ?? "正在抽取候选帧…" })), total > 0
2031
+ ? h(FramePickAxis, {
2032
+ project,
2033
+ directionKey: direction.key,
2034
+ total,
2035
+ duration,
2036
+ picks,
2037
+ api,
2038
+ start,
2039
+ busy: cutting
2040
+ })
2041
+ : h("div", { className: "SPR_thumbEmpty" }, cutting ? "正在抽取候选帧…" : "还没有候选帧"), candidates.error !== undefined ? h("p", { className: "SPR_error" }, candidates.error) : null);
2042
+ }
1882
2043
  // ── 阶段 3:抽帧 ─────────────────────────────────────────────────────
1883
2044
  const KEY_FRAMES_ONE = (key) => `frames:${key}`;
1884
2045
  const KEY_FRAMES_ALL = "frames:*all";
2046
+ const KEY_FRAMES_PICK = (key) => `frames:pick:${key}`;
1885
2047
  function renderFrameStage(ctx) {
1886
2048
  const { project, start, api, settingsDraft, saveSettings, tasks } = ctx;
2049
+ // 选帧草稿必须放在独立组件里。这里是普通函数,而且只在切到「提取序列帧」
2050
+ // 时才被调用;直接 useState 会算进 StudioPanel,前后两次渲染的 Hook 数量对不上。
2051
+ return h(FrameStage, { project, start, api, settingsDraft, saveSettings, tasks });
2052
+ }
2053
+ function FrameStage({ project, start, api, settingsDraft, saveSettings, tasks }) {
1887
2054
  const readyVideos = DIRECTION_KEYS.filter((key) => project.videos?.[key]?.file !== undefined);
1888
2055
  const allApproved = DIRECTION_KEYS.every((key) => project.frames?.[key]?.approved);
1889
2056
  const draft = settingsDraft ?? project.settings ?? {};
1890
2057
  // 宿主侧那次抽帧任务盖住了哪些方向。批量抽帧是「一次两个方向」慢慢做的,
1891
2058
  // 本地 pending 表只多留 700ms,盖不住还没轮到的那六个方向——只看它就会
1892
2059
  // 出现「先转圈、紧接着变回尚未抽帧、过一阵才出结果」。
2060
+ const [pickKey, setPickKey] = React.useState(null);
2061
+ const [pickCount, setPickCount] = React.useState(null);
1893
2062
  const hostExtract = hostJob(project, "frames:extract");
1894
- const extracting = tasks.any("frames:*") || hostExtract !== undefined;
2063
+ const hostPicking = Array.isArray(project.jobs) && project.jobs.some((job) => typeof job?.key === "string" && job.key.startsWith("frames:pick:"));
2064
+ const extracting = tasks.any("frames:*") || tasks.any("frames:pick:") || hostExtract !== undefined || hostPicking;
1895
2065
  const batchLabel = tasks.label(KEY_FRAMES_ALL) ?? "正在抽取全部序列帧…";
1896
2066
  return h(React.Fragment, null, h("div", { className: "SPR_fields" }, h(NumField, {
1897
2067
  label: "单格宽(px)",
@@ -1924,6 +2094,7 @@ window.__ModuleLoader__.load({
1924
2094
  max: 8,
1925
2095
  onChange: (value) => saveSettings({ concurrency: value })
1926
2096
  })), h("p", { className: "SPR_hint" }, "抽帧抽到的是「工作尺寸」(长边上限),不是最终格子尺寸。自动裁剪、统一缩放和像素量化都在第 4 步做,这样八个方向才能共享同一个裁剪框、脚底对齐同一条基线。改完这里需要重新抽帧。" +
2097
+ "「提取全部」对每一段视频用同一套等分;要某一段单独挑帧,点那张卡片上的「手动选帧」,拖圆圈即可(和转圈截帧一样)。" +
1927
2098
  "预览带是**双击看大图**:格子尺寸只有 256px,看不清动作和抠像质量。"), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
1928
2099
  primary: true,
1929
2100
  busy: tasks.has(KEY_FRAMES_ALL),
@@ -1937,44 +2108,80 @@ window.__ModuleLoader__.load({
1937
2108
  on: allApproved,
1938
2109
  disabled: extracting,
1939
2110
  onClick: () => void start(() => api.setApproved({ projectId: project.id, stage: "frames", approved: !allApproved }), { reload: true })
1940
- }, allApproved ? "取消全部通过" : "全部标记通过"), h(BusyBadge, { show: extracting, text: tasks.label(KEY_FRAMES_ALL) ?? "正在抽帧…" })), h("div", { className: "SPR_grid" }, DIRECTIONS.map((direction) => {
2111
+ }, allApproved ? "取消全部通过" : "全部标记通过"), h(BusyBadge, { show: extracting, text: tasks.label(KEY_FRAMES_ALL) ?? "正在抽帧…" })), h("div", { className: "SPR_grid" }, DIRECTIONS.flatMap((direction) => {
1941
2112
  const node = project.frames?.[direction.key];
1942
2113
  const taskKey = KEY_FRAMES_ONE(direction.key);
1943
2114
  // 这一批还没轮到 / 产物还没出来的方向也要盖着。两条路:本地刚点下去
1944
2115
  // (批量 key 在远程调用返回后还会多留 700ms,覆盖「下一次轮询还没回来」
1945
2116
  // 的那一下),以及宿主任务表(整段任务都在)。已经报错的方向不盖,
1946
2117
  // 否则失败原因被遮罩挡住,看着像还在跑。
1947
- const queued = (tasks.has(KEY_FRAMES_ALL) || jobCovers(hostExtract, direction.key)) && node?.status !== "error";
1948
- const nodeBusy = node?.status === "running" || tasks.has(taskKey) || queued;
2118
+ const hostPick = hostJob(project, KEY_FRAMES_PICK(direction.key));
2119
+ const queued = (tasks.has(KEY_FRAMES_ALL) || jobCovers(hostExtract, direction.key) || jobCovers(hostPick, direction.key)) && node?.status !== "error";
2120
+ const nodeBusy = node?.status === "running" || tasks.has(taskKey) || tasks.has(KEY_FRAMES_PICK(direction.key)) || tasks.any(`frames:slot:${direction.key}:`) || queued;
1949
2121
  const overlayText = tasks.label(taskKey) ?? (queued ? batchLabel : undefined) ?? "正在抽取序列帧…";
1950
- return h("div", { key: direction.key, className: "SPR_node", "data-busy": nodeBusy ? "true" : undefined }, h("div", { className: "SPR_nodeTop" }, h("span", { className: "SPR_nodeTitle" }, direction.label), nodeBusy ? h(Chip, { kind: "running", text: "抽帧中" }) : h(StatusChip, { node })), node?.strip !== undefined
1951
- ? h(MediaBox, { overlay: nodeBusy, text: overlayText }, h(ZoomableImage, {
1952
- className: "SPR_thumb",
1953
- src: assetUrl(project, node.strip, node.updatedAt),
1954
- alt: `${direction.label} 序列帧`,
1955
- caption: `${direction.label} · ${node.frames?.length ?? 0} 帧 · 视频 ${(node.duration ?? 0).toFixed(2)} 秒(点「×」/ 背景 / Esc 关闭)`
1956
- }))
1957
- : h("div", { className: "SPR_thumbEmpty" }, nodeBusy ? "正在抽帧…" : "尚未抽帧"), nodeBusy ? h(BusyBadge, { show: true, text: overlayText }) : null, node?.duration !== undefined
1958
- ? h("span", { className: "SPR_refRow" }, `${node.frames?.length ?? 0} 帧 · 视频 ${node.duration.toFixed(2)} 秒`)
1959
- : null, node?.error !== undefined ? h("p", { className: "SPR_error" }, node.error) : null, h("div", { className: "SPR_btnRow" }, h(BusyBtn, {
1960
- primary: node?.status !== "ready",
1961
- busy: tasks.has(taskKey),
1962
- busyText: "正在抽帧…",
1963
- disabled: project.videos?.[direction.key]?.file === undefined,
1964
- onClick: () => void start(() => api.runFrames({ projectId: project.id, keys: [direction.key] }), { reload: true }, {
1965
- key: taskKey,
1966
- label: `正在抽取「${direction.label}」序列帧…`
1967
- })
1968
- }, node?.status === "ready" ? "重新抽帧" : "抽取"), h(Btn, {
1969
- on: node?.approved === true,
1970
- disabled: node?.status !== "ready",
1971
- onClick: () => void start(() => api.setApproved({
1972
- projectId: project.id,
1973
- stage: "frames",
1974
- key: direction.key,
1975
- approved: node?.approved !== true
1976
- }), { reload: true })
1977
- }, node?.approved === true ? "已通过" : "通过")));
2122
+ return [
2123
+ h("div", { key: direction.key, className: "SPR_node", "data-busy": nodeBusy ? "true" : undefined }, h("div", { className: "SPR_nodeTop" }, h("span", { className: "SPR_nodeTitle" }, direction.label), nodeBusy ? h(Chip, { kind: "running", text: "抽帧中" }) : h(StatusChip, { node })), node?.strip !== undefined
2124
+ ? h(MediaBox, { overlay: nodeBusy, text: overlayText }, h(ZoomableImage, {
2125
+ className: "SPR_thumb",
2126
+ src: assetUrl(project, node.strip, node.updatedAt),
2127
+ alt: `${direction.label} 序列帧`,
2128
+ caption: `${direction.label} · ${node.frames?.length ?? 0} 帧 · 视频 ${(node.duration ?? 0).toFixed(2)} 秒(点「×」/ 背景 / Esc 关闭)`
2129
+ }))
2130
+ : h("div", { className: "SPR_thumbEmpty" }, nodeBusy ? "正在抽帧…" : "尚未抽帧"), nodeBusy ? h(BusyBadge, { show: true, text: overlayText }) : null, node?.duration !== undefined
2131
+ ? h("span", { className: "SPR_refRow" }, `${node.frames?.length ?? 0} 帧 · 视频 ${node.duration.toFixed(2)} 秒`)
2132
+ : null, (node?.candidates?.frames?.length ?? 0) > 0
2133
+ ? h("span", { className: "SPR_refRow" }, `手动选帧 · ${node.candidates.picks?.length ?? 0} 个圆圈 / ${node.candidates.frames.length} 张候选`)
2134
+ : null, node?.error !== undefined ? h("p", { className: "SPR_error" }, node.error) : null, h("div", { className: "SPR_btnRow" }, h(BusyBtn, {
2135
+ primary: node?.status !== "ready",
2136
+ busy: tasks.has(taskKey),
2137
+ busyText: "正在抽帧…",
2138
+ disabled: project.videos?.[direction.key]?.file === undefined || tasks.has(KEY_FRAMES_PICK(direction.key)) || hostPick !== undefined,
2139
+ onClick: () => void start(() => api.runFrames({ projectId: project.id, keys: [direction.key] }), { reload: true }, {
2140
+ key: taskKey,
2141
+ label: `正在抽取「${direction.label}」序列帧…`
2142
+ })
2143
+ }, node?.status === "ready" ? "重新抽帧" : "抽取"), h(BusyBtn, {
2144
+ busy: tasks.has(KEY_FRAMES_PICK(direction.key)),
2145
+ busyText: "正在抽候选帧…",
2146
+ disabled: project.videos?.[direction.key]?.file === undefined || (nodeBusy && !tasks.has(KEY_FRAMES_PICK(direction.key))),
2147
+ onClick: () => {
2148
+ if (pickKey === direction.key) {
2149
+ setPickKey(null);
2150
+ return;
2151
+ }
2152
+ setPickKey(direction.key);
2153
+ setPickCount(null);
2154
+ const ready = (project.frames?.[direction.key]?.candidates?.frames?.length ?? 0) > 0;
2155
+ if (!ready) {
2156
+ void start(() => api.prepareFramePick({ projectId: project.id, key: direction.key }), { reload: true }, {
2157
+ key: KEY_FRAMES_PICK(direction.key),
2158
+ label: `正在抽取「${direction.label}」的候选帧…`
2159
+ });
2160
+ }
2161
+ }
2162
+ }, pickKey === direction.key ? "收起选帧" : (node?.candidates?.frames?.length ?? 0) > 0 ? "调整选帧" : "手动选帧"), h(Btn, {
2163
+ on: node?.approved === true,
2164
+ disabled: node?.status !== "ready",
2165
+ onClick: () => void start(() => api.setApproved({
2166
+ projectId: project.id,
2167
+ stage: "frames",
2168
+ key: direction.key,
2169
+ approved: node?.approved !== true
2170
+ }), { reload: true })
2171
+ }, node?.approved === true ? "已通过" : "通过"))),
2172
+ pickKey === direction.key
2173
+ ? h(FramePickPanel, {
2174
+ key: `${direction.key}-pick`,
2175
+ project,
2176
+ direction,
2177
+ api,
2178
+ start,
2179
+ tasks,
2180
+ countDraft: pickCount,
2181
+ setCountDraft: setPickCount
2182
+ })
2183
+ : null
2184
+ ].filter(Boolean);
1978
2185
  })));
1979
2186
  }
1980
2187
  // ── 阶段 4:合成整图 ─────────────────────────────────────────────────
@@ -5556,6 +5763,10 @@ window.__ModuleLoader__.load({
5556
5763
  pollVideos: (payload) => call("pollVideos", payload),
5557
5764
  clearVideos: (payload) => call("clearVideos", payload),
5558
5765
  runFrames: (payload) => call("runFrames", payload),
5766
+ prepareFramePick: (payload) => call("prepareFramePick", payload),
5767
+ setFramePick: (payload) => call("setFramePick", payload),
5768
+ setFramePicks: (payload) => call("setFramePicks", payload),
5769
+ resetFramePicks: (payload) => call("resetFramePicks", payload),
5559
5770
  rekey: (payload) => call("rekey", payload),
5560
5771
  compose: (payload) => call("compose", payload),
5561
5772
  listImageJobs: () => call("listImageJobs"),
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@ import { DEFAULT_ROW_ORDER, DEFAULT_TURN_PROMPT, DEFAULT_VIDEO_PROMPT, DIRECTION
19
19
  import { checkFfmpeg } from "./media.js";
20
20
  import { testArk } from "./ark.js";
21
21
  import { COMP_SHARE_BASE_URL, COMP_SHARE_MODEL_ID, capabilityOf, isCompshareModel, normalizeDuration, normalizeResolution, pathPrefixOf, testMiniMax } from "./minimax.js";
22
- import { applyTurnPicks, clearVideos, disposePipeline, ensurePoller, listJobs, pollVideosOnce, resetTurnPicks, setImageMode, setTurnPick, setTurnPicks, startAllImages, startCompose, startExtract, startImage, startRekey, startTurnFrames, startTurnVideo, startVideos } from "./pipeline.js";
22
+ import { applyTurnPicks, clearVideos, disposePipeline, ensurePoller, listJobs, pollVideosOnce, resetFramePicks, resetTurnPicks, setFramePick, setFramePicks, setImageMode, setTurnPick, setTurnPicks, startAllImages, startCompose, startFramePick, startExtract, startImage, startRekey, startTurnFrames, startTurnVideo, startVideos } from "./pipeline.js";
23
23
  import { assetPath, createProject, deleteProject, listProjects, log, patchProject, projectDir, projectExists, readProject, } from "./store.js";
24
24
  import * as imagegen from "./imagegen.js";
25
25
  import * as seqgen from "./seqgen.js";
@@ -657,6 +657,24 @@ export class GameStudioGateway extends TypertRemoteService {
657
657
  }
658
658
  return startExtract(projectId, targets);
659
659
  }
660
+ async prepareFramePick(payload) {
661
+ const input = asRecord(payload);
662
+ const count = input.count === undefined || input.count === null ? undefined : clampInt(input.count, 32, 8, 64);
663
+ return startFramePick(asString(input.projectId), asString(input.key), count);
664
+ }
665
+ async setFramePick(payload) {
666
+ const input = asRecord(payload);
667
+ return setFramePick(asString(input.projectId), asString(input.key), Number(input.slot), Number(input.index));
668
+ }
669
+ async setFramePicks(payload) {
670
+ const input = asRecord(payload);
671
+ const picks = Array.isArray(input.picks) ? input.picks.map((value) => Number(value)) : [];
672
+ return setFramePicks(asString(input.projectId), asString(input.key), picks);
673
+ }
674
+ async resetFramePicks(payload) {
675
+ const input = asRecord(payload);
676
+ return resetFramePicks(asString(input.projectId), asString(input.key));
677
+ }
660
678
  async rekey(payload) {
661
679
  const projectId = asString(asRecord(payload).projectId);
662
680
  const project = await readProject(projectId);
package/lib/pipeline.js CHANGED
@@ -822,9 +822,294 @@ export async function pollVideosOnce(projectId) {
822
822
  }
823
823
  }
824
824
  // ── 阶段 3:抽帧 ─────────────────────────────────────────────────────────
825
+ /** 手动选帧的候选帧张数。和转圈轴用同一档范围:太少拖不动,太多抽帧变慢。 */
826
+ const WALK_CANDIDATE_DEFAULT = 32;
827
+ /**
828
+ * 把 `outputCount` 个输出帧均匀铺到 `candidateCount` 张候选帧上。
829
+ * 下标用「格心」(第 i 等份的中点),和转圈轴上圆圈的算法一致。
830
+ */
831
+ function evenSlotPicks(outputCount, candidateCount) {
832
+ const total = Math.max(1, candidateCount);
833
+ const count = Math.max(1, outputCount);
834
+ const picks = [];
835
+ for (let i = 0; i < count; i++) {
836
+ picks.push(Math.min(total - 1, Math.max(0, Math.round(((i + 0.5) * total) / count - 0.5))));
837
+ }
838
+ return picks;
839
+ }
840
+ /** 候选帧张数变了之后,按比例换算已经拖过的圆圈,避免下标对不上新条带。 */
841
+ function rescaleSlotPicks(picks, from, to) {
842
+ const ratio = from > 0 ? to / from : 1;
843
+ return picks.map((index) => clampInt(index * ratio, 0, Math.max(0, to - 1)));
844
+ }
845
+ /**
846
+ * 按候选帧缓存,把这个方向的序列帧切出来(绿幕 PNG + raw.bin),再走一遍抠像合成。
847
+ * 拖动圆圈只改下标,不必重新解码视频。
848
+ */
849
+ async function applyWalkPicks(projectId, key) {
850
+ const project = await readProject(projectId);
851
+ if (project === undefined)
852
+ throw new Error(`项目不存在:${projectId}`);
853
+ const candidates = project.frames[key]?.candidates;
854
+ if (candidates?.raw === undefined || (candidates.rawWidth ?? 0) <= 0 || (candidates.rawHeight ?? 0) <= 0) {
855
+ throw new Error("还没有候选帧,请先手动抽取");
856
+ }
857
+ const width = candidates.rawWidth;
858
+ const height = candidates.rawHeight ?? 0;
859
+ const raw = await readFile(assetPath(projectId, candidates.raw));
860
+ const frameBytes = width * height * 4;
861
+ const total = Math.max(0, Math.floor(raw.length / frameBytes));
862
+ if (total === 0)
863
+ throw new Error("候选帧缓存是空的,请重新抽取");
864
+ const outputCount = Math.max(1, project.settings.frameCount);
865
+ const picks = candidates.picks.length === outputCount
866
+ ? candidates.picks.map((index) => clampInt(index, 0, total - 1))
867
+ : evenSlotPicks(outputCount, total);
868
+ const slices = [];
869
+ const framePaths = [];
870
+ for (let slot = 0; slot < picks.length; slot++) {
871
+ const index = picks[slot];
872
+ slices.push(Buffer.from(raw.subarray(index * frameBytes, (index + 1) * frameBytes)));
873
+ framePaths.push(`frames/${key}/f${String(slot).padStart(2, "0")}.png`);
874
+ }
875
+ const rawRelative = `frames/${key}/raw.bin`;
876
+ await mkdir(dirname(assetPath(projectId, rawRelative)), { recursive: true });
877
+ await writeFile(assetPath(projectId, rawRelative), Buffer.concat(slices));
878
+ for (let slot = 0; slot < slices.length; slot++) {
879
+ await writeFile(assetPath(projectId, framePaths[slot]), encodePng(slices[slot], width, height));
880
+ }
881
+ await patchProject(projectId, (current) => {
882
+ const node = current.frames[key];
883
+ current.frames[key] = {
884
+ ...node,
885
+ status: "ready",
886
+ frames: framePaths,
887
+ keyed: [],
888
+ approved: false,
889
+ stale: false,
890
+ error: undefined,
891
+ raw: rawRelative,
892
+ rawWidth: width,
893
+ rawHeight: height,
894
+ rawFrameCount: picks.length,
895
+ duration: candidates.duration,
896
+ updatedAt: Date.now(),
897
+ candidates: node.candidates === undefined ? undefined : { ...node.candidates, picks, status: "ready", stale: false, error: undefined }
898
+ };
899
+ const label = directionOf(key)?.label ?? key;
900
+ log(current, "info", `「${label}」按手动选帧切出 ${picks.length} 帧`);
901
+ });
902
+ await renderSheet(projectId);
903
+ }
904
+ /**
905
+ * 从一个方向的行走视频里抽出候选帧,并按当前圆圈(没有就等分)切成序列帧。
906
+ * 只动这一个方向;其它方向的帧保持原样。
907
+ */
908
+ export async function startFramePick(projectId, key, count) {
909
+ if (directionOf(key) === undefined)
910
+ throw new Error(`未知方向:${key}`);
911
+ const project = await readProject(projectId);
912
+ if (project === undefined)
913
+ throw new Error(`项目不存在:${projectId}`);
914
+ if (project.videos[key]?.file === undefined)
915
+ throw new Error("还没有可抽帧的视频,请先在第 2 步生成视频");
916
+ const requested = clampInt(count ?? project.frames[key]?.candidates?.rawFrameCount ?? WALK_CANDIDATE_DEFAULT, TURN_FRAME_COUNT_MIN, TURN_FRAME_COUNT_MAX);
917
+ const label = directionOf(key)?.label ?? key;
918
+ const taskKey = `frames:pick:${key}`;
919
+ const started = kick(projectId, taskKey, `手动选帧·${label}`, async () => {
920
+ setJobTargets(projectId, taskKey, [key]);
921
+ const fresh = await readProject(projectId);
922
+ if (fresh === undefined)
923
+ throw new Error(`项目不存在:${projectId}`);
924
+ const video = fresh.videos[key];
925
+ if (video?.file === undefined)
926
+ throw new Error("还没有可抽帧的视频,请先在第 2 步生成视频");
927
+ const previous = fresh.frames[key]?.candidates;
928
+ await patchProject(projectId, (current) => {
929
+ const node = current.frames[key];
930
+ current.frames[key] = {
931
+ ...node,
932
+ status: "running",
933
+ error: undefined,
934
+ candidates: {
935
+ status: "running",
936
+ frames: previous?.frames ?? [],
937
+ times: previous?.times ?? [],
938
+ picks: previous?.picks ?? [],
939
+ raw: previous?.raw,
940
+ rawWidth: previous?.rawWidth,
941
+ rawHeight: previous?.rawHeight,
942
+ rawFrameCount: previous?.rawFrameCount,
943
+ duration: previous?.duration,
944
+ strip: previous?.strip,
945
+ error: undefined
946
+ }
947
+ };
948
+ log(current, "info", `开始抽取「${label}」的候选帧:${requested} 张`);
949
+ });
950
+ try {
951
+ const extracted = await extractFrames({
952
+ video: assetPath(projectId, video.file),
953
+ frameCount: requested,
954
+ longEdge: fresh.settings.workingLongEdge,
955
+ cropInset: fresh.settings.cropInset
956
+ });
957
+ const total = extracted.frames.length;
958
+ const outputCount = Math.max(1, fresh.settings.frameCount);
959
+ const picks = previous?.picks !== undefined && previous.picks.length === outputCount && (previous.rawFrameCount ?? 0) > 0
960
+ ? previous.rawFrameCount === total
961
+ ? previous.picks.map((index) => clampInt(index, 0, total - 1))
962
+ : rescaleSlotPicks(previous.picks, previous.rawFrameCount ?? total, total)
963
+ : evenSlotPicks(outputCount, total);
964
+ const rawRelative = `frames/${key}/candidates/raw.bin`;
965
+ await mkdir(dirname(assetPath(projectId, rawRelative)), { recursive: true });
966
+ await writeFile(assetPath(projectId, rawRelative), Buffer.concat(extracted.frames));
967
+ const files = [];
968
+ const times = [];
969
+ for (let i = 0; i < extracted.frames.length; i++) {
970
+ const relative = `frames/${key}/candidates/f${String(i).padStart(2, "0")}.png`;
971
+ await writeFile(assetPath(projectId, relative), encodePng(extracted.frames[i], extracted.width, extracted.height));
972
+ files.push(relative);
973
+ times.push((i * extracted.duration) / Math.max(1, extracted.frames.length));
974
+ }
975
+ const strip = composeSheet([{ key, frames: extracted.frames, width: extracted.width, height: extracted.height }], {
976
+ cellWidth: 96,
977
+ cellHeight: Math.max(24, Math.round((96 * extracted.height) / Math.max(1, extracted.width))),
978
+ frameCount: extracted.frames.length,
979
+ autoCrop: false,
980
+ fillRatio: 1,
981
+ pixelSize: 0,
982
+ fitMode: "stretch",
983
+ bottomMargin: 0
984
+ });
985
+ const stripRelative = `frames/${key}/candidates/strip.png`;
986
+ await writeFile(assetPath(projectId, stripRelative), encodePng(strip.rgba, strip.width, strip.height));
987
+ await patchProject(projectId, (current) => {
988
+ const node = current.frames[key];
989
+ current.frames[key] = {
990
+ ...node,
991
+ candidates: {
992
+ status: "ready",
993
+ frames: files,
994
+ times,
995
+ raw: rawRelative,
996
+ rawWidth: extracted.width,
997
+ rawHeight: extracted.height,
998
+ rawFrameCount: files.length,
999
+ duration: extracted.duration,
1000
+ strip: stripRelative,
1001
+ picks,
1002
+ stale: false,
1003
+ updatedAt: Date.now()
1004
+ }
1005
+ };
1006
+ log(current, "info", `「${label}」候选帧抽取完成:${files.length} 张 / 视频 ${extracted.duration.toFixed(2)} 秒`);
1007
+ });
1008
+ await applyWalkPicks(projectId, key);
1009
+ }
1010
+ catch (error) {
1011
+ const message = messageOf(error);
1012
+ await patchProject(projectId, (current) => {
1013
+ const node = current.frames[key];
1014
+ current.frames[key] = {
1015
+ ...node,
1016
+ status: node.raw === undefined ? "error" : node.status,
1017
+ error: message,
1018
+ candidates: node.candidates === undefined ? undefined : { ...node.candidates, status: "error", error: message }
1019
+ };
1020
+ log(current, "error", `「${label}」手动选帧失败:${message}`);
1021
+ });
1022
+ throw error;
1023
+ }
1024
+ finally {
1025
+ dropJobTarget(projectId, taskKey, key);
1026
+ }
1027
+ });
1028
+ return started ? { started: true } : { started: false, reason: "这个方向正在手动选帧" };
1029
+ }
1030
+ /** 改这个方向某一个输出帧落在哪张候选帧上(圆圈松手时调用)。 */
1031
+ export async function setFramePick(projectId, key, slot, index) {
1032
+ const project = await readProject(projectId);
1033
+ if (project === undefined)
1034
+ throw new Error(`项目不存在:${projectId}`);
1035
+ if (directionOf(key) === undefined)
1036
+ throw new Error(`未知方向:${key}`);
1037
+ const candidates = project.frames[key]?.candidates;
1038
+ const total = candidates?.frames?.length ?? 0;
1039
+ if (total === 0 || candidates?.raw === undefined)
1040
+ throw new Error("还没有候选帧,请先手动抽取");
1041
+ const outputCount = Math.max(1, project.settings.frameCount);
1042
+ const picks = candidates.picks.length === outputCount
1043
+ ? candidates.picks.map((value) => clampInt(value, 0, total - 1))
1044
+ : evenSlotPicks(outputCount, total);
1045
+ const nextSlot = clampInt(slot, 0, outputCount - 1);
1046
+ const nextIndex = clampInt(index, 0, total - 1);
1047
+ const unchanged = candidates.picks.length === outputCount &&
1048
+ candidates.picks[nextSlot] === nextIndex &&
1049
+ project.frames[key]?.status === "ready";
1050
+ picks[nextSlot] = nextIndex;
1051
+ await patchProject(projectId, (current) => {
1052
+ const node = current.frames[key];
1053
+ if (node.candidates !== undefined)
1054
+ node.candidates = { ...node.candidates, picks: [...picks] };
1055
+ });
1056
+ if (!unchanged)
1057
+ await applyWalkPicks(projectId, key);
1058
+ return { slot: nextSlot, index: nextIndex, changed: !unchanged, picks };
1059
+ }
1060
+ /** 一次写回这个方向的全部圆圈。长度必须等于「每段视频抽帧数」,整图才是整齐的格子。 */
1061
+ export async function setFramePicks(projectId, key, picks) {
1062
+ const project = await readProject(projectId);
1063
+ if (project === undefined)
1064
+ throw new Error(`项目不存在:${projectId}`);
1065
+ if (directionOf(key) === undefined)
1066
+ throw new Error(`未知方向:${key}`);
1067
+ const total = project.frames[key]?.candidates?.frames?.length ?? 0;
1068
+ if (total === 0)
1069
+ throw new Error("还没有候选帧,请先手动抽取");
1070
+ const outputCount = Math.max(1, project.settings.frameCount);
1071
+ if (picks.length !== outputCount) {
1072
+ throw new Error(`这一方向要选 ${outputCount} 帧(与「每段视频抽帧数」一致),收到 ${picks.length} 个位置`);
1073
+ }
1074
+ const next = picks.map((value) => {
1075
+ if (!Number.isFinite(Number(value)))
1076
+ throw new Error("截帧位置必须是数字");
1077
+ return clampInt(Number(value), 0, total - 1);
1078
+ });
1079
+ await patchProject(projectId, (current) => {
1080
+ const node = current.frames[key];
1081
+ if (node.candidates !== undefined)
1082
+ node.candidates = { ...node.candidates, picks: next };
1083
+ });
1084
+ await applyWalkPicks(projectId, key);
1085
+ return { picks: next };
1086
+ }
1087
+ /** 把这个方向的圆圈放回等分位置,并按新位置重切序列帧。 */
1088
+ export async function resetFramePicks(projectId, key) {
1089
+ const project = await readProject(projectId);
1090
+ if (project === undefined)
1091
+ throw new Error(`项目不存在:${projectId}`);
1092
+ if (directionOf(key) === undefined)
1093
+ throw new Error(`未知方向:${key}`);
1094
+ const total = project.frames[key]?.candidates?.frames?.length ?? 0;
1095
+ if (total === 0)
1096
+ throw new Error("还没有候选帧,请先手动抽取");
1097
+ const picks = evenSlotPicks(Math.max(1, project.settings.frameCount), total);
1098
+ await patchProject(projectId, (current) => {
1099
+ const node = current.frames[key];
1100
+ if (node.candidates !== undefined)
1101
+ node.candidates = { ...node.candidates, picks };
1102
+ const label = directionOf(key)?.label ?? key;
1103
+ log(current, "info", `「${label}」的选帧圆圈已回到等分位置`);
1104
+ });
1105
+ await applyWalkPicks(projectId, key);
1106
+ return { picks };
1107
+ }
825
1108
  /**
826
1109
  * 抽取序列帧。`keys` 是要抽的方向;省略则按「有视频的方向」全抽。
827
1110
  * 调用方(`runFrames`)已经把没有视频的方向滤掉了,这里再滤一次兜底。
1111
+ *
1112
+ * 这条路按时长等分,会清掉该方向上一次的手动选帧。要逐帧挑位置,走 `startFramePick`。
828
1113
  */
829
1114
  export function startExtract(projectId, keys) {
830
1115
  const started = kick(projectId, "frames:extract", "抽取序列帧", async () => {
package/lib/store.js CHANGED
@@ -246,7 +246,8 @@ function normalizeProject(raw) {
246
246
  frames: Array.isArray(node.frames) ? node.frames.map(String) : [],
247
247
  keyed: Array.isArray(node.keyed) ? node.keyed.map(String) : [],
248
248
  approved: node.approved === true,
249
- stale: node.stale === true
249
+ stale: node.stale === true,
250
+ candidates: normalizeFrameCandidates(node.candidates)
250
251
  };
251
252
  }
252
253
  }
@@ -303,6 +304,25 @@ function num(value, fallback) {
303
304
  const n = typeof value === "number" ? value : Number.parseFloat(String(value ?? ""));
304
305
  return Number.isFinite(n) ? n : fallback;
305
306
  }
307
+ function normalizeFrameCandidates(raw) {
308
+ if (raw === null || typeof raw !== "object")
309
+ return undefined;
310
+ return {
311
+ status: raw.status ?? "empty",
312
+ frames: Array.isArray(raw.frames) ? raw.frames.map(String) : [],
313
+ times: Array.isArray(raw.times) ? raw.times.map((value) => num(value, 0)) : [],
314
+ raw: typeof raw.raw === "string" ? raw.raw : undefined,
315
+ rawWidth: typeof raw.rawWidth === "number" ? raw.rawWidth : undefined,
316
+ rawHeight: typeof raw.rawHeight === "number" ? raw.rawHeight : undefined,
317
+ rawFrameCount: typeof raw.rawFrameCount === "number" ? raw.rawFrameCount : undefined,
318
+ duration: typeof raw.duration === "number" ? raw.duration : undefined,
319
+ strip: typeof raw.strip === "string" ? raw.strip : undefined,
320
+ picks: Array.isArray(raw.picks) ? raw.picks.map((value) => Math.max(0, Math.round(num(value, 0)))) : [],
321
+ error: typeof raw.error === "string" ? raw.error : undefined,
322
+ stale: raw.stale === true,
323
+ updatedAt: typeof raw.updatedAt === "number" ? raw.updatedAt : undefined
324
+ };
325
+ }
306
326
  function clampIntSetting(value, fallback, min, max) {
307
327
  return Math.min(max, Math.max(min, Math.round(num(value, fallback))));
308
328
  }
package/lib/tools.js CHANGED
@@ -300,8 +300,10 @@ function intentFromCall(method, payload) {
300
300
  const projectId = asString(payload.projectId);
301
301
  const jobId = asString(payload.jobId);
302
302
  const stage = typeof payload.stage === "string" ? payload.stage : undefined;
303
- if (projectId !== "")
304
- return { module: "sprite", projectId, stage };
303
+ if (projectId !== "") {
304
+ const framePick = method === "prepareFramePick" || method === "setFramePick" || method === "setFramePicks" || method === "resetFramePicks";
305
+ return { module: "sprite", projectId, stage: framePick ? "frames" : stage };
306
+ }
305
307
  if (jobId !== "") {
306
308
  const module = moduleForId(jobId);
307
309
  return module === undefined ? undefined : { module, jobId };
@@ -325,7 +327,9 @@ const CALL_DESCRIPTION = [
325
327
  " uploadSource({projectId,name,data:base64}) / savePrompts({projectId,images?,video?,turn?,videoPerDirection?,suffix?,resetImagesToDefault?,resetVideoToDefault?,resetTurnToDefault?}) /",
326
328
  " saveSettings({projectId,settings}) / setApproved({projectId,stage:images|videos|frames|sheet,key?,approved}) / revealProject({projectId}) /",
327
329
  " runImage({projectId,key,prompt?}) / runImages({projectId,force?}) / runVideos({projectId,keys?,regenerate?}) / pollVideos({projectId}) /",
328
- " clearVideos({projectId,keys?}) / runFrames({projectId,keys?}) / rekey({projectId}) / compose({projectId})",
330
+ " clearVideos({projectId,keys?}) / runFrames({projectId,keys?})【整段等分,同一套规则】 / rekey({projectId}) / compose({projectId})",
331
+ " prepareFramePick({projectId,key,count?})【只抽这一个方向的候选帧,免费】/ setFramePick({projectId,key,slot,index})【拖动第 slot 个输出帧到候选 index】/",
332
+ " setFramePicks({projectId,key,picks:[index,…]})【一次写回,长度必须等于每段抽帧数】/ resetFramePicks({projectId,key})【圆圈回到等分】",
329
333
  "阶段①「八方向绿幕图」有两种生成方式(默认转圈截帧):",
330
334
  " setImageMode({projectId,mode:turn|direct})【turn=转圈截帧(默认):先生成一段「原地匀速转一整圈」的视频,再按时间截出八个方向,一致性好;direct=逐方向生图(备选)】/",
331
335
  " runTurnVideo({projectId})【★花钱:一次 MiniMax 调用,整圈只有这一段视频】/ runTurnFrames({projectId,count?})【本地 ffmpeg 抽候选帧并切出八张方向图,免费】/",
package/lib/wire.js CHANGED
@@ -86,6 +86,25 @@ const resetTurnPicksSchema = z.object({
86
86
  });
87
87
  const cutTurnFramesSchema = z.object({ projectId: z.string(), keys: z.array(z.string()).optional() });
88
88
  const runKeysSchema = z.object({ projectId: z.string(), keys: z.array(z.string()).optional() });
89
+ /** 从一个方向的行走视频抽出候选帧。count 是候选张数(8~64),不是最终序列帧数。 */
90
+ const prepareFramePickSchema = z.object({
91
+ projectId: z.string(),
92
+ key: z.string(),
93
+ count: z.number().optional()
94
+ });
95
+ /** 拖动某一个输出帧的圆圈。slot 是输出帧序号,index 是候选帧下标。 */
96
+ const setFramePickSchema = z.object({
97
+ projectId: z.string(),
98
+ key: z.string(),
99
+ slot: z.number(),
100
+ index: z.number()
101
+ });
102
+ const setWalkPicksSchema = z.object({
103
+ projectId: z.string(),
104
+ key: z.string(),
105
+ picks: z.array(z.number())
106
+ });
107
+ const resetWalkPicksSchema = z.object({ projectId: z.string(), key: z.string() });
89
108
  const runVideosSchema = z.object({
90
109
  projectId: z.string(),
91
110
  keys: z.array(z.string()).optional(),
@@ -465,6 +484,10 @@ export const METHODS = [
465
484
  { method: "pollVideos", payload: projectOnlySchema, result: okSchema },
466
485
  { method: "clearVideos", payload: runKeysSchema, result: okSchema },
467
486
  { method: "runFrames", payload: runKeysSchema, result: startedSchema },
487
+ { method: "prepareFramePick", payload: prepareFramePickSchema, result: startedSchema },
488
+ { method: "setFramePick", payload: setFramePickSchema, result: jsonObject },
489
+ { method: "setFramePicks", payload: setWalkPicksSchema, result: jsonObject },
490
+ { method: "resetFramePicks", payload: resetWalkPicksSchema, result: jsonObject },
468
491
  { method: "rekey", payload: projectOnlySchema, result: startedSchema },
469
492
  { method: "compose", payload: projectOnlySchema, result: startedSchema },
470
493
  // 图片生成
@@ -535,6 +558,18 @@ export const METHODS = [
535
558
  ];
536
559
  export const PACKAGE_NAME = "dsh-game-material-master";
537
560
  export const SERVICE_NAME = "gameStudio";
561
+ /**
562
+ * 当前 DSH(typert 0.1.7+)的 strict codec 必须带 `create()`。
563
+ * 注册时只检查工厂存在;真正过边界时调用 `codec.create().parse(value)`。
564
+ * 旧写法把 Zod schema 挂在 `schema` 上,启动时会直接拒绝整份 manifest。
565
+ */
566
+ function strictCodec(typeSymbol, schema) {
567
+ return {
568
+ mode: "strict",
569
+ typeSymbol,
570
+ create: () => schema
571
+ };
572
+ }
538
573
  /** 注册给宿主 typert 网关的 package face。 */
539
574
  export const MANIFEST = {
540
575
  package: PACKAGE_NAME,
@@ -553,10 +588,10 @@ export const MANIFEST = {
553
588
  name: "payload",
554
589
  wire: "payload",
555
590
  source: "json",
556
- codec: { mode: "strict", typeSymbol: `${PACKAGE_NAME}#${spec.method}Payload`, schema: spec.payload }
591
+ codec: strictCodec(`${PACKAGE_NAME}#${spec.method}Payload`, spec.payload)
557
592
  }
558
593
  ],
559
- result: { mode: "strict", typeSymbol: `${PACKAGE_NAME}#${spec.method}Result`, schema: spec.result }
594
+ result: strictCodec(`${PACKAGE_NAME}#${spec.method}Result`, spec.result)
560
595
  })),
561
596
  model: { services: [], events: [], objects: [] }
562
597
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-game-material-master",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "游戏素材大师:DSH 插件,包含八方向图生成、图片生成、序列帧生成三个游戏素材模块,以及实验性的骨骼动画生成模块。八方向图默认「转圈截帧」(一段原地匀速转一圈的绿幕视频 → 按时间轴截出八个方向),也可逐方向生图;火山方舟 Seedream 生图 + MiniMax 图生视频 + 本地抠绿幕合成。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",