def multi_polyQuad(): args,counter = pm.ls(sl=True),1 w=400 window = pm.window(w=w,h=40) pm.columnLayout() progressMessage=pm.text(l='Running through Objects...',w=w) argName=pm.text(l='',w=w) progressControl = pm.progressBar(isInterruptable=True, beginProgress=True, maxValue=len(args), width=w) window.show() for arg in args: if pm.progressBar(progressControl, query=True, isCancelled=True ) : break progressMessage.setLabel('Cleaning up then Quadding object '+str(counter)+'/'+str(len(args))+':') argName.setLabel(arg) pm.select(arg,r=True) #cleanup mesh mel.eval('polyCleanupArgList 3 { "0","1","0","0","0","0","0","0","0","1e-05","0","1e-05","0","1e-05","0","1","0" };') #quad all polies pm.polyQuad(arg, a=30, kgb=False, ktb=False,khe=False,ws=True,ch=False) #merge all verts pm.polyMergeVertex((arg+'.vtx[0:'+str(pm.polyEvaluate(arg,v=True))+']'), d=.001,am=True,ch=0) pm.polyNormalPerVertex(arg,ufn=True) pm.polySoftEdge(arg,angle=68, ch=0) pm.progressBar(progressControl, edit=True, step=1) counter+=1 pm.progressBar(progressControl, edit=True, endProgress=True) pm.select(args, r=True) pm.selectMode(o=True) window.delete()
def PerlinNoiseFiller( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() Divisions = 15 Vmin = FMin Vmax = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to a random value weighted by the sum of its location for v in range(len(ObjectVerts)): loc = pm.xform( ObjectVerts[v], query=True, translation=True, worldSpace=True ) RawValue = PerlinNoise((loc[0]*200),(loc[1]*300),(loc[2]*250), Divisions) ModValue = math.fabs(math.cos(RawValue/10.0)) FValue = max(min(ModValue, Vmax), Vmin) pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def f3DNoise( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() min = FMin max = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) RandomVerts = list(ObjectVerts) random.shuffle(RandomVerts) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to a random value weighted by the sum of its location for v in range(len(ObjectVerts)): loc = pm.xform( RandomVerts[v], query=True, translation=True, worldSpace=True ) locValue = math.sqrt(abs(random.choice(loc))) RValue = random.uniform( min, max ) FValue = (locValue * RValue)/2 pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def MergeVertices(self): #select all objects in the scene pmc.select(all=True) #change selection mode to component pmc.selectMode(component=True) pmc.selectType(v=True)
def import_component(file_path, selected_object): """ This function opens the selected file and reads the information from the file :param file_path: :param selected_object: :return: """ try: f = open(file_path, 'r') except: pm.confirmDialog( t='Error', b=['OK'], m='Unable to read file: %s' % file_path ) raise component = cPickle.load(f) f.close() # this list is for storing the unmatched component ID's err_comps = [] # selected objects name if selected_object is None: selected_object = get_selected_object() else: None # this list is for storing the component ID's with the name of the object selection = [] # clearing any selection on the mesh pm.select(clear=True) # this for loop is for merging and the storing the component ID's with the object ID unmatched ID's is gonna be # stored in errComps list. for compValue in component: try: selection.append(selected_object+"."+compValue) except: try: err_comps.append(compValue[0]) except: err_comps.append(compValue) # changing the select mode into component mode pm.selectMode(component=True) # changing the hilite visibility to true pm.hilite(selected_object, r=True) # this is for checking the component types and changing the selection type to the chosen component if component[0].startswith("vtx["): pm.selectType(pv=True) elif component[0].startswith("vtxFace["): pm.selectType(pvf=True) elif component[0].startswith("e["): pm.selectType(pe=True) elif component[0].startswith("f["): pm.selectType(pf=True) else: None # applying the selection by using the list pm.select(selection, r=True) # checks the component errors if any if len(err_comps) > 0: import_error_window(err_comps) sys.stderr.write('Not all components could be loaded.') return selected_object
def selectNextItem(self): ''' ''' if self.txt_jntCurrent.getLabel() == 'Select mouth lips loop': self.txt_jntCurrent.setLabel('Select left eyelid loop') fullRefPath = self.imageRefPath + "LT_eyeLidLoop.jpg" pm.image(self.img_jntReference, image=fullRefPath, e=True) # assign selection to placement_grp attr sel = pm.ls(sl=True, fl=True) self.placementGrp.addAttr('mouthLipsLoop', dt='stringArray') self.placementGrp.attr('mouthLipsLoop').set(len(sel), *sel, type='stringArray') pm.select(cl=True) placementGrp.addMouthLoopPlacements(self.placementGrp) elif self.txt_jntCurrent.getLabel() == 'Select left eyelid loop': # READY! self.txt_jntCurrent.setLabel('Ready to Build!') fullRefPath = self.imageRefPath + "default.jpg" pm.image(self.img_jntReference, image=fullRefPath, e=True) self.btn_jntScrollRt.setEnable(False) self.btn_updateLocs.setEnable(True) self.btn_buildRig.setEnable(True) pm.setToolTo('selectSuperContext') # assign selection to placement_grp attr sel = pm.ls(sl=True, fl=True) self.placementGrp.addAttr('leftEyelidLoop', dt='stringArray') self.placementGrp.attr('leftEyelidLoop').set(len(sel), *sel, type='stringArray') placementGrp.addEyeLoopPlacements(self.placementGrp) # override for mathilda # placementGrp.addEyeLoopPlacements(self.placementGrp, [23,15,9,3]) # mathilda_override # pm.PyNode('LT_innerUpper_eyelid_pLoc').cv_id.set(18) placementGrp.addIndependentPlacers(self.placementGrp, self.indMapping) # align jaw pLoc cons = mc.aimConstraint('CT__mouthMover_pLoc', 'CT__jaw_pLoc', aim=[0, 0, 1], u=[1, 0, 0], wu=[1, 0, 0]) mc.delete(cons) pm.selectMode(object=True) mel.setObjectPickMask("Surface", False) placementGrp.snapPlacementsToMesh(self.placementGrp) placementGrp.mirrorAllPlacements(self.placementGrp) placementGrp.orientAllPlacements(self.placementGrp)
def editJointPivotTool(self): objs = pm.selected() pm.selectMode(co=True) pm.selectType(ra=True) pm.select(objs[0].rotateAxis, r=True) rotateCtx = pm.manipRotateContext(psc=pm.Callback(self.editJointPivotExit, objs)) pm.setToolTo(rotateCtx)
def cleanLaminaFaces(*args): mel.eval( 'polyCleanupArgList 3 { "1","1","0","0","0","0","0","0","0","1e-005","0","1e-005","0","1e-005","0","-1","1" }' ) pm.selectMode(object=True) pm.select(cl=True) return 'ok'
def cleanNonManifold(*args): mel.eval( 'polyCleanupArgList 3 { "1","1","0","0","0","0","0","0","0","1e-005","0","1e-005","0","1e-005","0","1","0" }' ) pm.selectMode(object=True) pm.select(cl=True) return 'ok'
def shadowMesh(triCount=10000): meshArg = pm.ls(sl=True) meshList = pm.duplicate(meshArg, rr=True) shadowGeo = pm.polyUnite(meshList, ch=False, name='ShadowGeo')[0] pm.delete(meshList) #deleting leftover garbage transform nodes pm.parent(shadowGeo, 'CharaA') newSkinClust = pm.skinCluster( shadowGeo, pm.listRelatives('CharaA', ad=True, type='joint')) #skinning begins pm.select(meshArg) pm.select(shadowGeo, add=True) pm.copySkinWeights( noMirror=True, surfaceAssociation='closestPoint', influenceAssociation='closestJoint') #copying skin weights pm.selectMode(o=True) #shadowmesh starts here pm.select(shadowGeo) mel.eval( 'polyCleanupArgList 3 { "0","1","1","0","0","0","0","0","0","1e-005","0","1e-005","0","1e-005","0","1","0" };' ) #clean up before reduction pm.selectMode(o=True) #reduce polycount to fall under budget pm.polyReduce(shadowGeo, ver=1, trm=2, triangleCount=triCount, sharpness=0, keepBorder=1, keepColorBorder=1, keepFaceGroupBorder=1, keepHardEdge=1, keepCreaseEdge=1, keepBorderWeight=0.5, keepMapBorderWeight=0, keepColorBorderWeight=0, keepFaceGroupBorderWeight=0, keepHardEdgeWeight=0.25, keepCreaseEdgeWeight=0, useVirtualSymmetry=0, symmetryTolerance=0.01, sx=0, sy=1, sz=0, sw=0, preserveTopology=1, keepQuadsWeight=1, vertexMapName="", replaceOriginal=1, cachingReduce=1, constructionHistory=1) pm.select(deselect=True) pm.bakePartialHistory(shadowGeo, prePostDeformers=True, preDeformers=True) pm.select(shadowGeo) print('EKKO shadowMesh successful!\nShadow Mesh specs:') print(pm.polyEvaluate(shadowGeo, fmt=True))
def setComponentSelectType(self, enabled=True, keys={}): pm.selectMode(component=True) kwargs = {} for k in keys: kwargs[k] = enabled for k in self.allkeys: if not kwargs.has_key(k): kwargs[k] = not enabled pm.selectType(**kwargs)
def select_cmd(self): """This command activates when the user selects any file. it keeps the file name and find the path using the directory path :return: None """ self.selectedFile = pm.textScrollList("txtScrlLs", q=True, si=True)[0] self.selectedFile, ID = self.selectedFile.split(" ") self.checkList = str(self.characterList + self.selectedFile + ".cse") pm.selectMode(component=True)
def double_click_cmd(self): """This command activates when the user double-clicks the file from the scroll list. It looks that the mesh object selected to activate the selection. :return: None """ pm.selectMode(object=True) if not self.get_s_object(): self.selectedObject = None self.selectedObject = import_component(self.checkList, self.selectedObject) populate_characters(self.dirName, self.selectedCharacter, self.characterList, self.selectedFile) else: import_component(self.checkList, self.selectedObject) populate_characters(self.dirName, self.selectedCharacter, self.characterList, self.selectedFile)
def rtb_toggle_select_mode(*args, **kwargs): if pm.control(prefix + '_symbolButton_select_mode', exists=True): componentMode = pm.selectMode(query=True, component=True) if not componentMode: pm.selectMode(component=True) pm.symbolButton(prefix + '_symbolButton_select_mode', edit=True, image='selectByComponent.png') else: pm.selectMode(object=True) pm.symbolButton(prefix + '_symbolButton_select_mode', edit=True, image='selectByObject.png')
def switchSelectType(cls, type, *args, **kwargs): ''' ''' if type == 'mesh': pm.selectMode(object=True) if type == 'vtx': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshVertex=True) if type == 'e': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshEdge=True) if type == 'f': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshFace=True)
def selectNextItem(self): ''' ''' if self.txt_jntCurrent.getLabel() == 'Select mouth lips loop': self.txt_jntCurrent.setLabel('Select left eyelid loop') fullRefPath = self.imageRefPath + "LT_eyeLidLoop.jpg" pm.image(self.img_jntReference, image=fullRefPath, e=True) # assign selection to placement_grp attr sel = pm.ls(sl=True, fl=True) self.placementGrp.addAttr('mouthLipsLoop', dt='stringArray') self.placementGrp.attr('mouthLipsLoop').set(len(sel), *sel, type='stringArray') pm.select(cl=True) placementGrp.addMouthLoopPlacements(self.placementGrp) elif self.txt_jntCurrent.getLabel() == 'Select left eyelid loop': # READY! self.txt_jntCurrent.setLabel('Ready to Build!') fullRefPath = self.imageRefPath + "default.jpg" pm.image(self.img_jntReference, image=fullRefPath, e=True) self.btn_jntScrollRt.setEnable(False) self.btn_updateLocs.setEnable(True) self.btn_buildRig.setEnable(True) pm.setToolTo('selectSuperContext') # assign selection to placement_grp attr sel = pm.ls(sl=True, fl=True) self.placementGrp.addAttr('leftEyelidLoop', dt='stringArray') self.placementGrp.attr('leftEyelidLoop').set(len(sel), *sel, type='stringArray') placementGrp.addEyeLoopPlacements(self.placementGrp) # override for mathilda # placementGrp.addEyeLoopPlacements(self.placementGrp, [23,15,9,3]) # mathilda_override # pm.PyNode('LT_innerUpper_eyelid_pLoc').cv_id.set(18) placementGrp.addIndependentPlacers(self.placementGrp, self.indMapping) # align jaw pLoc cons = mc.aimConstraint('CT__mouthMover_pLoc', 'CT__jaw_pLoc', aim=[0,0,1], u=[1,0,0], wu=[1,0,0]) mc.delete(cons) pm.selectMode(object=True) mel.setObjectPickMask("Surface", False) placementGrp.snapPlacementsToMesh(self.placementGrp) placementGrp.mirrorAllPlacements(self.placementGrp) placementGrp.orientAllPlacements(self.placementGrp)
def loop_to_joints(s=0.025): """Convert a mesh loop edge selection to a nurbs curve that has joints (w/ tweak controls) at each vertex. Opens dialog for naming.""" edges = pmc.selected(flatten=True) cage = edges[0].node() try: n = make_dialog("Name of this curve/region?") + "{}" except TypeError: pmc.warning("Aborted.") return c = pmc.PyNode(pmc.polyToCurve(n=n.format("_rider"))[0]) verts = set([v for e in edges for v in e.connectedVertices()]) grp = pmc.group(em=True, n=n.format("_grp")) c.setParent(grp) jn = "" for i, v in enumerate(verts): pmc.select(c) pmc.selectMode(component=True) pmc.select(c.u[i]) pmc.refresh() jn = make_dialog("Name of this joint?", jn) poci = pmc.nt.PointOnCurveInfo(n=n.format(jn + "_poci")) c.ws >> poci.inputCurve poci.parameter.set(i) ctrl_grp = pmc.group(em=True, n=n.format(jn + "_offset")) ctrl_grp.setParent(grp) ctrl = pmc.sphere(r=s, s=1, nsp=1, ch=0, n=n.format(jn + "_tweakCtrl"))[0] ctrl.setParent(ctrl_grp) j = pmc.joint(n=n.format(jn + "_rig")) j.setParent(ctrl) j.hide() poci.position >> ctrl_grp.translate nCon = pmc.normalConstraint(cage, ctrl_grp) poci.nt >> nCon.worldUpVector # remove graph cluster nCon.crp.disconnect() nCon.crt.disconnect() nCon.cro.disconnect() nCon.cpim.disconnect() nCon.ct.disconnect() poci.position >> nCon.constraintTranslate grp.wim >> nCon.cpim pmc.selectMode(object=True)
def add_to_selection_btn_cmd(self, *args): """This function gets the new selection of the components from the mesh and adds the selected file's stored components into the same selection :return: None """ selected_list = pm.ls(sl=True, fl=True) pm.select(cl=True) if pm.selectMode(q=True, object=True): None else: pm.selectMode(object=True) obj = get_selected_object() import_component(self.checkList, self.selectedObject) pm.select(selected_list, add=True) pm.selectMode(component=True) pm.hilite(obj, r=True) populate_characters(self.dirName, self.selectedCharacter, self.characterList, self.selectedFile)
def shadowMesh(arg = 2, triCount = 10000): #please ask kaneko-san to select all the mesh to be exported again shadowGeo = oneSkin(arg) print('EKKO shadowMesh in progress! Performing poly reduction now!') #shadowmesh starts here pm.selectMode(o = True) pm.select(shadowGeo) mel.eval('polyCleanupArgList 3 { "0","1","1","0","0","0","0","0","0","1e-005","0","1e-005","0","1e-005","0","1","0" };') #clean up before reduction pm.selectMode(o = True) #reduce polycount to fall under budget pm.polyReduce(shadowGeo, ver = 1, trm = 2, triangleCount = triCount, sharpness = 0, keepBorder = 1, keepColorBorder = 1, keepFaceGroupBorder = 1, keepHardEdge = 1, keepCreaseEdge = 1, keepBorderWeight = 0.5, keepMapBorderWeight = 0, keepColorBorderWeight = 0, keepFaceGroupBorderWeight = 0, keepHardEdgeWeight = 0.25, keepCreaseEdgeWeight = 0, useVirtualSymmetry = 0, symmetryTolerance = 0.01, sx = 0, sy = 1, sz = 0, sw = 0, preserveTopology = 1, keepQuadsWeight = 1, vertexMapName = "", replaceOriginal = 1, cachingReduce = 1, constructionHistory = 1) pm.select(deselect = True) pm.bakePartialHistory(shadowGeo, prePostDeformers = True, preDeformers = True) renamedGeo = pm.rename(shadowGeo, 'ShadowGeo') pm.select(renamedGeo) print('EKKO shadowMesh successful!\nShadow Mesh specs:') print(pm.polyEvaluate(shadowGeo, fmt = True))
def SetMiddleGrey( NObject ): NObjName = '%s' % NObject.name() # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to 0.5 Grey for v in range(len(ObjectVerts)): pm.polyColorPerVertex( ObjectVerts[v], colorRGB=(0.5,0.5,0.5), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def combineClean(instanceGroup, meshName, duplicateFaces=False): print("Combining mesh") mesh = pm.polyUnite(instanceGroup, name=meshName, constructionHistory=False) #print( "Merging %i" % len( mesh[ 0 ].vtx ) + " verticies" ) pm.polyMergeVertex(mesh[0].vtx, distance=0.1) #print( "Reduced to %i" % mesh[ 0 ].numVertices() + " verticies" ) if duplicateFaces: print("Cleaning up faces") pm.select(mesh[0]) pm.selectType(polymeshFace=True) pm.polySelectConstraint(mode=3, type=0x0008, topology=2) # Don't ask me how I did this mel.eval( 'polyCleanupArgList 3 { "0","2","0","0","0","0","0","0","0","1e-005","0","1e-005","1","0.3","0","-1","1" };' ) pm.delete() pm.polySelectConstraint(mode=0, topology=0) pm.selectType(polymeshFace=False) pm.selectMode(object=True) print("Faces reduced") if pm.PyNode(instanceGroup).exists(): pm.delete(instanceGroup) pm.delete(constructionHistory=True) pm.select(clear=True) print("Cleaning up complete") return mesh
def combineClean( instanceGroup, meshName, duplicateFaces = False ): print( "Combining mesh" ) mesh = pm.polyUnite( instanceGroup, name = meshName, constructionHistory = False ) #print( "Merging %i" % len( mesh[ 0 ].vtx ) + " verticies" ) pm.polyMergeVertex( mesh[ 0 ].vtx, distance = 0.1 ) #print( "Reduced to %i" % mesh[ 0 ].numVertices() + " verticies" ) if duplicateFaces: print( "Cleaning up faces" ) pm.select( mesh[ 0 ] ) pm.selectType( polymeshFace = True ) pm.polySelectConstraint( mode = 3, type = 0x0008, topology = 2 ) # Don't ask me how I did this mel.eval('polyCleanupArgList 3 { "0","2","0","0","0","0","0","0","0","1e-005","0","1e-005","1","0.3","0","-1","1" };') pm.delete() pm.polySelectConstraint( mode = 0, topology = 0 ) pm.selectType( polymeshFace = False ) pm.selectMode( object = True ) print( "Faces reduced" ) if pm.PyNode( instanceGroup ).exists(): pm.delete( instanceGroup ) pm.delete( constructionHistory = True ) pm.select( clear = True ) print( "Cleaning up complete" ) return mesh
def switchSelectionModeToEdge(item): ''' :Reference: doMenuComponentSelection in C:/Program Files/Autodesk/Maya2017/scripts/others/dagMenuProc.mel ''' pm.mel.eval('HideManipulators') if pm.selectMode(q=True, object=True): pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, edge=True) pm.selectType(edge=True) pm.hilite(item) else: pm.selectType(alc=False) pm.selectType(edge=True) not pm.selectMode(q=True, preset=True) or pm.hilite(item) try: not pm.mel.eval('exists dR_selTypeChanged') or pm.mel.eval( 'dR_selTypeChanged("edge")') except pm.MelError: pass
def SimpleNoise( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() min = FMin max = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to 0.5 Grey for v in range(len(ObjectVerts)): FValue = random.uniform( min, max ) pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def editJointPivotExit(self, objects): pm.select(objects, r=True) pm.selectMode(o=True)
def resetSelectionMasking(self): pm.selectMode(component=True) pm.selectMode(object=True) pm.mel.selectionMaskResetAll()
def setObjectSelectType(self, enabled, keys): pm.selectMode(object=True) kwargs = {} for k in keys: kwargs[k] = enabled pm.selectType(**kwargs)
def build(): ''' ''' mesh = nt.Mesh(u'CT_face_geoShape') placementGrp = nt.Transform(u'CT_placement_grp') #---------------------------------------------------------------------- bind if 'bind' in data.build_actions: bindGrp = face.createBndsFromPlacement(placementGrp) pm.refresh() else: bindGrp = nt.Transform(u'CT_bnd_grp') #--------------------------------------------------------- sec motion system if 'sec_motion_system' in data.build_actions: face.buildSecondaryControlSystem(placementGrp, bindGrp, mesh) pm.refresh() #------------------------------------------------------------ pri ctl system first if 'primary_ctl_system_first' in data.build_actions: # run a simple first pass # which can be used to block out mappings bndsForPriCtls = data.all_bnds_for_priCtls priCtl.setupPriCtlFirstPass(bindGrp, bndsForPriCtls) priCtl.driveAttachedPriCtlsRun(bindGrp) #------------------------------------------------------------ pri ctl system second if 'primary_ctl_system_second' in data.build_actions: if data.priCtlMappings: # if priCtlMappings is set up, use the data priCtlMappings = data.priCtlMappings priCtl.setupPriCtlSecondPass(priCtlMappings) priCtl.driveAttachedPriCtlsRun(bindGrp) pm.refresh() else: pm.warning('no data for pri ctl system') #-------------------------------------------------------------- load weights if 'load_weights' in data.build_actions: priCtlWeights = data.priCtlWeights priCtl.setPriCtlSecondPassWeights(priCtlWeights) pm.refresh() #--------------------------------------------------------------------- clean if 'clean' in data.build_actions: print 'clean' face.cleanFaceRig() pm.select(cl=True) pm.refresh() #--------------------------------------------------------------- skin_layers if 'skin_layers' in data.build_actions: mll = skin.setupSkinLayers(None, layers=[ 'base', 'jaw', 'cheeks', 'crease', 'lips', 'mouthbag', 'nose', 'brow' ]) _, skn = mll.getTargetInfo() pm.PyNode(skn).skinningMethod.set(1) pm.PyNode(skn).deformUserNormals.set(0) #---------------------------------------------------------------------- eyes if 'eyes' in data.build_actions: buildEyeRig(placementGrp) #------------------------------------------------------------------ eyeballs if 'eyeballs' in data.build_actions: #------------------------------------------ EYEBALL RIG (SIMPLE AIM CONSTRAINTS) eye.buildEyeballRig() eye.addEyeAim(prefix='LT_', distance=25) # BROKEN if there is already a # node named LT_eyeball_grp!!! eye.addEyeAim(prefix='RT_', distance=25) # BROKEN #--------------------------------------------------------------- fleshy_eyes if 'fleshy_eyes' in data.build_actions: import rigger.modules.poseReader as poseReader reload(poseReader) xfo = pm.PyNode('LT_eyeball_bnd') poseReader.radial_pose_reader(xfo) xfo = pm.PyNode('RT_eyeball_bnd') poseReader.radial_pose_reader(xfo) eye.addFleshyEye() #--------------------------------------------------------------- sticky lips if 'sticky_lips' in data.build_actions: import rigger.modules.sticky as sticky reload(sticky) sticky.Sticky(up_bnd=pm.PyNode('CT_upper_lip_bnd'), low_bnd=pm.PyNode('CT_lower_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperSide_lip_bnd'), low_bnd=pm.PyNode('LT_lowerSide_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperSneer_lip_bnd'), low_bnd=pm.PyNode('LT_lowerSneer_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperPinch_lip_bnd'), low_bnd=pm.PyNode('LT_lowerPinch_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperSide_lip_bnd'), low_bnd=pm.PyNode('RT_lowerSide_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperSneer_lip_bnd'), low_bnd=pm.PyNode('RT_lowerSneer_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperPinch_lip_bnd'), low_bnd=pm.PyNode('RT_lowerPinch_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.addStickyToFRS() sticky.patchOldSticky() #----------------------------------------------------------------- auto_sdks if 'auto_sdks' in data.build_actions: import utils.rigging as rt pCtl = pm.PyNode('CT__mouthMover_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'child', suffix='_autoRotate') rt.connectSDK(pCtl.tx, offsetGrp.ry, {-1.2: -15, 0: 0, 1.2: 15}) rt.connectSDK(pCtl.tx, offsetGrp.rz, {-1.2: -12, 0: 0, 1.2: 12}) rt.connectSDK(pCtl.tx, offsetGrp.tz, {-1.2: 0.4, 0: 0, 1.2: 0.4}) # squint pCtl = pm.PyNode('LT__squint_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'parent', suffix='_autoVolume') rt.connectSDK(pCtl.ty, offsetGrp.tz, {0: 0, 1: 0.5}) pCtl = pm.PyNode('RT__squint_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'parent', suffix='_autoVolume') rt.connectSDK(pCtl.ty, offsetGrp.tz, {0: 0, 1: 0.5}) # inbrow import rigger.modules.secCtl as secCtl reload(secCtl) sCtl = pm.PyNode('LT_in_brow_ctrl') offsetGrp = secCtl.addOffset(sCtl, 'parent', suffix='_autoVolume') rt.connectSDK(sCtl.tx, offsetGrp.tz, {0: 0, -1: 0.2}) sCtl = pm.PyNode('RT_in_brow_ctrl') offsetGrp = secCtl.addOffset(sCtl, 'parent', suffix='_autoVolume') rt.connectSDK(sCtl.tx, offsetGrp.tz, {0: 0, 1: 0.2}) if 'finish_mathilda' in data.build_actions: # a few mathilda specific things to finalize rig # for demo reel purposes # 1. lock all TZs for better volume allCtls = pm.ls('*_ctrl', type='transform') for ctl in allCtls: ctl.tz.set(l=True, k=False) # 2. hide eye aim locators eyeAimLocs = [ nt.Transform(u'LT_eye_aim_loc'), nt.Transform(u'RT_eye_aim_loc') ] for loc in eyeAimLocs: loc.v.set(False) # 3. go to object mode so we can select controls pm.selectMode(object=True) # 4. bind tongue and teeth geos = [ nt.Transform(u'CT_lowerGums_geo'), nt.Transform(u'CT_tongue_geo'), nt.Transform(u'CT_lowerTeeth_geo') ] for geo in geos: pm.parentConstraint(pm.PyNode('CT__jaw_bnd'), geo, mo=True) ''' # 5. reference all geos to make it easier to select controls allGeos = pm.PyNode('CT_geo_grp').getChildren(ad=True, type='mesh') for geo in allGeos: geo.overrideEnabled.set(True) geo.overrideDisplayType.set(True) ''' # 6. smooth face mesh to make it look nicer pm.PyNode('CT_face_geoShape').displaySmoothMesh.set(2)
def build(): ''' ''' mesh = nt.Mesh(u'CT_face_geoShape') placementGrp = nt.Transform(u'CT_placement_grp') #---------------------------------------------------------------------- bind if 'bind' in data.build_actions: bindGrp = face.createBndsFromPlacement(placementGrp) pm.refresh() else: bindGrp = nt.Transform(u'CT_bnd_grp') #--------------------------------------------------------- sec motion system if 'sec_motion_system' in data.build_actions: face.buildSecondaryControlSystem(placementGrp, bindGrp, mesh) pm.refresh() #------------------------------------------------------------ pri ctl system first if 'primary_ctl_system_first' in data.build_actions: # run a simple first pass # which can be used to block out mappings bndsForPriCtls = data.all_bnds_for_priCtls priCtl.setupPriCtlFirstPass(bindGrp, bndsForPriCtls) priCtl.driveAttachedPriCtlsRun(bindGrp) #------------------------------------------------------------ pri ctl system second if 'primary_ctl_system_second' in data.build_actions: if data.priCtlMappings: # if priCtlMappings is set up, use the data priCtlMappings = data.priCtlMappings priCtl.setupPriCtlSecondPass(priCtlMappings) priCtl.driveAttachedPriCtlsRun(bindGrp) pm.refresh() else: pm.warning('no data for pri ctl system') #-------------------------------------------------------------- load weights if 'load_weights' in data.build_actions: priCtlWeights = data.priCtlWeights priCtl.setPriCtlSecondPassWeights(priCtlWeights) pm.refresh() #--------------------------------------------------------------------- clean if 'clean' in data.build_actions: print 'clean' face.cleanFaceRig() pm.select(cl=True) pm.refresh() #--------------------------------------------------------------- skin_layers if 'skin_layers' in data.build_actions: # initial bind mll = skin.setupSkinLayers(None, layers=[['base', None]]) # split masks for up and low lips upVerts, lowVerts = skin.splitLipsVertices(mll) mll = skin.setupSkinLayers(mll, layers=[['neck', None], ('jaw', lowVerts), ('cheeks', upVerts), ('chin', lowVerts), ('crease', upVerts), ('lips', None), ('nose', None), ('brow', None) ]) _, skn = mll.getTargetInfo() pm.PyNode(skn).skinningMethod.set(1) pm.PyNode(skn).deformUserNormals.set(0) #---------------------------------------------------------------------- eyes if 'eyes' in data.build_actions: buildEyeRig(placementGrp) #------------------------------------------------------------------ eyeballs if 'eyeballs' in data.build_actions: #------------------------------------------ EYEBALL RIG (SIMPLE AIM CONSTRAINTS) eye.buildEyeballRig() eye.addEyeAim(prefix='LT_', distance=25) # BROKEN if there is already a # node named LT_eyeball_grp!!! eye.addEyeAim(prefix='RT_', distance=25) # BROKEN #--------------------------------------------------------------- fleshy_eyes if 'fleshy_eyes' in data.build_actions: import rigger.modules.poseReader as poseReader reload(poseReader) xfo = pm.PyNode('LT_eyeball_bnd') poseReader.radial_pose_reader(xfo) xfo = pm.PyNode('RT_eyeball_bnd') poseReader.radial_pose_reader(xfo) eye.addFleshyEye() #--------------------------------------------------------------- sticky lips if 'sticky_lips' in data.build_actions: import rigger.modules.sticky as sticky reload(sticky) sticky.Sticky(up_bnd=pm.PyNode('CT_upper_lip_bnd'), low_bnd=pm.PyNode('CT_lower_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperSide_lip_bnd'), low_bnd=pm.PyNode('LT_lowerSide_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperSneer_lip_bnd'), low_bnd=pm.PyNode('LT_lowerSneer_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('LT_upperPinch_lip_bnd'), low_bnd=pm.PyNode('LT_lowerPinch_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperSide_lip_bnd'), low_bnd=pm.PyNode('RT_lowerSide_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperSneer_lip_bnd'), low_bnd=pm.PyNode('RT_lowerSneer_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.Sticky(up_bnd=pm.PyNode('RT_upperPinch_lip_bnd'), low_bnd=pm.PyNode('RT_lowerPinch_lip_bnd'), center=pm.PyNode('CT__jaw_pri_ctrl')) sticky.addStickyToFRS() sticky.patchOldSticky() #----------------------------------------------------------------- auto_sdks if 'auto_sdks' in data.build_actions: import utils.rigging as rt pCtl = pm.PyNode('CT__mouthMover_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'child', suffix='_autoRotate') rt.connectSDK(pCtl.tx, offsetGrp.ry, {-1.2:-15, 0:0, 1.2:15}) rt.connectSDK(pCtl.tx, offsetGrp.rz, {-1.2:-12, 0:0, 1.2:12}) rt.connectSDK(pCtl.tx, offsetGrp.tz, {-1.2:0.4, 0:0, 1.2:0.4}) # squint pCtl = pm.PyNode('LT__squint_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'parent', suffix='_autoVolume') rt.connectSDK(pCtl.ty, offsetGrp.tz, {0:0, 1:0.5}) pCtl = pm.PyNode('RT__squint_pri_ctrl') offsetGrp = priCtl.addOffset(pCtl, 'parent', suffix='_autoVolume') rt.connectSDK(pCtl.ty, offsetGrp.tz, {0:0, 1:0.5}) # inbrow import rigger.modules.secCtl as secCtl reload(secCtl) sCtl = pm.PyNode('LT_in_brow_ctrl') offsetGrp = secCtl.addOffset(sCtl, 'parent', suffix='_autoVolume') rt.connectSDK(sCtl.tx, offsetGrp.tz, {0:0, -1:0.2}) sCtl = pm.PyNode('RT_in_brow_ctrl') offsetGrp = secCtl.addOffset(sCtl, 'parent', suffix='_autoVolume') rt.connectSDK(sCtl.tx, offsetGrp.tz, {0:0, 1:0.2}) if 'finish_mathilda' in data.build_actions: # a few mathilda specific things to finalize rig # for demo reel purposes # 1. lock all TZs for better volume allCtls = pm.ls('*_ctrl', type='transform') for ctl in allCtls: ctl.tz.set(l=True, k=False) # 2. hide eye aim locators eyeAimLocs = [nt.Transform(u'LT_eye_aim_loc'), nt.Transform(u'RT_eye_aim_loc')] for loc in eyeAimLocs: loc.v.set(False) # 3. go to object mode so we can select controls pm.selectMode(object=True) # 4. bind tongue and teeth ''' geos = [nt.Transform(u'CT_lowerGums_geo'), nt.Transform(u'CT_tongue_geo'), nt.Transform(u'CT_lowerTeeth_geo')] ''' geos = [nt.Transform(u'CT_tongue_geo'), nt.Transform(u'CT_lowerTeeth_geo')] for geo in geos: pm.parentConstraint(pm.PyNode('CT__jaw_bnd'), geo, mo=True) '''
def editJointPivotExit(self, objects): pm.select(objects, r=True) # self.freezeRotation() pm.selectMode(o=True)
def oneSkin(arg = 2): meshArg = pm.ls(sl = True) if len(meshArg) == 1: pm.confirmDialog(title = 'Error', message = 'Mesh is already one skin') return if arg == 0:#arg = 0 don't retain old data. weightGeo = pm.polyUniteSkinned(meshArg, ch = True, mergeUVSets = True) #[0] is the mesh, [1] is the skindata charaGeo = pm.duplicate(weightGeo[0], name = 'CharaGeo') newSkinClust = pm.skinCluster(charaGeo, pm.skinCluster(weightGeo[1], q = True, influence = True)) #skin object pm.select(weightGeo) pm.select(charaGeo, add = True) pm.copySkinWeights(noMirror = True, surfaceAssociation = 'closestComponent', influenceAssociation = 'oneToOne') #copying skin weights pm.delete(meshArg, weightGeo) pm.parent(charaGeo, world = True) print('EKKO oneSkin successful!') return charaGeo elif arg == 1: #retain data meshDupe = pm.duplicate(meshArg, rr = True) skinDictionary = {} counter = 0 for i in meshArg: skinDictionary[i] = meshDupe[counter] counter += 1 for i in meshArg: pm.skinCluster(skinDictionary[i], pm.skinCluster(i, q = True, influence = True)) #copy skin first for i in meshArg: pm.select(i) pm.select(skinDictionary[i], add = True) pm.copySkinWeights(noMirror = True, surfaceAssociation = 'closestComponent', influenceAssociation = 'closestJoint') #copying skin weights charaGeo = pm.polyUniteSkinned(meshDupe, ch = False) #charaGeo[0] is the mesh/transform, [1] is the skin node pm.parent(charaGeo[0], world = True) renamedGeo = pm.rename(charaGeo[0], 'CharaGeo') pm.delete(meshDupe) #deleting garbage data print('EKKO oneSkin successful!') return renamedGeo elif arg == 2: #original method, if mesh is unclean and keeps crashing meshList = pm.duplicate(meshArg, rr = True) charaGeo = pm.polyUnite(meshList, ch = False, name = 'CharaGeo')[0] pm.delete(meshList) #deleting leftover garbage transform nodes pm.parent(charaGeo, world = True) newSkinClust = pm.skinCluster(charaGeo, pm.ls(type = 'joint')) #skinning begins pm.select(meshArg) pm.select(charaGeo, add = True) pm.copySkinWeights(noMirror = True, surfaceAssociation = 'closestPoint', influenceAssociation = 'closestJoint') #copying skin weights pm.selectMode(o = True) pm.select(deselect = True) pm.select(charaGeo) print('EKKO oneSkin successful!') return charaGeo print('EKKO oneSkin successful!')