mcpField
G
godot-asset-generator

godot-asset-generator

github.com/jwynia创意与媒体1791.0k 次安装35 周前更新
代码仓库

关于 godot-asset-generator

Godot Asset Generator 是使用图像生成 API 制作 2D 游戏素材并将其整理为 Godot 4.x 可用格式的技能。它涵盖批量生成、图像处理、精灵表打包和导入文件生成。

主要功能

  1. 01通过支持的 API 生成图像
  2. 02批量生成相关素材
  3. 03处理并调整精灵图尺寸
  4. 04将图像打包为精灵表
  5. 05生成 Godot 导入文件

适用场景

  1. 01制作 Godot 游戏精灵图
  2. 02批量生成动画帧
  3. 03生成图块集和 UI 图标
  4. 04整理生成图像以供 Godot 导入

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/jwynia/agent-skills --skill godot-asset-generator

安装后在 Claude Code 中输入/godot-asset-generator确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/prompts/
pixel-art-templates.json
assets/style-guides/
style-guide-template.json
references/api-guides/
openai-dalle.md
references/godot-integration/
import-settings.md
references/prompting/
pixel-art.md
scripts/
batch-generate.ts
generate-image.ts
generate-import-files.ts
pack-spritesheet.ts
process-sprite.ts

详细介绍

Godot 资源生成器

使用 AI 图像生成 API 生成游戏资源,并为在 Godot 4.x 中使用做好准备。此技能涵盖从概念设计到可用于 Godot 的精灵图的完整美术流程。

何时使用此技能

在以下情况下使用此技能:

  • 使用 AI 生成游戏精灵图、角色或物体
  • 为平台游戏或俯视视角游戏创建图块集
  • 生成 UI 元素、图标或菜单资源
  • 批量生成动画帧
  • 准备 AI 生成的资源,以便导入 Godot
  • 按照风格指南创建风格统一的资源集

以下情况不要使用此技能:

  • 创建 3D 模型或纹理(仅限 2D 资源)
  • 手工绘制像素画或插画(请使用美术软件)
  • 制作复杂的逐帧动画(请使用动画工具)
  • 使用已有资源(请直接使用 Godot)

先决条件

必需:

  • 已安装 Deno 运行时
  • 至少一个 API 密钥:
    • 用于 DALL-E 3 的 OPENAI_API_KEY
    • 用于 Replicate(SDXL、Flux)的 REPLICATE_API_TOKEN
    • 用于 fal.ai 的 FAL_KEY

可选:

  • 用于高级图像处理的 ImageMagick
  • 用于生成导入文件的 Godot 4.x 项目

快速开始

生成单张图像
deno run --allow-env --allow-net --allow-write scripts/generate-image.ts \
  --provider dalle \
  --prompt "pixel art knight character, front view, 16-bit style, transparent background" \
  --output ./assets/knight.png
批量生成动画帧
deno run --allow-env --allow-net --allow-read --allow-write scripts/batch-generate.ts \
  --spec ./batch-spec.json \
  --output ./generated/
