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

48 lines
1.5 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
版权所有: 深圳时光科技有限公司
联系方式: q.100@qq.com
创建日期: 2023/08/08
"""
import maya.cmds as cmds
def sg_reset_blend_shapes():
"""
重置所有网格的混合变形目标名称
移除混合变形目标名称中的网格名称前缀
"""
# 遍历前50个网格
for j in range(50):
# 获取网格名称
mesh = cmds.SGGetMeshes(i=j)
blend_shape = f"{mesh}_blendShapes"
# 检查混合变形器是否存在
if cmds.objExists(blend_shape):
# 获取所有权重属性
attr_weight = f"{blend_shape}.weight"
current_blend_shape_list = cmds.listAttr(attr_weight, m=True)
# 遍历每个混合变形目标
for i, bs_name in enumerate(current_blend_shape_list):
# 检查是否有网格名称前缀
prefix = f"{mesh}__"
if bs_name.startswith(prefix):
# 移除前缀
new_name = bs_name.replace(prefix, "")
try:
# 重命名混合变形目标
cmds.aliasAttr(
new_name,
f"{blend_shape}.w[{i}]"
)
except:
# 忽略重命名失败的情况
pass
# 如果直接运行此脚本
if __name__ == '__main__':
sg_reset_blend_shapes()