def select_in_sphere(item, radius=1.0): """ Using soft select, get all items which are inside soft select radius. """ # If any current selection, save for later, selected = pm.selected() # Select specified item, pm.select(item) # Activate soft select, global falloff with a distance equal to given radius pm.softSelect( softSelectEnabled=True, softSelectFalloff=2, softSelectDistance=radius, ) # Call OpenMaya function to get the items affected by current soft select, items = get_softselection() # Disable and reset soft select pm.softSelect( softSelectEnabled=False, softSelectReset=True, ) # Return to previous selection if there was any, if selected: pm.select(selected) else: pm.select(clear=True) # Return the list of pymel objects for items return pm.ls(items)
def callback(cmd, _): if not (cmd.count('softSelect ') and pm.window('softselectskin', exists=True)): return current_radius = pm.softSelect(q=True, softSelectDistance=True) current_curve = pm.softSelect(q=True, softSelectCurve=True) try: pm.floatSliderGrp(slider, e=True, value=current_radius) pm.gradientControlNoAttr(curve, e=True, asString=current_curve) except NameError: pass
def cbsTrans(*args, **kwargs): sculptTrans = kwargs.setdefault('sculptTrans', pm.ls(sl=True)[0])# (string) The mesh to get the tweak edits extracted from shape = kwargs.setdefault('shape') # (string) The shape node of the sculptTrans node tweak = kwargs.setdefault('tweak') # (string) The tweak node that is going to be cleared skin = kwargs.setdefault('skin') # (string) The skinCluster node that drives the base mesh base = kwargs.setdefault('base') # (string) The base mesh for the character #get some info sculptTrans, shape, tweak, skin = gatherInfo(sculptTrans, shape, tweak, skin) if not 'baseTransform' in pm.listAttr(sculptTrans, ud=True): pm.error('This model has not been prepared for sculpting. If you accidentally started, simply run Clear Tweaks to extract what has been done') if not base: base = sculptTrans.baseTransform.get() baseRef = sculptTrans.baseReference.get() #turn off a couple things that might mess with things pm.symmetricModelling(e=True, symmetry= False) pm.softSelect(e=True, softSelectEnabled=False) #first, let's unlock the guys from the old function pm.lockNode(base, l=False) pm.lockNode(sculptTrans, l=False) pm.setAttr('%s.v'%base, True) #extract from the sculpted shape newShape = clearTweaks(base=base, tweak=tweak) pm.delete(sculptTrans) newOrig = pm.duplicate(base, n='%s_editReference'%base)[0] pm.connectAttr(('%s.outMesh' %newOrig.getShapes()[1]), ('%s.inMesh' %newOrig.getShape())) pm.select(cl=True) deviation = False for v in range(pm.polyEvaluate(base, v=True)): refPos = pm.xform('%s.vtx[%i]'%(baseRef, v), q=True, t=True) adjPos = pm.xform('%s.vtx[%i]'%(newOrig, v), q=True, t=True) if not refPos == adjPos: deviation=True pm.move('%s.vtx[%i]' %(newShape, v), (refPos[0]-adjPos[0], refPos[1]-adjPos[1], refPos[2]-adjPos[2]), r=True) pm.move('%s.vtx[%i]'%(base, v), (refPos[0]-adjPos[0], refPos[1]-adjPos[1], refPos[2]-adjPos[2]), os=True, r=True) pm.select('%s.vtx[%i]' %(base, v), add=True) if deviation: pm.warning('It appears there were issues extracting from the mesh, steps have been taken to try and remedy, but unexpected results may occur') #apply a texture to the new shape. pm.select(newShape, r=True) pm.sets('initialShadingGroup', e=True, forceElement=True) pm.delete(newOrig, baseRef) return newShape
def cbsStart(*args, **kwargs): base = kwargs.setdefault('base', pm.ls(sl=True)[0]) # (string) The base model for the character shape = kwargs.setdefault('shape') # (string) The shape node of the base model tweak = kwargs.setdefault('tweak') # (string) The tweak node of the base model that is being skinned skin = kwargs.setdefault('skin') # (string) The skinCluster node that is driving the base model #gather some info base, shape, tweak, skin = gatherInfo(base, shape, tweak, skin) verts = pm.polyEvaluate(base, v=True) #do a quick check to make sure this part hasn't been done before if base.hasAttr('baseTransform'): pm.error('You have already run the "Start" function on this model, so it is already ready to go.' + 'If corrections have already been made, click "Extract Shape to finish the process"') for i in pm.listHistory(base, lv=1): if i.type() == 'polySmoothFace': pm.error('The selected shape is connected to a smooth modifier. This hinders the ability to track edits. %s must be deleted.' % i) #turn off a couple things that might mess with things pm.symmetricModelling(e=True, symmetry= False) pm.softSelect(e=True, softSelectEnabled=False) for i in range(verts): x = pm.getAttr(('%s.vlist[0].vertex[%i].xVertex'%(tweak, i))) y = pm.getAttr(('%s.vlist[0].vertex[%i].yVertex'%(tweak, i))) z = pm.getAttr(('%s.vlist[0].vertex[%i].zVertex'%(tweak, i))) if not (x+y+z) == 0: pm.error('You have used the tweak node. No me gusta. If you really wanna clear it, run clearTweaks and try again. It will save what you have') #ok, let's get started, first instance the original mesh sculptTrans = pm.instance(base, n=('%s_corrective_sculpt'%base))[0] pm.reorderDeformers(skin, tweak, base) pm.setAttr('%s.v'%base, False) #Here, we'll make a duplicate of the base to look back on later if need be (for instance, using sculpt geometry tends to not register on tweak) baseRef = pm.duplicate(base, n='%s_editReference'%base)[0] pm.connectAttr(('%s.outMesh' %baseRef.getShapes()[1]), ('%s.inMesh' %baseRef.getShape())) #We'll also hook up the original so we can get it later pm.addAttr(sculptTrans, ln='baseTransform', at='message') pm.addAttr(sculptTrans, ln='baseReference', at='message') pm.connectAttr('%s.message'%base, '%s.baseTransform'%sculptTrans) pm.connectAttr('%s.message'%baseRef, '%s.baseReference'%sculptTrans) #now to keep things from changing between functions, we'll lock the three nodes involved in the #other script so our pesky little user won't delete or rename anything pm.lockNode(base, l=True) pm.lockNode(sculptTrans, l=True)
def moveJaw(pAwayOrBack, *Args): pm.softSelect(softSelectEnabled=False) global jawIsAway if globalGender[0] == 'Female': jawSelection = pm.select('Body_Female.vtx[8267:9986]') if globalGender[0] == 'Male': jawSelection = pm.select('Body_Male.vtx[12853:14572]') pm.symmetricModelling(s=False) if (pAwayOrBack == 'Away'): pm.xform(translation=(0, 0, -200), relative=True) jawIsAway = 1 if (pAwayOrBack == 'Back'): pm.xform(translation=(0, 0, 200), relative=True) jawIsAway = 0 pm.softSelect(softSelectEnabled=True) pm.symmetricModelling(s=True)
def happyFace(self, *args): self.upperLip = self.selectedCurve endPoint = pm.getAttr(self.upperLip + ".spans") + 1 endVtx = self.upperLip + ".cv[%d]"%endPoint startPoint = 0 startVtx = self.upperLip + ".cv[%d]"%startPoint tempVar = 0.5 ##test #pm.softSelect(sse = 1, ssd = 4.50, ssf = 0, ssc='0,1,2,1,0,2') pm.softSelect(sse = 1, ssd = 1) #pm.move(thisCurve.cv[0], [0,.5,0], relative = True, objectSpace = True, worldSpaceDistance = True) #pm.nurbsCurveToBezier() #pm.xform(startVtx, t =[0,0.5,0],relative = True, objectSpace = True) #pm.xform(endVtx, t =[0,0.5,0],relative = True, objectSpace = True) pm.softSelect(sse = 0) #pm.scale(thisCurve + ".cv[%d:%d]"%(endPoint/2 - 1,endPoint), [1,1.25,1], relative = True, objectSpace = True) #pm.scale(thisCurve + ".cv[%d:%d]"%(0,endPoint/2), [1,1.25,1], relative = True, objectSpace = True) #pm.scale(startVtx, [1,1.5,1], relative = True, objectSpace = True) for i in range(endPoint): vtxName = self.upperLip + ".cv[%d]"%i print vtxName print str(tempVar) + " TEMPVAR" print endPoint/2 if i < endPoint/2: pm.move(vtxName, [0,tempVar,0], relative = True, objectSpace = True) tempVar -= .05 if i == endPoint/2: pm.move(vtxName, [0,tempVar,0], relative = True, objectSpace = True) tempVar += .05 if i > endPoint/2: pm.move(vtxName, [0,tempVar,0], relative = True, objectSpace = True) tempVar += .05 if(tempVar >= .5): tempVar = .5
def moveCurves(self, *args): facialCurves = pm.textField(self.loadCurves2, q = True, text = True) pm.softSelect(sse = 1)
def cbsStart(*args, **kwargs): base = kwargs.setdefault( 'base', pm.ls(sl=True)[0]) # (string) The base model for the character shape = kwargs.setdefault( 'shape') # (string) The shape node of the base model tweak = kwargs.setdefault( 'tweak' ) # (string) The tweak node of the base model that is being skinned skin = kwargs.setdefault( 'skin') # (string) The skinCluster node that is driving the base model #gather some info base, shape, tweak, skin = gatherInfo(base, shape, tweak, skin) verts = pm.polyEvaluate(base, v=True) #do a quick check to make sure this part hasn't been done before if base.hasAttr('baseTransform'): pm.error( 'You have already run the "Start" function on this model, so it is already ready to go.' + 'If corrections have already been made, click "Extract Shape to finish the process"' ) for i in pm.listHistory(base, lv=1): if i.type() == 'polySmoothFace': pm.error( 'The selected shape is connected to a smooth modifier. This hinders the ability to track edits. %s must be deleted.' % i) #turn off a couple things that might mess with things pm.symmetricModelling(e=True, symmetry=False) pm.softSelect(e=True, softSelectEnabled=False) for i in range(verts): x = pm.getAttr(('%s.vlist[0].vertex[%i].xVertex' % (tweak, i))) y = pm.getAttr(('%s.vlist[0].vertex[%i].yVertex' % (tweak, i))) z = pm.getAttr(('%s.vlist[0].vertex[%i].zVertex' % (tweak, i))) if not (x + y + z) == 0: pm.error( 'You have used the tweak node. No me gusta. If you really wanna clear it, run clearTweaks and try again. It will save what you have' ) #ok, let's get started, first instance the original mesh sculptTrans = pm.instance(base, n=('%s_corrective_sculpt' % base))[0] pm.reorderDeformers(skin, tweak, base) pm.setAttr('%s.v' % base, False) #Here, we'll make a duplicate of the base to look back on later if need be (for instance, using sculpt geometry tends to not register on tweak) baseRef = pm.duplicate(base, n='%s_editReference' % base)[0] pm.connectAttr(('%s.outMesh' % baseRef.getShapes()[1]), ('%s.inMesh' % baseRef.getShape())) #We'll also hook up the original so we can get it later pm.addAttr(sculptTrans, ln='baseTransform', at='message') pm.addAttr(sculptTrans, ln='baseReference', at='message') pm.connectAttr('%s.message' % base, '%s.baseTransform' % sculptTrans) pm.connectAttr('%s.message' % baseRef, '%s.baseReference' % sculptTrans) #now to keep things from changing between functions, we'll lock the three nodes involved in the #other script so our pesky little user won't delete or rename anything pm.lockNode(base, l=True) pm.lockNode(sculptTrans, l=True)
def cbsTrans(*args, **kwargs): sculptTrans = kwargs.setdefault( 'sculptTrans', pm.ls(sl=True) [0]) # (string) The mesh to get the tweak edits extracted from shape = kwargs.setdefault( 'shape') # (string) The shape node of the sculptTrans node tweak = kwargs.setdefault( 'tweak') # (string) The tweak node that is going to be cleared skin = kwargs.setdefault( 'skin') # (string) The skinCluster node that drives the base mesh base = kwargs.setdefault( 'base') # (string) The base mesh for the character #get some info sculptTrans, shape, tweak, skin = gatherInfo(sculptTrans, shape, tweak, skin) if not 'baseTransform' in pm.listAttr(sculptTrans, ud=True): pm.error( 'This model has not been prepared for sculpting. If you accidentally started, simply run Clear Tweaks to extract what has been done' ) if not base: base = sculptTrans.baseTransform.get() baseRef = sculptTrans.baseReference.get() #turn off a couple things that might mess with things pm.symmetricModelling(e=True, symmetry=False) pm.softSelect(e=True, softSelectEnabled=False) #first, let's unlock the guys from the old function pm.lockNode(base, l=False) pm.lockNode(sculptTrans, l=False) pm.setAttr('%s.v' % base, True) #extract from the sculpted shape newShape = clearTweaks(base=base, tweak=tweak) pm.delete(sculptTrans) newOrig = pm.duplicate(base, n='%s_editReference' % base)[0] pm.connectAttr(('%s.outMesh' % newOrig.getShapes()[1]), ('%s.inMesh' % newOrig.getShape())) pm.select(cl=True) deviation = False for v in range(pm.polyEvaluate(base, v=True)): refPos = pm.xform('%s.vtx[%i]' % (baseRef, v), q=True, t=True) adjPos = pm.xform('%s.vtx[%i]' % (newOrig, v), q=True, t=True) if not refPos == adjPos: deviation = True pm.move('%s.vtx[%i]' % (newShape, v), (refPos[0] - adjPos[0], refPos[1] - adjPos[1], refPos[2] - adjPos[2]), r=True) pm.move('%s.vtx[%i]' % (base, v), (refPos[0] - adjPos[0], refPos[1] - adjPos[1], refPos[2] - adjPos[2]), os=True, r=True) pm.select('%s.vtx[%i]' % (base, v), add=True) if deviation: pm.warning( 'It appears there were issues extracting from the mesh, steps have been taken to try and remedy, but unexpected results may occur' ) #apply a texture to the new shape. pm.select(newShape, r=True) pm.sets('initialShadingGroup', e=True, forceElement=True) pm.delete(newOrig, baseRef) return newShape
def sliderChangeCommand(*Args): pValue = pm.floatSlider("SoftSelectSlider", query=True, value=True) pm.softSelect(softSelectDistance=pValue) print(pValue)
def createUI(pWindowTitle): windowID = 'myWindowID' globalGender[0] = getGender() if cmds.window(windowID, exists=True): cmds.deleteUI(windowID) cmds.window(windowID, title=pWindowTitle, width=440) # root column layout cmds.rowColumnLayout() cmds.image(image='icons\EqualReality\PolyMorphTitle.jpg') cmds.button(label='Load Base Model', command=importCallback, height=50, backgroundColor=(0.066, 0.447, 0.443)) cmds.separator(h=4, style='none', backgroundColor=(0.07, 0.121, 0.152)) cmds.button(label='Load Photogrammetry Reference', command=importReferenceCallback, height=35, backgroundColor=(0.109, 0.227, 0.29)) #cmds.separator(h = 20, style='none', backgroundColor = (0.133,0.164,0.239)) #cmds.button(label='Edit', command=editCallback, backgroundColor = (0.109,0.458,0.16)) cmds.separator(h=4, style='none', backgroundColor=(0.07, 0.121, 0.152)) if pm.ls('Trace'): #populate my fields by reading the files nameKey = [] nameRead = open( 'EqualRealityData\SelectionData%s.txt' % (globalGender[0]), 'r+') vertexRead = open( 'EqualRealityData\SelectedVerticies%s.txt' % (globalGender[0]), 'r+') eyeRead = open( 'EqualRealityData\SavedVertexPositions%sEye.txt' % (globalGender[0]), 'r+') for line in nameRead.readlines(): mySelName = re.sub('\r\n', '', line) nameKey.append(mySelName) if globalNameKey.count(mySelName) < 1: globalNameKey.append(mySelName) for line in vertexRead.read().split('\r\n\r\n'): if line not in globalVertexKey: globalVertexKey.append(line) for line in eyeRead.read().split('\r\n\r\n'): if line != None and line not in globalEyeKey: globalEyeKey.append(line) eyeRead.close() nameRead.close() vertexRead.close() pm.softSelect(softSelectEnabled=True) pm.symmetricModelling(s=True) cmds.separator(h=8, style='none', backgroundColor=(0.07, 0.121, 0.152)) pm.rowColumnLayout(numberOfColumns=2, columnWidth=[(1, 120), (2, 325)]) pm.separator(style='none', backgroundColor=(0.27, 0.345, 0.376)) pm.checkBox('GuidesVisible', label='Show Guides for Reference Alignment', height=25, backgroundColor=(0.27, 0.345, 0.376), onCommand=referenceLines, offCommand=referenceLines) pm.setParent('..') cmds.separator(h=4, style='none', backgroundColor=(0.07, 0.121, 0.152)) global OnStart if OnStart == 1: print('this is the first time ive run') moveJaw('Away') OnStart = 0 myState = rolloutParameters(name='modellingToolkit', query=True) cmds.frameLayout(backgroundColor=(0.301, 0.423, 0.513), collapsable=True, collapse=myState, label='Modelling Toolkit') cmds.separator(h=2, style='none') #Pick Eye Shape createImageButtonGroup('Eye') cmds.setParent('..') myState = rolloutParameters(name='bodypartSelection', query=True) cmds.frameLayout(backgroundColor=(0.25, 0.349, 0.423), collapsable=True, collapse=myState, label='Bodypart Selection') cmds.rowColumnLayout(numberOfColumns=3, columnWidth=[(1, 380), (2, 30), (3, 30)]) cmds.rowColumnLayout(numberOfColumns=3, columnWidth=[(1, 80), (2, 180), (3, 115)]) cmds.text(label=' Soft Select: ', align='left') cmds.floatSlider("SoftSelectSlider", changeCommand=sliderChangeCommand, min=0, max=8) cmds.text(label=' Move Jaw Away ', align='right') cmds.setParent('..') #cmds.setParent('..') cmds.checkBox(value=jawIsAway, label='', onCommand=functools.partial(moveJaw, 'Away'), offCommand=functools.partial(moveJaw, 'Back')) cmds.separator(h=20, style='none') cmds.separator(h=20, style='none') cmds.separator(h=20, style='none') cmds.separator(h=20, style='none') global lockedGroups for pSelection in nameKey: bodypartSelection(pSelection) cmds.separator(h=20, style='none') #lock perminant entries if pSelection in lockedGroups: cmds.separator(h=20, style='none') else: cmds.button('DeleteButton%s' % (pSelection), label='X', backgroundColor=(0.815, 0.098, 0.098), command=functools.partial(removeButtonCallback, pSelection)) cmds.setParent('..') pm.separator(h=5, style='none') pm.textFieldButtonGrp("addingNewFields", label='New Type: ', placeholderText=' selection name...', buttonLabel='Add', buttonCommand=addButtonCallback) cmds.separator(h=5, style='none') cmds.setParent('..') cmds.setParent('..') myState = rolloutParameters(name='bakeModel', query=True) cmds.frameLayout(backgroundColor=(0.329, 0.482, 0.431), collapsable=True, collapse=myState, label='Bake Model') cmds.separator(h=4, style='none') cmds.button(backgroundColor=(0.235, 0.388, 0.349), label='Place Eyes', command=eyesCallback) #cmds.separator(h = 4, style = 'none') cmds.button(backgroundColor=(0.235, 0.388, 0.349), label='Bake', command=bakeCallback) cmds.setParent('..') cmds.showWindow()
def show(): pm.loadPlugin('%s/sss-plug-ins.py' % os.path.dirname(__file__), quiet=True) if pm.window('softselectskin', exists=True): pm.deleteUI('softselectskin') with pm.window('softselectskin', **main_window_flags) as win: with pm.formLayout('main_form') as main_layout: with pm.frameLayout('softselect_frame', **softselect_frame_flags) as softselect_framelayout: with pm.formLayout('softselect_form') as lyt: current_radius = pm.softSelect(q=True, softSelectDistance=True) current_curve = pm.softSelect(q=True, softSelectCurve=True) slider = pm.floatSliderGrp('fsg_radius', value=current_radius, **falloff_radius_slider_flags) with pm.formLayout('curve_formlayout') as curve_formlayout: curve_display = pm.text('curve_display', **falloff_curve_display_flags) curve = pm.gradientControlNoAttr('gc_curve', asString=current_curve, **falloff_curve_flags) attach = { 'e': True, 'attachForm': [ (curve_display, 'top', 0), (curve_display, 'bottom', 0), (curve_display, 'left', 0), (curve, 'top', 0), (curve, 'bottom', 0), (curve, 'right', 0), ], 'attachControl': [ (curve, 'left', 0, curve_display), ] } pm.formLayout(curve_formlayout, **attach) callback = softselect_changed_callback_generator(slider, curve) callback_id = om.MCommandMessage.addCommandCallback(callback) attach = { 'e': True, 'attachForm': [ (slider, 'top', 5), (slider, 'left', 5), (slider, 'right', 5), (curve_formlayout, 'left', 5), (curve_formlayout, 'right', 5), ], 'attachControl': [ (curve_formlayout, 'top', 5, slider), ] } pm.formLayout(lyt, **attach) with pm.frameLayout('skeleton_frame', **skeleton_frame_flags) as skeleton_framelayout: with pm.formLayout('skeleton_formlayout') as skeleton_formlayout: tsl = pm.textScrollList('skeleton_list', **skeleton_list_flags) callback = selection_changed_callback_generator(tsl) pm.scriptJob(event=['SelectionChanged', callback], parent=win) attach = { 'e': True, 'attachForm': [ (tsl, 'top', 5), (tsl, 'left', 5), (tsl, 'right', 5), ], } pm.formLayout(skeleton_formlayout, **attach) attach = { 'e': True, 'attachForm': [ (softselect_framelayout, 'top', 5), (softselect_framelayout, 'left', 5), (softselect_framelayout, 'right', 5), (skeleton_framelayout, 'left', 5), (skeleton_framelayout, 'right', 5), ], 'attachControl': [ (skeleton_framelayout, 'top', 5, softselect_framelayout), ] } pm.formLayout(main_layout, **attach) omui.MUiMessage.addUiDeletedCallback(win, lambda *_: om.MMessage.removeCallback(callback_id))
} skeleton_frame_flags = { 'label': 'Skeletons', 'collapsable': True } falloff_radius_slider_flags = { 'label': 'Falloff Radius: ', 'field': True, 'minValue': 0.0, 'maxValue': 100.0, 'fieldMinValue': 0.0, 'fieldMaxValue': 100.0, 'columnWidth': [1, 100], 'changeCommand': lambda d: pm.softSelect(e=True, softSelectDistance=d), } falloff_curve_display_flags = { 'label': 'Falloff Curve: ', 'width': 100, 'align': 'right', } falloff_curve_flags = { 'height': 120, 'changeCommand': lambda c: pm.softSelect(e=True, softSelectCurve=c), } skeleton_list_flags = { 'height': 120,