MetaFusion/docs/dna_viewer_api_build_meshes.md

107 lines
3.1 KiB
Markdown
Raw Normal View History

2025-01-06 23:33:41 +08:00
# 网格工具
以下方法的目的是提供:
- 从给定 DNA 文件路径构建网格的简单机制
- 返回和打印 DNA 文件中包含的网格信息
## 导入
```
from dna_viewer import DNA, Config, build_meshes
```
```
DNA_PATH_ADA = f"{ROOT_DIR}/data/dna_files/Ada.dna"
DNA_PATH_TARO = f"{ROOT_DIR}/data/dna_files/Taro.dna"
```
## 创建 Config 实例([`Config`](../dna_viewer/builder/config.py#35))
创建一个将在网格构建过程中使用的配置对象。
```
config = Config(
add_joints=True,
add_blend_shapes=True,
add_skin_cluster=True,
add_ctrl_attributes_on_root_joint=True,
add_animated_map_attributes_on_root_joint=True,
lod_filter=[0, 1],
mesh_filter=["head"],
)
```
以下是 `Config` 类的一些属性:
- `add_joints: bool` - 表示是否应添加关节的标志,默认为 `True`
- `add_blend_shapes: bool` - 表示是否应添加变形的标志,默认为 `True`
- `add_skin_cluster: bool` - 表示是否应添加蒙皮簇的标志,默认为 `True`
- `add_ctrl_attributes_on_root_joint: bool` - 表示是否应将控制属性作为属性添加到根关节的标志,默认为 `False`。它们在引擎中用作 Rig Logic 输入的动画曲线。
- `add_animated_map_attributes_on_root_joint: bool` - 表示是否应将动画贴图属性添加到根关节作为属性的标志,默认为 `True`。它们在引擎中用作动画贴图的动画曲线。
**重要**: 某些标志值的组合可能会导致骨骼不可用或禁用某些功能!
## 构建网格 ([`build_meshes`](../dna_viewer/api.py#L26))
用于构建骨骼元素(关节、网格、变形和蒙皮簇),不包含 Rig Logic。
它返回已添加到场景中的网格的长名称。
```
config = Config(
add_joints=True,
add_blend_shapes=True,
add_skin_cluster=True,
add_ctrl_attributes_on_root_joint=True,
add_animated_map_attributes_on_root_joint=True,
lod_filter=[0, 1],
mesh_filter=["head"],
)
mesh_names = build_meshes(
dna=dna_ada,
config=config
)
```
这使用以下参数:
- `dna: DNA` - 通过 `DNA` 获得的 DNA 实例。
- `config: Config` - 配置实例。
```
mesh_names = build_meshes(dna=dna_ada)
```
这默认添加 DNA 文件中的所有网格。
### 示例
**重要**: 运行此示例之前需要执行上述[环境设置](dna_viewer_api.md#environment-setup)。
```
from dna_viewer import DNA, Config, build_meshes
# if you use Maya, use absolute path
ROOT_DIR = f"{ospath.dirname(ospath.abspath(__file__))}/..".replace("\\", "/")
# Sets DNA file path
DNA_PATH_ADA = f"{ROOT_DIR}/data/dna_files/Ada.dna"
dna_ada = DNA(DNA_PATH_ADA)
# Starts the mesh build process with all the default values
build_meshes(dna=dna_ada)
# Creates the options to be passed in `build_meshes`
config = Config(
add_joints=True,
add_blend_shapes=True,
add_skin_cluster=True,
add_ctrl_attributes_on_root_joint=True,
add_animated_map_attributes_on_root_joint=True,
lod_filter=[0, 1],
mesh_filter=["head"],
)
# Starts the mesh building process with the provided parameters
# In this case it will create every mesh contained in LODs 0 and 1 with 'head` in it's name,
build_meshes(
dna=dna_ada,
config=config,
)
```