Last active
May 29, 2019 12:54
-
-
Save land-Y/48149252bdf7312391e39ad381732e40 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import maya.cmds as mc | |
class SymIns: | |
def __init__(self, oGr, oIns, oNull): | |
self.oGr = oGr | |
self.oIns = oIns | |
self.oNull = oNull | |
#シンメトリモデルの管理用ノードに親子付け | |
def MakeSym_gr(self): | |
oLs = mc.ls(assemblies=1) | |
if self.oGr in oLs: | |
print ("すでに" + self.oGr + "が存在します") | |
return self.oGr | |
else: | |
#objの中が1ならロケーター、0ならグループ | |
if self.oNull == 0: | |
mc.group(em=1, w=1, n=self.oGr.format(0)) | |
return self.oGr | |
else: | |
mc.spaceLocator(r=True, n=self.oGr.format(0)) | |
oSL = mc.ls(sl=True, dag=True, type='shape') | |
mc.setAttr(oSL[0] + ".visibility", 0) | |
return self.oGr | |
#ポリゴンだけ選択フィルタ | |
def get_mesh_node_list_cmds(self): | |
#ペアレント構造のロングネームをインスタンス名とする | |
oSel = mc.ls(sl=1, type="transform", l=1) | |
nSel = [] | |
for s in oSel: | |
if mc.nodeType(s) == "mesh" or mc.nodeType(s) == "transform" and self.oIns not in s and "mesh" in [mc.nodeType(x) for x in mc.listHistory(s, f=1)]: | |
nSel.append(s) | |
return nSel | |
def DelIns(self, oMesh): | |
for i in oMesh: | |
i = i.strip("|") | |
oLis = [] | |
oLis.append(i) | |
mc.select(i) | |
oIns = mc.listRelatives(s=1) | |
mc.select(oIns) | |
oIns = mc.listRelatives(ap=1) | |
print oIns | |
print oLis | |
if oIns != oLis: | |
oLis = [] | |
oLis.append(oIns[1]) | |
print oLis | |
mc.delete(oLis) | |
else: | |
pass | |
def MakeIns(self, oMesh, oIns): | |
for i in oMesh: | |
i = i.strip("|") | |
oT = mc.xform(i, q=1, ws=1, t=1) | |
oR = mc.xform(i, q=1, ws=1, ro=1) | |
oS = mc.xform(i, q=1, ws=1, s=1) | |
oT[0] = oT[0]*-1 | |
oR[1] = oR[1]*-1 | |
oR[2] = oR[2]*-1 | |
oS[0] = oS[0]*-1 | |
oDup = mc.duplicate(i, rc=1, rr=1, ilf=1, st=1) | |
mc.delete(mc.listRelatives(oDup, ad=1, type='transform')) | |
mc.xform(oDup[0], ws=1, t=(oT)) | |
mc.xform(oDup[0], ws=1, ro=(oR)) | |
mc.xform(oDup[0], ws=1, s=(oS)) | |
#一旦ワールドにペアレントして、Sum_grの子供に、念の為(ペアレントに同名があっても無視)最上位にあるSym_grのみ確認 | |
self.oGr = mc.ls(self.oGr, assemblies=1) | |
mc.parent(oDup+self.oGr) | |
mc.rename(i+oIns, ignoreShape=1) | |
# クラス呼び出し 0でグループ、1でロケーターに親子付け | |
oS = "Sym_gr" | |
oI = "__INS__" | |
SI = SymIns(oS, oI, 0) | |
oMesh = SI.get_mesh_node_list_cmds() | |
SI.MakeSym_gr() | |
SI.DelIns(oMesh) | |
SI.MakeIns(oMesh, oI) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment