72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import maya.cmds as cmds
|
|
from Core import ProgressBar, GetMeshes, GetBlendShape, GetBlendShapeTargets, SetBlendShapes
|
|
|
|
def create_blend_shape():
|
|
"""
|
|
为模型创建混合变形目标
|
|
- 处理索引0到49的模型
|
|
- 为每个模型创建对应的混合变形目标
|
|
- 显示进度条指示创建进度
|
|
"""
|
|
# 开始进度条
|
|
ProgressBar(sp=True)
|
|
|
|
# 遍历处理每个模型
|
|
for mesh_index in range(50):
|
|
# 获取模型名称
|
|
mesh = GetMeshes(m=mesh_index)
|
|
|
|
if cmds.objExists(mesh):
|
|
# 获取混合变形节点名称
|
|
blend_shape = GetBlendShape(mesh)
|
|
|
|
# 获取目标数量
|
|
count = GetBlendShapeTargets(dr="r", tc=mesh_index)
|
|
|
|
# 如果没有混合变形节点且有目标需要创建
|
|
if not cmds.objExists(blend_shape) and count > 0:
|
|
# 构建混合变形节点名称
|
|
blend_shape_name = f"{GetMeshes(i=mesh_index)}_blendShapes"
|
|
|
|
# 设置进度条
|
|
ProgressBar(max=count)
|
|
ProgressBar(t=f"[{blend_shape_name}] Creating Target Mesh...")
|
|
|
|
# 创建混合变形节点
|
|
cmds.blendShape(mesh, name=blend_shape_name)
|
|
|
|
# 创建每个目标
|
|
for index in range(count):
|
|
# 更新进度条
|
|
ProgressBar(apr=1)
|
|
|
|
# 获取目标名称
|
|
bs_name = GetBlendShapeTargets(dr="r", bsn=(mesh_index, index))
|
|
|
|
# 复制模型作为目标
|
|
cmds.duplicate(mesh, returnRootsOnly=True, name=bs_name)
|
|
|
|
# 设置混合变形目标
|
|
SetBlendShapes(ct=mesh_index, index=index, target=bs_name)
|
|
|
|
# 添加到混合变形节点
|
|
cmds.blendShape(
|
|
blend_shape_name,
|
|
edit=True,
|
|
tangentSpace=True,
|
|
target=(mesh, index, bs_name, 1.0),
|
|
weight=(index, 0)
|
|
)
|
|
|
|
# 删除临时目标模型
|
|
cmds.delete(bs_name)
|
|
|
|
# 结束进度条
|
|
ProgressBar(ep=True)
|
|
|
|
# 执行主函数
|
|
if __name__ == "__main__":
|
|
create_blend_shape() |