MetaFusion/scripts/utils/SaveBlendShape.py

64 lines
1.9 KiB
Python
Raw Normal View History

2025-02-07 05:10:30 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
from scripts.utils.Core import (
GetMeshes,
GetBlendShape,
SaveBlendShapeMappings,
SaveBlendShapes,
ProgressBar
)
def save_blend_shape():
"""
保存所有网格的混合变形目标
"""
# 保存混合变形映射
SaveBlendShapeMappings(reset=False)
# 初始化进度条
ProgressBar(sp=True)
# 遍历前50个网格
for mesh_index in range(50):
# 获取网格
mesh = GetMeshes(m=mesh_index)
if cmds.objExists(mesh):
# 获取混合变形器
blend_shape = GetBlendShape(mesh)
if cmds.objExists(blend_shape):
# 获取混合变形目标数量
count = cmds.blendShape(blend_shape, query=True, weightCount=True)
if count:
# 设置进度条
ProgressBar(max_value=count)
ProgressBar(t=f"[{blend_shape}] Save Target Mesh...")
# 处理每个混合变形目标
for index in range(count):
# 更新进度条
ProgressBar(apr=1)
# 重新生成目标并保存
bs_name = cmds.sculptTarget(
blend_shape,
edit=True,
regenerate=True,
target=index
)
SaveBlendShapes(bs=mesh_index, i=index, value=bs_name[0])
# 删除临时目标
cmds.delete(bs_name)
# 结束进度条
ProgressBar(ep=True)
# 如果直接运行此脚本
if __name__ == '__main__':
save_blend_shape()