MetaFusion/scripts/utils/FastBindSkinCluster.py
2025-02-07 05:10:30 +08:00

52 lines
1.7 KiB
Python
Raw Permalink 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 -*-
import os
import maya.cmds as cmds
from scripts.utils.Core import GetMeshes, Descriptor, FindSkinCluster, SkinCluster
def fast_bind_skin_cluster():
"""
快速绑定蒙皮权重
- 遍历所有网格
- 查找对应的蒙皮权重文件
- 应用蒙皮权重
"""
# 遍历所有网格0-53
for i in range(54):
# 获取网格名称
mesh = GetMeshes(m=i)
# 检查网格是否存在
if not cmds.objExists(mesh):
continue
# 获取蒙皮权重文件路径
path = os.path.join(Descriptor(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 = FindSkinCluster(mesh)
# 如果存在蒙皮变形器,则解除绑定
if cmds.objExists(skin_cluster):
cmds.skinCluster(mesh, edit=True, unbind=True)
# 导入蒙皮权重
try:
SkinCluster(mesh=mesh, import_file=skin_file_path)
except:
pass # 忽略导入错误