# modelgen

> 智能体用来把一句话、一张图片或一个模型文件变成 3D 资源，并进行贴图、绑定骨骼、制作动画、转换格式和减面的命令。

Source: https://air.build/cn/docs/cli/modelgen/

`modelgen` 制作 3D 模型。给它一段提示词、一张或多张图片、一个模型文件或之前的某个任务，它就会生成模型，依次运行你串在后面的处理步骤（贴图、绑定骨骼、动画、转换、减面……），等待完成并下载文件。每次生成或每个步骤都是 3D 服务上的一个_任务_；`modelgen` 不在本地保存任何状态，之前的任务可以通过 id、短 id 或名称再次找到。

## 在哪里运行

云端团队和 Mac 团队的智能体都能使用同一个命令。登录凭据和智能体归属信息都来自智能体的运行环境，无需任何设置。它依赖 `curl` 和 `jq`。参见[选择智能体的运行位置](https://air.build/cn/docs/get-started/where-agents-run/)。

## 用法概要

```text
modelgen <command> [options]
modelgen --help | --version
```

| Command | 作用 |
| --- | --- |
| `make <input...>` | 把任意输入变成完成的 3D 文件，可选场景预设和处理链。 |
| `generate <endpoint> <input...>` | 严格按要求进行一次生成。 |
| `model <step> [input]` | `refine`、`texture`、`stylize`、`convert`、`import`。 |
| `anim <step> [input]` | `check`（能否绑定骨骼？）、`rig`、`retarget`。 |
| `mesh <step> [input]` | `segment`、`complete`、`decimate`、`smartsegment`。 |
| `task get`, `task list`, `task watch` | 读取、列出和等待任务。 |
| `files upload <path>` | 上传图片或模型，并输出其文件令牌。 |
| `history` | 你最近的任务。 |
| `redo [target]` | 用新的种子重新运行之前的任务。 |
| `balance` | 本周期的 AI 用量与方案 AI 额度的对比。 |
| `docs` | 输出内置的参考文档。 |
| `doctor` | 检查运行环境、登录状态和连通性。 |

### 全局选项

| Option | 含义 |
| --- | --- |
| `--json` | 在 stdout 上输出一行 JSON。stdout 是管道时默认开启。 |
| `--quiet` | stderr 上不输出进度行。 |
| `--yes`, `--no-open` | 接受但忽略；不会有任何提示或打开操作。 |
| `-h`, `--help` | 命令的帮助，例如 `modelgen make --help`。 |

### 任务选项

`make`、`generate`、`model`、`anim`、`mesh` 和 `redo` 接受以下选项：

| Option | 取值 | 默认值 | 含义 |
| --- | --- | --- | --- |
| `-o`, `--out` | 文件夹 | `$TMPDIR/modelgen-out/<name>-<id8>/` | 文件的保存位置。文件会放在其中的 `modelgen-out/<name>-<id8>/` 里。 |
| `--no-wait` | — | 关闭 | 提交后立即返回任务 id 和 `"status":"queued"`。 |
| `--no-download` | — | 关闭 | 等待完成，但不下载。 |
| `--timeout` | 秒 | `1800` | 等待多久。超时后任务仍会继续运行。 |
| `--name` | 文本 | 取自提示词或文件名 | 名称，之后可用 `@name` 再次找到这个任务。 |
| `-p`, `--param` | `key=value` | — | 传给服务的任意额外字段，可重复。`true`、`false`、数字和 JSON 会转成相应类型。 |
| `--notify` | — | — | 接受但忽略。 |

## 输入

凡是接受输入的地方，输入都可以是：

| Input | 示例 | 含义 |
| --- | --- | --- |
| 文本 | `"a red fox, stylized"` | 提示词（用于 `make` 和文本类 endpoint）。 |
| 图片文件 | `fox.png` | `.png`、`.jpg`、`.jpeg`、`.webp`、`.bmp`、`.tiff`、`.tif`，最大 20 MB。会先上传。 |
| 模型文件 | `chair.glb` | `.glb`、`.fbx`、`.obj`、`.stl`，最大 150 MB。会先上传。`.gltf` 不能单独上传（它引用了其他文件）；请导出为 `.glb` 或传入网址。 |
| 网址 | `https://…/fox.png` | 原样传给服务。 |
| 文件令牌 | `file_…` | 来自 `modelgen files upload`。 |
| 任务 id | `task_…` 或 UUID | 之前的某个任务。 |
| 短 id | `3f9a2c` | 你某个任务 id 的前 6–35 个十六进制字符；必须只匹配一个任务。 |
| `@last` |  | 你最新的成功任务。 |
| `@last:any` |  | 你最新的任务，无论状态如何。 |
| `@2`, `@3`, … |  | 你最近 50 个任务中第 2、第 3……新的成功任务。 |
| `@name` | `@fox` | 具有该名称的任务。多个任务同名时，使用最新的成功任务（并给出警告）。 |

`model`、`anim` 或 `mesh` 没有拿到输入时，会从管道传入的 `modelgen` 命令读取任务，否则使用 `@last`。

## make

```text
modelgen make [options] <input...>
```

| Option | 取值 | 默认值 | 含义 |
| --- | --- | --- | --- |
| `--for` | 场景，见下文 | 无 | 预设模型、生成设置和处理链。 |
| `--then` | 处理链，例如 `"texture,rig,convert:fbx"` | 场景的处理链，或无 | 按顺序在结果上运行的步骤。会替换场景的处理链。 |
| `--model` | 生成模型 id（id 列在 `modelgen make --help` 中） | 服务的高保真模型 | 原样传入。 |
| `-n`, `--candidates` | 1–4 | `1` | 并行生成这么多候选结果，每个使用各自的种子。仅适用于文本或图片输入，且不能与 `--then` 同时使用。 |
| `--seed` | 数字 | 随机 | 几何种子（`model_seed`）。 |

`make` 如何处理输入：

| 你传入的 | 它运行 |
| --- | --- |
| 文本 | text-to-model |
| 一张图片或一个网址 | image-to-model |
| 2–4 张图片或网址 | multiview-to-model |
| 一个模型文件 | import |
| 任务引用 | 只运行 `--then` 处理链，此时它为必填 |

多视图时，文件名包含 `front`、`back`、`left` 或 `right` 的文件会用作对应视图；其他文件按正面优先的顺序填补剩余位置。正面视图为必需。

当提示词提到低多边形（例如 `low-poly`、`lowpoly`、`low poly`、`voxel`），或 `-p face_limit=` 不超过 20000 时，会自动选用服务的低多边形模型。`--model` 始终优先。

### 场景（`--for`）

| Scenario | 生成 | 之后的处理链 |
| --- | --- | --- |
| `game-mobile` | 低多边形模型，PBR 贴图（standard），15000 面 | `convert:format=FBX;texture_size=2048` |
| `game-pc` | PBR 贴图（detailed） | `convert:format=FBX` |
| `film` | PBR，四边形网格，精细的几何和贴图 | 无 |
| `print` | 无贴图 | `convert:format=STL;flatten_bottom=true` |
| `ar-web` | PBR 贴图 | `decimate:face_limit=20000,convert:format=USDZ` |
| `anim` | PBR 贴图 | `rig-check`、`rig`（GLB）、带 `preset:idle` 和 `preset:walk` 的 `retarget` |
| `toy` | 低多边形模型，PBR 贴图，20000 面 | 无 |

### 处理链（`--then`）

步骤之间用逗号分隔。步骤可以带一个单独的值 `step:value`，或带设置 `step:key=value;key=value`。`[...]` 或引号中的值会被视为整体，所以 `retarget:animations=["preset:idle","preset:walk"]` 是一个步骤。

| Step | 单独的值设置的是 | 接受 |
| --- | --- | --- |
| `refine` | — | 仅成功的 text-to-model 任务 |
| `texture` | `texture_quality` | 任何产出模型的任务 |
| `stylize` | `style` | 任何模型 |
| `convert` | `format` | 任何模型 |
| `rig-check`（也可写 `check`） | — | 任何模型；原样传递下去 |
| `rig` | `rig_type` | 任何模型 |
| `retarget`（也可写 `animate`） | `animation` | 仅 `rig` 任务 |
| `segment` | `model` | 任何模型 |
| `complete` | — | 仅 `segment` 任务 |
| `decimate`（也可写 `lowpoly`） | `face_limit` | 任何模型 |

`import` 和 `smartsegment` 只接受文件或网址，不能放进处理链。无效的处理链会在运行任何步骤之前被拒绝。只下载最后一步的文件。如果 `rig-check` 判定模型无法绑定骨骼，处理链就在此停止，结果中带有 `stopped_early`（源模型仍会下载）；如果它建议了 `rig_type`，下一个 `rig` 会使用它。

## generate

```text
modelgen generate <endpoint> [options] <input...>
```

| Endpoint | 输入 | 结果 |
| --- | --- | --- |
| `text-to-model` | 提示词 | 3D 模型 |
| `image-to-model` | 一张图片 | 3D 模型 |
| `multiview-to-model` | 2–4 张视图图片 | 3D 模型 |
| `text-to-image` | 提示词 | 图片 |
| `image-to-image` | 一张图片，加 `--prompt`（或 `-p template=…`） | 编辑后的图片 |
| `image-to-multiview` | 一张图片 | 四视图 |
| `edit-multiview` | 多视图任务 | 编辑后的视图 |
| `image-to-splat` | 一张图片 | 高斯泼溅（Gaussian splat） |

`--model <id>` 为 3D endpoint 选择模型（对图片类 endpoint 则原样传递）；`--prompt <text>` 是 `image-to-image` 的提示词。与 `make` 不同，`generate` 从不根据提示词的字眼选用低多边形模型。

### 生成检查

发送任何请求之前，`modelgen` 会检查并调整生成设置：

| Setting | 规则 |
| --- | --- |
| `prompt` | 最多 1024 个字符。 |
| `negative_prompt` | 最多 255 个字符。 |
| `pbr=true` | 会开启 `texture`（警告）。 |
| `generate_parts=true` | 会关闭 `texture`、`pbr` 和 `quad`（警告）；之后可用 `modelgen model texture` 贴图。 |
| 低多边形模型 | 移除 `quad`、`smart_low_poly`、`generate_parts` 和 `geometry_quality`（警告）；`face_limit` 必须在 50–20000 之间。 |
| `smart_low_poly=true` | `face_limit` 必须在 500–20000 之间（使用 `quad` 时为 500–10000）。 |
| `texture_quality` | `standard`、`detailed` 或 `extreme`。 |
| `quad=true` | 输出为 FBX（警告）。 |

## model、anim、mesh

```text
modelgen model|anim|mesh <step> [options] [input]
```

| Step | Options | 说明 |
| --- | --- | --- |
| `model refine` | — | 精修 text-to-model 草稿任务。 |
| `model texture` | `--texture-quality standard,detailed,extreme`；`--texture-alignment original_image,geometry` | 为模型重新贴图。 |
| `model stylize` | `--style lego,voxel,voronoi,minecraft`（必填）；`--block-size 32–128`（minecraft） |  |
| `model convert` | `--format GLTF,USDZ,FBX,OBJ,STL,3MF`（默认 `GLTF`）；`--texture-size <px>`；`--texture-format BMP,DPX,HDR,JPEG,OPEN_EXR,PNG,TARGA,TIFF,WEBP`；`--face-limit <n>`；`--quad`；`--flatten-bottom`；`--fbx-preset <preset>`（`blender`、`3dsmax`，或 `modelgen model convert --help` 中列出的其他预设）；`--export-orientation +x,-x,+y,-y`；`--scale-factor <n>`；`--auto-size`；`--pivot-to-center-bottom`；`--export-vertex-colors` | `--quad` 不能导出 GLTF。`--fbx-preset` 只适用于 FBX，`--export-vertex-colors` 只适用于 OBJ 和 GLTF；否则会被移除并给出警告。 |
| `model import` | — | 导入 GLB、FBX、OBJ 或 STL 文件或网址（最大 150 MB）。 |
| `anim check` | — | 判断模型能否绑定骨骼（`riggable`），并建议一个 `rig_type`。 |
| `anim rig` | `--rig-type biped,quadruped,hexapod,octopod,avian,serpentine,aquatic`；`--spec <convention>`（规范列在 `modelgen anim --help` 中）；`--out-format glb,fbx` | 绑定骨骼。不指定 `-p model=` 时，会根据体型选择绑定模型。 |
| `anim retarget` | `--animation preset:walk preset:run …`（1–5 个）；`--out-format glb,fbx`；`--animate-in-place` | 仅用于已绑定骨骼的任务。 |
| `mesh segment` | `--model <id>` | 把模型拆分为多个部件。 |
| `mesh complete` | `--completion-mode ai_completion,quick_cap` | 仅用于 `segment` 任务。 |
| `mesh decimate` | `--face-limit <n>`（500–20000，使用 `--quad` 时为 500–10000）；`--quad`；`--no-bake`；`-p model=v2.0` 或 `v1.0` | 高模转低模，除非指定 `--no-bake`，否则会烘焙贴图。使用 `v1.0` 时 `--face-limit` 为必填（500–2000000，使用 `--quad` 时为 500–150000）。 |
| `mesh smartsegment` | `--seg-type image,model`（默认 `model`）；`--granularity coarse,medium,fine`；`--hint <text>` | 只接受文件或网址。 |

步骤会拒绝它无法处理的任务，例如 `retarget only accepts animate_rig tasks (input is a texture_model task)`。源任务必须已成功。

支持管道：在 JSON 模式下（管道输出时默认如此），步骤会从上一条命令的输出中读取任务 id，所以 `modelgen anim check fox.glb | modelgen anim rig` 会为刚检查过的模型绑定骨骼。如果上一条命令失败，它的错误行会让下一条命令停止：`the previous command in the pipe failed (…); nothing was run.`

## 文件和输出

任务成功后，文件会下载到 `<out>/modelgen-out/<name>-<first 8 of the id>/`（`<out>` 为 `-o`，否则为 `$TMPDIR` 或 `/tmp`）。除非 `-o` 指向项目文件夹，否则不会往项目里写任何东西。文件夹中包括：

- 任务的每个输出各一个文件，以输出命名，例如 `pbr_model.glb`、`rendered_image.webp`；
- `preview.<ext>`，有渲染图时的一份副本；
- `task.json`，包含任务 id、类型、状态、输入、输出字段、消耗的点数、创建时间和文件列表。

在终端中结果如下：

```text
task <task_id> success
vendor credits consumed: <n>
artifacts: /abs/path/modelgen-out/fox-1a2b3c4d
model file: /abs/path/modelgen-out/fox-1a2b3c4d/pbr_model.glb
preview: /abs/path/modelgen-out/fox-1a2b3c4d/preview.webp
```

JSON 格式：`task_id`、`type`、`status`、`credits_consumed`、`output_dir`、`files`、`model_file`、`preview`，处理链还有 `chain`（每一步的结果）、`source_task_id` 和 `stopped_early`。使用 `-n` 时为 `{"candidates":[…],"chain":[]}`。进度（`<type> · <status> <n>% · <id8>`）输出到 stderr。

下载地址几分钟内就会过期。下载失败时，运行 `modelgen task get <id> --download` 获取新地址。

## task、files、history、redo

```text
modelgen task get <task> [--step] [--download] [-o <dir>]
modelgen task list [tasks...] [--limit <n>]
modelgen task watch <task> [--download] [-o <dir>] [--timeout <seconds>]
modelgen files upload <path>
modelgen history [--limit <n>]
modelgen redo [target] [--seed <n>] [task options]
```

| Command | 说明 |
| --- | --- |
| `task get` | 单个任务的详情：id、类型、状态、进度、点数和输出地址。`--step` 附加流水线步骤详情；`--download` 在任务成功时保存文件。 |
| `task list` | 一次查看多个任务；不带 id 时列出你最新的任务（`--limit`，默认 10）。不属于你的 id 列在 `missed` 下。 |
| `task watch` | 等待任务结束（默认 1800 秒）。在 JSON 模式下，每次变化输出一行 `{"event":"progress","task_id":…,"status":…,"progress":…}`。 |
| `files upload` | 输出可作为输入使用的 `file_token`。 |
| `history` | 你最近的任务（`--limit` 1–50，默认 20）：日期、名称、类型、状态和 id。 |
| `redo` | 用新的种子（或 `--seed`）重新发送之前某个任务的请求。默认为 `@last`。 |

## balance、docs、doctor

`modelgen balance` 显示本周期的 AI 用量与方案 AI 额度的对比：

```text
AI usage: <percent>% of this period's plan allowance (<n> credits beyond the plan)
credits left: <n> (<n> credits owed)
```

方案不含 AI 额度时，第一行为 `AI usage: the plan includes no AI allowance, paid with credits`。额度和积分都用完时，会追加 `! AI allowance and credits exhausted — ask your user to add credits or upgrade the plan`。JSON 格式：`used_usd`、`included_usd`、`overage_usd`、`credit_balance_usd`、`used_percent`、`overage_credits`、`credits_left`、`credits_owed`、`has_capacity`、`period_end`。方案详见 [air.build/pricing](https://air.build/pricing/)；用量也可在设置 › [方案与用量](https://air.build/cn/docs/settings/plan-usage/)中查看。

`modelgen docs` 输出内置指南；`--topic` 输出某一篇内置文档：`commands/<cmd>`、`examples/<scenario>`、`models` 或 `common-errors`。

`modelgen doctor` 检查 `curl`、`jq`、后端地址、团队登录、智能体身份、服务是否有响应、内置文档和终端，每项一行，标记为 `✓`、`✗` 或 `!`。关键检查失败时以 `1` 退出。

## 退出码和错误

错误以 `Error: <message>` 输出到 stderr。在 JSON 模式下，或 stdout 是管道时，错误还会以 `{"error":true,"exit_code":<n>,"reason":"…"}` 输出到 stdout。

| Exit code | 含义 | 处理方法 |
| --- | --- | --- |
| `0` | 成功。 | — |
| `1` | 意外错误，或 `doctor` 检查未通过。 | 运行 `modelgen doctor`。 |
| `2` | 用法或参数无效；没有发送任何请求。 | 阅读消息并修正命令。 |
| `3` | 登录失败，或不在 AirBuild 智能体的运行环境中。 | 由智能体来运行。 |
| `4` | AI 额度和积分已用完。 | 请团队拥有者充值积分或更换方案。 |
| `5` | 被内容政策拒绝。 | 修改提示词或图片。 |
| `6` | 任务失败、被取消或已过期，或等待超时。 | 阅读消息。超时后任务仍在运行：`modelgen task get <id>`。 |
| `7` | 网络或服务错误，或下载失败。 | 重试；下载问题请用 `modelgen task get <id> --download`。 |
| `8` | 找不到。 | 检查 id 或名称。 |
| `9` | 服务繁忙。 | 稍等后重试。 |

| Message | Exit |
| --- | --- |
| `no input given.` | 2 |
| `file not found: "PATH" (if you meant a text prompt, quote a sentence instead).` | 2 |
| `"PATH" exists but has an unsupported extension ".EXT" (…).` | 2 |
| `NAME is N MB, over the 20 MB image limit.` / `… over the 150 MB model limit.` | 2 |
| `a task reference needs processing steps: add --then (e.g. modelgen make @last --then texture,convert:fbx).` | 2 |
| `unknown step "X" (valid: …).` / `unknown scenario "X" (valid: …).` | 2 |
| `step "X" only accepts … tasks, but the previous step produces "…".` | 2 |
| `at most 4 candidates per run (-n 4).` | 2 |
| `multiview needs 2–4 images (got N).` / `multiview requires a front view — name one file with "front" or pass it first.` | 2 |
| `no successful task yet.` / `no task named "@X"; "modelgen history" lists your tasks.` | 2 |
| `"X" matches N of your tasks; give more characters or the full id.` | 2 |
| `task ID is running; processing steps need a successful upstream task (wait with "modelgen task watch ID").` | 2 |
| `task ID failed: <reason>`（还有 `cancelled`、`banned`、`expired`） | 6 |
| `task ID is still running after Ns (it keeps running server-side; check later with "modelgen task get ID")` | 6 |
| `artifact download failed (…)` | 7 |
| `could not reach the Airbuild creative service: …` | 7 |

短暂的网络故障和繁忙应答会自动重试几次，之后 `modelgen` 才会放弃。

## 示例

```bash
# A prompt to a textured model, downloaded under $TMPDIR
modelgen make "a stylized red fox, game asset" --name fox

# A mobile game asset from a concept image, in the project folder
modelgen make concept.png --for game-mobile -o Assets/Models

# Rig and animate an earlier task, then export FBX
modelgen make @fox --then "rig-check,rig,retarget:animations=[\"preset:idle\",\"preset:walk\"],convert:fbx"

# Simplify an earlier task and convert the result for AR
modelgen mesh decimate @fox --face-limit 8000 --no-download --json | modelgen model convert --format USDZ
```
