101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import maya.cmds as cmds
|
|
from Core import GetMeshes
|
|
|
|
def del_blend_shape(mesh_index, in_tgt_grp):
|
|
"""
|
|
删除指定网格的混合变形目标组
|
|
|
|
参数:
|
|
mesh_index (int): 网格索引
|
|
in_tgt_grp (int): 目标组索引
|
|
"""
|
|
# 获取混合变形节点名称
|
|
bsn = f"{GetMeshes(i=mesh_index)}_blendShapes"
|
|
|
|
# 检查节点是否存在
|
|
if not cmds.objExists(bsn):
|
|
return
|
|
|
|
# 检查目标组是否被锁定
|
|
weight_attr = f"{bsn}.weight[{in_tgt_grp}]"
|
|
if cmds.getAttr(weight_attr, lock=True):
|
|
cmds.warning(f"There is no such attribute: {weight_attr}")
|
|
return
|
|
|
|
# 移除组合变形(如果存在)
|
|
source = cmds.connectionInfo(f"{bsn}.w[{in_tgt_grp}]", sourceFromDestination=True)
|
|
if source:
|
|
source_parts = source.split('.')
|
|
if len(source_parts) == 2:
|
|
if cmds.nodeType(source_parts[0]) == "combinationShape":
|
|
cmds.delete(source_parts[0])
|
|
|
|
# 处理父目录关系
|
|
parent_dir_attr = f"{bsn}.parentDirectory[{in_tgt_grp}]"
|
|
parent_directory = cmds.getAttr(parent_dir_attr)
|
|
|
|
if parent_directory > 0:
|
|
child_indices_attr = f"{bsn}.targetDirectory[{parent_directory}].childIndices"
|
|
child_indices = cmds.getAttr(child_indices_attr)
|
|
|
|
try:
|
|
location = child_indices.index(in_tgt_grp)
|
|
if location + 1 < len(child_indices):
|
|
next_target_attr = f"{bsn}.nextTarget[{in_tgt_grp}]"
|
|
cmds.setAttr(next_target_attr, child_indices[location + 1])
|
|
except ValueError:
|
|
pass
|
|
|
|
# 移除权重数组中的元素
|
|
attrs_to_remove = [
|
|
f"{bsn}.weight[{in_tgt_grp}]",
|
|
f"{bsn}.parentDirectory[{in_tgt_grp}]",
|
|
f"{bsn}.nextTarget[{in_tgt_grp}]",
|
|
f"{bsn}.targetVisibility[{in_tgt_grp}]",
|
|
f"{bsn}.targetParentVisibility[{in_tgt_grp}]"
|
|
]
|
|
|
|
for attr in attrs_to_remove:
|
|
cmds.removeMultiInstance(attr, b=True)
|
|
|
|
# 处理输入目标
|
|
input_target_attr = f"{bsn}.inputTarget"
|
|
input_target_indices = cmds.getAttr(input_target_attr, multiIndices=True) or []
|
|
|
|
# 检查是否需要重置
|
|
needs_reset = False
|
|
for index in input_target_indices:
|
|
target_index_attr = f"{bsn}.inputTarget[{index}].sculptTargetIndex"
|
|
if cmds.getAttr(target_index_attr) == in_tgt_grp:
|
|
needs_reset = True
|
|
break
|
|
|
|
# 如果需要重置,设置雕刻目标为-1
|
|
if needs_reset:
|
|
cmds.sculptTarget(bsn, e=True, target=-1)
|
|
|
|
# 处理每个输入目标
|
|
for index in input_target_indices:
|
|
# 移除目标组内的每个输入目标项
|
|
item_attr = f"{bsn}.inputTarget[{index}].inputTargetGroup[{in_tgt_grp}].inputTargetItem"
|
|
item_indices = cmds.getAttr(item_attr, multiIndices=True) or []
|
|
|
|
for item_index in item_indices:
|
|
cmds.blendShapeDeleteInBetweenTarget(bsn, in_tgt_grp, item_index)
|
|
|
|
# 移除目标组内的每个目标权重
|
|
weights_attr = f"{bsn}.inputTarget[{index}].inputTargetGroup[{in_tgt_grp}].targetWeights"
|
|
cmds.removeMultiInstance(weights_attr, b=True, allChildren=True)
|
|
|
|
# 移除整个目标组
|
|
group_attr = f"{bsn}.inputTarget[{index}].inputTargetGroup[{in_tgt_grp}]"
|
|
cmds.removeMultiInstance(group_attr, b=True)
|
|
|
|
# 移除别名(如果存在)
|
|
weight_attr = f"{bsn}.weight[{in_tgt_grp}]"
|
|
alias = cmds.aliasAttr(weight_attr, query=True)
|
|
if alias:
|
|
cmds.aliasAttr(f"{bsn}.{alias}", remove=True) |