MetaFusion/scripts/utils/AddBlendShape.py
2025-02-07 05:10:30 +08:00

27 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
from Core import GetMeshes, GetBlendShape
def AddBlendShape(targetName):
# 获取当前选择的对象
sel = cmds.ls(selection=True)
for obj in sel:
for j in range(50):
meshe = GetMeshes(m=j)
if obj == meshe:
if targetName:
blendShape = GetBlendShape(meshe)
if not cmds.objExists(blendShape):
blendShape = GetMeshes(i=j) + "_blendShapes"
cmds.blendShape(meshe, automatic=True, name=blendShape)
attrWeight = blendShape + ".weight"
currentBlendShapeList = cmds.listAttr(attrWeight, multi=True)
if targetName not in currentBlendShapeList:
cmds.duplicate(meshe, returnRootsOnly=True, name=targetName)
targetIndex = cmds.getAttr(attrWeight, size=True)
cmds.blendShape(blendShape, edit=True, target=(meshe, targetIndex, targetName, 1), weight=(targetIndex, 0))
cmds.delete(targetName)
cmds.select(sel, replace=True)