有些工具或外掛會產生出向這種一個 transform 裡存在多個 shapes 的物件。這可能是為了效能關係或其他因素,不過就可能會造成其他一些軟體,工具,或 renderer 無法正常運作。
以下這段小程式可以幫你把這些shapes 拆成"正常"獨立的物件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as mc | |
import pymel.core as pm | |
def separateShapes(grp=None): | |
grp = grp or mc.ls(sl=1)[0] | |
SUFFIX = "_separated_geo" | |
def getUniqueName(name): | |
newName = name | |
idx = 1 | |
while True: | |
if not mc.objExists(newName): | |
break | |
else: | |
newName = "{0}_{1}".format(name,idx) | |
idx+=1 | |
return newName | |
def getAwesomeName(shapeName): | |
name = str(shapeName).split('|')[-1].split(':')[-1].split('.')[0] | |
name = name + SUFFIX | |
return getUniqueName(name) | |
shapes = mc.ls(grp,dag=1,ni=1,shapes=1) | |
newTrs = [] | |
with pm.UndoChunk(): | |
for eachShape in shapes: | |
newName = getAwesomeName(eachShape) | |
newTr = mc.createNode("transform", name=newName) | |
mc.parent(eachShape, newTr, shape=True, r=True) | |
newTrs.append(newTr) | |
return newTrs | |
separateShapes() |
覺得實用+1
回覆刪除作者已經移除這則留言。
回覆刪除覺得實用+1
回覆刪除