def cMuscle_setupSystemforRelative(ms): shapes = pm.deformer(ms, q=True, geometry=True) if shapes: shape = shapes[0] rels = cMuscle_getDeformers('cMuscleRelative', shape) if len(rels) >= 1: rel = rels[0] else: rels = pm.deformer(shape, type='cMuscleRelative', frontOfChain=True) skins = cMuscle_getDeformers('skinCluster', shape) rel.point.connect(ms.relativePoint) ms.relativeSticky.set(1) msg = mel.eval('uiRes("m_cMuscle.kSetupMuscleSystemForRelativeStickyDeformation")') pm.format(msg, stringArg=ms.name()) print msg return rel
def cMuscle_connectToSystem(systems): if len(systems) <= 0: pm.warning(mel.eval('uiRes("m_cMuscle.kMustSelectMuscleObjectsAndMuscleSystemDeformerOrGeometry")')) mOs = pm.listRelatives(systems, shapes=True, ni=True, type='cMuscleObject') hist = pm.listHistory(systems, il=1, pdo=True) muscleSystems = pm.ls(hist, type='cMuscleSystem') muscleSystems = list(set(muscleSystems)) if len(mOs) <= 0: pm.warning(mel.eval('uiRes("m_cMuscle.kMustSelectMuscleObject2")')) if len(muscleSystems) <= 0: pm.warning(mel.eval('uiRes("m_cMuscle.kMustSelectMuscleSystem2")')) maxDist, hasNurbs, avgDist = -1, 0, 0.0 for mo in mOs: if mo.type() == 1: avgDist += mel.eval('cMuscle_autoCalcStickyBindDistance(%s)'%mo) hasNurbs+=1 break distMode = 0 #Only query for Max Dist if adding NURBs in. if hasNurbs: avgDist = avgDist/hasNurbs labelAutoCalculate = mel.eval('uiRes("m_cMuscle.kAutoCalculate")') labelAvgValue = mel.eval('uiRes("m_cMuscle.kAvgValue")') labelAllPoints = mel.eval('uiRes("m_cMuscle.kAllPoints")') labelCancel = mel.eval('uiRes("m_cMuscle.kCancel2")') result = pm.promptDialog( title = mel.eval('uiRes("m_cMuscle.kStickyBindMaximumDistance")'), message = mel.eval('uiRes("m_cMuscle.kMaxDistanceFromCenterOfMuscle")'), text = avgDist, button = [labelAutoCalculate,labelAvgValue,labelAllPoints,labelCancel], defaultButton = labelAutoCalculate , cancelButton = labelCancel, dismissString = labelCancel) if result == labelCancel: return maxDist = pm.promptDialog(q=True, text=True) if result == labelAllPoints or maxDist == -1: distMode, maxDist = 0, -1 elif result == labelAutoCalculate or maxDist == 0: distMod, maxDist = 1, 0 elif result == lableAvgValue: distMode = 2 else: return for muscleSystem in muscleSystems: muscleSystem.envelope.set(0.0) for mo in mOs: parents = mo.listRelatives(p=True) xform = parents[0] if distMode == 1: maxDist = cMuscle_autoCalcStickyBindDistance(mo) for muscleSystem in muscleSystems: muscleSystem.envelope.set(0.0) existMuscles = pm.cMuscleQuery(system=muscleSystem, muscle=True) alreadyConnected=0 if existMuscles: for existMuscle in existMuscles: if mo==e: alreadyConnected=1 break if alreadyConnected: msg = mel.eval('uiRes("m_cMuscle.kMuscleObjectAlreadyConnectedToMuscleNode")') msg = pm.format( msg, stringArg=[mo, muscleSystem] ) pm.warning( msg, sl=0 ) break musIdxs = pm.cMuscleQuery(system=muscleSystem, muscle=True, index=True) musIdxs = sort(musIdxs) idx, done = 0,0 for index in musIdx: if index != musIdxs[index]: idx=index done=1 break cons = mo.worldMatrixStartBase.listConnections(s=True, d=False, p=0, scn=1) hasBase=0 if cons[0] != '': hasBase=1 pm.select(xform, r=True) mel.eval('cMuscle_resetBindPose(%s, 0)'%hasBase) mo.muscleData.connect(muscleSystem.muscleData[idx], f=True) mel.eval('cMuscle_bindSticky(%s, %s, %f)'%(mo,muscleSystem,maxDist))