def cntLod02ToLod03(*args): selLs = cmds.ls(sl=True, dag=True, g=True, ni=True) lod02ShpLs = selLs if selLs else cmds.ls( 'lod02_GRP', dag=True, g=True, ni=True) for shp in lod02ShpLs: lod02Geo = cmds.listRelatives(shp, p=True)[0] lod03Geo = lod02Geo.split('lod02_')[-1] if cmds.objExists(lod03Geo): lod03DefLs = tak_lib.getAllDef(lod03Geo) else: OpenMaya.MGlobal.displayWarning( '"%s" is not exists that matching with "%s". Skip this' % (lod03Geo, lod02Geo)) continue if not lod03DefLs: try: cmds.blendShape(lod02Geo, lod03Geo, frontOfChain=True, w=[0, 1]) except: OpenMaya.MGlobal.displayWarning( '"%s" has different topology compare to "%s". Connect using wrap' % (lod02Geo, lod03Geo)) cmds.select(lod03Geo, lod02Geo) cmds.CreateWrap()
def create(self, _HiRez=pm.selected(), _LoRez=pm.selected()): """ Creates a default wrap Select target - HiRez first, then the source - LoRez @param Hirez: Target which will receive the wrap : str or selection @param Lorez: Source : str of selection """ ## Define Variable type if isinstance(_HiRez, str) and isinstance(_LoRez, str): print('string') HiRez = _HiRez LoRez = _LoRez elif len(_HiRez) == 2: print('selection of 2') HiRez = _HiRez[0] LoRez = _LoRez[1] else: print('Else') HiRez = _HiRez LoRez = _LoRez pre_wraps = set(pm.ls(type='wrap')) pm.select(HiRez, LoRez, r=True) mc.CreateWrap() post_wraps = set(pm.ls(type='wrap')) wrapNode = list(post_wraps - pre_wraps)[0] name = pm.rename(wrapNode, '{}_wrap'.format(HiRez)) self.wrapNode = None self.wrapNode = wrapNode sys.stdout.write('wrap deformer created \n') return self.wrapNode
def makePairs(self): sel = cmds.ls(os=1) garments = cmds.listRelatives(sel[0]) # len(garments) patterns = cmds.listRelatives(sel[1]) # len(patterns) retopos = cmds.listRelatives(sel[2]) # len(retopos) retopos_BB_width = {} retopos_BB_length = {} retopos_BB_center = {} patterns_BB_width = {} patterns_BB_length = {} patterns_BB_center = {} # In case that uv doesn't exists. cmds.select(retopos, r=1) mel.eval("performPolyAutoProj 0;") cmds.select(sel, r=1) # In case wrong bb for i in retopos: cmds.polyMergeVertex(i, d=0.001) # Matching for i in retopos: BB = cmds.polyEvaluate(i, b=1) retopos_BB_width[i] = BB[0][1] - BB[0][0] retopos_BB_length[i] = BB[1][1] - BB[1][0] retopos_BB_center[i] = [(BB[0][1] + BB[0][0]) / 2, (BB[1][1] + BB[1][0]) / 2] for i in patterns: BB = cmds.polyEvaluate(i, b=1) patterns_BB_width[i] = BB[0][1] - BB[0][0] patterns_BB_length[i] = BB[1][1] - BB[1][0] patterns_BB_center[i] = [(BB[0][1] + BB[0][0]) / 2, (BB[1][1] + BB[1][0]) / 2] pair_pattern_retopo = {} # len(pair_pattern_retopo) for i in patterns: for j in retopos: if abs(patterns_BB_width[i] - retopos_BB_width[j]) < 1 \ and abs(patterns_BB_length[i] - retopos_BB_length[j]) < 1 \ and abs(patterns_BB_center[i][0] - retopos_BB_center[j][0]) < 1 \ and abs(patterns_BB_center[i][1] - retopos_BB_center[j][1]) < 1: pair_pattern_retopo[i] = j for i in pair_pattern_retopo: cmds.transferAttributes(i, pair_pattern_retopo[i], transferUVs=1) for i in pair_pattern_retopo: cmds.select(pair_pattern_retopo[i], i, r=1) cmds.CreateWrap() for i in pair_pattern_retopo: pairGarment = i[:-8] pattern = i blendObjs = [pairGarment, pattern] # 0: target 1: origin blendName = cmds.blendShape(blendObjs, o='world', n='clothTransfer#') cmds.hide(sel[1]) cmds.displaySurface(sel[0], x=1) cmds.hide(sel[1]) cmds.displaySurface(sel[0], x=1) layerName = cmds.createDisplayLayer(n="garment#", e=1) cmds.editDisplayLayerMembers(layerName, sel[0]) cmds.setAttr(layerName + '.displayType', 2)
def mirror_blendshape(sel=None, axis=[-1, 1, 1]): ''' 1. select the basemesh (the one with a symmetry) 2. select also the blendshape you want to mirror if you want to change the mirror axis, write the expression as: mirror_blendshape(axis=[1,-1,1]) First one is X, then Y and Z. ''' returnList = [] if not sel: # Get Current selection sel = mc.ls(sl=True) elif not isinstance(sel, list): sel = [sel] if not len(sel) == 2: sys.exit('select a mesh and a target for the new mesh') basemesh = sel[0] blendshp = sel[1] name_mirror = '' naming = blendshp.split('_') if naming[0] == 'l': naming[0] = 'r' name_mirror = '_'.join(naming) elif naming[0] == 'r': naming[0] = 'l' name_mirror = '_'.join(naming) else: name_mirror = 'mirrored_' + str(blendshp) temp_mesh = mc.duplicate(basemesh, n='__temp__mesh__') temp_shape = mc.duplicate(basemesh, n='temp__blendshape') # create blendshape on duplicated mesh bs_node = mc.blendShape(blendshp, temp_mesh, n='temp__BS') mc.xform(temp_mesh, s=axis) mc.select(temp_shape, temp_mesh) wrap_sel = mc.ls(sl=True) mc.CreateWrap(wrap_sel) mc.setAttr('temp__BS' + '.' + blendshp, 1) mc.duplicate(temp_shape, n=name_mirror) mc.delete(temp_mesh) mc.delete(temp_shape)
def attach_plane_rig( self, objects ): plane_name = 'plane_nurb' if plane_name in objects: cmds.select( plane_name, deselect = True ) transform_nodes = oopmaya.get_object_type( objects, 'mesh' ) cmds.select( transform_nodes ) cmds.select( plane_name, add = True ) cmds.CreateWrap()
def execute(self, *a): org = cmds.textField('bssdTf_org', q=1, text=1) new = cmds.textField('bssdTf_new', q=1, text=1) sl = cmds.ls(selection=1, long=1) sls = cmds.ls(selection=1) for i, x in enumerate(sl): bs = cmds.blendShape(org, x, weight=[0, 1]) cmds.duplicate(new, name='bssd_dTemp') cmds.delete(cmds.parentConstraint(x, 'bssd_dTemp')) cmds.select(['bssd_dTemp', x], r=1) cmds.CreateWrap() cmds.setAttr(bs[0] + '.envelope', 0) cmds.rename(x, sls[i] + '_old') n = cmds.duplicate('bssd_dTemp', name=sls[i]) cmds.select(n, r=1) cmds.delete('bssd_dTemp') cmds.delete(bs[0]) cmds.delete(sls[i] + '_old')
def _createWrap(self): cmds.CreateWrap()
# Load cloth preset #cmds.nodePreset( list='nClothShape1' ) #cmds.nodePreset( save=("nClothShape1","tunic_1") ) #cmds.nodePreset( load=('nClothShape1', 'tunic_1') ) ######################### ## PREPARE HERO MESHES ## ######################### # Wrap Colliders to viking's character alembic # NOTE: if the dynamic constraints freak out, try changing the order that you do (collisionMesh wrap to character mesh) and (create dynamicConstraint) mc.select('viking_collision_mesh_cloth_model_main_viking_collision_mesh_cloth', replace=True) #Wrap Body mc.select(vikingBodyGeo, add=True) #wrap the collision mesh to viking skin mc.CreateWrap() # Wrap bracelets to viking's character alembic mc.select('viking_tunic_model_main_bracelets', replace=True) #Wrap bracelets mc.select(vikingBodyGeo, add=True) #wrap the bracelets to viking skin mc.CreateWrap() # Wrap Tunic Beauty Mesh to Sim Mesh mc.select('viking_tunic_model_main_tunic_beauty_mesh', replace=True) mc.select('viking_tunic_model_main_tunic_sim_mesh', add=True) mc.CreateWrap() # From Brennan: Do your best to only have one thing wrapping per sim - they are slow to calculate # if you need to adjust the collision mesh for a weird cloth thing, you can duplicate the collisionmesh, # adjust the shape/add more or whatever, then make it a blend shape to the original collision mesh. # Blend shapes DO require the same exact # of polygons but they're also a lot faster than regular wraps.
import maya.cmds as cmds import pymel.core as pm sels = cmds.ls(sl=1) new_obj = sels[0] ori_obj = sels[1] new_shape = cmds.listRelatives(new_obj, shapes=1, children=1)[0] ori_shape = cmds.listRelatives(ori_obj, shapes=1, children=1)[0] cmds.CreateWrap(new_obj) object_ = ori_obj deform_list = cmds.findDeformers(object_) blend_deform_list = [] for deform in deform_list: if cmds.objectType(deform) == 'blendShape': blend_deform_list.append(deform) else: pass blend_node = blend_deform_list[0] blend_weight = cmds.getAttr(blend_node + '.weight')[0] blend_target_list = cmds.listAttr(blend_node + ".w", m=1) new_target_list = [] new_target_sh_list = [] main_target_list = []
cmds.disconnectAttr(connectionList[i], "%s.%s" % (bsNode, each)) cmds.setAttr("%s.%s" % (bsNode, each), 0) # Create Temp Wrapper try: lockAttr = cmds.listAttr(targetMesh, l=1) for each in lockAttr: cmds.setAttr("%s.%s" % (targetMesh, each), l=0) except TypeError: pass wrapper = cmds.duplicate(targetMesh, n="wrapper") cmds.parent(wrapper, w=1) cmds.select(cl=1) cmds.select(wrapper, sourceMesh, add=1) cmds.CreateWrap() # Duplicate Blendshape From New Mesh newBS = cmds.group(n="NEW_BS_GRP", em=1) for i, each in enumerate(bsList): if len(bsValue[i]) > 1: for n in bsValue[i]: cmds.setAttr("%s.%s" % (bsNode, each), n) dup = cmds.duplicate(wrapper, n="%s_%s" % (each, n)) cmds.parent(dup, newBS) cmds.setAttr("%s.%s" % (bsNode, each), 0) cmds.select(cl=1) else: cmds.setAttr("%s.%s" % (bsNode, each), float(bsValue[i][0])) dup = cmds.duplicate(wrapper, n="%s_%s" % (each, float(bsValue[i][0])))
def createRibbon(volumePreservation=True): self.RIBBON_MOD = moduleBase.ModuleBase() self.RIBBON_MOD.hiearchy_setup( '{Side}__Ribbon'.format(**self.nameStructure)) self.BUILD_MODULES += [self.RIBBON_MOD] self.RIBBON_MOD.RIG_GRP.inheritsTransform.set(0) pm.parent(self.RIBBON_MOD.MOD_GRP, self.RIG.MODULES_GRP) def createProxyPlane(name, interval=4): locs = locGen.locGenerator(interval, str(self.spine_ik_joints[0]), str(self.spine_ik_joints[-1])) first_loc = Locator.Locator.point_base( pm.PyNode(self.spine_ik_joints[0]).getRotatePivot( space='world')).locators[0] last_loc = Locator.Locator.point_base( pm.PyNode(self.spine_ik_joints[-1]).getRotatePivot( space='world')).locators[0] locs.insert(0, first_loc) locs.append(last_loc) proxy_plane = adbProxy.plane_proxy(locs, name, 'x', type='nurbs') pm.delete(locs) # pm.polyNormal(upper_proxy_plane, ch=1, userNormalMode=0, normalMode=0) pm.select(None) return proxy_plane def addVolumePreservation(): self.spine_squash_stretch = adbRibbon.SquashStrech( '{Side}__{Basename}_VolumePreservation'.format( **self.nameStructure), usingCurve=True, ExpCtrl=None, ribbon_ctrl=[ self.spine_ik_joints[0], self.spine_ik_joints[-1] ], # Top first, then bottom jointList=spine_folli.getResetJoints, jointListA=(spine_folli.getResetJoints[0:2], 0), jointListB=(spine_folli.getResetJoints[2:-3], 1.5), jointListC=(spine_folli.getResetJoints[-1:-3], 0), ) self.spine_squash_stretch.start(metaDataNode='transform') self.RIBBON_MOD.metaDataGRPS += [ self.spine_squash_stretch.metaData_GRP ] self.spine_squash_stretch.build() return self.spine_squash_stretch spine_proxy_plane = createProxyPlane( '{Side}__{Basename}_Plane__MSH'.format(**self.nameStructure), interval=4) _folliculeVis = 0 spine_folli = adbFolli.Folli( '{Side}__{Basename}_Folli_Plane'.format(**self.nameStructure), countU=1, countV=len(self.spine_chain_joints), vDir='U', radius=0.5, subject=spine_proxy_plane) spine_folli.start(metaDataNode='transform') self.RIBBON_MOD.metaDataGRPS += [spine_folli.metaData_GRP] spine_folli.build() spine_folli.getFollicules = _folliculeVis Joint.Joint(spine_folli.getJoints ).radius = self.config['JOINTS']["Macro_JNT"]['radius'] for i, jnt in enumerate(spine_folli.getJoints): self.nameStructure['Suffix'] = i + 1 pm.rename( jnt, '{Side}__{Basename}_END_0{Suffix}'.format( **self.nameStructure)) adb.AutoSuffix([jnt]) [ adb.changeColor_func(jnt, 'index', 20) for jnt in spine_folli.getJoints ] pm.parent(spine_folli.MOD_GRP, self.RIBBON_MOD.RIG_GRP) self.RIBBON_MOD.setFinalHiearchy( OUTPUT_GRP_LIST=spine_folli.getJoints, INPUT_GRP_LIST=spine_folli.getInputs, RIG_GRP_LIST=[spine_proxy_plane]) if volumePreservation: addVolumePreservationMod = addVolumePreservation() pm.parent(addVolumePreservationMod.MOD_GRP, self.RIG.MODULES_GRP) pm.select(addVolumePreservationMod.spineLenghtCurve, r=1) pm.select(spine_proxy_plane, add=1) mc.CreateWrap() addVolumePreservationMod.spineLenghtCurve.inheritsTransform.set( 0) wrapNode = adb.findDeformer( addVolumePreservationMod.spineLenghtCurve)[0] pm.PyNode(wrapNode).autoWeightThreshold.set(1) self.nameStructure['Suffix'] = NC.WRAP_SUFFIX wrapNode = pm.rename( wrapNode, '{Side}__{Basename}_volumePreservation__{Suffix}'.format( **self.nameStructure)) for grp in spine_folli.MOD_GRP.getChildren(): if len(grp.getChildren()) is 0: pm.delete(grp) moduleBase.ModuleBase.setupVisRule( [self.RIBBON_MOD.OUTPUT_GRP], self.RIBBON_MOD.VISRULE_GRP, '{Side}__{Basename}_MACRO_JNT__{Suffix}'.format( **self.nameStructure), False) self.RIBBON_MOD.RIG_GRP.v.set(0)
def createWrap(): cmds.CreateWrap()