覆盖文生 3D、图生 3D、多视图、批量生成,以及重拓扑、绑定、动画、智能分割、 纹理、PBR、智能 UV、部件补全、格式导出与下载。 代码组织:一个功能一个模块(tripo/features/),入口薄壳 tripocli.py。
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""格式转换导出 — convert a model to another format.
|
||
|
||
tripocli export -p <project_id> -f fbx --wait -o model.fbx
|
||
|
||
Export is asynchronous; once it succeeds the result is fetched through
|
||
``download_with_name`` using the *export* operator id.
|
||
"""
|
||
|
||
import os
|
||
|
||
from . import _common
|
||
|
||
NAME = "export"
|
||
HELP = "格式转换导出 (glb/fbx/obj/stl/usdz/3mf)"
|
||
|
||
FORMATS = ["glb", "fbx", "obj", "stl", "usdz", "3mf"]
|
||
|
||
|
||
def add_arguments(parser):
|
||
parser.add_argument("-p", "--project", required=True, help="项目 ID")
|
||
parser.add_argument("-f", "--format", required=True, choices=FORMATS, help="目标格式")
|
||
parser.add_argument("--operator", help="模型 operator_id(默认取项目当前 operator)")
|
||
parser.add_argument("-n", "--name", help="导出文件名前缀")
|
||
parser.add_argument("-m", "--model", help="覆盖 model_version(默认取项目自身版本)")
|
||
_common.add_wait_options(parser, "导出文件保存路径")
|
||
|
||
|
||
def run(ctx):
|
||
args = ctx.args
|
||
operator_id = args.operator
|
||
if not operator_id:
|
||
operator_id = ctx.client.project_operator(args.project).get("operator_id")
|
||
if not operator_id:
|
||
raise ValueError(f"无法确定项目 {args.project} 的 operator_id,请用 --operator 指定")
|
||
|
||
version = _common.project_version(ctx.client, args.project, args.model) or "default"
|
||
result = ctx.client.export(
|
||
args.project, operator_id, args.format, name=args.name or "model", model_version=version
|
||
) or {}
|
||
|
||
export_operator = result.get("operator_id")
|
||
if not args.wait:
|
||
ctx.out.data(
|
||
result,
|
||
human=lambda: (
|
||
ctx.out.line("✅ 导出任务已提交"),
|
||
ctx.out.line(f"export operator_id : {export_operator}"),
|
||
ctx.out.line(f"查询进度 : tripocli task status {export_operator}"),
|
||
),
|
||
)
|
||
return result
|
||
|
||
_common.wait_and_report(ctx, export_operator)
|
||
|
||
filename = args.output or f"{args.name or 'model'}.{args.format}"
|
||
url = ctx.client.download_url(export_operator, os.path.basename(filename))
|
||
output_path = None
|
||
if url:
|
||
output_path = os.path.abspath(filename)
|
||
ctx.client.download(url, output_path)
|
||
|
||
payload = {"export": result, "download_url": url, "output_file": output_path}
|
||
ctx.out.data(
|
||
payload,
|
||
human=lambda: (
|
||
ctx.out.line("🎉 导出完成"),
|
||
ctx.out.line(f"已保存: {output_path}") if output_path else ctx.out.line("⚠️ 未取到下载直链"),
|
||
),
|
||
)
|
||
return payload
|