当前位置: 首页 > article >正文

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文件 (略)


http://www.kler.cn/a/547043.html

相关文章:

  • 提供可传递的易受攻击的依赖项
  • 最新国内 ChatGPT Plus/Pro 获取教程
  • 【STM32】舵机SG90
  • 使用Java爬虫获取京东JD.item_sku API接口数据
  • 【Jenkins流水线搭建】
  • LLaMA-Factory 安装linux部署使用conda笔记
  • 安科瑞 EMS3.0:赋能企业能效管理,开启智慧能源新时代
  • TIP2022 | DRA | 从分布的角度理解和提升对抗性迁移性
  • 词袋模型和词嵌入模型区别和关联分析(词袋模型是否属于词嵌入模型)
  • 强化学习-DDPG
  • 希尔排序(C#)
  • MySQL 支持的事务隔离级别
  • 对比 LVS 负载均衡群集的 NAT 模式和 DR 模式,其各自的优势
  • Jetpack Compose初体验
  • 解决Did not find dashscope_api_key问题——jupyter设置环境变量
  • C++学习 mac上VScode运行C++
  • mars3d接入到uniapp的时候ios上所有地图的瓦片都无法加载解决方案
  • 通过服务器的 BMC(基板管理控制器)安装操作系统
  • AI时代前端开发:创造力的新引擎?
  • 每日Attention学习23——KAN-Block