文本生成纹理 API

文本生成纹理 API 是一项功能,允许您将 Meshy 的文本生成纹理能力集成到您自己的应用程序中。在本节中,您将找到开始使用此 API 所需的所有信息。


POST/openapi/v1/text-to-texture

创建文本生成纹理任务

该端点允许您创建一个新的文本生成纹理任务。请参阅文本生成纹理任务对象以查看文本生成纹理任务对象包含哪些属性。

参数

必需属性

  • Name
    model_url
    Type
    string
    Description

    为 Meshy 提供一个 3D 模型以进行贴图。目前支持 .fbx / .obj / .stl / .gltf / .glb 格式的模型。

    提供模型有两种方式:

    • 可公开访问的 URL:一个可以从公共互联网访问的 URL。
    • Data URI:模型的 base64 编码数据 URI。Data URI 示例:data:application/octet-stream;base64,<your base64-encoded model data>
  • Name
    object_prompt
    Type
    string
    Description

    描述 3D 模型是什么类型的物体。最多 600 个字符。

  • Name
    style_prompt
    Type
    string
    Description

    描述您期望的物体风格。最多 600 个字符。

可选属性

  • Name
    enable_original_uv
    Type
    boolean
    Description

    使用模型的原始 UV 而不是生成新的 UV。如果模型没有原始 UV,输出质量可能不佳。默认值为 true

  • Name
    enable_pbr
    Type
    boolean
    Description

    生成 PBR 贴图(金属度、粗糙度、法线),以及基础色贴图。默认值为 true

  • Name
    resolution
    Type
    string
    Description

    指定生成纹理的分辨率。可选值:

    • 1024
    • 2048
    • 4096
  • Name
    negative_prompt
    Type
    string
    Description

    描述纹理不应该是什么样子。最多 600 个字符。

  • Name
    art_style
    Type
    string
    Description

    描述您期望的美术风格。默认值为 realistic。可选值:

    • realistic:写实风格
    • fake-3d-cartoon:2.5D 卡通风格
    • japanese-anime:日式动漫风格
    • cartoon-line-art:卡通线稿风格
    • realistic-hand-drawn:写实手绘风格
    • fake-3d-hand-drawn:2.5D 手绘风格
    • oriental-comic-ink:东方漫画水墨风格

返回值

响应的 result 属性包含新创建的文本生成纹理任务的任务 id

请求

POST
/openapi/v1/text-to-texture
curl https://api.meshy.ai/openapi/v1/text-to-texture \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "model_url": "https://cdn.meshy.ai/model/example_model_2.glb",
    "object_prompt": "a monster mask",
    "style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
    "enable_original_uv": true,
    "enable_pbr": true,
    "resolution": "1024",
    "negative_prompt": "low quality, low resolution, low poly, ugly",
    "art_style": "realistic"
  }'

 ## Using Data URI example
curl https://api.meshy.ai/openapi/v1/text-to-texture \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "model_url": "data:application/octet-stream;base64,${YOUR_BASE64_ENCODED_MODEL_DATA}",
    "object_prompt": "a monster mask",
    "style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
    "enable_original_uv": true,
    "enable_pbr": true,
    "resolution": "1024",
    "negative_prompt": "low quality, low resolution, low poly, ugly",
    "art_style": "realistic"
  }'

响应

{
  "result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}

GET/openapi/v1/text-to-texture/:id

获取文本生成纹理任务

该端点允许您通过有效的任务 id 获取一个文本生成纹理任务。请参阅文本生成纹理任务对象以查看文本生成纹理任务对象包含哪些属性。

参数

  • Name
    id
    Type
    path
    Description

    要获取的文本生成纹理任务的唯一标识符。

返回值

响应包含文本生成纹理任务对象。详情请查阅文本生成纹理任务对象部分。

请求

GET
/openapi/v1/text-to-texture/018a210d-8ba4-705c-b111-1f1776f7f578
curl https://api.meshy.ai/openapi/v1/text-to-texture/018a210d-8ba4-705c-b111-1f1776f7f578 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

响应

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
    "fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
    "usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
  },
  "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
  "object_prompt": "a monster mask",
  "style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
  "art_style": "realistic",
  "negative_prompt": "low quality, low resolution, low poly, ugly",
  "progress": 100,
  "started_at": 1692771667037,
  "created_at": 1692771650657,
  "expires_at": 1692771679037,
  "finished_at": 1692771669037,
  "status": "SUCCEEDED",
  "texture_urls": [
    {
      "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
      "metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
      "normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX",
      "roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX"
    }
  ],
  "preceding_tasks": 0,
  "task_error": {
    "message": ""
  }
}

GET/openapi/v1/text-to-texture

列出文本生成纹理任务

该端点允许您获取文本生成纹理任务的列表。

参数

可选属性

  • Name
    page_num
    Type
    integer
    Description

    分页的页码。起始值和默认值为 1

  • Name
    page_size
    Type
    integer
    Description

    分页大小限制。默认 10 条,最大允许 50 条。

  • Name
    sort_by
    Type
    string
    Description

    排序字段。可选值:

    • +created_at:按创建时间升序排序。
    • -created_at:按创建时间降序排序。

返回值

返回文本生成纹理任务对象的分页列表。

请求

GET
/openapi/v1/text-to-texture
curl https://api.meshy.ai/openapi/v1/text-to-texture?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"

响应

[
  {
    "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "model_urls": {
      "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
      "fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
      "usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
    },
    "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
    "object_prompt": "a monster mask",
    "style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
    "art_style": "realistic",
    "negative_prompt": "low quality, low resolution, low poly, ugly",
    "progress": 100,
    "started_at": 1692771667037,
    "created_at": 1692771650657,
    "expires_at": 1692771679037,
    "finished_at": 1692771669037,
    "status": "SUCCEEDED",
    "texture_urls": [
      {
        "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
        "metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
        "normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX",
        "roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX"
      }
    ],
    "preceding_tasks": 0,
    "task_error": {
      "message": ""
    }
  }
]

