Text to 3D API
通过一次调用,将文本 prompt 转换为 3D 模型。
Text to 3D 已经运行在 /openapi/v2/text-to-3d 上,因此你的创建请求可以继续正常工作。有两条新规则:同时发送 texture_prompt 和 texture_image_url 会返回 400;而省略 mode 的带纹理的一次性调用请求,则需要提供 texture_model。请像处理其他任务一样,通过 Tasks 读取其任务信息,并从 output 中读取结果。设置为 v2 的 webhook 会以该格式投递 Text to 3D 任务。详见 Text to 3D 的变更内容。
创建 Text to 3D 任务
curl https://api.meshy.ai/openapi/v2/text-to-3d \
-X POST \
-H "Authorization: Bearer ${MESHY_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"prompt": "a stylized adult male explorer with short brown hair and a stubble beard, wearing an orange jacket, beige cargo pants and brown boots, full body, standing",
"ai_model": "meshy-7.1",
"should_texture": true,
"texture_model": "meshy-7"
}'参数
- Name
- should_texture
- Type
- boolean
- 默认值 true
- Description
是否为模型生成 texture。
true返回带 texture 的模型,false则只返回 mesh。设为false时,Meshy 会忽略texture_model以及其他 texture 相关参数。如果想在生成 texture 之前先检查 mesh,可以发送false,然后用 Retexture 对已完成的任务进行贴图,将其id用作input_task_id。如果同时发送了mode,Meshy 会忽略此设置。试用并预览
- Name
- mode
- Type
- string
- ⚠ 已弃用
- Description
两步式任务中的步骤,供已经使用 preview 和 refine 的集成方使用。请改为发送
should_texture。可选值:
preview:生成未带 texture 的 meshrefine:为 preview 任务的 mesh 添加 texture
- Name
- prompt
- Type
- string
- 必选
- Description
一次性(one-call)任务和 preview 任务为必填项。描述要生成的模型的文本,最多 800 个字符。超出长度将返回
400。refine 会改用其对应 preview 的 prompt。
- Name
- preview_task_id
- Type
- string
- 必选
- ⚠ 已弃用
- Description
请改为发送
should_texture: true,或使用 Retexture 为现有任务添加 texture。refine 任务为必填项。待贴图的 preview 任务的 ID。该任务必须是你自己的 preview 任务,且状态为SUCCEEDED。
- Name
- ai_model
- Type
- string
- 默认值 latest
- Description
生成 3D 模型所用的模型。
试用并预览标准模型:
latest:Meshy 7.1meshy-7.1meshy-6meshy-6-litemeshy-standard-latest:与latest相同
Smart Topology 模型会以
target_polycount设置的面数构建出干净的三角形 mesh:meshy-t2.5:为游戏资产提供更锐利的细节meshy-t2meshy-smart-topology-latest:Meshy T2.5,最新的 Smart Topology 模型。新版本发布时结果可能发生变化。若需要结果保持不变,请发送meshy-t2.5。
关于哪种模型适合你的项目(例如游戏角色或 3D 打印件),请参阅模型。
在 refine 中,
ai_model选择的是 texture 模型,因为 mesh 来自 preview。留空则使用与 preview 相匹配的模型进行贴图。关于 refine 可接受的取值,请参阅 Legacy preview 和 refine。
- Name
- model_type
- Type
- string
- ⚠ 已弃用
- Description
请留空。由
ai_model选择模型。
- Name
- geometry_resolution
- Type
- string
- 默认值 standard
- Description
生成多少 geometry 细节。仅适用于一次性(one-call)任务和 preview 任务。带此参数的 refine 会返回
400。试用并预览可选值:
standard2k:增加 Ultra pass4k:增加 Ultra pass,然后再增加超分辨率 pass
2k和4k需要meshy-7.1或latest。使用其他模型时将返回400。
- Name
- should_remesh
- Type
- boolean
- 默认值 true (meshy-6-lite), false (other models)
- Description
生成后是否对模型进行 remesh。
false保持生成时的 mesh 不变。仅适用于一次性(one-call)任务和 preview 任务。Smart Topology 模型会忽略此设置。试用并预览
should_remesh = true- Name
- topology
- Type
- string
- 默认值 triangle
- Description
重新生成 mesh 后模型的面类型,
triangle或quad。Smart Topology 模型只生成三角形,因此在 Smart Topology 模型下使用quad会返回400。使用texture_model: "meshy-n1"时,quad会返回400。试用并预览在
ai_model为meshy-7.1且should_remesh为true时生效。选择一个值会同时设置它。
- Name
- decimation_mode
- Type
- integer
- Description
按级别设置的自适应面数。设置此项时,Meshy 会忽略
target_polycount。可选值:
1:ultra2:high3:medium4:low
- Name
- target_polycount
- Type
- integer
- Description
目标面数。仅适用于一次性(one-call)任务和 preview 任务。取值范围和默认值取决于 mesh 的构建方式:
Mesh 范围 默认值 Remeshed 100到30000030000meshy-t2.5或meshy-smart-topology-latest100到3000015000meshy-t2100到150004000超出范围的值将返回
400。对于 low-poly 游戏资产,建议使用 Smart Topology 模型,而不是对标准模型做 remesh。请参阅模型。
- Name
- pose_mode
- Type
- string
- Description
角色模型的姿势,
a-pose或t-pose。留空表示不设置姿势。仅适用于一次性(one-call)任务和 preview 任务。试用并预览
should_texture = true- Name
- texture_model
- Type
- string
- 必选
- Description
除非
should_texture为false,否则为必填项。为一次性(one-call)任务生成 texture 的模型。每个ai_model都接受以下各个值。可选值:
meshy-7:Meshy 7,带 PBR 贴图、文本 prompt,texture 最高可达 8Kmeshy-n1:Meshy N1,仅根据参考图像生成 2K 基础色 texturemeshy-6-lite:Meshy 6 Lite,2K texture
使用
meshy-6或meshy-6-lite时,meshy-n1需要texture_image_url,因为这些模型不会根据 prompt 生成参考图像。未提供texture_model的带贴图请求会返回400,texture 模型不支持的选项也会返回400。设置了mode时,Meshy 会忽略texture_model。请参阅 Texture 模型。
- Name
- texture_prompt
- Type
- string
- Description
用于指导 texture 生成的文本,最多 800 个字符。超出长度将返回
400。请只发送texture_prompt或texture_image_url其中之一,不要同时发送两者。同时发送会返回400。使用meshy-n1时发送此参数会返回400。
- Name
- texture_image_url
- Type
- string
- Description
用于指导 texture 生成的图像,可以是公开 URL 或 Data URI(
data:image/png;base64,...)。使用meshy-n1时,Meshy 会以该图像作为正视图来生成 texture。当一次性(one-call)任务使用texture_model: "meshy-n1",且ai_model为meshy-6或meshy-6-lite时,此参数为必填项。图像必须为 JPG、JPEG、PNG 或 WebP 文件,大小不超过 20 MB,每边至少 32 像素,像素总数(宽 × 高)不超过 178,956,970。
- Name
- enable_pbr
- Type
- boolean
- 默认值 false
- Description
是否同时生成金属度、粗糙度和法线贴图。使用
meshy-n1时,设为true会返回400。试用并预览
- Name
- texture_resolution
- Type
- string
- 默认值 2k
- Description
基础色 texture 的尺寸。带此参数的 preview 会返回
400。试用并预览可选值:
2k4k8k
无论是在一次性(one-call)任务中由
texture_model选定,还是在 refine 中由ai_model选定,使用meshy-n1或meshy-6-lite时4k和8k都会返回400。
- Name
- remove_lighting
- Type
- boolean
- 默认值 true
- Description
是否从基础色 texture 中移除高光和阴影。只有
meshy-6使用此设置。Meshy 7 和 Smart Topology 模型会忽略它。使用meshy-6-lite时发送此参数会返回400。
- Name
- target_formats
- Type
- string[]
- 默认值 ["glb", "obj", "fbx", "stl", "usdz"]
- Description
要生成的文件格式。
可选值:
glbobjfbxstlusdz3mf
Text to 3D 不会应用其他 v2 endpoint 对打印文件所用的 150 mm 上限。STL 文件会保留模型原始尺寸,而 Meshy 会将
3mf文件缩放至 75 mm 高。
- Name
- alpha_thumbnail
- Type
- boolean
- 默认值 false
- Description
是否同时渲染一张背景透明的预览图,结果会返回在
output.alpha_thumbnail_url中。
- Name
- thumbnail_resolution
- Type
- integer
- 默认值 512
- Description
任务预览图的宽高(像素):
512或1024。该设置适用于output.thumbnail_url以及你请求的任何可选预览图。其他任何值都会返回400。
- Name
- moderation
- Type
- boolean
- 默认值 false
- Description
是否在生成前对以下输入内容进行有害内容筛查:
prompttexture_prompttexture_image_url
- Name
- auto_size
- Type
- boolean
- 默认值 false
- Description
是否估算物体的真实世界高度,并据此缩放模型。
auto_size = true- Name
- origin_at
- Type
- string
- 默认值 bottom
- Description
模型原点的放置位置,
bottom或center。
返回值
返回 202 Accepted,包含任务对象。任务起始状态为 PENDING,input 中包含你的请求内容,output 为 null。响应中还包含 result,其值与 id 相同,供 v2 之前编写的客户端使用。
以下响应头可帮助你跟踪任务:
失败模式
- Name
400 - Bad Request- Description
请求无法运行。例如:
- 缺少
prompt - 带 texture 的一次性(one-call)任务未发送
texture_model - 一次性(one-call)任务发送了
texture_model: "meshy-n1",并使用meshy-6或meshy-6-lite,但未提供texture_image_url - texture 模型不支持请求中的某个选项,例如对
meshy-n1使用enable_pbr: true preview_task_id与你任何状态为SUCCEEDED的 preview 任务都不匹配。错误消息会说明该任务不存在、尚未完成,还是不是 preview 任务- 同时发送了
texture_prompt和texture_image_url - 在 preview 中发送了
texture_resolution - 在 refine 中发送了
geometry_resolution,或该参数发送给了不支持它的模型 - 一次性(one-call)任务请求了
meshy-7(请改为发送meshy-7.1) - 一次性(one-call)任务发送了 Text to 3D 未定义的参数,例如拼写错误的参数名。设置了
mode时,Meshy 会忽略它。
错误消息会说明具体发现的问题。请参阅Errors。
- 缺少
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
以下情况之一适用:
- 账户 credits 不足。
- 账户已达到 credits 限额。
- 账户使用的是免费套餐。
请检查你的 credits 和套餐,然后重试。
- Name
403 - Forbidden- Description
内容审核拦截了 prompt 或输入图像。请修改输入内容后重试。
- Name
429 - Too Many Requests- Description
达到以下限制之一:
- 你发送的请求过多。请等待
Retry-After中给出的秒数后重试。 - 你排队或正在运行的任务过多。请等待部分任务完成后重试。
- 在无限制套餐下且 credits 已用尽时,达到了无需 credits 即可运行的任务数量上限。请等待某个任务完成,或增加 credits。
- 你发送的请求过多。请等待
获取结果
读取 Text to 3D 任务的方式与其他所有 v2 任务相同,均通过 Tasks 路由完成。要列出 Text to 3D 任务,可按 type 进行筛选:
text-to-3d:全部三种 Text to 3D 任务text-to-3d-preview:仅 preview 任务text-to-3d-refine:仅 refine 任务
单次调用任务没有自己的筛选条件。
| 目的 | 调用 |
|---|---|
| 获取单个任务 | GET /openapi/v2/tasks/{id} |
| 等待更新 | GET /openapi/v2/tasks/{id}/stream 或使用 webhook |
| 列出你的任务 | GET /openapi/v2/tasks?type=text-to-3d |
| 删除任务 | DELETE /openapi/v2/tasks/{id} |
Text to 3D output
当任务成功后,output 会包含以下字段。task 对象的其余部分对所有任务类型都是一样的。
对于 Text to 3D,expires_at 始终为 null。Meshy 仍会在任务完成 3 天后删除该任务,因此请在此期限内下载文件。企业账户的任务会被保留。参阅资产保留期。
curl https://api.meshy.ai/openapi/v2/tasks/01a1aeae-2720-72bd-952d-008784fbd525 \
-H "Authorization: Bearer ${MESHY_API_KEY}"加载中…- Name
- model_urls
- Type
- object
- Description
生成文件的签名 URL,按格式分类存放。
target_formats中的每种格式都会对应一个 URL,若未指定该字段,则对应默认格式。带贴图的obj还会附带一个mtl键,用于存放其材质文件的 URL。
- Name
- thumbnail_url
- Type
- string
- Description
模型预览图的签名 URL。
- Name
- alpha_thumbnail_url
- Type
- string | null
- Description
带透明背景的预览图签名 URL。除非你发送了
alpha_thumbnail: true,否则该值为null。
- Name
- texture_urls
- Type
- array
- Description
每个贴图集对应一项,其中包含以下各贴图的签名 URL:
base_colormetallicroughnessnormalmetallic_roughnessemission
未生成的贴图为
null。对于预览以及未贴图的一次性调用任务,该数组为空。
旧版 preview 和 refine
mode 已deprecated,但对于已经使用它的集成仍然可以正常工作。新的集成使用 should_texture 通过一次调用生成模型,其花费与一次 preview 加一次 refine 相同。
- 使用
"mode": "preview"、你的prompt以及 geometry 参数(例如geometry_resolution和should_remesh)创建一个 preview。preview 会生成未上贴图的 mesh。 - 等待该 preview 的状态变为
SUCCEEDED。 - 使用
"mode": "refine"、将该 preview 的id作为preview_task_id,以及 texture 参数,创建一个 refine。refine 会沿用该 preview 的 prompt 和 mesh。不设置ai_model时,将使用与该 preview 相匹配的模型进行 texture 处理;对于 Smart Topology 的 preview,这即是 Meshy 7。
在 refine 中,ai_model 指定 texture 模型,Meshy 会忽略 texture_model:
meshy-7:Meshy 7latest:最新的 texture 模型,目前为 Meshy 7meshy-6:Meshy 6meshy-6-lite:Meshy 6 Litemeshy-n1:Meshy N1,仅根据参考图生成 2K 的 base color texture
Smart Topology 的 preview(meshy-t2、meshy-t2.5)不支持 Meshy 6 Lite 贴图:对其使用 meshy-6-lite 进行 refine 时,会改用 Meshy 6 进行 texture 处理,因此在 enable_pbr: true 时也会返回一张 emission map。对 Meshy 6、Meshy 6 Lite 或 Meshy 7 的 preview 使用 meshy-6-lite 进行 refine 则不会返回 emission map,对未设置 ai_model 的 Smart Topology preview 进行 refine 同样不会返回。
要使用 Meshy N1 进行 refine,请发送 "ai_model": "meshy-n1"。Meshy 会根据 texture_image_url,或根据 meshy-7.1 或 latest 的 preview 所保存的参考图进行 texture 处理。任何其他 preview 在未发送 texture_image_url 的情况下都会返回 400。Meshy N1 仅生成 2K 的 base color texture。同时发送以下任意一项都会返回 400:
texture_promptenable_pbr: trueremove_lighting: truetexture_resolution为4k或8k
preview 的三角面数最多为 7,999,999。对已 remesh 为四边形网格的 preview 进行此操作会返回 400。要对一次调用的任务使用 Meshy N1 进行 texture 处理,请使用 Retexture。
在 preview 被删除之前,你可以对同一个 preview 进行多次 refine,例如使用不同的 texture prompt。你无法对一次调用的任务进行 refine。Meshy 会在 Text to 3D 任务完成 3 天后将其删除,Enterprise 账户则会保留其任务。对已删除的 preview 进行 refine 会返回 400;在保留期结束后,还会附带错误码 input_task_expired。请参阅资产保留期。
Legacy routes
v2 之前的 Text to 3D 读取路由仍然可用,因此你现有的代码可以继续运行。对于新代码,请使用 Tasks。
| 路由 | 替代方案 |
|---|---|
GET /openapi/v2/text-to-3d/{id} | GET /openapi/v2/tasks/{id} |
GET /openapi/v2/text-to-3d/{id}/stream | GET /openapi/v2/tasks/{id}/stream |
GET /openapi/v2/text-to-3d | GET /openapi/v2/tasks?type=text-to-3d |
DELETE /openapi/v2/text-to-3d/{id} | DELETE /openapi/v2/tasks/{id} |
这些路由返回原始 Text to 3D 任务对象的字段,其中 task_error 采用其 v2 形式。它们还会返回以下字段,与 Tasks 相同:
inputoutputexpires_at
列表路由返回一个普通数组,不包含 has_more。
/v2/text-to-3d 下(不带 /openapi)的相同路由已被 deprecated。它们的响应中带有 Deprecation 标头,以及一个指向 /openapi/v2/text-to-3d 路由的 Link 标头。