64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
|
#!/usr/bin/env python
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
"""
|
|||
|
版权所有: 清泉时代科技有限公司
|
|||
|
联系方式: q.100@qq.com
|
|||
|
创建日期: 2024/03/26
|
|||
|
"""
|
|||
|
|
|||
|
import maya.cmds as cmds
|
|||
|
import maya.mel as mel
|
|||
|
|
|||
|
def sg_bind_skin_cluster():
|
|||
|
"""
|
|||
|
为模型绑定蒙皮变形器
|
|||
|
- 处理LOD0到LOD7的所有模型
|
|||
|
- 根据模型索引获取对应的骨骼并绑定
|
|||
|
- 设置最大影响数
|
|||
|
"""
|
|||
|
# 遍历8个LOD级别
|
|||
|
for i in range(8):
|
|||
|
# 获取当前LOD级别的骨骼列表
|
|||
|
joint_lod = cmds.SGGetJoints(lod=i, type="string")
|
|||
|
|
|||
|
# 检查所有骨骼是否存在
|
|||
|
exists = True
|
|||
|
for joint in joint_lod:
|
|||
|
if not cmds.objExists(joint):
|
|||
|
exists = False
|
|||
|
break
|
|||
|
|
|||
|
# 如果所有骨骼都存在,处理当前LOD级别的模型
|
|||
|
if exists:
|
|||
|
# 获取当前LOD级别的模型索引列表
|
|||
|
lod_indices = cmds.SGGetMeshes(lod=i)
|
|||
|
|
|||
|
# 遍历处理每个模型
|
|||
|
for mesh_index in lod_indices:
|
|||
|
# 获取模型名称
|
|||
|
mesh = cmds.SGGetMeshes(m=mesh_index)
|
|||
|
|
|||
|
if cmds.objExists(mesh):
|
|||
|
# 检查是否已经有蒙皮变形器
|
|||
|
skin_cluster = mel.eval(f'findRelatedSkinCluster("{mesh}")')
|
|||
|
|
|||
|
if not cmds.objExists(skin_cluster):
|
|||
|
# 构建蒙皮变形器名称
|
|||
|
name = f"{cmds.SGGetMeshes(i=mesh_index)}_skinCluster"
|
|||
|
|
|||
|
# 获取影响骨骼和最大影响数
|
|||
|
influences = cmds.SGGetJoints(inf=mesh_index)
|
|||
|
max_influences = cmds.SGGetJoints(mi=mesh_index)
|
|||
|
|
|||
|
# 创建蒙皮变形器
|
|||
|
cmds.skinCluster(
|
|||
|
influences,
|
|||
|
mesh,
|
|||
|
name=name,
|
|||
|
maximumInfluences=max_influences,
|
|||
|
toSelectedBones=True
|
|||
|
)
|
|||
|
|
|||
|
# 执行权重绑定
|
|||
|
mel.eval('SGBindSkinClusterWeights')
|