您现在的位置是:首页 >技术杂谈 >Unity 接入Tripo API 文生模型,模型制作动画并下载使用网站首页技术杂谈

Unity 接入Tripo API 文生模型,模型制作动画并下载使用

Dongo2 2026-04-07 00:01:04
简介Unity 接入Tripo API 文生模型,模型制作动画并下载使用

目标:我们要实现的是一个文本小猫 通过 tripo 生成模型并拥有跑动的动作(如下为生成后放入到unity的小猫动作)

在这里插入图片描述

主要分为如下步骤进行 官方网站

  1. 请求文生模型 task id(原始task id)
  2. 使用原始task id预校验rig
  3. 使用原始task id生成 rig task id
  4. 使用rig task id生成动画 animation task id
  5. 使用动画文件animation task id 查询动画文件是否生成并且返回下载动画文件地址
  6. 导入动画文件到unity工程中,并生成animator文件

1:请求文生模型 task id(原始task id)

保存如下代码成一个.sh 文件并执行请求原始文生模型任务

#!/bin/bash 
export APIKEY="tsk_***"
curl https://api.tripo3d.ai/v2/openapi/task 
  -H 'Content-Type: application/json' 
  -H "Authorization: Bearer ${APIKEY}" 
  -d '{"type": "text_to_model", "prompt": "a small cat"}'

返回

$ /c/Users/dongwei_peng/Desktop/tripo/requestTaskID.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   118  100    68  100    50    160    117 --:--:-- --:--:-- --:--:--   277{"code":0,"data":{"task_id":"5b42ae63-0d62-4fa8-a218-dd8e0cafef22"}}

2:使用原始task id预校验rig

import requests

api_key = "tsk_***"
url = "https://api.tripo3d.ai/v2/openapi/task"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

data = {
    "type": "animate_prerigcheck",
    "original_model_task_id": "5b42ae63-0d62-4fa8-a218-dd8e0cafef22"
}

response = requests.post(url, headers=headers, json=data)

print(response.json())

返回

{'code': 0, 'data': {'task_id': '99374ad3-bf18-4695-8e4d-f2facd417ea5'}}

3:使用原始task id生成 rig task id

import requests

api_key = "tsk_***"
url = "https://api.tripo3d.ai/v2/openapi/task"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

data = {
    "type": "animate_rig",
    "original_model_task_id": "5b42ae63-0d62-4fa8-a218-dd8e0cafef22",
    "out_format": "glb"
}

response = requests.post(url, headers=headers, json=data)

print(response.json())

返回

{'code': 0, 'data': {'task_id': '4417ee3e-016e-44bb-b343-684800c379f4'}}

4: 使用rig task id生成动画 animation task id

import requests

api_key = "tsk_***"
url = "https://api.tripo3d.ai/v2/openapi/task"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

data = {
    "type": "animate_retarget",
    "original_model_task_id": "4417ee3e-016e-44bb-b343-684800c379f4",
    "out_format": "glb",
    "animation": "preset:run"
}

response = requests.post(url, headers=headers, json=data)

print(response.json())

返回

{'code': 0, 'data': {'task_id': '160f0598-61a4-41fb-8709-b73fb2edcc7f'}}

5:使用动画文件animation task id 查询动画文件是否生成并且返回下载动画文件地址

import requests

api_key = "tsk_***"
task_id = "160f0598-61a4-41fb-8709-b73fb2edcc7f"
url = f"https://api.tripo3d.ai/v2/openapi/task/{task_id}"

headers = {
    "Authorization": f"Bearer {api_key}"
}

response = requests.get(url, headers=headers)

print(response.json())

返回

{'code': 0, 'data': {'task_id': '160f0598-61a4-41fb-8709-b73fb2edcc7f', 'type': 'animate_retarget', 'status': 'success', 'input': {'original_model_id': '4417ee3e-016e-44bb-b343-684800c379f4', 'out_format': 'glb', 'animation': 'preset:run', 'spec': None}, 'output': {'model': 'https://tripo-data.cdn.bcebos.com/tcli_01c7f46f365f434b948c909f4ebcc0aa/20250212/160f0598-61a4-41fb-8709-b73fb2edcc7f/tripo_retarget_160f0598-61a4-41fb-8709-b73fb2edcc7f.glb?auth_key=1739404800-rmoVfenW-0-281dcf00a5950a088c7075bc7b6420fa'}, 'progress': 100, 'create_time': 1739352416, 'queuing_num': -1, 'running_left_time': -1, 'result': {'model': {'type': 'glb', 'url': 'https://tripo-data.cdn.bcebos.com/tcli_01c7f46f365f434b948c909f4ebcc0aa/20250212/160f0598-61a4-41fb-8709-b73fb2edcc7f/tripo_retarget_160f0598-61a4-41fb-8709-b73fb2edcc7f.glb?auth_key=1739404800-rmoVfenW-0-281dcf00a5950a088c7075bc7b6420fa'}}}}

6:导入动画文件到unity工程中,并生成animator文件 (略)

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。