@playcraft/cli 0.0.40 → 0.0.42
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.md +66 -3
- package/dist/atom-plan/validate-atom-plan.js +298 -0
- package/dist/cli-root-help.js +1 -1
- package/dist/commands/3d.js +363 -0
- package/dist/commands/create.js +337 -0
- package/dist/commands/image.js +1337 -43
- package/dist/commands/recommend.js +1 -1
- package/dist/commands/remix.js +213 -0
- package/dist/commands/skills.js +1379 -0
- package/dist/commands/tools-3d.js +473 -0
- package/dist/commands/tools-generation.js +452 -0
- package/dist/commands/tools-project.js +400 -0
- package/dist/commands/tools-research.js +37 -0
- package/dist/commands/tools-research.test.js +216 -0
- package/dist/commands/tools-utils.js +183 -0
- package/dist/commands/tools.js +7 -616
- package/dist/config.js +2 -0
- package/dist/index.js +19 -1
- package/dist/utils/version-checker.js +8 -11
- package/package.json +9 -3
- package/project-template/.claude/agents/designer.md +120 -0
- package/project-template/.claude/agents/developer.md +124 -0
- package/project-template/.claude/agents/pm.md +164 -0
- package/project-template/.claude/agents/refs/README.md +73 -0
- package/project-template/.claude/agents/refs/designer-art-style-catalog.md +533 -0
- package/project-template/.claude/agents/refs/designer-color-audio-recipes.md +153 -0
- package/project-template/.claude/agents/refs/designer-deliverable-spec.md +191 -0
- package/project-template/.claude/agents/refs/designer-dimension-axis.md +27 -0
- package/project-template/.claude/agents/refs/designer-handoff-v2-checklist.md +68 -0
- package/project-template/.claude/agents/refs/designer-master-composite-recipes.md +208 -0
- package/project-template/.claude/agents/refs/designer-style-exploration-flow.md +37 -0
- package/project-template/.claude/agents/refs/developer-dev-handoff.md +109 -0
- package/project-template/.claude/agents/refs/developer-impl-cookbook.md +134 -0
- package/project-template/.claude/agents/refs/developer-phase1-flow.md +136 -0
- package/project-template/.claude/agents/refs/pm-workflow-detail.md +551 -0
- package/project-template/.claude/agents/refs/reviewer-convergence-eval.md +130 -0
- package/project-template/.claude/agents/refs/reviewer-six-dimension-eval.md +6 -0
- package/project-template/.claude/agents/refs/ta-3d-flip-recipe.md +85 -0
- package/project-template/.claude/agents/refs/ta-atlas-deliverable-standard.md +67 -0
- package/project-template/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
- package/project-template/.claude/agents/refs/ta-image-generation-detail.md +356 -0
- package/project-template/.claude/agents/refs/ta-image-ops-reference.md +495 -0
- package/project-template/.claude/agents/refs/ta-pipeline-cookbook.md +1108 -0
- package/project-template/.claude/agents/refs/ta-tools-reference.md +111 -0
- package/project-template/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
- package/project-template/.claude/agents/reviewer.md +127 -0
- package/project-template/.claude/agents/technical-artist.md +122 -0
- package/project-template/.claude/hooks/README.md +44 -0
- package/project-template/.claude/hooks/validate-atom-plan.mjs +224 -0
- package/project-template/.claude/hooks/validate-workflow-stop.mjs +343 -0
- package/project-template/.claude/settings.json +36 -0
- package/project-template/.claude/settings.local.json +4 -0
- package/project-template/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
- package/project-template/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
- package/project-template/.claude/skills/playcraft-asset-state-sheet/SKILL.md +141 -0
- package/project-template/.claude/skills/playcraft-audio-generation/SKILL.md +280 -0
- package/project-template/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
- package/project-template/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +279 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +235 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +97 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +137 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
- package/project-template/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
- package/project-template/.claude/skills/playcraft-masking/SKILL.md +373 -0
- package/project-template/.claude/skills/playcraft-research/SKILL.md +212 -0
- package/project-template/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
- package/project-template/.claude/skills/playcraft-storyboard/SKILL.md +167 -0
- package/project-template/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
- package/project-template/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
- package/project-template/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
- package/project-template/.claude/skills/playcraft-workflow/SKILL.md +485 -0
- package/project-template/.claude/skills/playwright-cli/SKILL.md +390 -0
- package/project-template/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
- package/project-template/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/project-template/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/project-template/.claude/skills/playwright-cli/references/running-code.md +240 -0
- package/project-template/.claude/skills/playwright-cli/references/session-management.md +226 -0
- package/project-template/.claude/skills/playwright-cli/references/spec-driven-testing.md +312 -0
- package/project-template/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/project-template/.claude/skills/playwright-cli/references/test-generation.md +138 -0
- package/project-template/.claude/skills/playwright-cli/references/tracing.md +142 -0
- package/project-template/.claude/skills/playwright-cli/references/video-recording.md +157 -0
- package/project-template/.cursor/hooks.json +17 -0
- package/project-template/.cursor/rules/playcraft-orchestrator.mdc +137 -0
- package/project-template/.cursor/rules/playcraft-subagent-boundary.mdc +18 -0
- package/project-template/CLAUDE.md +280 -0
- package/project-template/assets/audio/bgm/.gitkeep +0 -0
- package/project-template/assets/audio/sfx/.gitkeep +0 -0
- package/project-template/assets/bundles/.gitkeep +0 -0
- package/project-template/assets/images/bg/.gitkeep +0 -0
- package/project-template/assets/images/reference/.gitkeep +0 -0
- package/project-template/assets/images/storyboard/.gitkeep +0 -0
- package/project-template/assets/images/tiles/.gitkeep +0 -0
- package/project-template/assets/images/ui/.gitkeep +0 -0
- package/project-template/assets/images/vfx/.gitkeep +0 -0
- package/project-template/assets/models/.gitkeep +0 -0
- package/project-template/docs/team/agent-conduct.md +121 -0
- package/project-template/docs/team/agent-runtime-matrix.md +62 -0
- package/project-template/docs/team/atom-plan-format.md +105 -0
- package/project-template/docs/team/collaboration.md +297 -0
- package/project-template/docs/team/core-model.md +50 -0
- package/project-template/docs/team/platform-capabilities.md +15 -0
- package/project-template/docs/team/workflow-changelog.md +65 -0
- package/project-template/docs/team/workflow-consistency-checklist.md +140 -0
- package/project-template/game/config/.gitkeep +0 -0
- package/project-template/game/gameplay/.gitkeep +0 -0
- package/project-template/game/scenes/.gitkeep +0 -0
- package/project-template/logs/.gitkeep +0 -0
- package/project-template/ta-workspace/logs/.gitkeep +0 -0
- package/project-template/ta-workspace/scripts/.gitkeep +0 -0
- package/project-template/ta-workspace/tmp/.gitkeep +0 -0
- package/project-template/templates/atom-plan.template.json +26 -0
- package/project-template/templates/atom-plan.template.md +108 -0
- package/project-template/templates/design-brief.template.md +195 -0
- package/project-template/templates/design-lens-checklist.reference.md +117 -0
- package/project-template/templates/design-methodology.md +99 -0
- package/project-template/templates/designer-log.template.md +114 -0
- package/project-template/templates/developer-log.template.md +134 -0
- package/project-template/templates/five-axis-framework.md +186 -0
- package/project-template/templates/intent-clarifications.template.md +58 -0
- package/project-template/templates/layout-spec.template.md +146 -0
- package/project-template/templates/project-state.template.md +237 -0
- package/project-template/templates/review-report.template.md +91 -0
- package/project-template/templates/style-exploration.template.md +93 -0
- package/project-template/templates/ta-log.template.md +343 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: playcraft-image-ops
|
|
3
|
+
description: TA 图形操作生产上下文指南。按可玩广告流水线阶段(提取/标准化/变换/合成/验证)组织 playcraft image 子命令,说明 WHEN 和 WHY 而非仅 HOW。完整 CLI 参数速查表见 refs/ta-image-ops-reference.md。
|
|
4
|
+
triggers: 裁剪,crop,叠图,合成,overlay,扩画布,pad,去白边,trim,旋转,rotate,翻转,flip,模糊,blur,色调,tint,灰度,grayscale,反色,negate,居中裁,等比裁,图层叠加,画布,像素级操作,图形处理,decompose-layers,图层分层,提取,extract
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# PlayCraft 图形操作 — 生产上下文指南
|
|
8
|
+
|
|
9
|
+
## 0. 在流水线中的位置
|
|
10
|
+
|
|
11
|
+
所有命令均为 `playcraft image <子命令>` 格式,基于 sharp 本地处理,无需后端。
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
TA Production Pipeline:
|
|
15
|
+
Extract (从 Composite/ASR 提取)
|
|
16
|
+
-> decompose-layers (302 整图语义分层,Master Composite;见 playcraft-masking skill)
|
|
17
|
+
-> crop (ASR 网格 / 已知 bbox 的像素级裁切)
|
|
18
|
+
-> segment (SAM3 单对象蒙版,见 playcraft-masking skill)
|
|
19
|
+
|
|
20
|
+
Process (标准化处理)
|
|
21
|
+
-> trim (去除多余透明边)
|
|
22
|
+
-> resize (统一到 assetSpec 尺寸)
|
|
23
|
+
-> pad (补齐到等宽画布)
|
|
24
|
+
-> remove-background -> 见 playcraft-masking skill
|
|
25
|
+
|
|
26
|
+
Transform (变体生成)
|
|
27
|
+
-> flip horizontal (左右镜像,节省生成成本)
|
|
28
|
+
-> rotate (方向调整)
|
|
29
|
+
-> tint (色调变体 / 禁用状态)
|
|
30
|
+
-> grayscale (锁定 / 未解锁状态)
|
|
31
|
+
|
|
32
|
+
Compose (合成叠加)
|
|
33
|
+
-> overlay (多层合成:背景 + 角色 + UI)
|
|
34
|
+
|
|
35
|
+
Verify (验证)
|
|
36
|
+
-> info (检查尺寸 / 格式 / 文件大小)
|
|
37
|
+
-> convert (最终格式转换 -- 生产阶段保持 PNG)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 1. 按阶段命令速查
|
|
43
|
+
|
|
44
|
+
| Stage | Command | One-liner | Key Param |
|
|
45
|
+
| --------- | ------------------ | --------------------------------------------------------------------------------- | ---------------------------------- |
|
|
46
|
+
| Extract | `decompose-layers` | `playcraft image decompose-layers --input X --output-dir ./layers --num-layers 4` | 后端 302;`--input` 宜为 HTTPS URL |
|
|
47
|
+
| Extract | `crop` | `playcraft image crop --input X --output Y --x N --y N --width W --height H` | x,y = 左上角原点 |
|
|
48
|
+
| Process | `trim` | `playcraft image trim --input X --output Y --threshold 10` | threshold: 0-255 |
|
|
49
|
+
| Process | `resize` | `playcraft image resize --input X --output Y --width W --height H` | 或 `--scale 0.5` |
|
|
50
|
+
| Process | `pad` | `playcraft image pad --input X --output Y --all 16` | 或 --top/bottom/left/right |
|
|
51
|
+
| Transform | `flip` | `playcraft image flip --input X --output Y --direction horizontal` | horizontal / vertical |
|
|
52
|
+
| Transform | `rotate` | `playcraft image rotate --input X --output Y --angle 90` | 角度(顺时针),背景默认透明 |
|
|
53
|
+
| Transform | `tint` | `playcraft image tint --input X --output Y --color "#FFD700"` | hex 颜色值 |
|
|
54
|
+
| Transform | `grayscale` | `playcraft image grayscale --input X --output Y` | 无额外参数 |
|
|
55
|
+
| Compose | `overlay` | `playcraft image overlay --base BG --overlay FG --output Y --gravity center` | 或 --x --y 精确坐标 |
|
|
56
|
+
| Verify | `info` | `playcraft image info --input X` | --json 供脚本解析 |
|
|
57
|
+
| Verify | `convert` | `playcraft image convert --input X --output Y --format webp --quality 85` | 生产阶段保持 PNG |
|
|
58
|
+
|
|
59
|
+
**overlay gravity 值**:center(默认) / north / south / east / west / northeast / northwest / southeast / southwest。
|
|
60
|
+
指定 --x + --y 时 gravity 被忽略,叠加图左上角放置在底图 (x, y) 坐标处。
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 2. 最常用配方
|
|
65
|
+
|
|
66
|
+
### 配方 A:标准化精灵尺寸 (trim -> info -> pad)
|
|
67
|
+
|
|
68
|
+
**场景**:AI 生成或分割提取的素材尺寸不一,需要统一到 assetSpec 指定的画布大小。
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
playcraft image trim --input raw_sprite.png --output /tmp/trimmed.png
|
|
72
|
+
playcraft image info --input /tmp/trimmed.png --json
|
|
73
|
+
# 根据 info 输出计算 pad 值:top/bottom = (目标高 - 当前高) / 2,left/right 同理
|
|
74
|
+
playcraft image pad --input /tmp/trimmed.png --output assets/images/tiles/sprite_128x128.png \
|
|
75
|
+
--top 8 --bottom 8 --left 16 --right 16
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**为什么这个顺序**:先 trim 去掉 AI 生成图的冗余透明边,再 pad 到精确尺寸。反过来做会把冗余透明边也算进画布。
|
|
79
|
+
|
|
80
|
+
### 配方 B:多层合成 (overlay chain: bg -> character -> UI)
|
|
81
|
+
|
|
82
|
+
**场景**:将背景、角色、UI 元素按层合成为最终画面。Layout Spec 中的 composite 通常需要这个流程。
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
playcraft image overlay --base assets/images/bg/background.png \
|
|
86
|
+
--overlay assets/images/character.png --output /tmp/step1.png --gravity center
|
|
87
|
+
playcraft image overlay --base /tmp/step1.png \
|
|
88
|
+
--overlay assets/images/ui/cta_button.png --output assets/images/final.png --gravity south
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**为什么逐层叠加**:overlay 每次只接受一个叠加层。从最底层开始,每一步的输出作为下一步的 base,保证 z-order 正确。
|
|
92
|
+
|
|
93
|
+
### 配方 C:镜像动画帧 (flip horizontal)
|
|
94
|
+
|
|
95
|
+
**场景**:已有 run_right 动画序列帧,需要 run_left。翻转比重新生成节省时间和 API 调用。
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
for f in assets/images/character/run_right_*.png; do
|
|
99
|
+
name=$(basename "$f" .png)
|
|
100
|
+
playcraft image flip --input "$f" \
|
|
101
|
+
--output "assets/images/character/${name/right/left}.png" \
|
|
102
|
+
--direction horizontal
|
|
103
|
+
done
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**为什么用 flip 而不重新生成**:AI 生成的镜像帧可能出现风格不一致,而 flip 保证像素级对称,且零 API 成本。
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 3. 关键注意事项
|
|
111
|
+
|
|
112
|
+
- **crop 不支持 batch**:`playcraft image batch --steps` 中 crop 会报 `unsupported command`。批量裁切用 for 循环或 Node.js 脚本。
|
|
113
|
+
- **生产阶段保持 PNG**:所有中间产物和最终资产用 PNG。WebP/AVIF 转换交给构建阶段 `playcraft build --convert-webp`。
|
|
114
|
+
- **tint 是混合不是替换**:深色图像 tint 效果弱,需要颜色替换时用 overlay + 纯色图层。
|
|
115
|
+
- **居中裁公式**:`x = (原图宽 - 目标宽) / 2`,`y = (原图高 - 目标高) / 2`(取整)。
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 4. 完整参考
|
|
120
|
+
|
|
121
|
+
完整 CLI 参数速查表、所有 gravity 值、rotation 选项、滤镜命令(blur / negate)及更多组合配方:
|
|
122
|
+
读取 `refs/ta-image-ops-reference.md`。
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: playcraft-masking
|
|
3
|
+
description: PlayCraft 蒙版与智能抠图完整指南。涵盖 decompose-layers(302 Qwen 整图分层)、segment(SAM3 语义分割)的文本/框选模式、mask+rgba 输出、remove-background 选型、蒙版合成与轮廓描边。TA 在处理抠图、蒙版或背景替换任务前必读。
|
|
4
|
+
triggers: 蒙版,mask,抠图,去背景,remove-background,语义分割,segment,SAM,SAM3,decompose-layers,图层分层,layered,背景替换,透明背景,RGBA,floodfill,ai抠图,轮廓描边,背景分离,foreground,主体提取
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# PlayCraft 蒙版与智能抠图完整指南
|
|
8
|
+
|
|
9
|
+
## 0. 工具速查
|
|
10
|
+
|
|
11
|
+
| 工具 | 适用场景 | 速度 | 质量 |
|
|
12
|
+
| -------------------------------------- | ------------------------------------------------- | ---------------------- | -------------------- |
|
|
13
|
+
| `remove-background --method floodfill` | 纯色背景(绿幕、白底、渐变色) | 快(本地) | 中等,边缘较硬 |
|
|
14
|
+
| `remove-background --method ai` | 任意复杂背景 | 慢(调后端) | 高,支持半透明/毛发 |
|
|
15
|
+
| `decompose-layers` | **整图**拆成 N 个语义 RGBA 层(Master Composite) | 慢(302,约 1–2 分钟) | 高,全尺寸分层 PNG |
|
|
16
|
+
| `segment` | 按 prompt **指定对象**抠图/蒙版 | 慢(SAM3) | 最高,产出 mask+rgba |
|
|
17
|
+
|
|
18
|
+
**决策逻辑**:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
要从整张合成稿一次性拆出背景/角色/UI 等多层?
|
|
22
|
+
├─ 是 → decompose-layers(需 Admin 配置 302 API Key;本地图需公网 URL 或 --input HTTPS)
|
|
23
|
+
└─ 否 → 背景是纯色/绿幕?
|
|
24
|
+
├─ 是 → remove-background --method floodfill
|
|
25
|
+
└─ 否 → 需要 mask 文件供后续合成?
|
|
26
|
+
├─ 是 → segment(或已知位置用 crop)
|
|
27
|
+
└─ 否 → remove-background --method ai
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**decompose-layers vs segment**:
|
|
31
|
+
|
|
32
|
+
- **decompose-layers**:无 per-object prompt,自动分层;适合 Master Composite 拆解;**不能**指定「只要第 3 格 tile」。ASR 优先用 `crop`。
|
|
33
|
+
- **segment**:开放词汇或框选单个对象;适合精确蒙版;密集网格上**禁止**纯 text prompt(见下文 §2)。
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 1. decompose-layers — 302 Qwen 整图语义分层
|
|
38
|
+
|
|
39
|
+
将整张图拆成 `num_layers` 张带透明通道的 PNG(默认 4 层),用于 Master Composite 元素提取(ASR 优先 crop,不用本命令)。
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
playcraft image decompose-layers \
|
|
43
|
+
--input assets/images/storyboard/master_composite.png \
|
|
44
|
+
--output-dir ta-workspace/tmp/layers \
|
|
45
|
+
--num-layers 4 \
|
|
46
|
+
--prompt ""
|
|
47
|
+
|
|
48
|
+
# 输入已是公网 URL 时(推荐本地 dev)
|
|
49
|
+
playcraft image decompose-layers \
|
|
50
|
+
--input "https://example.com/composite.png" \
|
|
51
|
+
--output-dir ./layers-out
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**配置**:Admin → 系统 → AI → `provider=302`、`modelKind=image` + API Key(与 302 生图共用,**不必**单独添加 qwen-image-layered 模型项)。
|
|
55
|
+
|
|
56
|
+
**输出**:`layer_00.png` … `layer_{N-1}.png` + `decompose-layers-meta.json`。
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 2. remove-background — 去背景
|
|
61
|
+
|
|
62
|
+
### Floodfill 模式(纯色背景)
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# 基础用法(默认 floodfill,去除纯色背景)
|
|
66
|
+
playcraft image remove-background \
|
|
67
|
+
--input assets/images/tiles/tile_greenscreen.png \
|
|
68
|
+
--output assets/images/tiles/tile_transparent.png
|
|
69
|
+
|
|
70
|
+
# 调整容差(--tolerance,默认 30)
|
|
71
|
+
# 值越高,容错越大(适合渐变背景或有噪点的纯色背景)
|
|
72
|
+
playcraft image remove-background \
|
|
73
|
+
--input assets/images/character/character_white_bg.png \
|
|
74
|
+
--output assets/images/character/character_transparent.png \
|
|
75
|
+
--method floodfill \
|
|
76
|
+
--tolerance 50
|
|
77
|
+
|
|
78
|
+
# 边缘平滑度(--edge-smooth,默认 2,最大有效 4)
|
|
79
|
+
# 值越高,边缘越柔和(减少锯齿)
|
|
80
|
+
playcraft image remove-background \
|
|
81
|
+
--input assets/images/tiles/tile_white.png \
|
|
82
|
+
--output assets/images/tiles/tile_clean.png \
|
|
83
|
+
--tolerance 30 \
|
|
84
|
+
--edge-smooth 3
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Floodfill 参数说明**:
|
|
88
|
+
|
|
89
|
+
| 参数 | 默认值 | 说明 |
|
|
90
|
+
| --------------- | ------ | -------------------------------------------------- |
|
|
91
|
+
| `--tolerance` | 30 | 颜色容差(0-255):背景色在此范围内的像素都被去掉 |
|
|
92
|
+
| `--edge-smooth` | 2 | 边缘平滑(0-4):对边缘 alpha 做高斯平滑,减少锯齿 |
|
|
93
|
+
|
|
94
|
+
**什么时候调大 tolerance**:
|
|
95
|
+
|
|
96
|
+
- 白色背景但图中有浅色元素 → tolerance 太大会误删内容,建议 20-30
|
|
97
|
+
- 绿幕背景有轻微渐变 → 可试 40-60
|
|
98
|
+
- 背景有明显噪点 → 50+
|
|
99
|
+
|
|
100
|
+
### AI 模式(复杂背景)
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
playcraft image remove-background \
|
|
104
|
+
--input assets/images/character/character_scene.png \
|
|
105
|
+
--output assets/images/character/character_cutout.png \
|
|
106
|
+
--method ai \
|
|
107
|
+
--model small # small(快)或 medium(精细)
|
|
108
|
+
|
|
109
|
+
# 跳过 alpha 精化(更快,边缘稍粗)
|
|
110
|
+
playcraft image remove-background \
|
|
111
|
+
--input source.png \
|
|
112
|
+
--output output.png \
|
|
113
|
+
--method ai \
|
|
114
|
+
--no-refine
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**AI 模式 vs Floodfill 选型表**:
|
|
118
|
+
|
|
119
|
+
| 特征 | 选 floodfill | 选 ai |
|
|
120
|
+
| -------------------------------- | ------------ | ----- |
|
|
121
|
+
| 背景是纯色(绿、白、蓝) | 是 | — |
|
|
122
|
+
| 背景有复杂纹理/渐变/场景 | — | 是 |
|
|
123
|
+
| 角色有半透明部分(衣物、头发丝) | — | 是 |
|
|
124
|
+
| 需要快速批量处理 | 是 | — |
|
|
125
|
+
| 追求最高精度 | — | 是 |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 3. segment — SAM3 语义分割
|
|
130
|
+
|
|
131
|
+
`segment` 调用后端 SAM3 模型,对图片中的对象进行精确语义分割,产出**蒙版文件**(mask)和**透明抠图**(rgba)。
|
|
132
|
+
|
|
133
|
+
**适用场景**:
|
|
134
|
+
|
|
135
|
+
- 需要精确 mask 文件供后续合成操作使用
|
|
136
|
+
- 从游戏截图中精确分离多个游戏元素
|
|
137
|
+
- 需要不规则形状的蒙版(圆形徽章、异形 UI 元素)
|
|
138
|
+
|
|
139
|
+
### ⚠️ 模式选择决策(必读)
|
|
140
|
+
|
|
141
|
+
> **对网格/已知布局图(如 ASR state sheets、authoring sprite sheets),严禁使用纯 text prompt!**
|
|
142
|
+
>
|
|
143
|
+
> text prompt 在多元素密集图上歧义极大——SAM3 无法准确区分"整个 tile 方块"和"方块内的水果 icon"。
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
提取目标的位置已知或可计算?
|
|
147
|
+
├─ 是(网格布局、规则排列)
|
|
148
|
+
│ → 优先 playcraft image crop(最可靠,零 AI 歧义)
|
|
149
|
+
│ → 次选 segment --boxes(需要精确蒙版时)
|
|
150
|
+
│
|
|
151
|
+
├─ 位置大致可估、需要精确蒙版
|
|
152
|
+
│ → segment --boxes(用近似 bbox 框选)
|
|
153
|
+
│
|
|
154
|
+
└─ 位置完全未知、元素形状不规则
|
|
155
|
+
→ segment --text(最后手段)
|
|
156
|
+
→ prompt 必须极其具体,包含位置/颜色/上下文描述
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**常见错误示例**:
|
|
160
|
+
|
|
161
|
+
- ❌ `--text "apple tile icon"` → 可能只切出苹果水果,丢失 tile 方块底板
|
|
162
|
+
- ❌ `--text "panda character"` → 图上有 panda face tile + panda 角色,返回多个 instance
|
|
163
|
+
- ✅ `--boxes '[[50,50,450,450]]'` → 框选已知位置的完整元素
|
|
164
|
+
- ✅ `playcraft image crop --x 50 --y 50 --width 400 --height 400` → 零歧义直切
|
|
165
|
+
|
|
166
|
+
### 文本提示模式(仅用于位置未知、元素分布不规则场景)
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# 用文字描述要提取的对象(仅适用于元素位置无法提前计算的场景)
|
|
170
|
+
playcraft image segment \
|
|
171
|
+
--input assets/images/screenshot.png \
|
|
172
|
+
--text "the main character" \
|
|
173
|
+
--output-dir assets/images/segment_output/
|
|
174
|
+
|
|
175
|
+
# 提取特定游戏元素
|
|
176
|
+
playcraft image segment \
|
|
177
|
+
--input assets/images/game_scene.png \
|
|
178
|
+
--text "the treasure chest" \
|
|
179
|
+
--output-dir /tmp/segment/
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**text prompt 最佳实践**:
|
|
183
|
+
|
|
184
|
+
- 描述要尽可能具体:加颜色、位置、完整性描述
|
|
185
|
+
- ✅ `"the complete rounded square tile with green apple in top-left area"`
|
|
186
|
+
- ❌ `"apple tile icon"`(歧义:是苹果本身?还是整个 tile 方块?)
|
|
187
|
+
- 返回多个 instance 时,不要盲目取 score 最高的——检查 bbox 尺寸是否合理
|
|
188
|
+
|
|
189
|
+
### 框选模式(多对象精确分割)
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# --boxes 接受 JSON 数组,每个元素为 [x1, y1, x2, y2](左上角和右下角坐标)
|
|
193
|
+
playcraft image segment \
|
|
194
|
+
--input assets/images/game_scene.png \
|
|
195
|
+
--boxes '[[50, 100, 200, 300], [350, 150, 500, 400]]' \
|
|
196
|
+
--box-labels '["player", "enemy"]' \
|
|
197
|
+
--output-dir /tmp/segment/
|
|
198
|
+
|
|
199
|
+
# 单个框(无需 box-labels 时)
|
|
200
|
+
playcraft image segment \
|
|
201
|
+
--input assets/images/tile_sheet.png \
|
|
202
|
+
--boxes '[[0, 0, 128, 128]]' \
|
|
203
|
+
--output-dir /tmp/segment/
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 输出结构
|
|
207
|
+
|
|
208
|
+
`segment` 在 `--output-dir` 下生成:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
segment_output/
|
|
212
|
+
├── 00_mask.png # 二值蒙版(白=前景,黑=背景)
|
|
213
|
+
├── 00_rgba.png # 透明背景抠图(直接可用)
|
|
214
|
+
├── 01_mask.png # 第二个对象的蒙版(若多框)
|
|
215
|
+
├── 01_rgba.png # 第二个对象的透明抠图
|
|
216
|
+
└── segment-meta.json # 分割元数据(坐标、置信度等)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 阈值调节(边缘精细度)
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# --threshold(默认 0.3):越低保留越多细节,但可能包含噪点
|
|
223
|
+
# 越高边缘越干净,但可能丢失细节(毛发、透明边缘)
|
|
224
|
+
playcraft image segment \
|
|
225
|
+
--input game_scene.png \
|
|
226
|
+
--text "the hero character" \
|
|
227
|
+
--threshold 0.2 \ # 较低:保留更多边缘细节
|
|
228
|
+
--output-dir /tmp/segment/
|
|
229
|
+
|
|
230
|
+
# --mask-threshold:后端蒙版生成阈值(高级参数)
|
|
231
|
+
playcraft image segment \
|
|
232
|
+
--input source.png \
|
|
233
|
+
--text "the dragon" \
|
|
234
|
+
--threshold 0.3 \
|
|
235
|
+
--mask-threshold 0.5 \
|
|
236
|
+
--output-dir /tmp/segment/
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 仅生成蒙版(不要 rgba)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# --no-rgba:跳过 rgba 生成,只输出 mask(更快)
|
|
243
|
+
playcraft image segment \
|
|
244
|
+
--input source.png \
|
|
245
|
+
--text "the background elements" \
|
|
246
|
+
--no-rgba \
|
|
247
|
+
--output-dir /tmp/masks/
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 4. 蒙版合成工作流
|
|
253
|
+
|
|
254
|
+
### 工作流 A:换背景(最常用)
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# 1. 用 segment 提取角色(带透明背景)
|
|
258
|
+
playcraft image segment \
|
|
259
|
+
--input assets/images/character_with_bg.png \
|
|
260
|
+
--text "the game character" \
|
|
261
|
+
--output-dir /tmp/char_segment/
|
|
262
|
+
# → 产出 /tmp/char_segment/00_rgba.png
|
|
263
|
+
|
|
264
|
+
# 2. 用 overlay 把角色合成到新背景上
|
|
265
|
+
playcraft image overlay \
|
|
266
|
+
--base assets/images/bg/new_background.png \
|
|
267
|
+
--overlay /tmp/char_segment/00_rgba.png \
|
|
268
|
+
--output assets/images/character_on_new_bg.png \
|
|
269
|
+
--gravity center
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### 工作流 B:多层合成(背景 + 角色 + UI)
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# 层1:基础背景
|
|
276
|
+
cp assets/images/bg/background.png /tmp/composite.png
|
|
277
|
+
|
|
278
|
+
# 层2:叠加角色(居中偏下)
|
|
279
|
+
playcraft image overlay \
|
|
280
|
+
--base /tmp/composite.png \
|
|
281
|
+
--overlay assets/images/character/character_transparent.png \
|
|
282
|
+
--output /tmp/composite.png \
|
|
283
|
+
--gravity south
|
|
284
|
+
|
|
285
|
+
# 层3:叠加 UI 层(顶部)
|
|
286
|
+
playcraft image overlay \
|
|
287
|
+
--base /tmp/composite.png \
|
|
288
|
+
--overlay assets/images/ui/hud_overlay.png \
|
|
289
|
+
--output assets/images/final_scene.png \
|
|
290
|
+
--gravity north
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### 工作流 C:轮廓描边效果
|
|
294
|
+
|
|
295
|
+
用蒙版制作发光轮廓描边:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# 1. 提取蒙版
|
|
299
|
+
playcraft image segment \
|
|
300
|
+
--input assets/images/character.png \
|
|
301
|
+
--text "character" \
|
|
302
|
+
--output-dir /tmp/seg/
|
|
303
|
+
|
|
304
|
+
# 2. 把蒙版 tint 为描边颜色(金色)
|
|
305
|
+
playcraft image tint \
|
|
306
|
+
--input /tmp/seg/00_mask.png \
|
|
307
|
+
--output /tmp/outline_colored.png \
|
|
308
|
+
--color "#FFD700"
|
|
309
|
+
|
|
310
|
+
# 3. 扩大描边层(pad 向外扩 4px)
|
|
311
|
+
playcraft image pad \
|
|
312
|
+
--input /tmp/outline_colored.png \
|
|
313
|
+
--output /tmp/outline_padded.png \
|
|
314
|
+
--all 4
|
|
315
|
+
|
|
316
|
+
# 4. 叠回:描边层在底,原图在上
|
|
317
|
+
playcraft image overlay \
|
|
318
|
+
--base /tmp/outline_padded.png \
|
|
319
|
+
--overlay /tmp/seg/00_rgba.png \
|
|
320
|
+
--output assets/images/character_outlined.png \
|
|
321
|
+
--gravity center
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 工作流 D:批量替换素材背景
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
# 对多张带绿幕背景的素材批量去背
|
|
328
|
+
for f in assets/images/raw/tile_*_greenscreen.png; do
|
|
329
|
+
name=$(basename "$f" _greenscreen.png)
|
|
330
|
+
playcraft image remove-background \
|
|
331
|
+
--input "$f" \
|
|
332
|
+
--output "assets/images/tiles/${name}.png" \
|
|
333
|
+
--method floodfill \
|
|
334
|
+
--tolerance 40
|
|
335
|
+
done
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## 5. 常见问题排查
|
|
341
|
+
|
|
342
|
+
### 边缘有绿色/白色残留(floodfill)
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# 原因:tolerance 太低,部分背景像素未被删除
|
|
346
|
+
# 修复:适当提高 tolerance(每次 +10 尝试)
|
|
347
|
+
playcraft image remove-background \
|
|
348
|
+
--input source.png --output output.png \
|
|
349
|
+
--tolerance 50 # 从 30 提升到 50
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### segment 分割到了错误的对象
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# 原因:文本提示不够精确
|
|
356
|
+
# 修复方案 1:更具体的描述
|
|
357
|
+
--text "the blue warrior character in the center" # 加颜色/位置描述
|
|
358
|
+
|
|
359
|
+
# 修复方案 2:改用框选模式,精确框出目标区域
|
|
360
|
+
--boxes '[[x1, y1, x2, y2]]' # 先用 playcraft image info 确认图片尺寸
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### rgba 输出有半透明噪点
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
# 原因:threshold 太低
|
|
367
|
+
# 修复:提高 threshold(从 0.3 到 0.5)
|
|
368
|
+
playcraft image segment \
|
|
369
|
+
--input source.png \
|
|
370
|
+
--text "target object" \
|
|
371
|
+
--threshold 0.5 \
|
|
372
|
+
--output-dir /tmp/seg/
|
|
373
|
+
```
|