GET/openapi/v1/text-to-texture/:id/stream

流式文本生成纹理任务

该端点通过服务器发送事件(SSE)流式返回文本生成纹理任务的实时更新。

参数

  • Name
    id
    Type
    path
    Description

    要流式的文本生成纹理任务的唯一标识符。

返回值

返回文本生成纹理任务对象的流式数据,格式为服务器发送事件(SSE)。

对于 PENDINGIN_PROGRESS 状态的任务,响应流仅包含必要的 progressstatus 字段。

请求

GET
/openapi/v1/text-to-texture/018a210d-8ba4-705c-b111-1f1776f7f578/stream
curl -N https://api.meshy.ai/openapi/v1/text-to-texture/018a210d-8ba4-705c-b111-1f1776f7f578/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"

响应流

// 错误事件示例
event: error
data: {
  "status_code": 404,
  "message": "Task not found"
}

// 消息事件示例,展示任务进度。
// 对于 PENDING 或 IN_PROGRESS 状态的任务,响应流不会包含所有字段。
event: message
data: {
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "progress": 0,
  "status": "PENDING"
}

event: message
data: {
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "progress": 50,
  "status": "IN_PROGRESS"
}

event: message
data: {
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "progress": 100,
  "status": "SUCCEEDED",
  "created_at": 1692771650657,
  "started_at": 1692771667037,
  "finished_at": 1692771669037,
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
    "fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
    "usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
  },
  "texture_urls": [
    {
      "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
      "metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
      "normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX",
      "roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX"
    }
  ],
  "preceding_tasks": 0,
  "task_error": {
    "message": ""
  }
}

文本生成纹理任务对象

文本生成纹理任务对象是 Meshy 跟踪的一个工作单元,用于根据文本输入生成 3D 纹理。 该模型具有以下属性:

属性

  • Name
    id
    Type
    string
    Description

    任务的唯一标识符。虽然我们使用 k-sortable UUID 作为任务 id 的实现细节,但您不应对 id 的格式做任何假设。

  • Name
    model_url
    Type
    string
    Description

    Meshy 生成的可下载带纹理 3D 模型文件的 URL。

  • Name
    model_urls
    Type
    object
    Description

    Meshy 生成的可下载带纹理 3D 模型文件的 URL。

    • Name
      glb
      Type
      string
      Description

      GLB 文件的可下载 URL。

    • Name
      fbx
      Type
      string
      Description

      FBX 文件的可下载 URL。

    • Name
      usdz
      Type
      string
      Description

      USDZ 文件的可下载 URL。

  • Name
    object_prompt
    Type
    string
    Description

    创建任务时使用的原始 object_prompt

  • Name
    style_prompt
    Type
    string
    Description

    创建任务时使用的原始 style_prompt

  • Name
    art_style
    Type
    string
    Description

    创建任务时使用的原始 art_style

  • Name
    negative_prompt
    Type
    string
    Description

    创建任务时使用的原始 negative_prompt

  • Name
    thumbnail_url
    Type
    string
    Description

    模型文件缩略图的可下载 URL。

  • Name
    progress
    Type
    integer
    Description

    任务进度。如果任务尚未开始,则该属性为 0。任务成功后,该值为 100

  • Name
    started_at
    Type
    timestamp
    Description

    任务开始的时间戳,单位为毫秒。如果任务尚未开始,则该属性为 0

  • Name
    created_at
    Type
    timestamp
    Description

    任务创建的时间戳,单位为毫秒。

  • Name
    expires_at
    Type
    timestamp
    Description

    任务结果过期的时间戳,单位为毫秒。

  • Name
    finished_at
    Type
    timestamp
    Description

    任务完成的时间戳,单位为毫秒。如果任务尚未完成,则该属性为 0

  • Name
    status
    Type
    string
    Description

    任务状态。可能的值有:PENDINGIN_PROGRESSSUCCEEDEDFAILEDCANCELED

  • Name
    texture_urls
    Type
    array
    Description

    由任务生成的纹理 URL 对象数组。通常只包含一个纹理 URL 对象。每个纹理 URL 包含以下属性:

    • Name
      base_color
      Type
      string
      Description

      基础色贴图的可下载 URL。

    • Name
      metallic
      Type
      string
      Description

      金属度贴图的可下载 URL。

    • Name
      normal
      Type
      string
      Description

      法线贴图的可下载 URL。

    • Name
      roughness
      Type
      string
      Description

      粗糙度贴图的可下载 URL。

  • Name
    preceding_tasks
    Type
    integer
    Description

    前置任务数量。

  • Name
    task_error
    Type
    object
    Description

    错误对象,包含任务失败时的错误信息。如果任务成功,message 属性应为空。

    • Name
      message
      Type
      string
      Description

      详细错误信息。

示例文本生成纹理任务模型

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
    "fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
    "usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
  },
  "object_prompt": "a monster mask",
  "style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
  "art_style": "realistic",
  "negative_prompt": "low quality, low resolution, low poly, ugly",
  "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
  "progress": 1,
  "started_at": 1692771667037,
  "created_at": 1692771650657,
  "expires_at": 1692771679037,
  "finished_at": 1692771669037,
  "status": "SUCCEEDED",
  "texture_urls": [
    {
      "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
      "metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
      "normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX",
      "roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX"
    }
  ],
  "preceding_tasks": 0,
  "task_error": {
    "message": ""
  }
}