MetaFusion/scripts/Reference/SGFastBindSkinCluster.py

57 lines
1.7 KiB
Python
Raw Normal View History

2025-01-17 02:30:36 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
版权所有: 清泉时代科技有限公司
联系方式: q.100@qq.com
创建日期: 2024/03/26
"""
import os
import maya.cmds as cmds
def sg_fast_bind_skin_cluster():
"""
快速绑定蒙皮权重
- 遍历所有网格
- 查找对应的蒙皮权重文件
- 应用蒙皮权重
"""
# 遍历所有网格0-53
for i in range(54):
# 获取网格名称
mesh = cmds.SGGetMeshes(m=i)
# 检查网格是否存在
if not cmds.objExists(mesh):
continue
# 获取蒙皮权重文件路径
path = os.path.join(cmds.SGDescriptor(p=True), "skin_buffer")
# 检查路径是否存在
if not os.path.exists(path):
continue
# 获取所有.skin文件
skin_files = [f for f in os.listdir(path) if f.endswith('.skin')]
# 处理每个蒙皮文件
for skin_file in skin_files:
# 检查文件名是否包含网格名称
if mesh in skin_file:
# 构建完整的文件路径
skin_file_path = os.path.join(path, skin_file)
# 查找现有的蒙皮变形器
skin_cluster = cmds.findRelatedSkinCluster(mesh)
# 如果存在蒙皮变形器,则解除绑定
if cmds.objExists(skin_cluster):
cmds.skinCluster(mesh, edit=True, unbind=True)
# 导入蒙皮权重
try:
cmds.SGSkinCluster(mesh, import_file=skin_file_path)
except:
pass # 忽略导入错误