覆盖文生 3D、图生 3D、多视图、批量生成,以及重拓扑、绑定、动画、智能分割、 纹理、PBR、智能 UV、部件补全、格式导出与下载。 代码组织:一个功能一个模块(tripo/features/),入口薄壳 tripocli.py。
59 lines
2.6 KiB
Python
59 lines
2.6 KiB
Python
"""单图生成多视角图 — one image to four consistent views.
|
||
|
||
tripocli imgmv -i ./ref.png --wait -o ./views
|
||
|
||
Turns one reference image into 4 views (front/left/right/back), which can then be
|
||
fed to ``tripocli multiview --front/--left/--right/--back`` for a noticeably better
|
||
model than plain single-image 3D. Verified body:
|
||
``{image, model_version, amount, resolution, scale}``; the result asset has
|
||
``type: "multiview_images"`` with 4 entries in ``output.data`` (实测出图 4 张).
|
||
"""
|
||
|
||
from ..errors import TripoAPIError
|
||
from . import image_gen
|
||
|
||
NAME = "imgmv"
|
||
HELP = "单图生成多视角图(4 张,可喂给 multiview 提升 3D 质量)"
|
||
|
||
|
||
def add_arguments(parser):
|
||
parser.add_argument("-i", "--image", required=True, help="输入图片 (png/jpg/webp)")
|
||
parser.add_argument("--amount", type=int, default=4, choices=[1, 2, 3, 4], help="生成数量(默认 4,多视角本身需要 4 张)")
|
||
parser.add_argument("--scale", default="1:1", choices=image_gen.SCALES, help="图片比例(默认 1:1)")
|
||
parser.add_argument("--resolution", default="1K", choices=image_gen.RESOLUTIONS, help="分辨率(默认 1K)")
|
||
parser.add_argument("-m", "--model", default=image_gen.DEFAULT_MODEL,
|
||
help="图像模型(默认 nano-banana-2),也可直接传 model_version")
|
||
parser.add_argument("-w", "--wait", action="store_true", help="等待生成完成")
|
||
parser.add_argument("-o", "--output", help="图片保存目录(配合 --wait)")
|
||
parser.add_argument("--timeout", type=int, default=300, help="等待超时秒数(默认 300)")
|
||
|
||
|
||
def run(ctx):
|
||
args = ctx.args
|
||
ctx.out.line(f"📤 上传图片: {args.image}")
|
||
image = ctx.client.upload_image(args.image)
|
||
body = {
|
||
"image": image,
|
||
"model_version": image_gen.resolve_model(args.model),
|
||
"amount": args.amount,
|
||
"resolution": args.resolution,
|
||
"scale": args.scale,
|
||
}
|
||
data = ctx.client.get_data("POST", "/v2/studio/image/gen_multiview", body=body) or {}
|
||
asset_id = data.get("asset_id") or data.get("task_id")
|
||
if not asset_id:
|
||
raise TripoAPIError(f"gen_multiview 未返回 asset_id: {data}")
|
||
|
||
if not args.wait:
|
||
ctx.out.data(
|
||
data,
|
||
human=lambda: (
|
||
ctx.out.line(f"✅ 已提交 asset_id={asset_id}"),
|
||
ctx.out.line(f"取图: tripocli img --asset {asset_id} --wait -o ./views"),
|
||
),
|
||
)
|
||
return data
|
||
|
||
asset = image_gen._poll_asset(ctx.client, asset_id, args.timeout)
|
||
return image_gen._report(ctx, asset_id, asset, args.output)
|