68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""
|
||
|
版权所有: 深圳时光科技有限公司
|
||
|
联系方式: q.100@qq.com
|
||
|
创建日期: 2024/06/12
|
||
|
"""
|
||
|
|
||
|
import maya.cmds as cmds
|
||
|
|
||
|
def sg_save_blend_shape_mappings(reset_mappings):
|
||
|
"""
|
||
|
保存混合变形映射关系
|
||
|
Args:
|
||
|
reset_mappings (int): 是否重置映射
|
||
|
"""
|
||
|
# 初始化进度条
|
||
|
cmds.SGProgressBar(sp=True)
|
||
|
|
||
|
# 初始化映射索引
|
||
|
mapping = 0
|
||
|
|
||
|
# 获取所有混合变形目标名称
|
||
|
blend_shape_names = cmds.SGGetBlendShapes()
|
||
|
|
||
|
# 设置进度条
|
||
|
cmds.SGProgressBar(max=len(blend_shape_names))
|
||
|
cmds.SGProgressBar(t="Update BlendShape Mappings...")
|
||
|
cmds.SGProgressBar(pr=0)
|
||
|
|
||
|
# 获取所有存在的混合变形器和对应的网格索引
|
||
|
blend_shapes = []
|
||
|
mesh_indices = []
|
||
|
|
||
|
for mesh_index in range(50):
|
||
|
blend_shape = f"{cmds.SGGetMeshes(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:
|
||
|
# 更新进度条
|
||
|
cmds.SGProgressBar(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:
|
||
|
# 保存映射关系
|
||
|
cmds.SGSaveBlendShapes(
|
||
|
rm=reset_mappings,
|
||
|
ma=mapping,
|
||
|
m=mesh_indices[i],
|
||
|
value=blend_shape_name
|
||
|
)
|
||
|
mapping += 1
|
||
|
|
||
|
# 结束进度条
|
||
|
cmds.SGProgressBar(ep=True)
|
||
|
|
||
|
# 如果直接运行此脚本
|
||
|
if __name__ == '__main__':
|
||
|
pass
|