Created
May 27, 2019 09:14
-
-
Save land-Y/61336266985c6764870d8ef91b82f67d 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 cmds | |
def MirrorMesh(): | |
sellist = cmds.ls(selection=1,type="transform", l=1) | |
sellist = getMeshNode(sellist) | |
if len(cmds.ls("Sym_gr")) == 0: | |
parentLoc = cmds.spaceLocator() | |
parentLoc = cmds.rename(parentLoc,"Sym_gr") | |
else: | |
parentLoc = "Sym_gr" | |
cmds.select(sellist) | |
applyMirrorMesh(sellist,"__INST__",parentLoc) | |
def getMeshNode(targetList): | |
rebuildList = [] | |
for item in targetList: | |
if cmds.nodeType(item) == "mesh" or cmds.nodeType(item) == "transform" and "mesh" in [cmds.nodeType(x) for x in cmds.listHistory(item, f=1)]: | |
rebuildList.append(item) | |
return rebuildList | |
def scrapHierarchy(targetList): | |
for item in targetList: | |
if not cmds.listRelatives(item, p=1) == None: | |
cmds.parent(item, world=1) | |
def filteredSuffix(targetList, suffix=""): | |
filteredList = [] | |
for item in targetList: | |
itemName = item.split("|")[-1] | |
if suffix in item: | |
continue | |
if len(cmds.ls("*"+itemName+suffix+"*",l=1,type="transform")) == 0: | |
filteredList.append(item) | |
return filteredList | |
def applyMirrorMesh(targetList, suffix="", parentNode=None): | |
targetList = filteredSuffix(targetList, suffix) | |
dupList = cmds.duplicate(ilf=1, ic=1, rc=1) | |
if len(dupList) > len(targetList): | |
dellist = dupList[len(targetList):len(dupList)] | |
scrapHierarchy(dupList) | |
cmds.delete(dellist) | |
dupList = dupList[:len(targetList)] | |
else: | |
scrapHierarchy(dupList) | |
for i,item in enumerate(dupList): | |
gposList = cmds.xform(item, q=1, ws=1, t=1) | |
grotList = cmds.xform(item, q=1, ws=1, ro=1) | |
gsclList = cmds.xform(item, q=1, ws=1, s=1) | |
m_posx, m_roty, m_rotz, m_sclx = gposList[0]*-1, grotList[1]*-1, grotList[2]*-1, gsclList[0]*-1 | |
cmds.move(m_posx, item, x=1, ws=1) | |
cmds.rotate(m_roty, m_rotz, item, yz=1, ws=1) | |
cmds.scale(m_sclx, item, x=1) | |
item = cmds.rename(item,targetList[i].split("|")[-1]+suffix) | |
if not parentNode == None: | |
cmds.parent(item, parentNode) | |
cmds.select(targetList) | |
MirrorMesh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment