MetaFusion/scripts/Reference/SGAutomaticGrouping.py
2025-01-17 02:30:36 +08:00

66 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
版权所有: 清泉时代科技有限公司
联系方式: q.100@qq.com
创建日期: 2024/03/20
"""
import maya.cmds as cmds
def sg_automatic_grouping():
"""
自动对模型进行分组
- 处理head_lod0到head_lod7的分组
- 处理body_lod0到body_lod3的分组
"""
# 处理head模型的LOD分组
for i in range(8):
# 获取当前LOD级别的网格体索引列表
lod_mesh_indices = cmds.SGGetMeshes(lod=i)
group_name = f"head_lod{i}_grp"
# 如果分组不存在则创建
if not cmds.objExists(group_name):
cmds.group(empty=True, name=group_name)
# 遍历当前LOD级别的所有网格体
for mesh_index in lod_mesh_indices:
# 跳过索引大于等于50的网格体body部分
if mesh_index >= 50:
continue
# 获取网格体名称
mesh = cmds.SGGetMeshes(m=mesh_index)
# 如果网格体存在,将其放入对应分组
if cmds.objExists(mesh):
try:
cmds.parent(mesh, group_name)
except:
pass # 忽略可能的父子关系错误
# 处理body模型的LOD分组
body_groups = [
"body_lod0_grp",
"body_lod1_grp",
"body_lod2_grp",
"body_lod3_grp"
]
# 遍历处理body的4个LOD级别
for i in range(4):
body_index = 50 + i
mesh = cmds.SGGetMeshes(m=body_index)
# 如果分组不存在则创建
if not cmds.objExists(body_groups[i]):
cmds.group(empty=True, name=body_groups[i])
# 如果网格体存在,将其放入对应分组
if cmds.objExists(mesh):
try:
cmds.parent(mesh, body_groups[i])
except:
pass # 忽略可能的父子关系错误