3D模型渲染
更新时间:2026-06-15
简介
3D模型渲染处理器,支持多种3D格式渲染为2D图片。
功能描述
- 3D模型文件路径(支持本地路径)
- Open3D后端:.obj, .ply, .stl, .glb, .gltf
- 多视角渲染(默认8个方向)
- 自定义贴图支持
- 返回渲染图片的 Base64 字符串列表
- 可选将图片保存到 BOS
- 可选将图片保存到本地目录
算子参数
输入
| 输入 | 含义 |
|---|---|
| model_paths | 输入3D模型文件路径数组 |
| model_names | 可选,模型名称数组(用于生成输出文件名) |
| texture_paths | 可选,每个模型的自定义贴图路径数组 |
| views_configs | 可选,每个模型的自定义渲染视角配置数组 (list[dict]) |
输出
| 输出 | 含义 |
|---|---|
| result | pa.Array: 结果字典数组,包含每个模型对应的多视角渲染结果 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| image_suffix | str | '.png' | 输出图片的后缀名,默认 ".png"。 |
| output_dir | str | '' | 保存渲染图片的文件夹路径(支持本地路径或 BOS 路径)。 |
| texture_path | str | dict[str, str] | 自定义贴图绝对路径,支持单张图片路径(str)或PBR贴图字典(dict)。 字典键支持: "albedo", "metallic", "roughness", "normal", "ao"。 如果提供将覆盖所有模型的贴图。 |
| texture_relative_path | str | dict[str, str] | 自定义贴图相对路径(相对于模型文件所在目录)。 支持单张图片路径(str)或PBR贴图字典(dict)。 例如 "textures_base/texture_shaded.png" 或 {"albedo": "pbr/texture_base.png", "metallic": "pbr/metallic.png"}。 如果提供了 texture_path,此参数将被忽略。 |
| views | dict[str, dict[str, Any]] | None | 自定义渲染视角配置,字典格式 {view_name: {dist, elev, azim, ...}}。 如果为None,则使用默认的8个视角。 |
| target_size | list[int] | None | 渲染图片尺寸 [width, height]。 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.image.image_render import ImageRender
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 # TODO: 根据实际场景准备样本数据
19 samples = {"model_paths": [...], "model_names": [...]}
20 ds = daft.from_pydict(samples)
21 constructor_kwargs = {
22 "image_suffix": '.png',
23 "output_dir": '',
24 "texture_path": None,
25 "texture_relative_path": 'textures_base/texture_shaded.png',
26 "views": None,
27 }
28 ds = ds.with_column(
29 "result",
30 aihc_udf(
31 ImageRender,
32 construct_args=constructor_kwargs,
33 num_cpus=1,
34 concurrency=4,
35 batch_size=8,
36 )(col("model_paths"), col("model_names"), col("texture_paths")),
37 )
38 ds.show()
评价此篇文章