创建精灵图集
deno run --allow-read --allow-write scripts/pack-spritesheet.ts \
  --input ./generated/*.png \
  --output ./sprites/player-sheet.png \
  --columns 4

核心工作流

阶段 1:定义风格

生成资源前先定义美术风格:

  1. 选择美术风格:像素画、手绘、绘画风格或矢量风格
  2. 创建风格指南:记录颜色、修饰词和限制条件
  3. 测试提示词:生成示例以验证风格一致性
{
  "style": "pixel-art",
  "resolution": 64,
  "palette": "limited-16-colors",
  "modifiers": "16-bit, no anti-aliasing, clean pixels"
}
阶段 2:生成资源

使用合适的服务商生成资源:

  1. 单个资源:使用 generate-image.ts 生成单张图像
  2. 批量资源:使用 batch-generate.ts 批量生成多个相关资源
  3. 迭代优化:根据结果调整提示词
阶段 3:后期处理

将 AI 原始输出整理为可用于游戏的资源:

  1. 移除背景:从背景中提取精灵图
  2. 颜色校正:按需统一调色板
  3. 调整大小:缩放至精确的游戏分辨率
  4. 裁剪/补边:移除空白区域并为精灵图添加边距
deno run --allow-read --allow-write scripts/process-sprite.ts \
  --input ./raw/knight.png \
  --output ./processed/knight.png \
  --remove-bg \
  --resize 64x64 \
  --filter nearest
阶段 4:集成到 Godot

准备资源,以便导入 Godot:

  1. 打包精灵图集:将帧合并为经过优化的图集
  2. 生成导入文件:创建设置优化的 .import 文件
  3. 配置动画:设置 SpriteFrames 资源

API 服务商选择

服务商最适合质量成本速度
DALL-E 3风格统一、细节丰富卓越$$$中等
Replicate风格控制、多样化生成很好$$中等
fal.ai快速迭代、测试良好$快
DALL-E 3(OpenAI)

最适合生成高质量且风格统一的结果,提示词遵循能力出色。

--provider dalle --model dall-e-3
  • 尺寸:1024x1024、1792x1024、1024x1792
  • 质量:standard、hd
  • 风格:vivid、natural
Replicate(SDXL/Flux)

最适合控制风格并以较低成本批量生成。

--provider replicate --model stability-ai/sdxl
  • 模型选项更多(SDXL、Flux、专用模型)
  • 支持负面提示词
  • 支持 ControlNet 和 img2img
fal.ai

最适合快速迭代和测试提示词。

--provider fal --model fal-ai/flux/schnell
  • 推理速度最快
  • 适合制作原型
  • 单张图像成本较低

按美术风格编写提示词

像素画
"pixel art [subject], 16-bit style, clean pixels, no anti-aliasing,
limited color palette, retro game sprite, transparent background"

关键修饰词:16-bit、8-bit、pixel art、retro、clean pixels、no anti-aliasing

避免使用:realistic、detailed、smooth、gradient

手绘/插画
"hand-drawn illustration of [subject], ink lines, watercolor texture,
sketch style, game art, white background"

关键修饰词:hand-drawn、illustration、ink lines、sketch、watercolor

绘画风格/概念艺术
"digital painting of [subject], concept art style, painterly brush strokes,
dramatic lighting, game asset"

关键修饰词:digital painting、concept art、painterly、brush strokes

矢量/扁平设计
"flat design [subject], vector art style, clean edges, solid colors,
minimal shading, game icon, transparent background"

关键修饰词:flat design、vector、clean edges、solid colors、minimal

脚本参考

generate-image.ts

使用任意受支持的服务商生成单张图像。

deno run --allow-env --allow-net --allow-write scripts/generate-image.ts [options]

Options:
  --provider <name>   Provider: dalle, replicate, fal (required)
  --prompt <text>     Generation prompt (required)
  --output <path>     Output file path (required)
  --model <name>      Specific model (optional, provider-dependent)
  --size <WxH>        Image size, e.g., 1024x1024 (default: 1024x1024)
  --style <name>      Style preset: pixel-art, hand-drawn, painterly, vector
  --negative <text>   Negative prompt (Replicate/fal only)
  --quality <level>   Quality: standard, hd (DALL-E only)
  --json              Output metadata as JSON
  -h, --help          Show help
batch-generate.ts

根据规格文件生成多张图像。

deno run --allow-env --allow-net --allow-read --allow-write scripts/batch-generate.ts [options]

Options:
  --spec <path>       Path to batch specification JSON (required)
  --output <dir>      Output directory (required)
  --concurrency <n>   Parallel requests (default: 2)
  --delay <ms>        Delay between requests (default: 1000)
  --resume            Resume from last successful
  --json              Output results as JSON
  -h, --help          Show help

批量规格格式:

{
  "provider": "replicate",
  "model": "stability-ai/sdxl",
  "style": "pixel-art",
  "basePrompt": "16-bit pixel art, game sprite, transparent background",
  "assets": [
    { "name": "player-idle", "prompt": "knight standing idle, front view" },
    { "name": "player-walk-1", "prompt": "knight walking, frame 1 of 4" },
    { "name": "player-walk-2", "prompt": "knight walking, frame 2 of 4" }
  ]
}
process-sprite.ts

对生成的图像进行后处理,以便用于游戏。

deno run --allow-read --allow-write scripts/process-sprite.ts [options]

Options:
  --input <path>      Input image path (required)
  --output <path>     Output image path (required)
  --remove-bg         Remove background (make transparent)
  --resize <WxH>      Resize to dimensions
  --filter <type>     Resize filter: nearest, linear (default: nearest)
  --trim              Trim transparent whitespace
  --padding <n>       Add padding pixels
  --color-key <hex>   Color to make transparent (e.g., ff00ff)
  -h, --help          Show help
pack-spritesheet.ts

将多个精灵打包到精灵表中。

deno run --allow-read --allow-write scripts/pack-spritesheet.ts [options]

Options:
  --input <pattern>   Input files (glob pattern, required)
  --output <path>     Output sprite sheet path (required)
  --columns <n>       Number of columns (default: auto)
  --padding <n>       Padding between sprites (default: 0)
  --power-of-two      Force power-of-two dimensions
  --metadata <path>   Output JSON metadata path
  -h, --help          Show help

输出元数据:

{
  "image": "player-sheet.png",
  "size": { "width": 256, "height": 128 },
  "frames": [
    { "name": "idle", "x": 0, "y": 0, "width": 64, "height": 64 },
    { "name": "walk-1", "x": 64, "y": 0, "width": 64, "height": 64 }
  ]
}
generate-import-files.ts

生成设置最优的 Godot .import 文件。

deno run --allow-read --allow-write scripts/generate-import-files.ts [options]

Options:
  --input <path>      Input image or directory (required)
  --preset <name>     Preset: pixel-art, hd-sprite, ui (default: pixel-art)
  --frames <n>        Animation frame count (for sprite sheets)
  --columns <n>       Sprite sheet columns
  --fps <n>           Animation FPS (default: 12)
  -h, --help          Show help

Godot 导入设置

像素艺术精灵
Filter Mode: Nearest
Compression: Lossless
Mipmaps: Off
Fix Alpha Border: On
高清精灵
Filter Mode: Linear
Compression: VRAM Compressed
Mipmaps: On
UI 元素
Filter Mode: Linear (or Nearest for pixel UI)
Compression: Lossless
Mipmaps: Off

示例

示例 1:带行走动画的像素艺术角色
# 1. Create batch spec
cat > character-batch.json << 'EOF'
{
  "provider": "replicate",
  "style": "pixel-art",
  "basePrompt": "16-bit pixel art knight, game sprite, transparent background",
  "assets": [
    { "name": "knight-idle", "prompt": "standing idle, front view" },
    { "name": "knight-walk-1", "prompt": "walking, left foot forward" },
    { "name": "knight-walk-2", "prompt": "walking, standing straight" },
    { "name": "knight-walk-3", "prompt": "walking, right foot forward" },
    { "name": "knight-walk-4", "prompt": "walking, standing straight" }
  ]
}
EOF

# 2. Generate images
deno run --allow-env --allow-net --allow-read --allow-write \
  scripts/batch-generate.ts --spec character-batch.json --output ./raw/

# 3. Process sprites
for f in ./raw/knight-*.png; do
  deno run --allow-read --allow-write scripts/process-sprite.ts \
    --input "$f" --output "./processed/$(basename $f)" \
    --remove-bg --resize 64x64 --filter nearest
done

# 4. Pack sprite sheet
deno run --allow-read --allow-write scripts/pack-spritesheet.ts \
  --input "./processed/knight-*.png" \
  --output ./sprites/knight-sheet.png \
  --columns 5 --metadata ./sprites/knight-sheet.json

# 5. Generate Godot import
deno run --allow-read --allow-write scripts/generate-import-files.ts \
  --input ./sprites/knight-sheet.png --preset pixel-art \
  --frames 5 --columns 5 --fps 8
示例 2:图块集生成
# Generate individual tiles
deno run --allow-env --allow-net --allow-write scripts/generate-image.ts \
  --provider dalle \
  --prompt "seamless pixel art grass tile, top-down view, 32x32, game tileset" \
  --output ./tiles/grass.png \
  --style pixel-art

# Process and resize
deno run --allow-read --allow-write scripts/process-sprite.ts \
  --input ./tiles/grass.png --output ./tiles/grass-processed.png \
  --resize 32x32 --filter nearest
示例 3:UI 图标
# Batch generate UI icons
cat > ui-batch.json << 'EOF'
{
  "provider": "fal",
  "style": "vector",
  "basePrompt": "flat design game icon, clean edges, solid colors, transparent background",
  "assets": [
    { "name": "icon-sword", "prompt": "sword weapon icon" },
    { "name": "icon-shield", "prompt": "shield defense icon" },
    { "name": "icon-potion", "prompt": "health potion bottle icon" },
    { "name": "icon-coin", "prompt": "gold coin currency icon" }
  ]
}
EOF

deno run --allow-env --allow-net --allow-read --allow-write \
  scripts/batch-generate.ts --spec ui-batch.json --output ./icons/

常见问题

找不到 API 密钥
Error: OPENAI_API_KEY environment variable is not set

解决方案:运行前导出 API 密钥:

export OPENAI_API_KEY="sk-..."
批次中的风格不一致

问题:即使提示词相同,生成的图像风格也各不相同。

解决方案:

  • 使用更具体的风格修饰词
  • 使用带有 seed 参数的 Replicate,以确保可复现性
  • 生成更多图像并挑选最匹配的图像
  • 使用带参考图像的 img2img(Replicate)
背景移除失败

问题:--remove-bg 无法干净地分离精灵。

解决方案:

  • 在提示词中加入“透明背景”或“白色背景”
  • 使用 --color-key 并指定一种背景颜色
  • 使用更明确的提示词:“孤立在透明背景上”
  • 对于复杂图像,可能需要手动清理
像素艺术出现抗锯齿

问题:生成的像素艺术边缘经过了平滑处理。

解决方案:

  • 在提示词中加入“无抗锯齿”“清晰像素”
  • 以更大的尺寸生成,然后使用最近邻算法缩小
  • 在 process-sprite.ts 中使用 --filter nearest
  • 进行后处理以减少调色板颜色数量
速率限制

问题:API 返回 429 速率限制错误。

解决方案:

  • 增大 batch-generate.ts 中的 --delay
  • 减少 --concurrency
  • 等待后重试
  • 处理大量批次时使用其他提供商

其他资源

提示词指南
  • references/prompting/pixel-art.md - 像素艺术技巧详解
  • references/prompting/hand-drawn.md - 插画风格指南
  • references/prompting/consistent-characters.md - 角色一致性
API 指南
  • references/api-guides/openai-dalle.md - DALL-E 3 API 参考
  • references/api-guides/replicate-sdxl.md - Replicate 集成
  • references/api-guides/fal-ai.md - fal.ai 指南
Godot 集成
  • references/godot-integration/import-settings.md - 导入配置
  • references/godot-integration/animation-setup.md - AnimatedSprite2D 设置
模板
  • assets/prompts/pixel-art-templates.json - 像素艺术提示词模板
  • assets/prompts/character-templates.json - 角色提示词
  • assets/style-guides/style-guide-template.json - 风格指南架构

限制

  • 仅支持基于 API 的方式:需要互联网连接和 API 密钥(不支持本地模型)
  • 风格一致性:即使提示词相同,AI 也可能生成不同的变体
  • 分辨率限制:每个提供商都有尺寸限制
  • 仅支持 2D 资源:不适用于 3D 模型、纹理或复杂动画
  • 背景移除:复杂图像可能需要手动清理
  • 成本:API 调用会产生费用,尤其是处理大量批次时

评论

支持 Markdown