Image to 3D API
将一张图片转换为 3D 模型,可选择是否带 texture,并指定所需的输出格式。
从 v1 迁移?Image to 3D 的主要变化如下:
ai_model是唯一的模型设置项。请求中若带有model_type将返回400。- 带 texture 的模型需要
texture_model,即用于为 mesh 上色的模型。 target_formats默认值为 GLB。- 结果包含在
output中。
创建 Image to 3D 任务
curl https://api.meshy.ai/openapi/v2/image-to-3d \
-X POST \
-H "Authorization: Bearer ${MESHY_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"image_url": "https://cdn.meshy.ai/webapp-assets/doc/try-it/v2/inputs/santa.3dbe655f9980.jpg",
"ai_model": "meshy-7.1",
"should_texture": true,
"texture_model": "meshy-7"
}'参数
- Name
- image_url
- Type
- string
- 必选
- Description
除非你发送
input_task_id,否则此项为必填。要转换为模型的图片,可以是公开 URL 或 data URI(data:image/png;base64,...)。该图片必须是 JPG、JPEG、PNG 或 WebP 文件,大小不超过 20 MB,每边至少 32 像素,且不超过 178,956,970 像素(宽 × 高)。
- Name
- input_task_id
- Type
- string
- 必选
- Description
除非你发送
image_url,否则此项为必填。用作输入的 Text to Image 或 Image to Image 任务的 ID。该任务必须是你通过 API 创建的,状态为SUCCEEDED,且只生成了一张图片。如果你同时发送image_url和input_task_id,Meshy 会使用input_task_id。对于多视图图片任务,请使用 Multi-Image to 3D。
- 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 打印),请参见模型。
- Name
- geometry_resolution
- Type
- string
- 默认值 standard
- Description
要生成多少 geometry 细节。
试用并预览可用值:
standard2k:增加 Ultra 处理流程4k:增加 Ultra 处理流程,然后再进行超分辨率处理
2k和4k需要meshy-7.1或latest。使用其他模型时会返回400。
- Name
- should_texture
- Type
- boolean
- 默认值 true
- Description
是否生成 texture。
true返回带贴图的模型,false返回不带贴图的 mesh。设置为false时,Meshy 会忽略texture_model及其他 texture 参数。试用并预览
should_texture = true- Name
- texture_model
- Type
- string
- 必选
- Description
除非
should_texture为false,否则此项为必填。在同一任务中为 3D 模型生成 texture 的模型。每个ai_model都可以接受以下每个值。可用值:
meshy-7:Meshy 7,带 PBR 贴图、文本 prompt,支持高达 8K 的 texturemeshy-n1:Meshy N1,仅根据参考图像生成 2K 基础色 texturemeshy-6-lite:Meshy 6 Lite,2K texture
未指定
texture_model的带贴图请求会返回400,texture 模型不支持的选项也会返回400。texture 模型不会改变 积分 消耗。请参见Texture 模型。
- Name
- enable_pbr
- Type
- boolean
- 默认值 false
- Description
是否同时生成金属度、粗糙度和法线贴图。使用
texture_model: "meshy-n1"时,设置为true会返回400。试用并预览
- Name
- texture_resolution
- Type
- string
- 默认值 2k
- Description
基础色 texture 的尺寸。
试用并预览可用值:
2k4k8k
4k和8k需要texture_model: "meshy-7"。使用meshy-n1或meshy-6-lite时会返回400。
- Name
- texture_prompt
- Type
- string
- Description
用于指导 texture 的文本,最多 800 个字符。超出长度会返回
400。请发送texture_prompt或texture_image_url,不要同时发送两者。同时发送会返回400。使用texture_model: "meshy-n1"时,发送此参数会返回400。
- Name
- texture_image_url
- Type
- string
- Description
用于指导 texture 的图片,可以是公开 URL 或 data URI。其格式和大小规则与
image_url相同。使用texture_model: "meshy-n1"时,Meshy 会将该图片作为正面视图生成 texture;若未提供,则使用输入图像。
- Name
- target_formats
- Type
- string[]
- 默认值 ["glb"]
- Description
要生成的文件格式。Meshy 只会生成你列出的格式。
可用值:
glbobjfbxstlusdz3mf
Meshy 会将 STL 和 3MF 文件缩放到最长边不超过 150 mm。
- Name
- should_remesh
- Type
- boolean
- 默认值 true (meshy-6-lite), false (other models)
- Description
是否在生成后对模型进行 remesh。
false会保持生成时的 mesh 不变。Smart Topology 模型会忽略此设置。试用并预览
should_remesh = true- Name
- topology
- Type
- string
- 默认值 triangle
- Description
重新生成 mesh 后的模型面类型,
triangle或quad。Smart Topology 模型只生成三角形,因此在 Smart Topology 模型上使用quad会返回400。使用texture_model: "meshy-n1"时,如果模型被 remesh(meshy-6-lite默认会执行),quad会返回400。试用并预览在
ai_model为meshy-7.1且should_remesh为true时生效。选择一个值会同时设置它。
- Name
- decimation_mode
- Type
- integer
- Description
按级别设置的自适应面数。设置此项时,Meshy 会忽略
target_polycount。可用值:
1:极致2:高3:中4:低
- Name
- save_pre_remeshed_model
- Type
- boolean
- 默认值 false
- Description
是否同时在
output.model_urls.pre_remeshed_glb中返回 remesh 之前的 GLB。
- Name
- target_polycount
- Type
- integer
- Description
目标面数。其取值范围和默认值取决于 mesh 的构建方式:
Mesh 范围 默认值 Remeshed 100至30000030000meshy-t2.5或meshy-smart-topology-latest100至3000015000meshy-t2100至150004000超出范围的值会返回
400。对于 low-poly 的游戏资产,建议使用 Smart Topology 模型,而不是对标准模型进行 remesh。请参见模型。
- Name
- auto_polycount
- Type
- boolean
- Description
设为
true时,Meshy 会在meshy-t2.5的取值范围内,根据输入图像自动选择面数。此选项仅适用于meshy-t2.5(或解析为该模型的meshy-smart-topology-latest)。使用其他ai_model,或与target_polycount同时使用时,请求会返回400(parameters_conflict)。如果 Meshy 无法为该图像推荐面数,任务会使用
meshy-t2.5的默认值;请求仍会成功。任务的output.target_polycount会显示任务实际使用的面数。默认为false。
- Name
- pose_mode
- Type
- string
- Description
角色模型的姿势,
a-pose或t-pose。留空表示不设置姿势。试用并预览
- Name
- image_enhancement
- Type
- boolean
- 默认值 true
- Description
是否在生成前对输入图像进行清理。
false会完全按原样使用图像。meshy-6-lite和 Smart Topology 模型会忽略此设置。
- Name
- remove_lighting
- Type
- boolean
- 默认值 true
- Description
是否从基础色 texture 中移除高光和阴影。
texture_model所支持的 texture 模型不使用此设置,因此 Meshy 会忽略它。
- Name
- moderation
- Type
- boolean
- 默认值 false
- Description
是否在生成前对以下输入进行有害内容审查:
- 输入图像
texture_image_urltexture_prompt
- Name
- auto_size
- Type
- boolean
- 默认值 false
- Description
是否估算物体的真实世界高度,并据此缩放模型。
auto_size = true- Name
- origin_at
- Type
- string
- 默认值 bottom
- Description
模型 origin 的放置位置,
bottom或center。
- Name
- multi_view_thumbnails
- Type
- boolean
- 默认值 false
- Description
是否同时渲染正面、右侧、背面和左侧的预览图,并在
output.thumbnail_urls中返回。这会为任务增加约 5 秒的处理时间。
- Name
- thumbnail_resolution
- Type
- integer
- 默认值 512
- Description
任务预览图像的宽度和高度(像素):
512或1024。它适用于output.thumbnail_url以及你请求的任何可选预览图。任何其他值都会返回400。
返回值
202 Accepted,并返回任务对象。任务最初为 PENDING 状态,input 为你的请求内容,output 设为 null。
两个响应头可帮助你读取任务:
Location:任务在 Tasks 上的 URLRetry-After:首次读取前需要等待的秒数
失败情形
- Name
400 - Bad Request- Description
请求无法运行。例如:
- 既没有发送
image_url也没有发送input_task_id - 带贴图的请求未发送
texture_model - 同时发送了
texture_prompt和texture_image_url - 图像无法下载、超过 20 MB,或超出像素限制
- 该模型不支持所选
geometry_resolution - texture 模型不支持请求中的某个选项,例如
enable_pbr: true,或在meshy-n1上使用4ktexture
错误信息会说明具体发现的问题。请参见 Errors。
- 既没有发送
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
以下情形之一适用:
- 账户 积分 不足。
- 账户达到了 积分 限额。
- 账户使用的是免费套餐。
请检查你的 积分 和套餐,然后重试。
- Name
403 - Forbidden- Description
内容审核拦截了 prompt 或输入图像。请更改输入内容,然后重试。
- Name
404 - Not Found- Description
input_task_id与你的任何任务都不匹配。
- Name
429 - Too Many Requests- Description
达到了以下限制之一:
- 你发送的请求过多。请等待
Retry-After中指定的秒数,然后重试。 - 你排队或正在运行的任务过多。请等待部分任务完成后再重试。
- 在积分用尽的无限额套餐上,你已达到可在无 积分 情况下运行的任务数量上限。请等待某个任务完成,或增加 积分。
- 你发送的请求过多。请等待
Texture models
ai_model 用于选择构建 mesh 的模型,texture_model 用于选择为其绘制贴图的模型。texture_model 没有默认值,因此每个需要 texture 的请求都必须传入它。要为你的项目选择合适的组合,请参阅 Models。
下表展示了每个 ai_model 在每个 endpoint 上可配合使用的 texture 模型。任何其他组合都会返回 400。
ai_model | Image to 3D | Multi-Image to 3D | Text to 3D |
|---|---|---|---|
meshy-7.1、latest 或 meshy-standard-latest | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、meshy-n1 或 meshy-6-lite |
meshy-6 | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、带 texture_image_url 的 meshy-n1,或 meshy-6-lite |
meshy-6-lite | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、带 texture_image_url 的 meshy-n1,或 meshy-6-lite |
meshy-t2.5、meshy-t2 或 meshy-smart-topology-latest | meshy-7、meshy-n1 或 meshy-6-lite | 无。Multi-Image to 3D 没有 Smart Topology 模型。 | meshy-7、meshy-n1 或 meshy-6-lite |
Retexture 对任何模型都接受 meshy-7、meshy-n1 或 meshy-6-lite。
每个 texture 模型支持一组不同的选项,下表列出了这些选项。如果请求向某个 texture 模型提出了它不支持的选项,将返回 400。
| 选项 | meshy-7 | meshy-n1 | meshy-6-lite |
|---|---|---|---|
texture_resolution | 2k、4k 或 8k | 2k | 2k |
enable_pbr: true | 支持 | 不支持 | 支持 |
texture_prompt | 支持 | 不支持 | 支持 |
texture_image_url | 支持 | 支持,作为正视图 | 支持 |
多张参考图:texture_image_urls 或 multiview_image_urls | 支持 | 支持 | 不支持 |
对已 remesh 的模型使用 topology: "quad" | 支持 | 不支持 | 支持 |
Meshy N1 可为最多 7,999,999 个三角面的模型生成 texture。如果生成的模型超过该大小,任务会失败,Meshy 会退还其 积分。
texture 模型不会改变价格。一个带 texture 的任务的费用为 mesh 费用加上对应分辨率的 texture 费用。请参阅 Pricing。
获取结果
读取 Image to 3D 任务的方式与其他所有 v2 任务相同,均通过 Tasks 路由完成。若只想列出 Image to 3D 任务,可使用 type=image-to-3d 进行筛选。
| 目的 | 调用 |
|---|---|
| 获取单个任务 | GET /openapi/v2/tasks/{id} |
| 等待更新 | GET /openapi/v2/tasks/{id}/stream 或使用 webhook |
| 列出你的任务 | GET /openapi/v2/tasks?type=image-to-3d |
| 删除任务 | DELETE /openapi/v2/tasks/{id} |
Image to 3D 输出
当任务成功后,output 中包含以下字段。task object 的其余部分对每种任务类型都是一样的。output 中的 URL 会在 expires_at 之后失效。
curl https://api.meshy.ai/openapi/v2/tasks/01a1aeac-afb0-77bf-a47b-47a43ee563bc \
-H "Authorization: Bearer ${MESHY_API_KEY}"加载中…- Name
- model_urls
- Type
- object
- Description
生成文件的签名 URL,
target_formats中每种格式对应一个,以格式作为键。还可能出现两个额外的键:mtl:带贴图的obj的 material 文件pre_remeshed_glb:当你发送了save_pre_remeshed_model: true且模型经过了 remesh 时,remesh 之前的 GLB
- Name
- thumbnail_url
- Type
- string
- Description
模型 PNG 预览图的签名 URL,背景为透明。
- Name
- thumbnail_urls
- Type
- object | null
- Description
各预览图的签名 URL,以视角作为键:
frontrightbackleft
除非你发送了
multi_view_thumbnails: true,否则为null。渲染失败的视角会被省略。
- Name
- texture_urls
- Type
- array
- Description
每个 texture 集一项,其中包含以下每张贴图的签名 URL:
base_colormetallicroughnessnormalmetallic_roughnessemission
未生成的贴图为
null。对于没有 texture 的模型,该数组为空。
- Name
- target_polycount
- Type
- integer
- Description
Smart Topology 任务(
meshy-t2或meshy-t2.5)生成时使用的面数:可能是你发送的target_polycount、auto_polycount选定的值,或模型的默认值。其他任务类型不包含此字段。