69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import maya.cmds as cmds
|
|
from scripts.utils.Core import (
|
|
GetMeshes,
|
|
GetBlendShapes,
|
|
SaveBlendShapes,
|
|
ProgressBar
|
|
)
|
|
|
|
def save_blend_shape_mappings(reset_mappings):
|
|
"""
|
|
保存混合变形映射关系
|
|
|
|
参数:
|
|
reset_mappings (int): 是否重置映射
|
|
"""
|
|
# 初始化进度条
|
|
ProgressBar(sp=True)
|
|
|
|
# 初始化映射索引
|
|
mapping = 0
|
|
|
|
# 获取所有混合变形目标名称
|
|
blend_shape_names = GetBlendShapes()
|
|
|
|
# 设置进度条
|
|
ProgressBar(max_value=len(blend_shape_names))
|
|
ProgressBar(t="Update BlendShape Mappings...")
|
|
ProgressBar(pr=0)
|
|
|
|
# 获取所有存在的混合变形器和对应的网格索引
|
|
blend_shapes = []
|
|
mesh_indices = []
|
|
|
|
for mesh_index in range(50):
|
|
blend_shape = f"{GetMeshes(i=mesh_index)}_blendShapes"
|
|
if cmds.objExists(blend_shape):
|
|
blend_shapes.append(blend_shape)
|
|
mesh_indices.append(mesh_index)
|
|
|
|
# 处理每个混合变形目标名称
|
|
for blend_shape_name in blend_shape_names:
|
|
# 更新进度条
|
|
ProgressBar(apr=1)
|
|
|
|
# 检查每个混合变形器
|
|
for i, blend_shape in enumerate(blend_shapes):
|
|
# 获取当前混合变形器的所有权重属性
|
|
bs_node = cmds.listAttr(f"{blend_shape}.w", m=True)
|
|
|
|
# 如果找到匹配的目标名称
|
|
if bs_node and blend_shape_name in bs_node:
|
|
# 保存映射关系
|
|
SaveBlendShapes(
|
|
rm=reset_mappings,
|
|
ma=mapping,
|
|
m=mesh_indices[i],
|
|
value=blend_shape_name
|
|
)
|
|
mapping += 1
|
|
|
|
# 结束进度条
|
|
ProgressBar(ep=True)
|
|
|
|
# 如果直接运行此脚本
|
|
if __name__ == '__main__':
|
|
pass |