dsh-game-material-master 0.11.0 → 0.11.2
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/README.en.md +2 -0
- package/README.md +2 -0
- package/lib/chroma.js +74 -15
- package/lib/client.js +233 -48
- package/lib/config.js +6 -3
- package/lib/customimage.js +43 -0
- package/lib/directions.js +69 -8
- package/lib/imagegen.js +18 -4
- package/lib/imageprovider.js +7 -2
- package/lib/index.js +61 -12
- package/lib/isocompose.js +26 -17
- package/lib/isogen.js +7 -3
- package/lib/keycolor.js +251 -0
- package/lib/mapgen.js +11 -7
- package/lib/pipeline.js +10 -3
- package/lib/riggen.js +4 -4
- package/lib/seqgen.js +7 -0
- package/lib/store.js +23 -12
- package/lib/toolguides.js +14 -14
- package/lib/wire.js +13 -5
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -440,6 +440,8 @@ installation tree.
|
|
|
440
440
|
| MiniMax API Key | "Test connection" is free and can tell an invalid key apart from other errors |
|
|
441
441
|
| Video model | Defaults to `MiniMax-H3` (v2 protocol); Hailuo / I2V use v1; the UCloud version of H3 is selected explicitly |
|
|
442
442
|
| Base URL | Host root, without `/v1` or `/v2`. `api.minimax.cn` in mainland China, `api.minimaxi.com` internationally |
|
|
443
|
+
| Output size | Default for every image-generating module; accepts `1K` / `2K` / `4K` or `width x height`. An image task can switch its size source to Custom to affect only that task; tasks that follow the global value update with this setting |
|
|
444
|
+
| Key background color | Pure green `#00FF00` by default; switch to magenta / blue / white / black when the character wears green. "Green screen / #00FF00" in generated prompts is replaced accordingly, and every keying entry can pick its own color |
|
|
443
445
|
| Default parameters | Cell width and height, frame count, pixel block size, keying threshold, and so on |
|
|
444
446
|
| Local ComfyUI (image-to-video) | Routes image-to-video through a local **ComfyUI** instead of MiniMax; "Test connection" is read-only and free |
|
|
445
447
|
| Music generation (Puyue AI) | Puyue AI API key, base URL, default music model and timeouts; "Test connection" reads one page of history and does not generate anything (no generation credits). Generation is billed by platform credits; the plugin does not collect payment |
|
package/README.md
CHANGED
|
@@ -371,6 +371,8 @@ Windows 注册表里的同名变量 → WinGet / Scoop / Chocolatey 与 `C:\ffmp
|
|
|
371
371
|
| MiniMax API Key | 「测试连接」免费,能区分 Key 无效与其它错误 |
|
|
372
372
|
| 视频模型 | 默认 `MiniMax-H3`(v2 协议);Hailuo / I2V 走 v1;优云智算版 H3 显式选择 |
|
|
373
373
|
| Base URL | 主机根,不含 `/v1` `/v2`。国内 `api.minimax.cn`,国际 `api.minimaxi.com` |
|
|
374
|
+
| 输出尺寸 | 所有生图模块的**默认值**;支持 `1K` / `2K` / `4K` 或 `宽x高`。图片任务可单独把「尺寸来源」切成「自定义」,只影响那一个任务;跟随全局的任务会随这里变化 |
|
|
375
|
+
| 抠像背景色 | 默认纯绿 `#00FF00`;角色穿绿衣服时改成品红 / 蓝 / 白 / 黑等。生成提示词里的「绿幕 / #00FF00」会跟着替换,所有抠像入口都能单独选 |
|
|
374
376
|
| 默认参数 | 单格宽高、抽帧张数、像素块边长、抠像阈值等 |
|
|
375
377
|
| 本地 ComfyUI(图生视频) | 勾选后图生视频改走**本机 ComfyUI**,替代 MiniMax;「测试连接」只读状态、免费 |
|
|
376
378
|
| 音乐生成(谱乐 AI) | 填谱乐 AI API Key、Base URL、默认音乐模型与超时;「测试连接」读一页历史,不产生生成费用。生成按平台积分计费,插件不代收 |
|
package/lib/chroma.js
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* 基线上;再按盒式平均重采样到目标尺寸,最后量化成 pixelSize 的方块。
|
|
24
24
|
*/
|
|
25
25
|
import { encodePng } from "./png.js";
|
|
26
|
+
import { DEFAULT_KEY_COLOR, isGreenKeyColor, keyColorRgb, keyDominantChannels, normalizeKeyColor } from "./keycolor.js";
|
|
26
27
|
export const DEFAULT_KEY_OPTIONS = {
|
|
28
|
+
keyColor: DEFAULT_KEY_COLOR,
|
|
27
29
|
keyLow: 14,
|
|
28
30
|
keyHigh: 80,
|
|
29
31
|
despill: 0.65,
|
|
@@ -269,11 +271,27 @@ export function segmentBackgroundDetailed(rgba, width, height, globalTolerance,
|
|
|
269
271
|
}
|
|
270
272
|
return { mask: background, samples: built.samples, kept: built.kept, dropped: built.dropped };
|
|
271
273
|
}
|
|
274
|
+
/** 两个像素到某个背景色的 RGB 距离。 */
|
|
275
|
+
function keyDistance(rgba, offset, key) {
|
|
276
|
+
const dr = rgba[offset] - key.r;
|
|
277
|
+
const dg = rgba[offset + 1] - key.g;
|
|
278
|
+
const db = rgba[offset + 2] - key.b;
|
|
279
|
+
return Math.sqrt(dr * dr + dg * dg + db * db);
|
|
280
|
+
}
|
|
272
281
|
/** 没启用空间分割时,用颜色判据粗略估一个背景占比,供界面判断可信度。 */
|
|
273
|
-
function
|
|
282
|
+
function countKeyBackground(rgba, high, keyColor) {
|
|
283
|
+
const key = keyColorRgb(keyColor);
|
|
284
|
+
const green = isGreenKeyColor(keyColor);
|
|
274
285
|
let count = 0;
|
|
286
|
+
if (green) {
|
|
287
|
+
for (let p = 0; p < rgba.length; p += 4) {
|
|
288
|
+
if (rgba[p + 1] - Math.max(rgba[p], rgba[p + 2]) >= high)
|
|
289
|
+
count++;
|
|
290
|
+
}
|
|
291
|
+
return count;
|
|
292
|
+
}
|
|
275
293
|
for (let p = 0; p < rgba.length; p += 4) {
|
|
276
|
-
if (
|
|
294
|
+
if (keyDistance(rgba, p, key) <= high)
|
|
277
295
|
count++;
|
|
278
296
|
}
|
|
279
297
|
return count;
|
|
@@ -283,6 +301,10 @@ function countGreenBackground(rgba, high) {
|
|
|
283
301
|
* 输入输出都是 `width * height * 4` 字节、非预乘 alpha。
|
|
284
302
|
*/
|
|
285
303
|
export function keyGreen(rgba, width, height, options) {
|
|
304
|
+
const keyColor = normalizeKeyColor(options.keyColor ?? DEFAULT_KEY_COLOR);
|
|
305
|
+
const key = keyColorRgb(keyColor);
|
|
306
|
+
const greenMode = isGreenKeyColor(keyColor);
|
|
307
|
+
const dominant = keyDominantChannels(keyColor);
|
|
286
308
|
const low = Math.max(0, Math.min(255, options.keyLow));
|
|
287
309
|
const high = Math.max(low + 1, Math.min(255, options.keyHigh));
|
|
288
310
|
const span = high - low;
|
|
@@ -315,33 +337,70 @@ export function keyGreen(rgba, width, height, options) {
|
|
|
315
337
|
const g = rgba[p + 1];
|
|
316
338
|
const b = rgba[p + 2];
|
|
317
339
|
const srcAlpha = rgba[p + 3];
|
|
318
|
-
const other = r > b ? r : b;
|
|
319
|
-
const greenness = g - other;
|
|
320
340
|
let alpha = 1;
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
341
|
+
if (greenMode) {
|
|
342
|
+
const other = r > b ? r : b;
|
|
343
|
+
const greenness = g - other;
|
|
344
|
+
if (greenness >= high)
|
|
345
|
+
alpha = 0;
|
|
346
|
+
else if (greenness > low)
|
|
347
|
+
alpha = 1 - (greenness - low) / span;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
const distance = keyDistance(rgba, p, key);
|
|
351
|
+
if (distance >= high)
|
|
352
|
+
alpha = 1;
|
|
353
|
+
else if (distance > low)
|
|
354
|
+
alpha = (distance - low) / span;
|
|
355
|
+
else
|
|
356
|
+
alpha = 0;
|
|
357
|
+
}
|
|
325
358
|
alpha *= srcAlpha / 255;
|
|
326
|
-
//
|
|
359
|
+
// 空间上确认为背景的像素直接全透明;颜色判据只负责前景里的残余色边。
|
|
327
360
|
if (background !== undefined && background[i] === 1)
|
|
328
361
|
alpha = 0;
|
|
362
|
+
let outR = r;
|
|
329
363
|
let outG = g;
|
|
330
|
-
|
|
364
|
+
let outB = b;
|
|
365
|
+
if (despill > 0) {
|
|
331
366
|
const weight = despill * (1 - alpha);
|
|
332
|
-
if (weight > 0)
|
|
333
|
-
|
|
367
|
+
if (weight > 0) {
|
|
368
|
+
if (greenMode) {
|
|
369
|
+
const other = r > b ? r : b;
|
|
370
|
+
if (g > other)
|
|
371
|
+
outG = Math.round(g - (g - other) * weight);
|
|
372
|
+
}
|
|
373
|
+
else if (dominant.length > 0) {
|
|
374
|
+
const others = [0, 1, 2].filter((channel) => !dominant.includes(channel));
|
|
375
|
+
const values = [r, g, b];
|
|
376
|
+
const otherMax = others.length === 0 ? 0 : Math.max(...others.map((channel) => values[channel]));
|
|
377
|
+
for (const channel of dominant) {
|
|
378
|
+
const value = values[channel];
|
|
379
|
+
const excess = value - otherMax;
|
|
380
|
+
if (excess <= 0)
|
|
381
|
+
continue;
|
|
382
|
+
const next = Math.round(value - excess * weight);
|
|
383
|
+
if (channel === 0)
|
|
384
|
+
outR = next;
|
|
385
|
+
else if (channel === 1)
|
|
386
|
+
outG = next;
|
|
387
|
+
else
|
|
388
|
+
outB = next;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
334
392
|
}
|
|
335
|
-
out[p] =
|
|
393
|
+
out[p] = outR;
|
|
336
394
|
out[p + 1] = outG;
|
|
337
|
-
out[p + 2] =
|
|
395
|
+
out[p + 2] = outB;
|
|
338
396
|
out[p + 3] = Math.round(alpha * 255);
|
|
339
397
|
}
|
|
340
398
|
if (options.edgeShrink > 0)
|
|
341
399
|
shrinkAlpha(out, width, height, Math.min(8, Math.round(options.edgeShrink)));
|
|
342
400
|
return {
|
|
343
401
|
rgba: out,
|
|
344
|
-
|
|
402
|
+
keyColor,
|
|
403
|
+
backgroundFraction: background !== undefined ? backgroundCount / pixels : countKeyBackground(rgba, high, keyColor) / pixels,
|
|
345
404
|
usedSegmentation: background !== undefined,
|
|
346
405
|
borderSamples,
|
|
347
406
|
borderSamplesDropped
|