def __init__(self, obj, deleteOldShapeGrp=True): # Create backup Group self.shapeGrp = pm.group(n='oldShape_GRP', em=True) self.shapeGrp.visibility.set(0) # Get Shape and skin from Object skinCluster = skin.findRelatedSkinCluster(obj) if skinCluster: self.skin = skinCluster else: print('Missing SkinCluster') # Get joint influence of the skin influnces = self.skin.getInfluence(q=True) # influences is joint for joint in influnces: constraint = pm.listRelatives(joint, children=True, type='constraint') if constraint: ctrl, jnt = util.getDriverDrivenFromConstraint(constraint[0]) # duplicate mesh for a control emptyTransform, ctrlShape = self.duplicateSourceMesh(obj=obj, ctrl=ctrl) # move new shape under control and delete empty transform self.moveShapeAndbackUp(source=ctrlShape, destination=ctrl) pm.delete(emptyTransform) # connect control shape to skinCluster self.connectSkinCluster(ctrlShape, ctrl) # delete faces in the new shape based on selected joint self.deleteVertex(joint=joint, newShape=ctrlShape) # delete non deformer history common.deleteNonDeformerHistory(ctrlShape) # prevent chidlren selection hilight shape = ctrl[0].getShape() ctrl[0].selectionChildHighlighting.set(0) shape.selectionChildHighlighting.set(0) if deleteOldShapeGrp: pm.delete(self.shapeGrp) print('DONE!')
def deleteVertex(self, joint, newShape, threshold=0.45): verts = [] skincluster = skin.findRelatedSkinCluster(newShape) for x in range(pm.polyEvaluate(newShape, v=1)): v = pm.skinPercent(skincluster, '%s.vtx[%d]' % (newShape, x), transform=joint, q=1) if v > threshold: verts.append('%s.vtx[%d]' % (newShape, x)) pm.select(verts) faces = pm.polyListComponentConversion(verts, fromVertex=True, toFace=True) # pm.select(faces) toDelete = invertSelection(newShape, faces) pm.polyDelFacet(toDelete, ch=False)
def __init__(self, geo, doParentCnst=True, threshold=0.45): self.proxyGeoList = [] pivotLocator = pm.spaceLocator(n='pivotGeo_LOC') # Create proxy geo Group self.shapeGrp = pm.group(n='fastGeo_GRP', em=True) # Get Shape and skin from Object skinCluster = skin.findRelatedSkinCluster(geo) if not skinCluster: print('Missing SkinCluster') else: self.skin = skinCluster # Get joint influence of the skin influnces = self.skin.getInfluence(q=True) # influences is joint for joint in influnces: # duplicate mesh for a control transform, dupliShape = self.duplicateSourceMesh(obj=geo, joint=joint) common.centerPivot(transform, pivotLocator) # copy skinCluster skin.copyBind(pm.ls(geo)[0], transform) # delete faces in the new shape based on selected joint self.deleteVertex(joint=joint, newShape=dupliShape, threshold=threshold) # delete non deformer history common.deleteHistory(dupliShape) # parent under proxy group pm.parent(transform, self.shapeGrp) self.proxyGeoList.append(transform) # parentConstraint with joint if doParentCnst: pm.parentConstraint(joint, transform, mo=True) # delete pivot locator pm.delete(pivotLocator)
def __init__(self, cvList, skinGeo, prefix='face', headJnt='head_JNT', pointsNumber=5, scale=0.1, baseRig=None ): """ Build Facial Setup :param cvList: list of facial curves :param prefix: str, prefix to name new objects :param rigScale: float, scale factor for size of controls :param baseRig: instance of base.module.Base class """ cvList = pm.ls(cvList) skinGeo = pm.ls(skinGeo)[0] headJnt = pm.ls(headJnt)[0] # make rig module self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig) # attributes self.spacing = 1.0 / (pointsNumber - 1) # setup deformation # geo setup faceGeo = pm.duplicate(skinGeo, n=prefix + '_GEO')[0] pm.parent(faceGeo, self.rigmodule.partsNoTransGrp) deform.blendShapeDeformer(skinGeo, [faceGeo], 'face_BS', frontOfChain=True) # joints setup headFaceJnt = pm.duplicate(headJnt, renameChildren=True)[0] jointsDuplicates = pm.listRelatives(headFaceJnt, c=True, ad=True) jointsDuplicates.append(headFaceJnt) for jnt in jointsDuplicates: pm.rename(jnt, str(jnt.name()).replace('_JNT1', 'Face_JNT')) pm.parent(jointsDuplicates[-1], self.rigmodule.jointsGrp) pm.skinCluster(faceGeo, headFaceJnt) faceGeoSkincluster = skin.findRelatedSkinCluster(faceGeo) pm.skinCluster(faceGeo, edit=True, ai=cvList, ug=True) faceGeoSkincluster.useComponents.set(1) pm.parent(pm.ls('*_CRVBase'), self.rigmodule.partsNoTransGrp) fullLocList = [] fullClusterList = [] for cv in pm.ls(cvList): pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=4, d=1, tol=0.01) pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=1, kep=1, kt=0, s=4, d=3, tol=0.01) pm.parent(cv, self.rigmodule.partsNoTransGrp) locList = self.setupCurve(cv, pointsNumber) fullLocList.extend(locList) # cluster chainCurveCVs = pm.ls(cv + '.cv[*]', fl=1) numChainCVs = len(chainCurveCVs) curveClusters = [] for i in range(numChainCVs): cls = pm.cluster(chainCurveCVs[i], n=str(cv.name()) + 'Cluster%d' % (i + 1))[1] curveClusters.append(cls) fullClusterList.extend(curveClusters) clusterGrp = pm.group(fullClusterList, n='faceCluster_GRP', p=self.rigmodule.partsNoTransGrp) follicleList = [] for loc, cls in zip(fullLocList, fullClusterList): ctrl = control.Control(str(loc.name()).replace('_LOC', ''), translateTo=loc, shape='sphere', parent=self.rigmodule.controlsGrp, doModify=True, scale=scale) follicle = followCtrl.makeControlFollowSkin(skinGeo, ctrl.getControl(), cls)[-1] follicleList.extend([follicle]) follicleGrp = pm.group(follicleList, n='faceFollicle_GRP', p=self.rigmodule.partsNoTransGrp)