移动/游戏
用 AI 图像 API 批量生成并处理 Godot 2D…
当需要为 Godot 4.x 生成 2D 游戏美术素材(角色精灵、动画帧、tileset、UI 图标)并完成导入配置时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
用 AI 图像 API 批量生成并处理 特定
解决思路
- 先定义美术风格:选择像素风/手绘/绘画风/矢量风,编写风格指南(颜色、修饰词、约束),并生成样本验证风格一致性,例如 {"style":"pixel-art","resolution":64,"palette":"limited-16-colors","modifiers":"16-bit, no anti-aliasing, clean pixels"}。
- 按需选择生成方式:单张素材用 generate-image.ts,多张相关素材用 batch-generate.ts,并根据结果迭代优化 prompt。
- 选择 API 提供商:DALL-E 3 适合高一致性高细节(--provider dalle --model dall-e-3,尺寸 1024x1024/1792x1024/1024x1792,quality standard/hd,style vivid/natural);Replicate 适合风格控制与批量(--provider replicate --model stability-ai/sdxl,支持 negative prompt、ControlNet、img2img);fal.ai 适合快速迭代与测试(--provider fal --model fal-ai/flux/schnell)。
- 按风格编写 prompt:像素风用 "pixel art [subject], 16-bit style, clean pixels, no anti-aliasing, limited color palette, retro game sprite, transparent background",避免 realistic/detailed/smooth/gradient;手绘风用 hand-drawn/illustration/ink lines/sketch/watercolor;绘画风用 digital painting/concept art/painterly/brush strokes;矢量扁平风用 flat design/vector/clean edges/solid colors/minimal。
- 用 generate-image.ts 生成单图:deno run --allow-env --allow-net --allow-write scripts/generate-image.ts --provider <dalle|replicate|fal> --prompt <text> --output <path>,可选 --model、--size WxH、--style、--negative、--quality、--json。
- 用 batch-generate.ts 批量生成:deno run --allow-env --allow-net --allow-read --allow-write scripts/batch-generate.ts --spec <batch-spec.json> --output <dir>,可选 --concurrency(默认 2)、--delay(默认 1000ms)、--resume、--json;batch spec 包含 provider、model、style、basePrompt 和 assets 数组(每项含 name 与 prompt)。
- 对原始输出做后处理:用 process-sprite.ts 执行 --remove-bg 去背景、--color-key <hex> 指定透明色、--resize WxH 缩放、--filter nearest|linear(像素风用 nearest)、--trim 去空白、--padding <n> 加内边距。
- 用 pack-spritesheet.ts 打包图集:--input <glob> --output <path> --columns <n> --padding <n> --power-of-two --metadata <path>,输出 JSON 元数据含 image、size 与每帧的 name/x/y/width/height。
- 用 generate-import-files.ts 生成 Godot .import 文件:--input <path> --preset pixel-art|hd-sprite|ui --frames <n> --columns <n> --fps <n>(默认 12)。
- 按素材类型配置 Godot 导入:像素风精灵用 Filter Mode: Nearest、Compression: Lossless、Mipmaps: Off、Fix Alpha Border: On;HD 精灵用 Filter Mode: Linear、Compression: VRAM Compressed、Mipmaps: On;UI 元素用 Filter Mode: Linear(像素 UI 用 Nearest)、Compression: Lossless、Mipmaps: Off。
- 完整流程示例(像素角色行走动画):写 batch spec 定义 idle 与 walk-1~4 帧 → batch-generate.ts 生成到 ./raw/ → 循环 process-sprite.ts 去背景并 resize 64x64 用 nearest → pack-spritesheet.ts 打包为 knight-sheet.png 并输出 metadata → generate-import-files.ts 以 pixel-art 预设、frames 5、columns 5、fps 8 生成导入文件。
- tileset 生成:用 generate-image.ts 以 "seamless pixel art grass tile, top-down view, 32x32, game tileset" 生成,再用 process-sprite.ts --resize 32x32 --filter nearest 处理。
- UI 图标生成:写 batch spec 用 fal 提供商、vector 风格、basePrompt "flat design game icon, clean edges, solid colors, transparent background",批量生成 sword/shield/potion/coin 等图标。
- 排查常见问题:API key 未设置时先 export OPENAI_API_KEY/REPLICATE_API_TOKEN/FAL_KEY;批量风格不一致时用更具体的风格修饰词、Replicate seed、多生成后挑选或用 img2img 参考图;去背景失败时在 prompt 加 transparent/white background、用 --color-key、写 "isolated on transparent background" 或手动清理;像素风出现抗锯齿时在 prompt 加 no anti-aliasing/clean pixels、先大尺寸生成再用 nearest 缩小、用 --filter nearest 或做调色板缩减;遇到 429 限流时增大 --delay、降低 --concurrency、等待重试或换提供商。
适用边界 · 注意事项
- 创建 3D 模型或纹理(仅支持 2D 素材)
- 手工像素画或插画(应使用美术软件)
- 复杂逐帧动画(应使用动画工具)或处理已有素材(直接用 Godot)