dsh-game-material-master 0.1.0 → 0.2.0

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/store.js CHANGED
@@ -15,7 +15,7 @@
15
15
  import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
16
16
  import { join, resolve, sep } from "node:path";
17
17
  import { randomUUID } from "node:crypto";
18
- import { DEFAULT_VIDEO_PROMPT, DIRECTION_KEYS, DEFAULT_ROW_ORDER, defaultImagePrompts } from "./directions.js";
18
+ import { DEFAULT_TURN_PROMPT, DEFAULT_VIDEO_PROMPT, DIRECTION_KEYS, DEFAULT_ROW_ORDER, TURN_FRAME_COUNT_DEFAULT, TURN_DIRECTION_DEFAULT, TURN_FRAME_COUNT_MAX, TURN_FRAME_COUNT_MIN, defaultImagePrompts, defaultTurnPicks } from "./directions.js";
19
19
  import { DEFAULT_CONFIG, ROW_ORDER_VERSION, isLegacyRowOrder, loadConfig, projectsRoot } from "./config.js";
20
20
  /** 每个项目一条读-改-写串行链,见 patchProject。 */
21
21
  const locks = new Map();
@@ -53,7 +53,8 @@ export function settingsFromConfig(config, rowOrder) {
53
53
  edgeShrink: config.edgeShrink,
54
54
  rowOrder: rowOrder ?? (config.rowOrder.length > 0 ? [...config.rowOrder] : [...DEFAULT_ROW_ORDER]),
55
55
  rowOrderVersion: ROW_ORDER_VERSION,
56
- concurrency: config.concurrency
56
+ concurrency: config.concurrency,
57
+ turnFrameCount: TURN_FRAME_COUNT_DEFAULT
57
58
  };
58
59
  }
59
60
  function emptyImages() {
@@ -62,6 +63,17 @@ function emptyImages() {
62
63
  out[key] = { status: "empty", approved: false };
63
64
  return out;
64
65
  }
66
+ /** 八方向的默认截帧位置(转圈方向决定它们的先后)。 */
67
+ export function freshPicks(frameCount, direction = TURN_DIRECTION_DEFAULT) {
68
+ return defaultTurnPicks(frameCount, direction);
69
+ }
70
+ function emptyTurn(frameCount = TURN_FRAME_COUNT_DEFAULT) {
71
+ return {
72
+ video: { status: "empty", approved: false },
73
+ frames: { status: "empty", frames: [], times: [], picks: freshPicks(frameCount), approved: false },
74
+ direction: TURN_DIRECTION_DEFAULT
75
+ };
76
+ }
65
77
  function emptyVideos() {
66
78
  const out = {};
67
79
  for (const key of DIRECTION_KEYS)
@@ -76,7 +88,7 @@ function emptyFrames() {
76
88
  }
77
89
  export async function ensureLayout(id) {
78
90
  const base = projectDir(id);
79
- for (const sub of ["source", "images", "videos", "frames", "keyed", "preview", "out"]) {
91
+ for (const sub of ["source", "images", "videos", "frames", "keyed", "preview", "out", "turn"]) {
80
92
  await mkdir(join(base, sub), { recursive: true });
81
93
  }
82
94
  }
@@ -84,6 +96,7 @@ export async function createProject(name) {
84
96
  const config = await loadConfig();
85
97
  const id = `p${Date.now().toString(36)}${randomUUID().slice(0, 6)}`;
86
98
  const now = Date.now();
99
+ const settings = settingsFromConfig(config);
87
100
  const project = {
88
101
  id,
89
102
  name: name.trim() === "" ? "未命名项目" : name.trim(),
@@ -93,6 +106,7 @@ export async function createProject(name) {
93
106
  prompts: {
94
107
  images: defaultImagePrompts(),
95
108
  video: DEFAULT_VIDEO_PROMPT,
109
+ turn: DEFAULT_TURN_PROMPT,
96
110
  videoPerDirection: {},
97
111
  suffix: ""
98
112
  },
@@ -100,7 +114,11 @@ export async function createProject(name) {
100
114
  videos: emptyVideos(),
101
115
  frames: emptyFrames(),
102
116
  sheet: { status: "empty", approved: false },
103
- settings: settingsFromConfig(config),
117
+ settings,
118
+ // 新项目默认走转圈截帧:「一致性」比「单张清晰度」更值钱,而八方向图
119
+ // 恰恰最容易在一致性上翻车。逐方向生图保留为备选,随时可切。
120
+ imageMode: "turn",
121
+ turn: emptyTurn(settings.turnFrameCount),
104
122
  log: []
105
123
  };
106
124
  await ensureLayout(id);
@@ -171,6 +189,7 @@ export function summarize(project) {
171
189
  createdAt: project.createdAt,
172
190
  updatedAt: project.updatedAt,
173
191
  hasSource: project.source !== null,
192
+ imageMode: project.imageMode,
174
193
  imageReady: DIRECTION_KEYS.filter((k) => project.images[k]?.status === "ready").length,
175
194
  videoReady: DIRECTION_KEYS.filter((k) => project.videos[k]?.status === "ready").length,
176
195
  framesReady: DIRECTION_KEYS.filter((k) => project.frames[k]?.status === "ready").length,
@@ -202,7 +221,8 @@ function normalizeProject(raw) {
202
221
  ? settings.rowOrder.map(String)
203
222
  : [...DEFAULT_ROW_ORDER],
204
223
  rowOrderVersion: ROW_ORDER_VERSION,
205
- concurrency: num(settings.concurrency, defaults.concurrency)
224
+ concurrency: num(settings.concurrency, defaults.concurrency),
225
+ turnFrameCount: clampIntSetting(settings.turnFrameCount, defaults.turnFrameCount, TURN_FRAME_COUNT_MIN, TURN_FRAME_COUNT_MAX)
206
226
  };
207
227
  const images = emptyImages();
208
228
  for (const key of DIRECTION_KEYS) {
@@ -236,6 +256,7 @@ function normalizeProject(raw) {
236
256
  const value = raw?.prompts?.images?.[key];
237
257
  images_prompts[key] = typeof value === "string" && value.trim() !== "" ? value : defaultPrompts[key];
238
258
  }
259
+ const imageMode = deriveImageMode(raw);
239
260
  return {
240
261
  id: String(raw?.id ?? ""),
241
262
  name: typeof raw?.name === "string" && raw.name.trim() !== "" ? raw.name : "未命名项目",
@@ -245,6 +266,7 @@ function normalizeProject(raw) {
245
266
  prompts: {
246
267
  images: images_prompts,
247
268
  video: typeof raw?.prompts?.video === "string" && raw.prompts.video.trim() !== "" ? raw.prompts.video : DEFAULT_VIDEO_PROMPT,
269
+ turn: typeof raw?.prompts?.turn === "string" && raw.prompts.turn.trim() !== "" ? raw.prompts.turn : DEFAULT_TURN_PROMPT,
248
270
  videoPerDirection: raw?.prompts?.videoPerDirection !== null && typeof raw?.prompts?.videoPerDirection === "object"
249
271
  ? { ...raw.prompts.videoPerDirection }
250
272
  : {},
@@ -265,9 +287,14 @@ function normalizeProject(raw) {
265
287
  rowOrder: Array.isArray(raw?.sheet?.rowOrder) ? raw.sheet.rowOrder.map(String) : undefined,
266
288
  cellWidth: raw?.sheet?.cellWidth,
267
289
  cellHeight: raw?.sheet?.cellHeight,
268
- frameCount: raw?.sheet?.frameCount
290
+ frameCount: raw?.sheet?.frameCount,
291
+ backgroundFraction: typeof raw?.sheet?.backgroundFraction === "number" ? raw.sheet.backgroundFraction : undefined,
292
+ borderSamplesDropped: typeof raw?.sheet?.borderSamplesDropped === "number" ? raw.sheet.borderSamplesDropped : undefined,
293
+ borderSamples: typeof raw?.sheet?.borderSamples === "number" ? raw.sheet.borderSamples : undefined
269
294
  },
270
295
  settings: merged,
296
+ imageMode,
297
+ turn: normalizeTurn(raw?.turn, merged.turnFrameCount),
271
298
  reviewMode: raw?.reviewMode === "manual" ? "manual" : raw?.reviewMode === "auto" ? "auto" : undefined,
272
299
  log: Array.isArray(raw?.log) ? raw.log.slice(-200) : []
273
300
  };
@@ -276,6 +303,78 @@ function num(value, fallback) {
276
303
  const n = typeof value === "number" ? value : Number.parseFloat(String(value ?? ""));
277
304
  return Number.isFinite(n) ? n : fallback;
278
305
  }
306
+ function clampIntSetting(value, fallback, min, max) {
307
+ return Math.min(max, Math.max(min, Math.round(num(value, fallback))));
308
+ }
309
+ /**
310
+ * 补齐项目的转圈状态。
311
+ *
312
+ * 老项目(这个字段还不存在时创建的)里 `picks` 一个都没有,这里补成默认的
313
+ * 均分位置——补出来的位置和「用户从没拖过」等价,所以可以安全地当默认值用。
314
+ */
315
+ function normalizeTurn(raw, frameCount) {
316
+ const direction = raw?.direction === "cw" ? "cw" : raw?.direction === "ccw" ? "ccw" : TURN_DIRECTION_DEFAULT;
317
+ const fallback = freshPicks(frameCount, direction);
318
+ const picks = {};
319
+ const rawPicks = raw?.frames?.picks;
320
+ for (const key of DIRECTION_KEYS) {
321
+ const value = rawPicks !== null && typeof rawPicks === "object" ? Number(rawPicks[key]) : Number.NaN;
322
+ // 只做「是个合法的非负下标」这一层收敛,**不按 settings.turnFrameCount 夹**:
323
+ // 候选帧的权威张数是 turn.frames.rawFrameCount(抽帧时写下的),而 settings
324
+ // 里的那个值随时可能被用户先改小——按它夹会把用户拖好的位置当场压平
325
+ // (实测:32 帧调到 16 之后 back/upRight/downRight 全挤到最后一帧)。
326
+ // 真正的夹取放在用它的地方:applyTurnPicks 按实际帧数夹。
327
+ picks[key] = Number.isFinite(value)
328
+ ? Math.min(TURN_FRAME_COUNT_MAX - 1, Math.max(0, Math.round(value)))
329
+ : fallback[key];
330
+ }
331
+ const times = Array.isArray(raw?.frames?.times) ? raw.frames.times.map((value) => num(value, 0)) : [];
332
+ return {
333
+ video: {
334
+ status: (raw?.video?.status ?? "empty"),
335
+ taskId: typeof raw?.video?.taskId === "string" ? raw.video.taskId : undefined,
336
+ remoteStatus: typeof raw?.video?.remoteStatus === "string" ? raw.video.remoteStatus : undefined,
337
+ file: typeof raw?.video?.file === "string" ? raw.video.file : undefined,
338
+ approved: raw?.video?.approved === true,
339
+ error: typeof raw?.video?.error === "string" ? raw.video.error : undefined,
340
+ firstFrame: typeof raw?.video?.firstFrame === "string" ? raw.video.firstFrame : undefined,
341
+ elapsedMs: typeof raw?.video?.elapsedMs === "number" ? raw.video.elapsedMs : undefined,
342
+ updatedAt: typeof raw?.video?.updatedAt === "number" ? raw.video.updatedAt : undefined
343
+ },
344
+ frames: {
345
+ status: (raw?.frames?.status ?? "empty"),
346
+ frames: Array.isArray(raw?.frames?.frames) ? raw.frames.frames.map(String) : [],
347
+ times,
348
+ raw: typeof raw?.frames?.raw === "string" ? raw.frames.raw : undefined,
349
+ rawWidth: typeof raw?.frames?.rawWidth === "number" ? raw.frames.rawWidth : undefined,
350
+ rawHeight: typeof raw?.frames?.rawHeight === "number" ? raw.frames.rawHeight : undefined,
351
+ rawFrameCount: typeof raw?.frames?.rawFrameCount === "number" ? raw.frames.rawFrameCount : undefined,
352
+ duration: typeof raw?.frames?.duration === "number" ? raw.frames.duration : undefined,
353
+ picks,
354
+ strip: typeof raw?.frames?.strip === "string" ? raw.frames.strip : undefined,
355
+ approved: raw?.frames?.approved === true,
356
+ error: typeof raw?.frames?.error === "string" ? raw.frames.error : undefined,
357
+ stale: raw?.frames?.stale === true,
358
+ updatedAt: typeof raw?.frames?.updatedAt === "number" ? raw.frames.updatedAt : undefined
359
+ },
360
+ direction
361
+ };
362
+ }
363
+ /**
364
+ * 老项目(`imageMode` 还不存在时建的)沿用逐方向生图:它们已经有八张图了,
365
+ * 直接跳到空白的转圈页只会让人以为产物丢了。新项目走 `createProject`,默认 turn。
366
+ *
367
+ * `imageMode` 与上面这条判断是**唯一**一处「新旧默认不同」的地方,其余一律
368
+ * 以字段为准——否则读一遍写一遍就会把用户的显式选择改掉。
369
+ */
370
+ function deriveImageMode(raw) {
371
+ if (raw?.imageMode === "direct")
372
+ return "direct";
373
+ if (raw?.imageMode === "turn")
374
+ return "turn";
375
+ const hasImages = DIRECTION_KEYS.some((key) => typeof raw?.images?.[key]?.file === "string");
376
+ return hasImages ? "direct" : "turn";
377
+ }
279
378
  /** 往项目日志里追加一条(最多保留 200 条)。 */
280
379
  export function log(project, level, message) {
281
380
  project.log.push({ at: Date.now(), level, message });
package/lib/tools.js CHANGED
@@ -100,6 +100,20 @@ function spriteSnapshot(project) {
100
100
  const count = (cells, status) => cells.filter((cell) => cell.status === status).length;
101
101
  const approved = (cells) => cells.filter((cell) => cell.approved).length;
102
102
  const images = cellsOf(project.images, assetBase, (node) => ({ file: node.file }));
103
+ // 转圈模式下每张方向图都是「第几帧」切出来的:验收包带上这个下标,
104
+ // agent 才说得清「正面那帧截早了」这类问题,也才知道 setTurnPick 该往哪调。
105
+ if (project.imageMode === "turn") {
106
+ const total = project.turn?.frames?.frames?.length ?? 0;
107
+ const duration = Number(project.turn?.frames?.duration ?? 0);
108
+ for (const cell of images) {
109
+ if (total <= 0)
110
+ continue;
111
+ const index = Math.min(total - 1, Math.max(0, Number(project.turn?.frames?.picks?.[cell.direction] ?? 0)));
112
+ cell.frameIndex = index;
113
+ cell.frameTotal = total;
114
+ cell.frameSeconds = Number(((index * duration) / total).toFixed(2));
115
+ }
116
+ }
103
117
  const videos = cellsOf(project.videos, assetBase, (node) => ({ file: node.file }));
104
118
  const frames = cellsOf(project.frames, assetBase, (node) => ({ file: node.strip, extra: { frameCount: node.frames?.length ?? 0 } }));
105
119
  const sheetCell = [
@@ -111,6 +125,11 @@ function spriteSnapshot(project) {
111
125
  stale: false,
112
126
  file: project.sheet?.file,
113
127
  url: assetUrl(assetBase, project.sheet?.file),
128
+ // 抠像诊断:背景占比偏低 / 边框采样被大量排除,都是「抠歪了」的信号。
129
+ ...(typeof project.sheet?.backgroundFraction === "number" ? { backgroundFraction: project.sheet.backgroundFraction } : {}),
130
+ ...(typeof project.sheet?.borderSamplesDropped === "number" && project.sheet.borderSamplesDropped > 0
131
+ ? { borderSamplesDropped: project.sheet.borderSamplesDropped, borderSamples: project.sheet.borderSamples }
132
+ : {}),
114
133
  ...(typeof project.sheet?.error === "string" && project.sheet.error !== "" ? { error: project.sheet.error } : {})
115
134
  }
116
135
  ];
@@ -121,6 +140,29 @@ function spriteSnapshot(project) {
121
140
  sourceFile: project.source?.file ?? null,
122
141
  reviewMode: project.reviewMode ?? null,
123
142
  busy,
143
+ /**
144
+ * 阶段①的生成方式与它的转圈状态。
145
+ *
146
+ * 转圈模式下「八个方向图」不是八个节点各自生成的,而是同一段视频的八个
147
+ * 截帧位置——验收包里必须把视频、缩略条带和八个位置一起给出来,
148
+ * 否则 agent 看不到「圈转没转对」,只能对着一张张方向图猜。
149
+ */
150
+ imageMode: project.imageMode ?? "turn",
151
+ turn: {
152
+ direction: project.turn?.direction ?? "cw",
153
+ videoStatus: project.turn?.video?.status ?? "empty",
154
+ videoUrl: assetUrl(assetBase, project.turn?.video?.file),
155
+ firstFrame: project.turn?.video?.firstFrame ?? null,
156
+ remoteStatus: project.turn?.video?.remoteStatus ?? null,
157
+ error: project.turn?.video?.error ?? null,
158
+ framesStatus: project.turn?.frames?.status ?? "empty",
159
+ stripUrl: assetUrl(assetBase, project.turn?.frames?.strip),
160
+ frameCount: project.turn?.frames?.frames?.length ?? 0,
161
+ duration: project.turn?.frames?.duration ?? null,
162
+ stale: project.turn?.frames?.stale === true
163
+ },
164
+ /** 八个方向各自截在第几帧(转圈模式专用;逐方向生图时是空的)。 */
165
+ turnPicks: project.imageMode === "turn" ? { ...(project.turn?.frames?.picks ?? {}) } : {},
124
166
  stages: [
125
167
  { stage: "images", title: "① 八方向绿幕图", ready: count(images, "ready"), running: count(images, "running"), error: count(images, "error"), approved: approved(images), total: 8, cells: images },
126
168
  { stage: "videos", title: "② 行走动作视频", ready: count(videos, "ready"), running: count(videos, "running"), error: count(videos, "error"), approved: approved(videos), total: 8, cells: videos },
@@ -275,15 +317,21 @@ function intentFromCall(method, payload) {
275
317
  return undefined;
276
318
  }
277
319
  // ── 工具注册 ────────────────────────────────────────────────────────────
278
- /** `game_material_call` 的描述:把 45 个方法的用途与入参写清楚。 */
320
+ /** `game_material_call` 的描述:把每个远程方法的用途与入参写清楚。 */
279
321
  const CALL_DESCRIPTION = [
280
322
  "调用「游戏素材大师」插件的任意远程方法——插件界面上的每个功能都能在这里调用。",
281
323
  "配置:getConfig() / saveConfig(payload: 任意配置字段,如 arkApiKey、arkModel、minimaxModel、cellWidth…) / testArk() / testMinimax()",
282
324
  "八方向图:listProjects() / createProject({name}) / getProject({projectId}) / deleteProject({projectId}) / renameProject({projectId,name}) /",
283
- " uploadSource({projectId,name,data:base64}) / savePrompts({projectId,images?,video?,videoPerDirection?,suffix?,resetImagesToDefault?,resetVideoToDefault?}) /",
325
+ " uploadSource({projectId,name,data:base64}) / savePrompts({projectId,images?,video?,turn?,videoPerDirection?,suffix?,resetImagesToDefault?,resetVideoToDefault?,resetTurnToDefault?}) /",
284
326
  " saveSettings({projectId,settings}) / setApproved({projectId,stage:images|videos|frames|sheet,key?,approved}) / revealProject({projectId}) /",
285
327
  " runImage({projectId,key,prompt?}) / runImages({projectId,force?}) / runVideos({projectId,keys?,regenerate?}) / pollVideos({projectId}) /",
286
328
  " clearVideos({projectId,keys?}) / runFrames({projectId,keys?}) / rekey({projectId}) / compose({projectId})",
329
+ "阶段①「八方向绿幕图」有两种生成方式(默认转圈截帧):",
330
+ " setImageMode({projectId,mode:turn|direct})【turn=转圈截帧(默认):先生成一段「原地匀速转一整圈」的视频,再按时间截出八个方向,一致性好;direct=逐方向生图(备选)】/",
331
+ " runTurnVideo({projectId})【★花钱:一次 MiniMax 调用,整圈只有这一段视频】/ runTurnFrames({projectId,count?})【本地 ffmpeg 抽候选帧并切出八张方向图,免费】/",
332
+ " setTurnPick({projectId,key,index})【改某个方向的截帧位置(圆圈拖动),只重切那一张】/ setTurnPicks({projectId,picks:{front:index,…}})【看完整圈条带后整份写回】/",
333
+ " resetTurnPicks({projectId,direction?cw|ccw})【八个位置回到默认等分;direction 决定左右斜向怎么排】/ cutTurnFrames({projectId,keys?})",
334
+ " 转圈模式的产物就是 images/<方向>.png(与逐方向生图完全相同),所以阶段②③④不用换做法。",
287
335
  "图片生成:listImageJobs() / createImageJob({name}) / getImageJob({jobId}) / deleteImageJob({jobId}) /",
288
336
  " saveImageJob({jobId,name?,prompt?,suffix?,settings?,keying?,approved?,index?}) / uploadImageRef({jobId,name,data}) / removeImageRef({jobId,file}) /",
289
337
  " addImageItem({jobId,name,data}) / removeImageItem({jobId,index}) / runImageJob({jobId,count?}) / keyImageJob({jobId})",
@@ -603,6 +651,11 @@ export function registerStudioTools(host, gateway) {
603
651
  ...entry,
604
652
  cells: entry.cells.filter((cell) => direction === undefined || cell.direction === direction)
605
653
  }));
654
+ // 转圈模式要审的不只是八张方向图:整圈视频转得对不对、缩略条带与八个
655
+ // 位置是不是落在该落的朝向上,都得能点开看。逐方向生图下这些是空的。
656
+ packet.imageMode = snapshot.imageMode;
657
+ packet.turn = snapshot.turn;
658
+ packet.turnPicks = snapshot.turnPicks;
606
659
  packet.nextActions = spriteNextActions(snapshot, stage, direction);
607
660
  }
608
661
  else if (module === "image") {
@@ -735,6 +788,16 @@ const PROMPT_SECTION = [
735
788
  "序列帧是 video → frames → sheet;骨骼动画是 parts → layout → rig → atlas。每次提交类调用之后**立刻** `game_material_wait`。",
736
789
  "骨骼动画只有第 ① 步(runRigSheet)花钱,②③④ 都是本地计算,重跑不额外计费;装配失败时用 runRigLayout({jobId, names:[…]}) 只重跑那几个部件。",
737
790
  "",
791
+ "### 八方向图的第①步有两种生成方式(默认「转圈截帧」)",
792
+ "`getProject` 返回的 `imageMode` 决定这一步怎么做,产物都是 `images/<方向>.png`,第②③④步不变:",
793
+ " · `turn`(默认)**转圈截帧**:`runTurnVideo({projectId})` 生成一段「角色原地匀速转一整圈」的绿幕视频(★一次 MiniMax 计费),",
794
+ " 视频到手后宿主**自动**抽候选帧并切出八个方向(本机 ffmpeg,免费);",
795
+ " 八个方向的位置就是同一段视频的八个截帧下标,可以用 `setTurnPick({projectId,key,index})` 逐个调(只重切那一张),",
796
+ " 或 `resetTurnPicks({projectId,direction?'cw'|'ccw'})` 回到默认等分。八个方向同源,一致性最好。",
797
+ " 视频转得不对(转速不匀 / 动作太多 / 第一帧不是正面)时传 `runTurnVideo` 重做一次,别去调坐标。",
798
+ " · `direct` **逐方向生图**(备选):`runImages({projectId})` 按依赖顺序逐个生图,单张更清晰但八个方向容易不一致。",
799
+ "`setImageMode({projectId,mode:'turn'|'direct'})` 随时切换,两种方式的产物互不删除。",
800
+ "",
738
801
  "### 骨骼动画的自动摆位不准时:给「视觉先验」(重要)",
739
802
  "第 ② 步的自动定位是**纯几何匹配**,对「模型重画过的部件」(裙摆、袖子这类服装裁片)会失手:",
740
803
  "它在错误位置也可能拿到不低的分数。这时**你(agent)就是那个视觉模型**,去做一次语义对应:",
@@ -850,7 +913,8 @@ function intakeFor(module, id, told, config, target) {
850
913
  known.默认每段抽帧数 = config?.frameCount;
851
914
  known.默认像素块 = config?.pixelSize;
852
915
  known.默认行序 = config?.rowOrder;
853
- known.四个阶段 = "① 八方向绿幕图 → ② 行走动作视频 → ③ 提取序列帧 → ④ 抠绿幕合成整图";
916
+ known.阶段1两种生成方式 = "转圈截帧(默认):一段「原地匀速转一整圈」的绿幕视频 → 按时间轴截出八个方向;逐方向生图(备选):八个方向各自生图";
917
+ known.四个阶段 = "① 八方向绿幕图(转圈截帧 / 逐方向生图)→ ② 行走动作视频 → ③ 提取序列帧 → ④ 抠绿幕合成整图";
854
918
  }
855
919
  if (module === "image") {
856
920
  known.默认张数范围 = "1~8(Seedream 约 0.2 元/张)";
@@ -886,12 +950,19 @@ function intakeFor(module, id, told, config, target) {
886
950
  else {
887
951
  ask("source", "用哪张角色设定图作为源图?(PNG / JPG,≤30MB)", "八方向图从这一张出发派生其余七个方位,没有它无法开始。", "给我文件路径后我用 game_material_upload({module:'sprite', id, kind:'source', path}) 上传。");
888
952
  }
953
+ // 阶段①有两条路,代价与产物形态完全不同,必须问清楚(默认转圈截帧)。
954
+ if (target?.imageMode !== undefined) {
955
+ known.阶段1生成方式 = target.imageMode === "turn" ? "转圈截帧(默认)" : "逐方向生图";
956
+ }
957
+ ask("generateMode", "阶段①「八方向绿幕图」用哪种生成方式?默认是「转圈截帧」(先生成一段原地匀速转一整圈的绿幕视频,再按时间截出八个方向——八个方向同源、一致性最好,一次视频调用;位置可以在时间轴上拖);也可以选「逐方向生图」(每个方向单独生图,单张更清晰,但八方向容易不一致,八次调用)。", "这一步决定后面整条链路的产物形态与花费,先定下来再动手。", "转圈截帧:setImageMode({projectId,mode:'turn'}) → runTurnVideo({projectId}) → game_material_wait(视频到手会自动抽帧切图)→ 需要时 setTurnPick({projectId,key,index}) 调位置;逐方向生图:setImageMode({projectId,mode:'direct'}) → runImages({projectId})。");
889
958
  if (target?.reviewMode)
890
959
  known.审核模式 = target.reviewMode;
891
960
  ask("suffix", "有没有跨方向都要遵守的统一要求?(例如「必须穿同一双靴子」「不要出现文字」;可留空)", "会追加到每一张生图提示词末尾,改一次八个方向全生效。", "用 game_material_call 的 savePrompts({projectId, suffix}) 保存。");
892
- ask("scope", "八个方向全做,还是只做指定方向?", "只做部分方向能明显省钱省时间。", "开始生成时 runImage({projectId,key}) 做单个方向,runImages({projectId}) 做全部。");
961
+ if (target?.imageMode !== "turn") {
962
+ ask("scope", "八个方向全做,还是只做指定方向?", "只做部分方向能明显省钱省时间。", "开始生成时 runImage({projectId,key}) 做单个方向,runImages({projectId}) 做全部。");
963
+ }
893
964
  ask("tuning", "默认参数要改吗?(单格尺寸 / 每段抽帧数 / 像素块大小 / 行序 / 并发数;不改就用默认)", "这些决定了最终精灵图的规格。", "要改就用 saveSettings({projectId, settings})。");
894
- ask("prompts", "每个方向的生图/视频提示词要用默认模板,还是你自己写?(默认模板已经把方位与可见部位写对了,建议先用默认)", "方位写错会导致八个方向看起来是抬头 / 低头而不是转身。", "要改就用 savePrompts。");
965
+ ask("prompts", "每个方向的生图/视频提示词要用默认模板,还是你自己写?(默认模板已经把方位与可见部位写对了,建议先用默认;转圈截帧对应的是「转圈视频提示词」)", "方位写错会导致八个方向看起来是抬头 / 低头而不是转身。", "要改就用 savePrompts。");
895
966
  }
896
967
  if (module === "image") {
897
968
  if (hasPrompt)
@@ -1106,7 +1177,7 @@ function renderStatus(value) {
1106
1177
  if (Array.isArray(value.projects)) {
1107
1178
  const lines = [
1108
1179
  `项目(${value.projects.length}):`,
1109
- ...value.projects.map((p) => ` - ${p.id} ${p.name} — 图 ${p.imageReady}/8 · 视频 ${p.videoReady}/8 · 帧 ${p.framesReady}/8${p.sheetReady ? " · 整图✓" : ""}`),
1180
+ ...value.projects.map((p) => ` - ${p.id} ${p.name} — 图 ${p.imageReady}/8 · 视频 ${p.videoReady}/8 · 帧 ${p.framesReady}/8${p.sheetReady ? " · 整图✓" : ""}${p.imageMode === "turn" ? " · 阶段①转圈截帧" : p.imageMode === "direct" ? " · 阶段①逐方向生图" : ""}`),
1110
1181
  `图片任务(${value.imageJobs.length}):`,
1111
1182
  ...value.imageJobs.map((j) => ` - ${j.id} ${j.name} — ${j.ready}/${j.total} 张(抠像 ${j.keyed})`),
1112
1183
  `序列帧任务(${value.sequenceJobs.length}):`,
@@ -1128,6 +1199,27 @@ function renderStatus(value) {
1128
1199
  lines.push(detail);
1129
1200
  }
1130
1201
  }
1202
+ // 八方向图:阶段①的两种生成方式差异很大,状态里必须写明走的是哪条、
1203
+ // 转圈视频与八个截帧位置各是什么——否则 agent 只能对着一张张方向图猜。
1204
+ if (value.imageMode !== undefined && value.turn !== undefined) {
1205
+ const turn = value.turn ?? {};
1206
+ lines.push(` 阶段①生成方式:${value.imageMode === "turn" ? "转圈截帧(默认)" : "逐方向生图(备选)"}`);
1207
+ if (value.imageMode === "turn") {
1208
+ lines.push(` 转圈视频:${turn.videoStatus ?? "empty"}${turn.remoteStatus ? `(${turn.remoteStatus})` : ""}` +
1209
+ `${turn.frameCount > 0 ? ` · 候选帧 ${turn.frameCount} 张 / 时长 ${Number(turn.duration ?? 0).toFixed(2)} 秒` : " · 还没有候选帧"}` +
1210
+ `${turn.stale === true ? " · 候选帧已过期,需要重新抽帧" : ""}`);
1211
+ if (typeof turn.videoUrl === "string")
1212
+ lines.push(` 转圈视频地址:${turn.videoUrl}`);
1213
+ if (typeof turn.stripUrl === "string")
1214
+ lines.push(` 整圈缩略条带:${turn.stripUrl}`);
1215
+ const picks = value.turnPicks ?? {};
1216
+ const pickKeys = Object.keys(picks);
1217
+ if (pickKeys.length > 0)
1218
+ lines.push(` 八个截帧位置:${pickKeys.map((key) => `${key}=${picks[key]}`).join(" ")}`);
1219
+ if (typeof turn.error === "string" && turn.error !== "")
1220
+ lines.push(` 转圈视频错误:${turn.error}`);
1221
+ }
1222
+ }
1131
1223
  if (Array.isArray(value.parts)) {
1132
1224
  const ready = value.parts.filter((part) => part.status === "ready").length;
1133
1225
  const placed = value.parts.filter((part) => part.placed).length;
@@ -1227,9 +1319,29 @@ function spriteNextActions(snapshot, stage, direction) {
1227
1319
  const pick = (key) => (stage === undefined || stage === key ? byStage[key] : undefined);
1228
1320
  const images = pick("images");
1229
1321
  if (images !== undefined && images.ready < images.total) {
1230
- actions.push(snapshot.sourceFile === null
1231
- ? "还没有源图:先用 game_material_call({method:'uploadSource', payload:{projectId,name,data}}) 上传一张设定图"
1232
- : `绿幕图还差 ${images.total - images.ready} 张:game_material_call({method:'runImages', payload:{projectId}}) 然后 game_material_wait`);
1322
+ // 转圈截帧是默认路径,它的下一步与逐方向生图完全不同,提示必须分开写——
1323
+ // 报错信息里点错方法,模型会照着 runImages 一路跑到「八个方向不一致」上去。
1324
+ const turn = snapshot.turn ?? {};
1325
+ if (snapshot.imageMode === "turn") {
1326
+ if (turn.videoStatus !== "ready") {
1327
+ actions.push(snapshot.sourceFile === null
1328
+ ? "还没有源图:先用 game_material_call({method:'uploadSource', payload:{projectId,name,data}}) 上传一张设定图"
1329
+ : `转圈视频还没有:game_material_call({method:'runTurnVideo', payload:{projectId}}) 然后 game_material_wait(★花钱一次,约几分钟);视频到手会自动抽候选帧并切出八个方向`);
1330
+ }
1331
+ else {
1332
+ actions.push(`转圈视频已就绪,还差 ${images.total - images.ready} 张方向图:game_material_call({method:'runTurnFrames', payload:{projectId}}) 然后 game_material_wait(本地免费)`);
1333
+ }
1334
+ if (turn.frameCount > 0) {
1335
+ actions.push(`★ 先核对八个朝向:read_image 看 turn.stripUrl(整圈候选帧条带),确认每个方向落在第几帧——左侧脸/右侧脸反了就是转圈方向反了,` +
1336
+ `用 resetTurnPicks({direction:'cw'|'ccw'}) 一键重排;模型起步/收尾减速(前几帧还停在正面)时用 ` +
1337
+ `setTurnPicks({projectId, picks:{front:1, downRight:6, …}}) 整份写回(index 取 0…${Math.max(0, turn.frameCount - 1)})`);
1338
+ }
1339
+ }
1340
+ else {
1341
+ actions.push(snapshot.sourceFile === null
1342
+ ? "还没有源图:先用 game_material_call({method:'uploadSource', payload:{projectId,name,data}}) 上传一张设定图"
1343
+ : `绿幕图还差 ${images.total - images.ready} 张:game_material_call({method:'runImages', payload:{projectId}}) 然后 game_material_wait`);
1344
+ }
1233
1345
  }
1234
1346
  const videos = pick("videos");
1235
1347
  if (videos !== undefined && videos.ready < videos.total && (images === undefined || images.ready === images.total)) {
package/lib/wire.js CHANGED
@@ -27,13 +27,17 @@ const promptsSchema = z.object({
27
27
  projectId: z.string(),
28
28
  images: z.record(z.string(), z.string()).optional(),
29
29
  video: z.string().optional(),
30
+ /** 转圈模式的旋转视频提示词(整圈只有这一份)。 */
31
+ turn: z.string().optional(),
30
32
  videoPerDirection: z.record(z.string(), z.string()).optional(),
31
33
  /** 统一附加提示词:追加到每个方向的生图提示词末尾;空串表示关闭。 */
32
34
  suffix: z.string().optional(),
33
35
  /** 一键把八个方向的生图提示词重置为当前默认模板。 */
34
36
  resetImagesToDefault: z.boolean().optional(),
35
37
  /** 一键把视频提示词重置为当前默认模板。 */
36
- resetVideoToDefault: z.boolean().optional()
38
+ resetVideoToDefault: z.boolean().optional(),
39
+ /** 一键把转圈视频提示词重置为当前默认模板。 */
40
+ resetTurnToDefault: z.boolean().optional()
37
41
  });
38
42
  const settingsSchema = z.object({ projectId: z.string(), settings: z.record(z.string(), z.unknown()) });
39
43
  const approvedSchema = z.object({
@@ -54,6 +58,33 @@ const setReviewModeSchema = z.object({
54
58
  });
55
59
  const runImageSchema = z.object({ projectId: z.string(), key: z.string(), prompt: z.string().optional() });
56
60
  const runImagesSchema = z.object({ projectId: z.string(), force: z.boolean().optional() });
61
+ // ── 阶段①的另一种生成方式:转圈截帧 ────────────────────────────────────
62
+ /** 生成方式:`turn` = 转一圈再按时间截帧(默认);`direct` = 逐方向生图(备选)。 */
63
+ const setImageModeSchema = z.object({ projectId: z.string(), mode: z.enum(["turn", "direct"]) });
64
+ const runTurnFramesSchema = z.object({
65
+ projectId: z.string(),
66
+ /** 候选帧张数;不给就沿用项目里的 `settings.turnFrameCount`。 */
67
+ count: z.number().optional()
68
+ });
69
+ const setTurnPickSchema = z.object({
70
+ projectId: z.string(),
71
+ /** 方向 key(front / back / downLeft / …)。 */
72
+ key: z.string(),
73
+ /** 候选帧下标(0 起)。 */
74
+ index: z.number()
75
+ });
76
+ /** 一次写多个截帧位置(agent 看完整圈条带后整份写回)。 */
77
+ const setTurnPicksSchema = z.object({
78
+ projectId: z.string(),
79
+ /** 方向 key → 候选帧下标。只给要改的方向。 */
80
+ picks: z.record(z.string(), z.number())
81
+ });
82
+ const resetTurnPicksSchema = z.object({
83
+ projectId: z.string(),
84
+ /** 转圈方向;不给就沿用当前值。 */
85
+ direction: z.enum(["cw", "ccw"]).optional()
86
+ });
87
+ const cutTurnFramesSchema = z.object({ projectId: z.string(), keys: z.array(z.string()).optional() });
57
88
  const runKeysSchema = z.object({ projectId: z.string(), keys: z.array(z.string()).optional() });
58
89
  const runVideosSchema = z.object({
59
90
  projectId: z.string(),
@@ -423,6 +454,13 @@ export const METHODS = [
423
454
  { method: "revealProject", payload: projectIdSchema, result: okSchema },
424
455
  { method: "runImage", payload: runImageSchema, result: startedSchema },
425
456
  { method: "runImages", payload: runImagesSchema, result: startedSchema },
457
+ { method: "setImageMode", payload: setImageModeSchema, result: okSchema },
458
+ { method: "runTurnVideo", payload: projectOnlySchema, result: startedSchema },
459
+ { method: "runTurnFrames", payload: runTurnFramesSchema, result: startedSchema },
460
+ { method: "setTurnPick", payload: setTurnPickSchema, result: jsonObject },
461
+ { method: "setTurnPicks", payload: setTurnPicksSchema, result: jsonObject },
462
+ { method: "resetTurnPicks", payload: resetTurnPicksSchema, result: jsonObject },
463
+ { method: "cutTurnFrames", payload: cutTurnFramesSchema, result: okSchema },
426
464
  { method: "runVideos", payload: runVideosSchema, result: startedSchema },
427
465
  { method: "pollVideos", payload: projectOnlySchema, result: okSchema },
428
466
  { method: "clearVideos", payload: runKeysSchema, result: okSchema },
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "dsh-game-material-master",
3
- "version": "0.1.0",
4
- "description": "游戏素材大师:DSH 插件,包含八方向图生成、图片生成、序列帧生成三个游戏素材模块。火山方舟 Seedream 生图 + MiniMax 图生视频 + 本地抠绿幕合成。",
3
+ "version": "0.2.0",
4
+ "description": "游戏素材大师:DSH 插件,包含八方向图生成、图片生成、序列帧生成三个游戏素材模块,以及实验性的骨骼动画生成模块。八方向图默认「转圈截帧」(一段原地匀速转一圈的绿幕视频 → 按时间轴截出八个方向),也可逐方向生图;火山方舟 Seedream 生图 + MiniMax 图生视频 + 本地抠绿幕合成。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/universe-st/dsh-game-material-master.git"
10
+ },
11
+ "homepage": "https://github.com/universe-st/dsh-game-material-master#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/universe-st/dsh-game-material-master/issues"
14
+ },
7
15
  "exports": {
8
16
  ".": "./lib/index.js",
9
17
  "./client": "./lib/client.js",