59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
import maya.cmds as cmds
|
||
import maya.mel as mel
|
||
from Core import GetMeshes, GetJoints
|
||
|
||
def bind_skin_cluster():
|
||
"""
|
||
为模型绑定蒙皮变形器
|
||
- 处理LOD0到LOD7的所有模型
|
||
- 根据模型索引获取对应的骨骼并绑定
|
||
- 设置最大影响数
|
||
"""
|
||
# 遍历8个LOD级别
|
||
for i in range(8):
|
||
# 获取当前LOD级别的骨骼列表
|
||
joint_lod = GetJoints(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 = GetMeshes(lod=i)
|
||
|
||
# 遍历处理每个模型
|
||
for mesh_index in lod_indices:
|
||
# 获取模型名称
|
||
mesh = GetMeshes(m=mesh_index)
|
||
|
||
if cmds.objExists(mesh):
|
||
# 检查是否已经有蒙皮变形器
|
||
skin_cluster = mel.eval(f'findRelatedSkinCluster("{mesh}")')
|
||
|
||
if not cmds.objExists(skin_cluster):
|
||
# 构建蒙皮变形器名称
|
||
name = f"{GetMeshes(i=mesh_index)}_skinCluster"
|
||
|
||
# 获取影响骨骼和最大影响数
|
||
influences = GetJoints(inf=mesh_index)
|
||
max_influences = GetJoints(mi=mesh_index)
|
||
|
||
# 创建蒙皮变形器
|
||
cmds.skinCluster(
|
||
influences,
|
||
mesh,
|
||
name=name,
|
||
maximumInfluences=max_influences,
|
||
toSelectedBones=True
|
||
)
|
||
|
||
# 执行权重绑定
|
||
mel.eval('SGBindSkinClusterWeights') |