def edit(self, *args): # duplicate skin geometry for saving skin weights self.skinGeo = cmds.ls(sl=True)[0] cmds.duplicate(self.skinGeo, n='tempGeo') cmds.select('tempGeo', r=True) tak_cleanUpModel.delHis() tak_cleanUpModel.delInterMediObj() cmds.setAttr('%s.visibility' % 'tempGeo', False) # transfer skin weights from skin geometry to the temporary geometry cmds.select(self.skinGeo, r=True) cmds.select('tempGeo', add=True) tak_misc.TransSkinWeights() # clean up skin geometry cmds.select(self.skinGeo, r=True) tak_cleanUpModel.delHis() tak_cleanUpModel.delInterMediObj() '''# assign sculpt shader if not cmds.objExists('correctiveCorrective_mat'): shaderName = cmds.shadingNode('lambert', n = 'correctiveCorrective_mat', asShader = True) cmds.setAttr("%s.color" %shaderName, 0.686, 0.316, 0.121) else: shaderName = 'correctiveCorrective_mat' cmds.select(self.skinGeo, r = True) cmds.hyperShade(assign = shaderName)''' # show heads up display tak_lib.showHUD('editSkinGeoModeDisplay', 'Edit Skin Geometry Mode')
def setUpQualoth(): ''' Setup Qualoth simulation. ''' # Select in order cloth source to simulate, blend shape cloth source, collider geometrys # Blend shape cloth source should be skined selList = cmds.ls(sl = True) simSrc = selList[0] bsCloth = selList[1] colliders = selList[2:] clothName = str(bsCloth).split('_')[0] # Create groups qualothGrp = cmds.createNode('transform', n = clothName + '_qualoth_grp') colliderGrp = cmds.createNode('transform', n = clothName + '_qualoth_collider_grp') constraintGrp = cmds.createNode('transform', n = clothName + '_qualoth_cnst_grp') cmds.parent(colliderGrp, constraintGrp, qualothGrp) # Duplicate simulation source geometry for goal constraint geo goalGeo = cmds.duplicate(simSrc, n = clothName + '_cnst') cmds.hide(goalGeo) # Create qlCloth cmds.select(simSrc, r = True) clothShp = mel.eval('qlCreateCloth;') clothTrnf = cmds.listRelatives(clothShp, p = True)[0] clothOut = cmds.rename('%sOut' %clothTrnf, clothName + '_qlOut') clothTrnf = cmds.rename(clothTrnf, clothName + '_qlCloth') cmds.parent(clothOut, clothTrnf, qualothGrp) # Set collider for collider in colliders: cmds.select(clothOut, collider, r = True) colliderShp = mel.eval('qlCreateCollider;') colliderPrnt = cmds.listRelatives(colliderShp, p = True)[0] colliderOffset = cmds.rename(colliderPrnt + 'Offset', collider + '_qlColliderOffset') colliderPrnt = cmds.rename(colliderPrnt, collider + '_qlCollider') cmds.parent(collider, colliderOffset, colliderPrnt, colliderGrp) # Goal constraint with goal geo cmds.select(clothOut, goalGeo, r = True) goalCnst = mel.eval('qlCreateGoalConstraint;') goalCnstTrnsf = cmds.listRelatives(goalCnst, p = True)[0] cmds.setAttr('%s.attractionMethod' %goalCnst, 2) # Copy skin from blend shape geo to goal geo cmds.select(bsCloth, goalGeo, r = True) tak_misc.TransSkinWeights() cmds.parent(goalCnstTrnsf, goalGeo[0], goalGeo[0] + '_Goal', constraintGrp) # Add outCloth to blend shape geo as influence skinClst = mel.eval('findRelatedSkinCluster("%s");' %bsCloth) cmds.skinCluster(skinClst, e = True, ug = True, ps = 0, ns = 10, dr = 4, ai = clothOut) cmds.setAttr('%s.useComponents' %skinClst, 1) # vtxNumber = cmds.polyEvaluate(bsCloth, vertex = True) # for i in xrange(0, vtxNumber, 1): # cmds.skinPercent(skinClst, '%s.vtx[%d]' %(bsCloth, i), transformValue = [(clothOut, 1)]) # Clean up outliner cmds.parent(simSrc, bsCloth, qualothGrp)
def done(self, *args): # remove heads up display cmds.headsUpDisplay('editSkinGeoModeDisplay', remove=True) # delete history cmds.select(self.skinGeo, r=True) tak_cleanUpModel.delHis() tak_cleanUpModel.delInterMediObj() # transfer skin weights from temporary geometry to the original geometry cmds.select('tempGeo', r=True) cmds.select(self.skinGeo, add=True) tak_misc.TransSkinWeights() '''# copy original shader cmds.select('tempGeo', r = True) cmds.select(self.skinGeo, add = True) tak_misc.copyMat()''' # delete temporary geometry cmds.delete('tempGeo')
def buildStickyLips(cls, *args): ''' Main method. ''' # Duplicate geometry oriGeo = cls.upperLipEdges[0].rsplit('.e')[0] logger.debug('Geometry Name: %s' % oriGeo) dupGeo = cmds.duplicate(oriGeo, n=oriGeo + '_stickyLipsSrcCrv_geo')[0] cmds.select(dupGeo, r=True) tak_cleanUpModel.delHis() tak_cleanUpModel.delInterMediObj() cmds.select(oriGeo, dupGeo, r=True) tak_misc.TransSkinWeights() # Convert polygon edges to curves dupGeoUpperEdges = cls.rplcStrInList(cls.upperLipEdges, oriGeo, dupGeo) cmds.select(dupGeoUpperEdges, r=True) upperLipCrv = mel.eval('polyToCurve -form 2 -degree 3;') upperLipCrv = cmds.rename(upperLipCrv[0], 'upper_lip_sticky_crv') dupGeoLowerEdges = cls.rplcStrInList(cls.lowerLipEdges, oriGeo, dupGeo) cmds.select(dupGeoLowerEdges, r=True) lowerLipCrv = mel.eval('polyToCurve -form 2 -degree 3;') lowerLipCrv = cmds.rename(lowerLipCrv[0], 'lower_lip_sticky_crv') # Create sticky lips curve stickyLipsCrv = cmds.duplicate(upperLipCrv, n='stickyLips_crv')[0] stickyLipsCrvShp = cmds.listRelatives(stickyLipsCrv, s=True)[0] upperLipCrvShp = cmds.listRelatives(upperLipCrv, s=True)[0] lowerLipCrvShp = cmds.listRelatives(lowerLipCrv, s=True)[0] avgCrvNode = cmds.createNode('avgCurves', n='stickyLips_avgCurve') cmds.setAttr('%s.automaticWeight' % avgCrvNode, 0) cmds.setAttr('%s.normalizeWeights' % avgCrvNode, 0) cmds.connectAttr('%s.worldSpace[0]' % upperLipCrvShp, '%s.inputCurve1' % avgCrvNode) cmds.connectAttr('%s.worldSpace[0]' % lowerLipCrvShp, '%s.inputCurve2' % avgCrvNode) cmds.connectAttr('%s.outputCurve' % avgCrvNode, '%s.create' % stickyLipsCrvShp) # Grouping stklGrp = cmds.createNode('transform', n='stickyLips_grp') cmds.parent(dupGeo, upperLipCrv, lowerLipCrv, stickyLipsCrv, stklGrp) cmds.setAttr('%s.visibility' % stklGrp, 0) # Assign wire deformer to the geometry wire = cmds.wire(oriGeo, w=stickyLipsCrv)[0] cmds.setAttr('%s.scale[0]' % wire, 0) cmds.setAttr('%s.envelope' % wire, 2) cmds.setAttr('%s.envelope' % wire, lock=True) cmds.connectAttr('%s.outputCurve' % avgCrvNode, '%sBaseWireShape.create' % stickyLipsCrv) # Weighting vtxNumber = cmds.polyEvaluate(oriGeo, vertex=True) cmds.percent(wire, '%s.vtx[0:%d]' % (oriGeo, vtxNumber - 1), v=0) wireVtxList = cmds.polyListComponentConversion(cls.upperLipEdges, cls.lowerLipEdges, tv=True) cmds.percent(wire, wireVtxList, v=1)
return cnstConSrc # Transfer Skin Weights with Matching Name # import tak_misc selMeshes = cmds.ls(sl = True) prefix = 'lod02_' for mesh in selMeshes: if cmds.objExists(prefix + mesh): cmds.select(mesh, prefix + mesh, r = True) try: tak_misc.TransSkinWeights() except: pass # Connect Shape # selLs = cmds.ls(sl = True) srcGeo = selLs[0] trgGeo = selLs[1] srcShp = cmds.listRelatives(srcGeo, s = True)[0] trgShp = cmds.listRelatives(trgGeo, s = True)[0]
def setUpNcloth(cls, *args): """ Main method. """ solverName = cmds.textFieldGrp(cls.widgets['solverNameTxtFldGrp'], q=True, text=True) nClothGeoList = cmds.textScrollList(cls.widgets['nClothGeoTxtScrLs'], q=True, allItems=True) colliderGeoList = cmds.textScrollList(cls.widgets['colliderGeoTxtScrLs'], q=True, allItems=True) # Create new solver if not cmds.objExists(solverName + '_nucleus'): solver = cmds.createNode('nucleus', n=solverName + '_nucleus') cmds.setAttr('%s.subSteps' % solver, 20) cmds.setAttr('%s.maxCollisionIterations' % solver, 20) cmds.setAttr('%s.timeScale' % solver, 1.0) cmds.setAttr('%s.spaceScale' % solver, 0.1) cmds.setAttr('%s.visibility' % solver, 0) cmds.connectAttr('time1.outTime', solver + '.currentTime', f=True) else: solver = solverName + '_nucleus' # Clean up outliner if not cmds.objExists(solverName + '_dyn_grp'): allGrp = cmds.createNode('transform', n=solverName + '_dyn_grp') else: allGrp = solverName + '_dyn_grp' if not cmds.objExists(solverName + '_collider_grp'): colliderGrp = cmds.createNode('transform', n=solverName + '_collider_grp') else: colliderGrp = solverName + '_collider_grp' try: cmds.parent(solver, colliderGrp, allGrp) except: pass # Collider set up if colliderGeoList: for colliderGeo in colliderGeoList: cmds.select(colliderGeo, r=True) nRgdShp = mel.eval('makeCollideNCloth;') nRgdTrsf = cmds.listRelatives(nRgdShp, p=True)[0] newNRgdName = cmds.rename(nRgdTrsf, colliderGeo + '_nRigid') # Get assigned solver to cloth newNRgdShp = cmds.listRelatives(newNRgdName, s=True) solverAssignedRgdShp = cmds.listConnections(newNRgdShp, s=False, d=True) cmds.select(newNRgdName, r=True) mel.eval('assignNSolver "%s";' % solver) # If auto created solver exists delete # if not solverAssignedRgdShp == solver: # cmds.delete(solverAssignedRgdShp) cmds.parent(newNRgdName, colliderGeo, colliderGrp) # Connect time node outTime attribute to solver currentTime attribute newNRgdShp = cmds.listRelatives(newNRgdName, s=True)[0] timeNode = cmds.listConnections('%s.currentTime' % newNRgdShp)[0] try: cmds.connectAttr('%s.outTime' % timeNode, '%s.currentTime' % solver) except: pass if nClothGeoList: for clothGeo in nClothGeoList: # Duplicate geo for 'Attract to Matching Mesh' nConstraint clothName = clothGeo.split('_dyn')[0] goalGeo = cmds.duplicate(clothGeo, n=clothName + '_goal_geo')[0] # Clean up gaolGeo and transfer skin from clothGeo cmds.select(goalGeo, r=True) tak_cleanUpModel.delHis() tak_cleanUpModel.delInterMediObj() cmds.select(clothGeo, goalGeo, r=True) tak_misc.TransSkinWeights() # Create nCloth cmds.select(clothGeo, r=True) origNclothShp = mel.eval('createNCloth 0;') nClothTrsf = cmds.listRelatives(origNclothShp, p=True)[0] newClothName = cmds.rename(nClothTrsf, clothName + '_nCloth') # Get assigned solver to cloth nClothShp = cmds.ls(cmds.listHistory(newClothName), type='nCloth') solverAssignedNcloth = list(set(cmds.ls(cmds.listConnections(nClothShp), type='nucleus')))[0] # Change solver cmds.select(newClothName, r=True) mel.eval('assignNSolver "%s";' % solver) # If auto created solver exists delete if not solverAssignedNcloth == solver: cmds.delete(solverAssignedNcloth) # Attract to Matching Mesh nConstraint cmds.select(goalGeo, clothGeo, r=True) goalCnstNodes = mel.eval('createNConstraint match 0;') cmds.setAttr('%s.constraintMethod' % goalCnstNodes[1], 0) goalCnstNRgdPrnt = cmds.listRelatives(goalCnstNodes[0], p=True)[0] goalCnstNRgd = cmds.rename(goalCnstNRgdPrnt, clothName + '_goal_cnst_nRigid') goalCnstDynCnstPrnt = cmds.listRelatives(goalCnstNodes[1], p=True)[0] goalCnstDynCnst = cmds.rename(goalCnstDynCnstPrnt, clothName + '_goal_dynCnst') # Clean up outliner clothGrp = cmds.createNode('transform', n=clothName + '_nCloth_grp') nCnstGrp = cmds.createNode('transform', n=clothName + '_nCnst_grp') cmds.setAttr('%s.visibility' % nCnstGrp, 0) cmds.parent(clothGeo, newClothName, clothGrp) cmds.parent(goalGeo, goalCnstNRgd, goalCnstDynCnst, nCnstGrp) cmds.parent(nCnstGrp, clothGrp) cmds.parent(clothGrp, allGrp)