Python maya.cmds.skinCluster() Examples
The following are 30
code examples of maya.cmds.skinCluster().
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: dpCopySkin.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def dpCopySkin(self, sourceItem, destinationList, skinInfList, *args): """ Do the copy skin from sourceItem to destinationList using the skinInfList. """ for item in destinationList: # get correct naming skinClusterName = utils.extractSuffix(item) if "|" in skinClusterName: skinClusterName = skinClusterName[skinClusterName.rfind("|")+1:] # create skinCluster node cmds.skinCluster(skinInfList, item, name=skinClusterName+"_SC", toSelectedBones=True, maximumInfluences=3, skinMethod=0) cmds.select(sourceItem) cmds.select(item, toggle=True) # copy skin weights from sourceItem to item node cmds.copySkinWeights(noMirror=True, surfaceAssociation="closestPoint", influenceAssociation=["label", "oneToOne", "closestJoint"]) # log result print self.langDic[self.langName]['i083_copiedSkin'], sourceItem, item
Example #2
Source File: dpCopySkin.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def dpCheckSkinCluster(self, shapeList, *args): """ Verify if there's a skinCluster node in the list of history of the shape. Return True if yes. Return False if no. Return -1 if there's another node with the same name. """ for shapeNode in shapeList: if not shapeNode.endswith("Orig"): try: histList = cmds.listHistory(shapeNode) if histList: for histItem in histList: if cmds.objectType(histItem) == "skinCluster": return True except: return -1 return False
Example #3
Source File: weight_transfer_multiple.py From SIWeightEditor with MIT License | 6 votes |
def pre_transfer_for_noskin_comp(self): reselection_flag = False for node in self.hl_nodes: skin_cluster = cmds.ls(cmds.listHistory(node), type='skinCluster') if not skin_cluster: #print 'pre transfer :', node, self.copy_mesh[0] weight.transfer_weight(self.copy_mesh[0], node, transferWeight=False) cmds.bakePartialHistory(node, ppt=True) reselection_flag = True if reselection_flag: #print 'reselect for undo :' #アンドゥ、リドゥのためにエディタ側のスキン情報を更新しておく cmds.select(self.transfer_comp, r=True) siweighteditor.WINDOW.get_set_skin_weight() #インフルエンス合わせのために転送側の全てのインフルエンスを格納しておく
Example #4
Source File: weight_transfer_multiple.py From SIWeightEditor with MIT License | 6 votes |
def stock_copy_mesh(self): hl_node = cmds.ls(hl=True, l=True) sel_node = cmds.ls(sl=True, l=True) temp_copy_mesh = common.search_polygon_mesh(hl_node+sel_node, fullPath=True) self.copy_mesh = [] for node in temp_copy_mesh: skin_cluster = cmds.ls(cmds.listHistory(node), type='skinCluster') if skin_cluster: self.copy_mesh.append(node) if not self.copy_mesh: cmds.confirmDialog( title='Error', message= self.msg02) return self.msg02 return 'Set Copy Mesh :\n'+str(self.copy_mesh) #print 'copy mesh :',self.copy_mesh
Example #5
Source File: miscFunc.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 6 votes |
def selectInfluenceJoints(): try: sel = cmds.ls(sl=1, ap=1)[0] try: skinNode = utils.findRelatedSkinCluster(sel) infs = cmds.skinCluster(skinNode, q=1, inf=1) except: om.MGlobal.displayError("No skinCluster found in history of %s." % sel) return cmds.select(infs) except: om.MGlobal.displayError("Please select something.") return
Example #6
Source File: ml_copySkin.py From ml_tools with MIT License | 6 votes |
def copySkinComponents(source, destinationVerts): if not mc.listRelatives(source, shapes=True): raise RuntimeError('Source object must be geometry.') sourceSkin = utl.getSkinCluster(source) if not sourceSkin: raise RuntimeError("Source mesh doesn't have a skinCluster to copy from.") destMesh = mc.ls(destinationVerts[0], o=True)[0] destMesh = mc.listRelatives(destMesh, parent=True)[0] destSkin = copySkinInfluences(source, destMesh) tempSet = mc.sets(destinationVerts) mc.select(source, tempSet) mc.copySkinWeights(noMirror=True, surfaceAssociation='closestPoint', influenceAssociation='closestJoint', normalize=True) mc.delete(tempSet) mc.select(destinationVerts)
Example #7
Source File: ml_copySkin.py From ml_tools with MIT License | 6 votes |
def copySkinInfluences(source, dest): sourceSkin = utl.getSkinCluster(source) if not sourceSkin: return False joints = mc.skinCluster(sourceSkin, query=True, influence=True) destSkin = utl.getSkinCluster(dest) if not destSkin: destSkin = mc.skinCluster(joints, dest, toSelectedBones=True)[0] else: destJoints = mc.skinCluster(destSkin, query=True, influence=True) for joint in [x for x in joints if x not in destJoints]: mc.skinCluster(destSkin, edit=True, addInfluence=joint, lockWeights=False, weight=0) return destSkin
Example #8
Source File: skinio.py From cmt with MIT License | 6 votes |
def __init__(self, skin_cluster): """Constructor""" self.node = skin_cluster self.shape = cmds.listRelatives( cmds.deformer(skin_cluster, q=True, g=True)[0], parent=True, path=True )[0] # Get the skinCluster MObject self.mobject = shortcuts.get_mobject(self.node) self.fn = OpenMayaAnim.MFnSkinCluster(self.mobject) self.data = { "weights": {}, "blendWeights": [], "name": self.node, "shape": self.shape, }
Example #9
Source File: main.py From ssds with MIT License | 5 votes |
def bindToSkin(meshPaths, skinIndex, skinWeight, skinJnts, numMaxInfluences): asl = om.MSelectionList() asl.clear() jntNames = [sj.name for sj in skinJnts] for sj in skinJnts: m = om.MMatrix(sj.bindPose.tolist()) m = om.MTransformationMatrix(m) om.MFnTransform(sj.path).setTransformation(m) asl.add(sj.path) offset = 0 for meshPath in meshPaths: mesh = om.MFnMesh(meshPath) sl = om.MSelectionList(asl) sl.add(meshPath) om.MGlobal.setActiveSelectionList(sl) meshName = om.MFnDagNode(mesh.parent(0)).name() skinName = cmds.skinCluster(maximumInfluences = numMaxInfluences, name = meshName + 'Cluster', toSelectedBones = True)[0] skinObj = om.MGlobal.getSelectionListByName(skinName).getDependNode(0) skin = oma.MFnSkinCluster(skinObj) vertexIndices = om.MIntArray(mesh.numVertices, 0) for i in xrange(mesh.numVertices): vertexIndices[i] = i singleIndexedComp = om.MFnSingleIndexedComponent() vertexComp = singleIndexedComp.create(om.MFn.kMeshVertComponent) singleIndexedComp.addElements(vertexIndices) infDags = skin.influenceObjects() numInfDags = len(infDags) infIndices = om.MIntArray(numInfDags, 0) for i in xrange(numInfDags): infIndices[i] = i weights = om.MDoubleArray(mesh.numVertices * numInfDags, 0) for v in xrange(mesh.numVertices): for j, w in zip(skinIndex[offset + v], skinWeight[offset + v]): if j >= 0: weights[v * numInfDags + j] = w skin.setWeights(meshPath, vertexComp, infIndices, weights) offset += mesh.numVertices skin.findPlug('deformUserNormals', True).setBool(False)
Example #10
Source File: weight_transfer_multiple.py From SIWeightEditor with MIT License | 5 votes |
def store_all_influence(self): skin_cluster = cmds.ls(cmds.listHistory(self.marged_mesh), type='skinCluster') if not skin_cluster: return skin_cluster = skin_cluster[0] self.all_influences = cmds.ls(cmds.skinCluster(skin_cluster, q=True, inf=True), l=True) #print 'get all influences', self.all_influences #足りないインフルエンスを追加しておく
Example #11
Source File: weight.py From SIWeightEditor with MIT License | 5 votes |
def symmetry_weight(srcNode=None, dstNode=None, symWeight=True): ''' ウェイトシンメトリする関数 srcNode→反転元 dstNode→反転先 symWeight→ウェイトミラーするかどうか ''' # スキンクラスタを取得 if srcNode is None: return srcShapes = cmds.listRelatives(srcNode, s=True, pa=True, type='mesh') if srcShapes: srcSkinCluster = cmds.ls(cmds.listHistory(srcNode), type='skinCluster') # スキンクラスタがあったらジョイントラベルを設定してウェイトミラー if srcSkinCluster: # バインド状態を転送する関数呼び出し skinJointAll = cmds.skinCluster(srcSkinCluster, q=True, inf=True) #ジョイントを取得 for skinJoint in skinJointAll: # ジョイントラベル設定関数呼び出し joint_label(skinJoint, visibility=False) if symWeight is False or dstNode is None: return transfer_weight(srcNode, dstNode, transferWeight=False, returnInfluences=True) dstShapes = cmds.listRelatives(dstNode, s=True, pa=True, type='mesh') dstSkinCluster = cmds.listConnections(dstShapes[0] + '.inMesh', s=True, d=False) cmds.copySkinWeights(ss=srcSkinCluster[0], ds=dstSkinCluster[0], mirrorMode='YZ', surfaceAssociation='closestComponent', influenceAssociation='label', normalize=True)
Example #12
Source File: ml_resetBind.py From ml_tools with MIT License | 5 votes |
def main(): sel = mc.ls(sl=True) for each in sel: shapes = mc.listRelatives(each, shapes=True) for shape in shapes: #get skin cluster history = mc.listHistory(shape, groupLevels=True, pruneDagObjects=True) skins = mc.ls(history, type='skinCluster') for skin in skins: joints = mc.skinCluster(skin, query=True, influence=True) mc.setAttr(skin+'.envelope', 0) mc.skinCluster(skin, edit=True, unbindKeepHistory=True) #delete bindPose dagPose = mc.dagPose(each, query=True, bindPose=True) if dagPose: mc.delete(dagPose) dagPose = mc.listConnections(skin+'.bindPose', d=False, type='dagPose') if dagPose: mc.delete(dagPose) mc.skinCluster(joints, shape, toSelectedBones=True) mc.setAttr(skin+'.envelope', 1) if sel: mc.select(sel)
Example #13
Source File: ml_softWeights.py From ml_tools with MIT License | 5 votes |
def softSelectionSkinWeights(*args): model = mc.ls(sl=True, o=True) joints = mc.ls(model, type='joint') mc.select(joints, deselect=True) weights = getSoftSelectionWeights() if not model or not joints or not weights: raise RuntimeError('Select vertices followed by a joint') if len(joints) > 1: raise RuntimeError('Only one joint can be selected at a time') joint = joints[0] skin = utl.getSkinCluster(model[0]) if not skin: raise RuntimeError('Mesh must have an existing skinCluster') influences = mc.skinCluster(skin, query=True, influence=True) if joint not in influences: mc.skinCluster(skin, edit=True, addInfluence=joint, lockWeights=False, weight=0) for influence in influences: mc.skinCluster(skin, edit=True, influence=influence, lockWeights=False) for vertex, weight in weights.items(): mc.skinPercent(skin, vertex, transformValue=(joint, weight)) mc.select(joint) # ______________________ # - -/__ Revision History __/- - - - - - - - - - - - - - - - - - - - - - - - # # Revision 1: 2016-12-31 : Initial publish # # Revision 2: 2018-02-17 : Updating license to MIT.
Example #14
Source File: skinio.py From cmt with MIT License | 5 votes |
def gather_data(self): """Gather all the skinCluster data into a dictionary so it can be serialized. :return: The data dictionary containing all the skinCluster data. """ dag_path, components = self.__get_geometry_components() self.gather_influence_weights(dag_path, components) self.gather_blend_weights(dag_path, components) for attr in SkinCluster.attributes: self.data[attr] = cmds.getAttr("%s.%s" % (self.node, attr)) return self.data
Example #15
Source File: skinio.py From cmt with MIT License | 5 votes |
def get_skin_clusters(nodes): """Get the skinClusters attached to the specified node and all nodes in descendents. :param nodes: List of dag nodes. @return A list of the skinClusters in the hierarchy of the specified root node. """ if isinstance(nodes, string_types): nodes = [nodes] all_skins = [] for node in nodes: relatives = cmds.listRelatives(node, ad=True, path=True) or [] relatives.insert(0, node) relatives = [shortcuts.get_shape(node) for node in relatives] for relative in relatives: history = cmds.listHistory(relative, pruneDagObjects=True, il=2) or [] skins = [x for x in history if cmds.nodeType(x) == "skinCluster"] if skins: all_skins.append(skins[0]) return list(set(all_skins))
Example #16
Source File: test_cmt_skinio.py From cmt with MIT License | 5 votes |
def setUp(self): self.joint1 = cmds.joint(p=(-0.5, -0.5, 0)) self.joint2 = cmds.joint(p=(0, 0.0, 0)) self.joint3 = cmds.joint(p=(0.5, 0.5, 0)) self.shape = cmds.polyCube()[0] cmds.delete(self.shape, ch=True) self.skin = cmds.skinCluster(self.joint1, self.joint2, self.joint3, self.shape)[ 0 ] self.expected = { "bindMethod": 1, "blendWeights": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "dropoffRate": 4.0, "heatmapFalloff": 0.0, "maintainMaxInfluences": False, "maxInfluences": 2, "name": u"skinCluster1", "normalizeWeights": 1, "shape": u"pCube1", "skinningMethod": 0, "useComponents": False, "weightDistribution": 0, "weights": { "joint1": [0.9, 0.5, 0.5, 0.0, 0.5, 0.0, 0.9, 0.5], "joint2": [ 0.10000000000000002, 0.5, 0.5, 0.5, 0.5, 0.5, 0.10000000000000002, 0.5, ], "joint3": [0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0], }, }
Example #17
Source File: dm2skin.py From dm2skin with The Unlicense | 5 votes |
def dm2skin_getMaxInfluences(mesh): """Finds a skin cluster on the given mesh and returns the number of influences it is set to have.""" skinClusterStr = 'findRelatedSkinCluster("' + mesh + '")' skinCluster = mel.eval(skinClusterStr) if not skinCluster: return 0 allInfluences = cmds.skinCluster(skinCluster, q=True, inf=True) return len(allInfluences)
Example #18
Source File: dm2skin.py From dm2skin with The Unlicense | 5 votes |
def dm2skin_getNeighbouringJoints(joint, vertexString=None, cluster=None, influences=3): """This gets a list of nearby joints in the skin cluster to joint up to the number of influences. These will be the ones we use in our minimization later""" if not cmds.objExists(joint): return False if influences < 3: return False if not cluster: return False clusterJoints = cmds.skinCluster(cluster, q=True, inf=True) pos1 = cmds.xform(vertexString, q=True, ws=True, t=True) parentJoint = cmds.listRelatives(joint, parent=True) subtract = 1 # add the main joint resultList = [joint] # i've found it works best to always include the parent if parentJoint and parentJoint in clusterJoints: resultList.insert(0, parentJoint[0]) subtract = 2 # for the rest of the available influences get a list of nearby joints in space measureList = [] for measureJnt in clusterJoints: if measureJnt not in resultList: jntPos2 = cmds.xform(measureJnt, q=True, ws=True, t=True) #this just gets the length of the vector between the two joints dist = math.sqrt(reduce(lambda x, y: x + y, [math.pow(jntPos2[i] - pos1[i], 2) for i in range(len(pos1))])) measureList.append((measureJnt, dist)) # sort the list in ascending order so we get the closest joints first measureList.sort(key=lambda dist: dist[1]) ascendingList = [entry[0] for entry in measureList[0:influences - subtract]] return resultList + ascendingList
Example #19
Source File: dm2skin.py From dm2skin with The Unlicense | 5 votes |
def dm2skin_getLargestInfluenceOnVert(vertex, skinCluster=None): """Given a vertex returns the largest influence in the provided skin cluster that acts upon it.""" if not skinCluster: return False vertInfs = cmds.skinCluster(skinCluster, q=True, inf=True) vertVals = cmds.skinPercent(skinCluster, vertex, q=True, value=True) return vertInfs[vertVals.index(max(vertVals))]
Example #20
Source File: skin.py From maya-skinning-tools with GNU General Public License v3.0 | 5 votes |
def getSkinCluster(mesh, joints): """ This function will check if the provided mesh has a skin cluster attached to it. If it doesn't a new skin cluster will be created with the provided joints as influences. No additional arguments are used to setup the skin cluster. This is something that needs to be done afterwards by the user. If a skin cluster already exists all provided joints will be added to the skin cluster as an influence. :param str mesh: :param list joints: :return: Skin cluster :rtype: str """ # full path joints joints = cmds.ls(joints, l=True) # get skin cluster sk = skin.getSkinCluster(mesh) if not sk: # create skin cluster sk = cmds.skinCluster( joints, mesh, dropoffRate=0.1, )[0] else: # make sure all provided joints are an influence of the skin cluster # that is already attached to the mesh influence.addInfluences(sk, joints) return sk
Example #21
Source File: influence.py From maya-skinning-tools with GNU General Public License v3.0 | 5 votes |
def addInfluences(skinCluster, influences): """ Add influences to the skin cluster. Expects full path influences. Will try to reach the bind pose before attached the new influences to the skin cluster. :param str skinCluster: :param list influences: """ # get existing influences existing = cmds.skinCluster(skinCluster, query=True, influence=True) existing = cmds.ls(existing, l=True) # try restoring dag pose try: cmds.dagPose(existing, restore=True, g=True, bindPose=True) except: cmds.warning("Unable to reach dagPose!") # add influences for influence in influences: if influence not in existing: cmds.skinCluster( skinCluster, edit=True, addInfluence=influence, weight=0.0 )
Example #22
Source File: miscFunc.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 5 votes |
def applyRigidSkin(): """""" sel = cmds.ls(sl=1, ap=1) if len(sel) < 2: om.MGlobal.displayError("Please select joints first, then mesh.") return mesh = sel.pop() cmds.skinCluster(sel, mesh, tsb=1, mi=0, nw=1, bm=1) #----------------------------------------------------------------------
Example #23
Source File: weight.py From SISideBar with MIT License | 5 votes |
def symmetry_weight(srcNode=None, dstNode=None, symWeight=True): ''' ウェイトシンメトリする関数 srcNode→反転元 dstNode→反転先 symWeight→ウェイトミラーするかどうか ''' # スキンクラスタを取得 if srcNode is None: return srcShapes = cmds.listRelatives(srcNode, s=True, pa=True, type='mesh') if srcShapes: srcSkinCluster = cmds.ls(cmds.listHistory(srcNode), type='skinCluster') # スキンクラスタがあったらジョイントラベルを設定してウェイトミラー if srcSkinCluster: # バインド状態を転送する関数呼び出し skinJointAll = cmds.skinCluster(srcSkinCluster, q=True, inf=True) #ジョイントを取得 for skinJoint in skinJointAll: # ジョイントラベル設定関数呼び出し joint_label(skinJoint, visibility=False) if symWeight is False or dstNode is None: return transfer_weight(srcNode, dstNode, transferWeight=False, returnInfluences=True) dstShapes = cmds.listRelatives(dstNode, s=True, pa=True, type='mesh') dstSkinCluster = cmds.listConnections(dstShapes[0] + '.inMesh', s=True, d=False) cmds.copySkinWeights(ss=srcSkinCluster[0], ds=dstSkinCluster[0], mirrorMode='YZ', surfaceAssociation='closestComponent', influenceAssociation='label', normalize=True)
Example #24
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def skinFromUI(self, *args): """ Skin the geometries using the joints, reading from UI the selected items of the textScrollLists or getting all items if nothing selected. """ # get joints to be skinned: uiJointSkinList = cmds.textScrollList( self.allUIs["jntTextScrollLayout"], query=True, selectItem=True) if not uiJointSkinList: uiJointSkinList = cmds.textScrollList( self.allUIs["jntTextScrollLayout"], query=True, allItems=True) # check if all items in jointSkinList exists, then if not, show dialog box to skinWithoutNotExisting or Cancel jointSkinList, jointNotExistingList = [], [] for item in uiJointSkinList: if cmds.objExists(item): jointSkinList.append(item) else: jointNotExistingList.append(item) if jointNotExistingList: notExistingJointMessage = self.langDic[self.langName]['i069_notSkinJoint'] +"\n\n"+ ", ".join(str(jntNotExitst) for jntNotExitst in jointNotExistingList) +"\n\n"+ self.langDic[self.langName]['i070_continueSkin'] btYes = self.langDic[self.langName]['i071_yes'] btNo = self.langDic[self.langName]['i072_no'] confirmSkinning = cmds.confirmDialog(title='Confirm Skinning', message=notExistingJointMessage, button=[btYes,btNo], defaultButton=btYes, cancelButton=btNo, dismissString=btNo) if confirmSkinning == btNo: jointSkinList = None # get geometries to be skinned: geomSkinList = cmds.textScrollList( self.allUIs["modelsTextScrollLayout"], query=True, selectItem=True) if not geomSkinList: geomSkinList = cmds.textScrollList( self.allUIs["modelsTextScrollLayout"], query=True, allItems=True) # check if we have repeated listed geometries in case of the user choose to not display long names: if self.validateGeoList(geomSkinList): if jointSkinList and geomSkinList: for geomSkin in geomSkinList: if (args[0] == "Add"): cmds.skinCluster(geomSkin, edit=True, ai=jointSkinList, toSelectedBones=True, removeUnusedInfluence=False, lockWeights=True, wt=0.0) elif (args[0] == "Remove"): cmds.skinCluster(geomSkin, edit=True, ri=jointSkinList, toSelectedBones=True) else: baseName = utils.extractSuffix(geomSkin) skinClusterName = baseName+"_SC" if "|" in skinClusterName: skinClusterName = skinClusterName[skinClusterName.rfind("|")+1:] cmds.skinCluster(jointSkinList, geomSkin, toSelectedBones=True, dropoffRate=4.0, maximumInfluences=3, skinMethod=0, normalizeWeights=1, removeUnusedInfluence=False, name=skinClusterName) print self.langDic[self.langName]['i077_skinned'] + ', '.join(geomSkinList), else: print self.langDic[self.langName]['i029_skinNothing'], ###################### End: Skinning.
Example #25
Source File: uExport.py From uExport with zlib License | 4 votes |
def LOD_transferWeights(meshes, jointsToRemove, jointToTransferTo, debug=1, pruneWeights=0.001, *args): ''' Original function by Charles Anderson @ Epic Games ''' for mesh in meshes: # Find the skin cluster for the current mesh cluster = findCluster(mesh) if debug: print "MESH: ", mesh print "CLUSTER: ", cluster # Prune weights on the current mesh if pruneWeights: cmds.skinPercent(cluster, mesh, prw=pruneWeights) # Find all of the current influences on the current skin cluster. meshInfluences = cmds.skinCluster(cluster, q=True, inf=True) #print "Current Influences: ", meshInfluences for joint in jointsToRemove: if joint in meshInfluences: #print "Current Joint: ", joint # If the jointToTransferTo is not already an influence on the current mesh then add it. currentInfluences = cmds.skinCluster(cluster, q=True, inf=True) if jointToTransferTo not in currentInfluences: cmds.skinCluster(cluster, e=True, wt=0, ai=jointToTransferTo) # Now transfer all of the influences we want to remove onto the jointToTransferTo. for x in range(cmds.polyEvaluate(mesh, v=True)): #print "TRANSFERRING DATA....." value = cmds.skinPercent(cluster, (mesh+".vtx["+str(x)+"]"), t=joint, q=True) if value > 0: cmds.skinPercent(cluster, (mesh+".vtx["+str(x)+"]"), tmw=[joint, jointToTransferTo]) # Remove unused influences currentInfluences = cmds.skinCluster(cluster, q=True, inf=True) #print "Current Influences: ", currentInfluences influencesToRemove = [] weightedInfs = cmds.skinCluster(cluster, q=True, weightedInfluence=True) #print "Weighted Influences: ", weightedInfs for inf in currentInfluences: #print "Influence: ", inf if inf not in weightedInfs: #print "Update Influences to Remove List: ", inf influencesToRemove.append(inf) #print "ToRemove Influences: ", influencesToRemove if influencesToRemove != []: for inf in influencesToRemove: cmds.skinCluster(cluster, e=True, ri=inf) ## UI RELATED ######################################################################## #event filter to grab and discern right/left click
Example #26
Source File: skinio.py From cmt with MIT License | 4 votes |
def export_skin(file_path=None, shapes=None): """Exports the skinClusters of the given shapes to disk. :param file_path: Path to export the data. :param shapes: Optional list of dag nodes to export skins from. All descendent nodes will be searched for skinClusters also. """ if shapes is None: shapes = cmds.ls(sl=True) or [] # If no shapes were selected, export all skins skins = get_skin_clusters(shapes) if shapes else cmds.ls(type="skinCluster") if not skins: raise RuntimeError("No skins to export.") if file_path is None: if len(skins) == 1: file_path = shortcuts.get_save_file_name( "Skin Files (*{})".format(EXTENSION), KEY_STORE ) else: file_path = shortcuts.get_directory_name(KEY_STORE) if not file_path: return directory = file_path if len(skins) > 1 else os.path.dirname(file_path) if not os.path.exists(directory): os.makedirs(directory) for skin in skins: skin = SkinCluster(skin) data = skin.gather_data() if len(skins) > 1: # With multiple skinClusters, the user just chooses an export directory. Set the # name to the transform name. file_path = os.path.join( directory, "{}{}".format(skin.shape.replace("|", "!"), EXTENSION) ) logger.info( "Exporting skinCluster %s on %s (%d influences, %d vertices) : %s", skin.node, skin.shape, len(data["weights"].keys()), len(data["blendWeights"]), file_path ) with open(file_path, "w") as fh: json.dump(data, fh)
Example #27
Source File: ml_centerOfMass.py From ml_tools with MIT License | 4 votes |
def createCenterOfMass(*args): ''' Create a center of mass node, and constrain it to the character based on the selected root node. ''' sel = mc.ls(sl=True) if not len(sel) == 1: raise RuntimeError('Please select the root control of your puppet.') print 'Create Center Of Mass Node' print '--------------------------' meshes = meshesFromReference(sel[0]) or meshesFromHistory(sel[0]) if not meshes: raise RuntimeError('Could not determine geometry from selected control. Make sure geo is visible.') mc.select(meshes) mc.refresh() print 'Discovered Meshes:' for mesh in meshes: print '\t',mesh skinnedMeshes = [] for mesh in meshes: if utl.getSkinCluster(mesh): skinnedMeshes.append(mesh) continue hist = mc.listHistory(mesh, breadthFirst=True) skins = mc.ls(hist, type='skinCluster') if not skins: warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh)) continue outGeo = mc.listConnections(skins[0]+'.outputGeometry[0]', source=False) outGeo = mc.ls(outGeo, type=['mesh','transform']) if not outGeo: warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh)) continue skinnedMeshes.append(outGeo[0]) if not skinnedMeshes: raise RuntimeError('Could not determine skinned geometry from selected control. This tool will only work if geo is skinned.') locator = centerOfMassLocator(skinnedMeshes) mc.addAttr(locator, longName=COM_ATTR, attributeType='message') mc.connectAttr('.'.join((sel[0],'message')), '.'.join((locator,COM_ATTR))) mc.select(sel) return locator
Example #28
Source File: weight.py From SIWeightEditor with MIT License | 4 votes |
def toggle_mute_skinning(): msg01 = lang.Lang( en='No mesh selection.\nWould you like to process all of mesh in this scene?.', ja=u'選択メッシュがありません。\nシーン内のすべてのメッシュを処理しますか?').output() msg02 = lang.Lang(en='Yes', ja=u'はい').output() msg03 = lang.Lang(en='No', ja=u'いいえ').output() msg04 = lang.Lang( en='Skinning is disabled', ja=u'スキニングは無効になりました') .output() msg05 = lang.Lang( en='Skinning is enabled', ja=u'スキニングが有効になりました') .output() cmds.selectMode(o=True) objects = cmds.ls(sl=True, l=True) ad_node = [] for node in objects: children = cmds.ls(cmds.listRelatives(node, ad=True, f=True), type ='transform') ad_node += [node]+children #print len(ad_node) objects = set(ad_node) #print len(objects) if not objects: all_mesh = cmds.confirmDialog(m=msg01, t='', b= [msg02, msg03], db=msg02, cb=msg03, icn='question',ds=msg03) if all_mesh == msg02: objects = cmds.ls(type='transform') if not objects: return mute_flag = 1 skin_list = [] for node in objects: skin = cmds.ls(cmds.listHistory(node), type='skinCluster') if not skin: continue skin_list.append(skin) if cmds.getAttr(skin[0]+'.envelope') > 0: mute_flag = 0 for skin in skin_list: cmds.setAttr(skin[0]+'.envelope', mute_flag) if mute_flag == 0: cmds.confirmDialog(m=msg04) if mute_flag == 1: cmds.confirmDialog(m=msg05)
Example #29
Source File: weight.py From SISideBar with MIT License | 4 votes |
def toggle_mute_skinning(): msg01 = lang.Lang( en='No mesh selection.\nWould you like to process all of mesh in this scene?.', ja=u'選択メッシュがありません。\nシーン内のすべてのメッシュを処理しますか?').output() msg02 = lang.Lang(en='Yes', ja=u'はい').output() msg03 = lang.Lang(en='No', ja=u'いいえ').output() msg04 = lang.Lang( en='Skinning is disabled', ja=u'スキニングは無効になりました') .output() msg05 = lang.Lang( en='Skinning is enabled', ja=u'スキニングが有効になりました') .output() cmds.selectMode(o=True) objects = cmds.ls(sl=True, l=True) ad_node = [] for node in objects: children = cmds.ls(cmds.listRelatives(node, ad=True, f=True), type ='transform') ad_node += [node]+children #print len(ad_node) objects = set(ad_node) #print len(objects) if not objects: all_mesh = cmds.confirmDialog(m=msg01, t='', b= [msg02, msg03], db=msg02, cb=msg03, icn='question',ds=msg03) if all_mesh == msg02: objects = cmds.ls(type='transform') if not objects: return mute_flag = 1 skin_list = [] for node in objects: skin = cmds.ls(cmds.listHistory(node), type='skinCluster') if not skin: continue skin_list.append(skin) if cmds.getAttr(skin[0]+'.envelope') > 0: mute_flag = 0 for skin in skin_list: cmds.setAttr(skin[0]+'.envelope', mute_flag) if mute_flag == 0: cmds.confirmDialog(m=msg04) if mute_flag == 1: cmds.confirmDialog(m=msg05)
Example #30
Source File: dpCopySkin.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def dpMain(self, *args): """ Main function to analise and call copy skin process. """ selList = cmds.ls(selection=True) if selList and len(selList) > 1: # get first selected item sourceItem = selList[0] # get other selected items destinationList = selList[1:] # validade unique node name if len(cmds.ls(sourceItem)) == 1: shapeList = cmds.listRelatives(sourceItem, shapes=True) if shapeList: # check if there's a skinCluster node connected to the first selected item checkSkin = self.dpCheckSkinCluster(shapeList) if checkSkin == True: # get joints influence from skinCluster skinInfList = cmds.skinCluster(sourceItem, query=True, influence=True) if skinInfList: # call copySkin function self.dpCopySkin(sourceItem, destinationList, skinInfList) elif checkSkin == -1: mel.eval("warning \""+self.langDic[self.langName]["i163_sameName"]+" "+sourceItem+"\";") else: print self.langDic[self.langName]['e007_notSkinFound'] else: print self.langDic[self.langName]['e006_firstSkinnedGeo'] else: mel.eval("warning \""+self.langDic[self.langName]["i163_sameName"]+" "+sourceItem+"\";") else: print self.langDic[self.langName]['e005_selectOneObj']