Python maya.cmds.duplicate() Examples
The following are 24
code examples of maya.cmds.duplicate().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: ml_puppet.py From ml_tools with MIT License | 7 votes |
def snap(node, snapTo): #duplicate the node we want snap dup = mc.duplicate(node, parentOnly=True)[0] #unlock translates and rotates for a in ('.t','.r'): for b in 'xyz': mc.setAttr(dup+a+b, lock=False) mc.parentConstraint(snapTo, dup) for a in ('.t','.r'): for b in ('x','y','z'): try: mc.setAttr(node+a+b, mc.getAttr(dup+a+b)) except StandardError: pass mc.delete(dup)
Example #2
Source File: weight_transfer_multiple.py From SIWeightEditor with MIT License | 6 votes |
def dup_polygon_mesh(self): dup_objs = [] for node in self.copy_mesh: #子供のノード退避用ダミーペアレントを用意 dummy = common.TemporaryReparent().main(mode='create') common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut') #複製 dup = cmds.duplicate(node, rc=True)[0] cmds.bakePartialHistory(dup, pc=True) dup_objs.append(dup) #ウェイト転送 weight.WeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node) weight.WeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node) cmds.bakePartialHistory(dup, ppt=True) #親子付けを戻す common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent') #ダミーペアレントを削除 common.TemporaryReparent().main(dummyParent=dummy, mode='delete') #cmds.select(dup_objs) return dup_objs
Example #3
Source File: normal.py From SISideBar with MIT License | 6 votes |
def convert_edge_lock(): sel = cmds.ls(sl=True, l=True) meshes = common.search_polygon_mesh(sel, serchChildeNode=False) if not meshes: return for mesh in meshes: d_mesh = cmds.duplicate(mesh, rr=True)[0] modeling.setSoftEdge(mesh, angle=120) cmds.transferAttributes(d_mesh, mesh, flipUVs=0, transferPositions=0, transferUVs=0, sourceUvSpace="map1", searchMethod=3, transferNormals=1, transferColors=0, targetUvSpace="map1", colorBorders=1, sampleSpace=5) freeze.main(mesh) cmds.polyNormalPerVertex(mesh, ufn=True) cmds.delete(d_mesh) cmds.select(meshes)
Example #4
Source File: common.py From cmt with MIT License | 5 votes |
def duplicate_chain(start, end, prefix="", suffix="", search_for="", replace_with=""): """Duplicates the transform chain starting at start and ending at end. :param start: The start transform. :param end: The end transform. :param prefix: Prefix to add to the new chain. :param suffix: Suffix to add to the new chain. :param search_for: Search for token :param replace_with: Replace token :return: A list of the duplicated joints, a list of the original joints that were duplicated. """ joint = end joints = [] original_joints = [] while joint: name = "{0}{1}{2}".format(prefix, joint, suffix) if search_for or replace_with: name = name.replace(search_for, replace_with) original_joints.append(joint) duplicate_joint = cmds.duplicate(joint, name=name, parentOnly=True)[0] if joints: cmds.parent(joints[-1], duplicate_joint) joints.append(duplicate_joint) if joint == start: break joint = cmds.listRelatives(joint, parent=True, path=True) if joint: joint = joint[0] else: raise RuntimeError("{0} is not a descendant of {1}".format(end, start)) joints.reverse() original_joints.reverse() return joints, original_joints
Example #5
Source File: modeling.py From SIWeightEditor with MIT License | 5 votes |
def duplicate_with_skin(nodes, parentNode=None): #親子付けがあってもエラーはかないように修正 #print nodes # リストタイプじゃなかったらリストに変換する if not isinstance(nodes, list): nodes = [nodes] dupObjs = [] for node in nodes: #子供のノード退避用ダミーペアレントを用意 dummy = common.TemporaryReparent().main(mode='create') common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut') #複製 dup = cmds.duplicate(node)[0] #ウェイト転送メソッドをSimpleWeightコピペに変更 weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node) weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node) #親子付けを戻す common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent') #ダミーペアレントを削除 common.TemporaryReparent().main(dummyParent=dummy, mode='delete') if parentNode is not None: cmds.parent(dup, parentNode) dupObjs.append(dup) return dupObjs #シーン内、もしくは入力メッシュ内にゼロポリゴンオブジェクトがあるかどうか調べる関数
Example #6
Source File: ml_convertRotationOrder.py From ml_tools with MIT License | 5 votes |
def testAllRotateOrdersForGimbal(obj): #duplicate node without children dup = mc.duplicate(obj, name='temp#', parentOnly=True)[0] tolerences = list() for roo in ROTATE_ORDERS: mc.xform(dup, preserve=True, rotateOrder=roo) tolerences.append(gimbalTolerence(dup)) #delete node mc.delete(dup) return tolerences
Example #7
Source File: blendshape.py From cmt with MIT License | 5 votes |
def transfer_shapes(source, destination, blendshape=None): """Transfers the shapes on the given blendshape to the destination mesh. It is assumed the blendshape indirectly deforms the destination mesh. :param source: Mesh to transfer shapes from. :param destination: Mesh to transfer shapes to. :param blendshape: Optional blendshape node name. If no blendshape is given, the blendshape on the source mesh will be used. :return: The new blendshape node name. """ if blendshape is None: blendshape = get_blendshape_node(source) if blendshape is None: return connections = zero_weights(blendshape) targets = get_target_list(blendshape) new_targets = [] for t in targets: cmds.setAttr("{}.{}".format(blendshape, t), 1) new_targets.append(cmds.duplicate(destination, name=t)[0]) cmds.setAttr("{}.{}".format(blendshape, t), 0) cmds.delete(destination, ch=True) new_blendshape = cmds.blendShape(new_targets, destination, foc=True)[0] cmds.delete(new_targets) for t in targets: cmds.connectAttr( "{}.{}".format(blendshape, t), "{}.{}".format(new_blendshape, t) ) restore_weights(blendshape, connections) return new_blendshape
Example #8
Source File: meshretarget.py From cmt with MIT License | 5 votes |
def retarget(source, target, shapes, rbf=None, radius=0.5, stride=1): """Run the mesh retarget. :param source: Source mesh :param target: Modified source mesh :param shapes: List of meshes to retarget :param rbf: One of the RBF functions. See class RBF :param radius: Smoothing parameter for the rbf :param stride: Vertex stride to sample on the source mesh. Increase to speed up the calculation but less accurate. """ start_time = time.time() source_points = points_to_np_array(source, stride) target_points = points_to_np_array(target, stride) if rbf is None: rbf = RBF.linear weights = get_weight_matrix(source_points, target_points, rbf, radius) for shape in shapes: points = points_to_np_array(shape) n_points = points.shape[0] dist = get_distance_matrix(points, source_points, rbf, radius) identity = np.ones((n_points, 1)) h = np.bmat([[dist, identity, points]]) deformed = np.asarray(np.dot(h, weights)) points = [OpenMaya.MPoint(*p) for p in deformed] dupe = cmds.duplicate( shape, name="{}_{}_{}".format(shape, radius, rbf.__name__) )[0] set_points(dupe, points) end_time = time.time() print("Transferred in {} seconds".format(end_time - start_time))
Example #9
Source File: test_cmt_twist_decomposition.py From cmt with MIT License | 5 votes |
def setUp(self): self.start_joint = cmds.joint(p=(-0.3, -0.5, 0), name="start_joint") self.end_joint = cmds.joint(p=(0.5, 2.0, 0), name="end_joint") cmds.joint( self.start_joint, e=True, oj="xyz", secondaryAxisOrient="yup", zso=True ) cmds.setAttr("{}.jo".format(self.end_joint), 0, 0, 0) self.twist_joint = cmds.duplicate(self.end_joint, name="twist_joint")[0] cmds.delete( cmds.pointConstraint(self.start_joint, self.end_joint, self.twist_joint) ) self.world_plug = "{}.worldMatrix[0]".format(self.twist_joint) self.rest_m = self.local_matrix() self.tx = cmds.getAttr("{}.tx".format(self.twist_joint))
Example #10
Source File: main.py From ssds with MIT License | 5 votes |
def cloneMeshs(meshPaths): cloneMeshPaths = [] cloneGroup = cmds.group(empty = True, world = True, name = 'ssdsResult') cloneGroupSL = om.MGlobal.getSelectionListByName(cloneGroup) cloneGroupFn = om.MFnTransform(cloneGroupSL.getDagPath(0)) for path in meshPaths: mesh = om.MFnMesh(path) meshName = om.MFnDagNode(mesh.parent(0)).name() cloneMeshName = 'ssds:' + meshName sl = om.MSelectionList(); sl.clear() sl.add(path) om.MGlobal.setActiveSelectionList(sl) cmds.duplicate(returnRootsOnly = True, name = cloneMeshName, renameChildren = True) cmds.parent(cloneMeshName, cloneGroup) cmds.setAttr(cloneMeshName + '.inheritsTransform', False) cloneMeshSL = om.MGlobal.getSelectionListByName(cloneMeshName) cloneMeshPath = cloneMeshSL.getDagPath(0) cloneMeshPath.extendToShape() cloneMeshPaths.append(cloneMeshPath) return cloneMeshPaths, cloneGroup
Example #11
Source File: dm2skin.py From dm2skin with The Unlicense | 5 votes |
def createMush(self): mesh = self.sourceField.text() if not mesh: return if cmds.objExists(mesh + '_Mush'): print(mesh + '_Mush already exists!') return cmds.currentTime(cmds.playbackOptions(q=True, min=True)) dup = cmds.duplicate(mesh, inputConnections=True, n=mesh + '_Mush') cmds.deltaMush(dup, smoothingIterations=20, smoothingStep=0.5, pinBorderVertices=True, envelope=1)
Example #12
Source File: modeling.py From SISideBar with MIT License | 5 votes |
def duplicate_with_skin(nodes, parentNode=None): #親子付けがあってもエラーはかないように修正 print nodes # リストタイプじゃなかったらリストに変換する if not isinstance(nodes, list): nodes = [nodes] dupObjs = [] for node in nodes: #子供のノード退避用ダミーペアレントを用意 dummy = common.TemporaryReparent().main(mode='create') common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut') #複製 dup = cmds.duplicate(node)[0] #ウェイト転送メソッドをSimpleWeightコピペに変更 weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node) weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node) #親子付けを戻す common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent') #ダミーペアレントを削除 common.TemporaryReparent().main(dummyParent=dummy, mode='delete') if parentNode is not None: cmds.parent(dup, parentNode) dupObjs.append(dup) return dupObjs #シーン内、もしくは入力メッシュ内にゼロポリゴンオブジェクトがあるかどうか調べる関数
Example #13
Source File: dpUtils.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def zeroOut(transformList=[], offset=False): """ Create a group over the transform, parent the transform in it and set zero all transformations of the transform node. If don't have a transformList given, try to get the current selection. If want to create with offset, it'll be a, offset group between zeroGrp and transform. Return a list of names of the zeroOut groups. """ zeroList = [] if not transformList: transformList = cmds.ls(selection=True) if transformList: for transform in transformList: zeroGrp = cmds.duplicate(transform, name=transform+'_Zero_Grp')[0] zeroUserAttrList = cmds.listAttr(zeroGrp, userDefined=True) if zeroUserAttrList: for zUserAttr in zeroUserAttrList: try: cmds.deleteAttr(zeroGrp+"."+zUserAttr) except: pass allChildrenList = cmds.listRelatives(zeroGrp, allDescendents=True, children=True, fullPath=True) if allChildrenList: cmds.delete(allChildrenList) if offset: offsetGrp = cmds.duplicate(zeroGrp, name=transform+'_Offset_Grp')[0] cmds.parent(transform, offsetGrp, absolute=True) cmds.parent(offsetGrp, zeroGrp, absolute=True) else: cmds.parent(transform, zeroGrp, absolute=True) zeroList.append(zeroGrp) return zeroList
Example #14
Source File: dpBaseClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def duplicateModule(self, *args): """ This module will just do a simple duplicate from Maya because we have a scriptJob to do the creating a new instance setup. """ cmds.duplicate(self.moduleGrp)
Example #15
Source File: modeling.py From SISideBar with MIT License | 4 votes |
def marge_run(self): objects = common.search_polygon_mesh(self.objects, serchChildeNode=True, fullPath=True) print objects #print objects if len(objects) < 2: self.marged_mesh = objects return True skined_list = [] no_skin_list = [] parent_list = [cmds.listRelatives(obj, p=True, f=True) for obj in objects] for obj in objects: skin = cmds.ls(cmds.listHistory(obj), type='skinCluster') if skin: skined_list.append(obj) else: no_skin_list.append(obj) if no_skin_list and skined_list: skined_mesh = skined_list[0] for no_skin_mesh in no_skin_list: weight.transfer_weight(skined_mesh, no_skin_mesh, transferWeight=False, returnInfluences=False, logTransfer=False) if skined_list: marged_mesh = pm.polyUniteSkinned(objects)[0] pm.polyMergeVertex(marged_mesh, d=0.001) target_mesh = pm.duplicate(marged_mesh)[0] weight.transfer_weight(str(marged_mesh), str(target_mesh), transferWeight=True, returnInfluences=False, logTransfer=False) else: marged_mesh = pm.polyUnite(objects, o=True)[0] pm.polyMergeVertex(marged_mesh, d=0.001) target_mesh = pm.duplicate(marged_mesh)[0] #pm.delete(objects) for obj in objects: if pm.ls(obj): pm.delete(obj) pm.delete(marged_mesh) all_attr_list = [['.sx', '.sy', '.sz'], ['.rx', '.ry', '.rz'], ['.tx', '.ty', '.tz']] for p_node in parent_list: if cmds.ls(p_node, l=True): all_lock_list = [] for attr_list in all_attr_list: lock_list = [] for attr in attr_list: lock_list.append(pm.getAttr(target_mesh+attr, lock=True)) pm.setAttr(target_mesh+attr, lock=False) all_lock_list.append(lock_list) pm.parent(target_mesh, p_node[0]) for lock_list, attr_list in zip(all_lock_list, all_attr_list): for lock, attr in zip(lock_list, attr_list): continue pm.setAttr(target_mesh[0]+attr, lock=lock) break pm.rename(target_mesh, objects[0]) pm.select(target_mesh) self.marged_mesh = str(target_mesh) return True
Example #16
Source File: sqStickyLipsSetup.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def sqGenerateCurves(self, *args): self.edgeList = cmds.ls(selection=True, flatten=True) if not self.edgeList == None and not self.edgeList == [] and not self.edgeList == "": self.baseCurve = cmds.polyToCurve(name="baseCurve", form=2, degree=1)[0] cmds.select(self.baseCurve+".ep[*]") cmds.insertKnotCurve(cmds.ls(selection=True, flatten=True), constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() toDeleteList = [] p = 2 for k in range((sideA+2), (sideB-1)): if p%2 == 0: toDeleteList.append(self.baseCurve+".cv["+str(k)+"]") toDeleteList.append(self.baseCurve+".cv["+str(k+len(pointListA)-1)+"]") p = p+1 q = 2 m = sideA-2 if m >= 0: while m >= 0: if not m == sideA and not m == sideB: if q%2 == 0: toDeleteList.append(self.baseCurve+".cv["+str(m)+"]") m = m-1 q = q+1 cmds.delete(toDeleteList) cmds.insertKnotCurve([self.baseCurve+".u["+str(len(pointListA)-1)+"]", self.baseCurve+".ep["+str(len(pointListA)-1)+"]"], constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() posListA, posListB = [], [] for i in range(0, len(pointListA)-1): posListA.append(cmds.xform(pointListA[i], query=True, worldSpace=True, translation=True)) posListB.append(cmds.xform(pointListB[i], query=True, worldSpace=True, translation=True)) self.mainCurveA = cmds.curve(name="StickyLips_Main_A_Crv", degree=1, point=posListA) self.mainCurveB = cmds.curve(name="StickyLips_Main_B_Crv", degree=1, point=posListB) cmds.rename(cmds.listRelatives(self.mainCurveA, children=True, shapes=True)[0], self.mainCurveA+"Shape") cmds.rename(cmds.listRelatives(self.mainCurveB, children=True, shapes=True)[0], self.mainCurveB+"Shape") cmds.select(self.mainCurveA+".cv[*]") self.curveLenght = len(cmds.ls(selection=True, flatten=True)) cmds.select(clear=True) self.sqCheckCurveDirection(self.mainCurveA) self.sqCheckCurveDirection(self.mainCurveB) self.baseCurveA = cmds.duplicate(self.mainCurveA, name=self.mainCurveA.replace("_Main_", "_Base_"))[0] self.baseCurveB = cmds.duplicate(self.mainCurveB, name=self.mainCurveB.replace("_Main_", "_Base_"))[0] cmds.delete(self.baseCurve) self.maxIter = len(posListA) cmds.group(self.mainCurveA, self.mainCurveB, self.baseCurveA, self.baseCurveB, name="StickyLips_StaticData_Grp") else: mel.eval("warning \"Please, select an closed edgeLoop.\";")
Example #17
Source File: modeling.py From SISideBar with MIT License | 4 votes |
def face_extraction(faces=None, deleteOrg=True, selectDuplicated=True, transferWeight=True): ''' メッシュを選択したフェイスで切り分ける deleteOrg 切り分け元のフェイスを削除するかどうかを指定デフォルトTrue faces → 外部ツールからフェイスのリストを渡して実行したい場合の引数 ''' if faces is None: selection = cmds.ls(sl=True) else: selection = faces selObjects = [] for sel in selection: objNameTemp = sel.split('.') if not objNameTemp[0] in selObjects: selObjects.append(objNameTemp[0]) cmds.select(cl=True) duplicated = [] # 最後の選択格納用 # ハイライトされているオブジェクト毎に処理 for selObj in selObjects: # print 'currentObj : ' + str(selObj) compTemp = [] # バラバラのコンポーネントをオブジェクト毎に格納するリスト # 選択されているコンポーネントを整理 for sel in selection: objNameTemp = sel.split('.') objName = objNameTemp[0] # コンポーネントのオブジェクト名 # オブジェクト名が一致且つフェイス選択ならリスト入り if selObj == objName and '.f[' in sel: compTemp.append(sel) # print 'compTemp add : '+str(sel) # print 'compTemp ALL : '+str(compTemp) if len(compTemp) != 0: dupObj = cmds.duplicate(selObj, rr=True) # 子供のオブジェクト取得関数呼び出し children = cmds.listRelatives(dupObj[0], type='transform', ad=True) # 子供のオブジェクトがある場合は重複を避けるため削除 if children: cmds.delete(children) duplicated.append(dupObj[0]) if transferWeight: # ウェイト転送フラグが有効だったら weight.transfer_weight(selObj, dupObj, logTransfer=False) # ウェイトを転送 faces = ",".join(compTemp) # リストを括弧のない文字列に faces = faces.replace(selObj, dupObj[0]) # 名前置き換え delface = faces.split(',') cmds.select(delface, r=True) mel.eval('InvertSelection') # 選択の反転 deleter = cmds.ls(sl=True) cmds.delete(deleter) # 最初に選択されていなかったフェース部分のみ削除 # 削除フラグが立っていたら古いフェイス削除 if deleteOrg is True: cmds.delete(compTemp) if selectDuplicated: cmds.select(duplicated) return duplicated #クラスタデフォーマの書き戻し
Example #18
Source File: ml_worldBake.py From ml_tools with MIT License | 4 votes |
def parentBake(objs, parent=None, bakeOnOnes=False): #check objects can be parented parentReferenced = mc.referenceQuery(parent, isNodeReferenced=True) if parent else False culledObjs = [] for each in objs: eachParent = mc.listRelatives(each, parent=True) if mc.referenceQuery(each, isNodeReferenced=True): if parentReferenced: OpenMaya.MGlobal.displayWarning("Child and parent are both referenced, skipping: {} > {}".format(each, parent)) continue if eachParent and mc.referenceQuery(eachParent[0], isNodeReferenced=True): OpenMaya.MGlobal.displayWarning("Node is referenced and can't be reparented, skipping: {}".format(each)) continue if not parent and not eachParent: OpenMaya.MGlobal.displayWarning("Node is already child of the world, skipping: {}".format(each)) continue culledObjs.append(each) if not culledObjs: OpenMaya.MGlobal.displayWarning("No nodes could be reparented.") return source = [] destination = [] for each in culledObjs: source.append(mc.duplicate(each, parentOnly=True)[0]) mc.copyKey(each) mc.pasteKey(source[-1], option='replaceCompletely') try: if parent: destination.append(mc.parent(each, parent)[0]) else: destination.append(mc.parent(each, world=True)[0]) except RuntimeError as err: mc.delete(source) raise err utl.matchBake(source=source, destination=destination, bakeOnOnes=bakeOnOnes) mc.delete(source)
Example #19
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def transferShape(self, deleteSource=False, clearDestinationShapes=True, sourceItem=None, destinationList=None, applyColor=True, *args): """ Transfer control shape from sourceItem to destination list """ if not sourceItem: selList = cmds.ls(selection=True, type="transform") if selList and len(selList) > 1: # get first selected item sourceItem = selList[0] # get other selected items destinationList = selList[1:] if sourceItem: sourceShapeList = cmds.listRelatives(sourceItem, shapes=True, type="nurbsCurve", fullPath=True) if sourceShapeList: if destinationList: for destTransform in destinationList: needKeepVis = False sourceVis = None dupSourceItem = cmds.duplicate(sourceItem)[0] if applyColor: self.setSourceColorOverride(dupSourceItem, [destTransform]) destShapeList = cmds.listRelatives(destTransform, shapes=True, type="nurbsCurve", fullPath=True) if destShapeList: # keep visibility connections if exists: for destShape in destShapeList: visConnectList = cmds.listConnections(destShape+".visibility", destination=False, source=True, plugs=True) if visConnectList: needKeepVis = True sourceVis = visConnectList[0] break if clearDestinationShapes: cmds.delete(destShapeList) dupSourceShapeList = cmds.listRelatives(dupSourceItem, shapes=True, type="nurbsCurve", fullPath=True) for dupSourceShape in dupSourceShapeList: if needKeepVis: cmds.connectAttr(sourceVis, dupSourceShape+".visibility", force=True) cmds.parent(dupSourceShape, destTransform, relative=True, shape=True) cmds.delete(dupSourceItem) self.renameShape([destTransform]) if deleteSource: # update cvControls attributes: self.transferAttr(sourceItem, destinationList, ["className", "size", "degree", "cvRotX", "cvRotY", "cvRotZ"]) cmds.delete(sourceItem)
Example #20
Source File: ml_puppet.py From ml_tools with MIT License | 4 votes |
def swapAnimation(fromNode, toNode): if not mc.keyframe(fromNode, query=True, name=True): mc.cutKey(toNode, clear=True) return attrs = mc.listAttr(fromNode, keyable=True) if not attrs: return for attr in attrs: if not mc.attributeQuery(attr, node=toNode, exists=True): mc.cutKey(fromNode, attribute=attr, clear=True) continue fromPlug = '{}.{}'.format(fromNode, attr) toPlug = '{}.{}'.format(toNode, attr) srcCurve = mc.listConnections(fromPlug, source=True, destination=False, type='animCurve') dstCurve = mc.listConnections(toPlug, source=True, destination=False, type='animCurve') copySrc=None copyDst=None if srcCurve: copySrc = mc.duplicate(srcCurve[0])[0] if dstCurve: copyDst = mc.duplicate(dstCurve[0])[0] if copySrc: try: mc.cutKey(copySrc) mc.pasteKey(toNode, attribute=attr, option='replaceCompletely') except:pass if copyDst: try: mc.cutKey(copyDst) mc.pasteKey(fromNode, attribute=attr, option='replaceCompletely') except:pass for axis in getMirrorAxis(toNode): mc.scaleKey(toNode, attribute=axis, valueScale=-1) mc.scaleKey(fromNode, attribute=axis, valueScale=-1)
Example #21
Source File: modeling.py From SIWeightEditor with MIT License | 4 votes |
def face_extraction(faces=None, deleteOrg=True, selectDuplicated=True, transferWeight=True): ''' メッシュを選択したフェイスで切り分ける deleteOrg 切り分け元のフェイスを削除するかどうかを指定デフォルトTrue faces → 外部ツールからフェイスのリストを渡して実行したい場合の引数 ''' if faces is None: selection = cmds.ls(sl=True) else: selection = faces selObjects = [] for sel in selection: objNameTemp = sel.split('.') if not objNameTemp[0] in selObjects: selObjects.append(objNameTemp[0]) cmds.select(cl=True) duplicated = [] # 最後の選択格納用 # ハイライトされているオブジェクト毎に処理 for selObj in selObjects: compTemp = [] # バラバラのコンポーネントをオブジェクト毎に格納するリスト # 選択されているコンポーネントを整理 for sel in selection: objNameTemp = sel.split('.') objName = objNameTemp[0] # コンポーネントのオブジェクト名 # オブジェクト名が一致且つフェイス選択ならリスト入り if selObj == objName and '.f[' in sel: compTemp.append(sel) # print 'compTemp ALL : '+str(compTemp) if len(compTemp) != 0: dupObj = cmds.duplicate(selObj, rr=True) # 子供のオブジェクト取得関数呼び出し children = cmds.listRelatives(dupObj[0], type='transform', ad=True) # 子供のオブジェクトがある場合は重複を避けるため削除 if children: cmds.delete(children) duplicated.append(dupObj[0]) if transferWeight: # ウェイト転送フラグが有効だったら weight.transfer_weight(selObj, dupObj, logTransfer=False) # ウェイトを転送 faces = ",".join(compTemp) # リストを括弧のない文字列に faces = faces.replace(selObj, dupObj[0]) # 名前置き換え delface = faces.split(',') cmds.selectMode(co=True) cmds.hilite(dupObj) cmds.select(delface, r=True) #print 'del face :',delface for obj in dupObj: face_count = str(len(common.conv_comp(obj, mode='face'))) cmds.select(obj+'.f[0:'+face_count+']', tgl=True) #mel.eval('InvertSelection;') # 選択の反転 deleter = cmds.ls(sl=True) cmds.delete(deleter) # 最初に選択されていなかったフェース部分のみ削除 # 削除フラグが立っていたら古いフェイス削除 if deleteOrg is True: cmds.delete(compTemp) if selectDuplicated: cmds.select(duplicated) return duplicated #クラスタデフォーマの書き戻し
Example #22
Source File: modeling.py From SIWeightEditor with MIT License | 4 votes |
def marge_run(self): objects = common.search_polygon_mesh(self.objects, serchChildeNode=True, fullPath=True) #print 'marge target :', objects if len(objects) < 2: self.marged_mesh = objects return True skined_list = [] no_skin_list = [] parent_list = [cmds.listRelatives(obj, p=True, f=True) for obj in objects] for obj in objects: skin = cmds.ls(cmds.listHistory(obj), type='skinCluster') if skin: skined_list.append(obj) else: no_skin_list.append(obj) if no_skin_list and skined_list: skined_mesh = skined_list[0] for no_skin_mesh in no_skin_list: weight.transfer_weight(skined_mesh, no_skin_mesh, transferWeight=False, returnInfluences=False, logTransfer=False) if skined_list: marged_mesh = pm.polyUniteSkinned(objects)[0] pm.polyMergeVertex(marged_mesh, d=0.001) target_mesh = pm.duplicate(marged_mesh)[0] weight.transfer_weight(str(marged_mesh), str(target_mesh), transferWeight=True, returnInfluences=False, logTransfer=False) else: marged_mesh = pm.polyUnite(objects, o=True)[0] pm.polyMergeVertex(marged_mesh, d=0.001) target_mesh = pm.duplicate(marged_mesh)[0] #pm.delete(objects) for obj in objects: if pm.ls(obj): pm.delete(obj) pm.delete(marged_mesh) all_attr_list = [['.sx', '.sy', '.sz'], ['.rx', '.ry', '.rz'], ['.tx', '.ty', '.tz']] for p_node in parent_list: if cmds.ls(p_node, l=True): all_lock_list = [] for attr_list in all_attr_list: lock_list = [] for attr in attr_list: lock_list.append(pm.getAttr(target_mesh+attr, lock=True)) pm.setAttr(target_mesh+attr, lock=False) all_lock_list.append(lock_list) pm.parent(target_mesh, p_node[0]) for lock_list, attr_list in zip(all_lock_list, all_attr_list): for lock, attr in zip(lock_list, attr_list): #continue #print 'lock attr :', lock, target_mesh, attr pm.setAttr(target_mesh+attr, lock=lock) break pm.rename(target_mesh, objects[0]) pm.select(target_mesh) self.marged_mesh = str(target_mesh) return True
Example #23
Source File: weight_transfer_multiple.py From SIWeightEditor with MIT License | 4 votes |
def part_transfer(self): self.init_bake_data()#辞書初期化 #print 'part_transfer :', self.transfer_comp temp_node_dict = {} temp_nodes = [] for node in self.hl_nodes: #スキンクラスタがないとき用に元のメッシュにバインド情報だけ移す weight.transfer_weight(self.marged_mesh, node, transferWeight=False) self.adust_skin_influences(node)#インフルエンスを合わせる #ダミーに転写する temp_node = cmds.duplicate(node, rc=True) temp_node = cmds.ls(temp_node, l=True)[0] weight.transfer_weight(self.marged_mesh, temp_node) temp_node_dict[node] = temp_node temp_nodes.append(temp_node) #ダミーと元のウェイトを全取得 cmds.selectMode(o=True) #cmds.select(cl=True) cmds.select(self.hl_nodes, temp_nodes) self.store_weight_data() for node in self.hl_nodes: vtxArray = self.node_vtxArray_dict[node] #print 'node vtx array :', node , vtxArray temp_node = temp_node_dict[node] org_infs = self.influences_dict[node] temp_infs = self.influences_dict[temp_node] #inf_id_list = range(len(org_weights_list[0])) #inf_id_list = [temp_infs.index(inf) for inf in org_infs] #インフルエンスの並び順がずれていることがあるので名前でソートする inf_id_list = [org_infs.index(inf) for inf in temp_infs] # print 'adust weight data ;', node, vtxArray # print 'org_infs :', org_infs # print 'temp_infs :', temp_infs # print 'new_inf_list', inf_id_list #ウェイトを整理する org_weights_list = self.node_weight_dict[node] trans_weights_list = self.node_weight_dict[temp_node] #print 'get org weight :', org_weights_list #print 'get trans weight :', trans_weights_list new_weights = [] org_weights = [] for id in vtxArray: new_weights += trans_weights_list[id] org_weights += org_weights_list[id] #print 'bake inf ids :', inf_id_list #ノードごとのMArray群辞書にキャスト self.bake_node_id_dict[node] += vtxArray self.bake_node_weight_dict[node] += new_weights self.bake_node_inf_dict[node] += inf_id_list self.org_node_weight_dict[node] += org_weights self.undo_node_weight_dict[node] = [org_weights_list[id] for id in vtxArray] self.redo_node_weight_dict[node] = [trans_weights_list[id] for id in vtxArray] self.om_bake_skin_weight() cmds.delete(temp_nodes)
Example #24
Source File: sqStickyLipsSetup.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def sqCreateStikyLipsDeformers(self, *args): baseMesh = None mainCurveList = [self.mainCurveA, self.mainCurveB] for mainCurve in mainCurveList: if baseMesh == None: baseMesh = cmds.duplicate(self.receptList[0], name=self.receptList[0]+"Base")[0] cmds.setAttr(baseMesh+".visibility", 0) wrapNode = cmds.deformer(mainCurve, name="StickyLips_Wrap", type="wrap")[0] try: cmds.connectAttr(self.receptList[0]+".dropoff", wrapNode+".dropoff[0]", force=True) cmds.connectAttr(self.receptList[0]+".inflType", wrapNode+".inflType[0]", force=True) cmds.connectAttr(self.receptList[0]+".smoothness", wrapNode+".smoothness[0]", force=True) cmds.connectAttr(self.receptList[0]+"Shape.worldMesh[0]", wrapNode+".driverPoints[0]", force=True) except: pass cmds.connectAttr(baseMesh+"Shape.worldMesh[0]", wrapNode+".basePoints[0]", force=True) cmds.connectAttr(mainCurve+"Shape.worldMatrix[0]", wrapNode+".geomMatrix", force=True) cmds.setAttr(wrapNode+".maxDistance", 1) cmds.setAttr(wrapNode+".autoWeightThreshold", 1) cmds.setAttr(wrapNode+".exclusiveBind", 1) baseCurveList = [self.baseCurveA, self.baseCurveB] for c, baseCurve in enumerate(baseCurveList): wireNode = cmds.wire(self.receptList[1], name=baseCurve+"_Wire", groupWithBase=False, crossingEffect=0, localInfluence=0)[0] cmds.connectAttr(mainCurveList[c]+"Shape.worldSpace[0]", wireNode+".baseWire[0]", force=True) cmds.connectAttr(baseCurve+"Shape.worldSpace[0]", wireNode+".deformedWire[0]", force=True) self.wireNodeList.append(wireNode) wireLocList = [] for i in range(0, self.maxIter): wireLocList.append(baseCurve+".u["+str(i)+"]") cmds.dropoffLocator(1, 1, wireNode, wireLocList)