dsh-game-material-master 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 universe-st
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # 游戏素材大师 · DSH 插件
2
+
3
+ 从一张角色设定图出发,批量产出游戏要用的素材。**火山方舟 Seedream** 负责生图,
4
+ **MiniMax** 负责图生视频,抠像与合成全部在本地用 ffmpeg 完成——不需要任何系统图像库,
5
+ 素材也不会传到第三方服务。
6
+
7
+ ## 功能
8
+
9
+ | 模块 | 做什么 | 验收 |
10
+ |---|---|---|
11
+ | **八方向图生成** | 一张设定图 → 8 方位 × 8 帧行走精灵图 | WASD 操控预览,逐方向重做 |
12
+ | **图片生成** | 按提示词出图(可带参考图)→ 一键抠绿幕导出透明 PNG | 逐张通过 / 重做 |
13
+ | **序列帧生成** | 首尾帧或参考图 + 参考视频 → 生成视频 → 抽帧 → 抠像 → 横向合成 | 循环预览,按步骤通过 |
14
+ | **骨骼动画生成** | 角色整图 → 拆件 → 装配 → 骨骼动画(6 种预设)→ 导出 Spine / DragonBones 图集 | 逐阶段可视化验收 |
15
+
16
+ 每个模块的每个阶段都能单独重跑——哪一步不满意,就只重做那一步。
17
+
18
+ 四个模块的**全部功能都可以通过对话调用**:插件把整条流水线注册成 `game_material_*`
19
+ 工具,agent 能自己推进、等待、审查,也可以在每一步停下来让你验收。
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ # npm 安装(发布后)
25
+ dsh plugin --profile web add dsh-game-material-master
26
+
27
+ # 本地目录安装(开发时)
28
+ dsh plugin --profile web add /path/to/dsh-game-material-master
29
+ ```
30
+
31
+ 装完**重启 DSH**(宿主半区在启动时装入)。浏览器半区按磁盘上的 `lib/client.js`
32
+ 现取,刷新浏览器即可生效。
33
+
34
+ **依赖**:`ffmpeg` / `ffprobe` 需要在 `PATH` 上(macOS:`brew install ffmpeg`),
35
+ 也可用 `FFMPEG_PATH` / `FFPROBE_PATH` 指定绝对路径。本包**没有任何运行时 npm 依赖**,
36
+ `zod`、`cordis` 等全部从 DSH 自身的安装树解析。
37
+
38
+ > 从旧版 `dsh-8dir-sprites` 升级时,首次启动会自动迁移数据目录,已有项目无缝接上。
39
+
40
+ ## 配置
41
+
42
+ **设置 → 游戏素材大师**:
43
+
44
+ | 项 | 说明 |
45
+ |---|---|
46
+ | 火山方舟 API Key | 「测试连接」会真实生成一张 1K 小图(少量费用),同时验证 Key 与模型 |
47
+ | 生图模型 | 默认 `doubao-seedream-4-0-250828`,可切 4.5 / 5.0 Lite / Pro |
48
+ | MiniMax API Key | 「测试连接」免费,能区分 Key 无效与其它错误 |
49
+ | 视频模型 | 默认 `MiniMax-H3`(v2 协议);Hailuo / I2V 走 v1;优云智算版 H3 显式选择 |
50
+ | Base URL | 主机根,不含 `/v1` `/v2`。国内 `api.minimax.cn`,国际 `api.minimaxi.com` |
51
+ | 默认参数 | 单格宽高、抽帧张数、像素块边长、抠像阈值等 |
52
+
53
+ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显始终脱敏。
54
+ **模型是插件级设置,三个模块共用**,切换模型后任务自动对齐新档位。
55
+
56
+ ## 常见坑
57
+
58
+ - 提示词别用「剪影」——生图模型会照字面把角色画成纯黑轮廓。
59
+ - 区分「转身」和「视线」:写方位时要补「只绕竖轴转身、视线始终水平」,否则会变抬头仰视。
60
+ - 图生视频不保证守住纯色背景(可能被打光成渐变),所以抠像不认单一绿色。
61
+ - 重复提交会被拦截(界面与对话都拦),避免白花钱。
62
+
63
+ ## 产物位置
64
+
65
+ ```
66
+ <DSH_HOME>/game-material-master/
67
+ ├── projects/<id>/ 八方向图(source / images / videos / frames / keyed / preview / out)
68
+ ├── image-jobs/<id>/ 图片生成
69
+ ├── sequence-jobs/<id>/ 序列帧生成
70
+ └── rig-jobs/<id>/ 骨骼动画(sheet / parts / layout / rig / atlas)
71
+ ```
72
+
73
+ ## 开发
74
+
75
+ ```bash
76
+ npm run build # tsc → lib/,并剥掉浏览器束结尾的 export
77
+ npm run typecheck # 只做类型检查
78
+ ```
79
+
80
+ 本地自检(不联网、不花钱):`scripts/verify-host.mjs`(宿主链路)、`verify-tools.mjs`
81
+ (对话调用面)、`verify-pipeline.mjs`(抽帧 / 抠像 / 合成)、`verify-rig.mjs`
82
+ (骨骼算法层)等。真实 API 端到端脚本会花钱,按需运行。
83
+
84
+ 改代码后如何生效:
85
+
86
+ | 改了哪里 | 怎么生效 |
87
+ |---|---|
88
+ | `src/client.ts`(浏览器半区) | 刷新浏览器即可 |
89
+ | `src/*.ts` 宿主半区 | 重启 DSH(或 `--patch` 热重载) |
90
+
91
+ ## 已知取舍
92
+
93
+ - **像素风来自后处理**(抽帧阶段的像素量化),不来自提示词——Seedream 会忽略「像素画」类指令。
94
+ - **拆件质量由生图模型决定**,是当前最大瓶颈。模型偶尔会「换角色」或把角色拆成服装裁片;
95
+ 最可靠的路径是「上传自己的部件 PNG」(文件名即部件名),完全绕开生图。
96
+ - **自动装配只对「部件就是参考图上整块肢体」的素材可靠**;真实立绘走生图拆件时,
97
+ 建议用 agent 视觉先验或手工拖放校正(这些步骤都不花钱)。
98
+ - MiniMax 偶发内容审核拒绝(实测约 10%),换一版更中性的提示词重试即可。
99
+
100
+ ## 许可
101
+
102
+ [MIT](LICENSE)
103
+
104
+ > 完整工程文档(算法细节、自检契约、历史踩坑)见 [docs/ENGINEERING.md](docs/ENGINEERING.md)。
@@ -0,0 +1,6 @@
1
+ # dsh-game-material-master bundle patch.
2
+ # 用 `dsh plugin --profile web add <本包>` 安装时,profile 会自动把本包追加进
3
+ # dsh.profile.bundles 并应用这一层,插件随即挂载,无需手工编辑 cordis.patch.yml。
4
+ - insert:
5
+ - id: game-material-master
6
+ name: dsh-game-material-master
package/lib/ark.js ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * 火山方舟(Ark)图片生成客户端。
3
+ *
4
+ * 端点:`POST {baseUrl}/images/generations`
5
+ * 参考图既可以给 http(s) URL,也可以给 `data:image/...;base64,...`(本地图片走这条)。
6
+ * 返回的 URL 只有 24 小时有效期,所以拿到就立刻下载落盘。
7
+ */
8
+ export class ArkError extends Error {
9
+ status;
10
+ code;
11
+ constructor(message, status, code) {
12
+ super(message);
13
+ this.name = "ArkError";
14
+ this.status = status;
15
+ this.code = code;
16
+ }
17
+ }
18
+ function isFiveSeries(model) {
19
+ return /seedream-5-0/i.test(model);
20
+ }
21
+ function sniffExt(bytes) {
22
+ if (bytes.length >= 8 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47)
23
+ return "png";
24
+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff)
25
+ return "jpg";
26
+ if (bytes.length >= 12 && bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP")
27
+ return "webp";
28
+ return "png";
29
+ }
30
+ async function readErrorBody(response) {
31
+ const text = await response.text().catch(() => "");
32
+ if (text.trim() === "")
33
+ return { message: `HTTP ${response.status} ${response.statusText}` };
34
+ try {
35
+ const parsed = JSON.parse(text);
36
+ const err = parsed?.error ?? parsed;
37
+ const message = typeof err?.message === "string" ? err.message : text.slice(0, 500);
38
+ const code = typeof err?.code === "string" ? err.code : undefined;
39
+ return { message, code };
40
+ }
41
+ catch {
42
+ return { message: text.slice(0, 500) };
43
+ }
44
+ }
45
+ /**
46
+ * 调一次生图。`images` 为空时是文生图,非空时是图生图 / 多图参考。
47
+ * 无论远端返回 url 还是 b64_json,都统一返回图片字节。
48
+ */
49
+ export async function generateImage(request, signal) {
50
+ if (request.apiKey.trim() === "")
51
+ throw new ArkError("尚未配置火山方舟 API Key(设置 → 游戏素材大师)");
52
+ if (request.model.trim() === "")
53
+ throw new ArkError("尚未配置生图模型 ID");
54
+ const body = {
55
+ model: request.model,
56
+ prompt: request.prompt,
57
+ size: request.size,
58
+ response_format: "url",
59
+ watermark: request.watermark === true
60
+ };
61
+ if (request.images.length === 1)
62
+ body.image = request.images[0];
63
+ else if (request.images.length > 1)
64
+ body.image = request.images;
65
+ // output_format 只有 5.0 系列接受;4.x 传了会 400。
66
+ if (isFiveSeries(request.model))
67
+ body.output_format = "png";
68
+ const timeout = AbortSignal.timeout(Math.max(10000, request.timeoutMs));
69
+ const composed = signal === undefined ? timeout : AbortSignal.any([signal, timeout]);
70
+ let response;
71
+ try {
72
+ response = await fetch(`${request.baseUrl}/images/generations`, {
73
+ method: "POST",
74
+ headers: {
75
+ Authorization: `Bearer ${request.apiKey}`,
76
+ "Content-Type": "application/json"
77
+ },
78
+ body: JSON.stringify(body),
79
+ signal: composed
80
+ });
81
+ }
82
+ catch (error) {
83
+ const reason = error instanceof Error ? error.message : String(error);
84
+ if (timeout.aborted)
85
+ throw new ArkError(`生图请求超时(${Math.round(request.timeoutMs / 1000)} 秒)`);
86
+ if (signal?.aborted === true)
87
+ throw new ArkError("生图请求已被取消");
88
+ throw new ArkError(`无法连接火山方舟:${reason}`);
89
+ }
90
+ if (!response.ok) {
91
+ const { message, code } = await readErrorBody(response);
92
+ throw new ArkError(`火山方舟生图失败(HTTP ${response.status}):${message}`, response.status, code);
93
+ }
94
+ const payload = (await response.json().catch(() => undefined));
95
+ const item = payload?.data?.[0];
96
+ if (item === undefined) {
97
+ throw new ArkError(`火山方舟返回里没有图片:${JSON.stringify(payload).slice(0, 400)}`);
98
+ }
99
+ if (typeof item.b64_json === "string" && item.b64_json !== "") {
100
+ const bytes = Buffer.from(item.b64_json, "base64");
101
+ return { bytes, ext: sniffExt(bytes), usage: payload?.usage };
102
+ }
103
+ if (typeof item.url === "string" && item.url !== "") {
104
+ const download = await fetch(item.url, { signal: composed }).catch((error) => {
105
+ throw new ArkError(`下载生成结果失败:${error instanceof Error ? error.message : String(error)}`);
106
+ });
107
+ if (!download.ok) {
108
+ throw new ArkError(`下载生成结果失败(HTTP ${download.status})`);
109
+ }
110
+ const bytes = Buffer.from(await download.arrayBuffer());
111
+ return { bytes, ext: sniffExt(bytes), remoteUrl: item.url, usage: payload?.usage };
112
+ }
113
+ throw new ArkError(`火山方舟返回里既没有 url 也没有 b64_json:${JSON.stringify(item).slice(0, 400)}`);
114
+ }
115
+ /**
116
+ * 连通性自检:真实生成一张 1K 小图。
117
+ * 只有真跑一次才能同时验证「Key 有效」和「模型/接入点可用」——这是最常见的两个坑。
118
+ */
119
+ export async function testArk(request) {
120
+ const result = await generateImage({
121
+ ...request,
122
+ prompt: "一张纯绿色背景的空白测试图,画面中只有一个居中的小圆点",
123
+ images: [],
124
+ size: "1K",
125
+ watermark: false
126
+ });
127
+ return { ok: true, model: request.model, bytes: result.bytes.length, ext: result.ext };
128
+ }