def nclothAttrFlood(value, ncloths=[], attr='inputAttract', operation='Replace '): ''' flood ncloth vertex attr ''' if ncloths == []: ncloths = pm.selected() # pm.select(ncloth) pm.mel.setNClothMapType(attr, "", 1) pm.mel.artAttrNClothToolScript(4, attr) pm.mel.artAttrPaintOperation('artAttrCtx', operation) pm.artAttrCtx(pm.currentCtx(), e=1, value=value) pm.artAttrCtx(pm.currentCtx(), clear=1, e=1)
def getManipTool(self, *args): if pm.currentCtx() == "moveSuperContext": self.a = False QMetaObject.invokeMethod(self.translateButton, "clicked") elif pm.currentCtx() == "RotateSuperContext": self.a = False QMetaObject.invokeMethod(self.rotateButton, "clicked") elif pm.currentCtx() == "scaleSuperContext": self.a = False QMetaObject.invokeMethod(self.scaleButton, "clicked")
def getManipTool(self, *args): if pm.currentCtx() == "moveSuperContext": self.updateHostState = False QMetaObject.invokeMethod(self.translateButton, "clicked") elif pm.currentCtx() == "RotateSuperContext": self.updateHostState = False QMetaObject.invokeMethod(self.rotateButton, "clicked") elif pm.currentCtx() == "scaleSuperContext": self.updateHostState = False QMetaObject.invokeMethod(self.scaleButton, "clicked") else: # self.SRT_stateUpdate()
def _changed(s): """ Tool changed. Update everyone """ with _print_exc(): tool, callback = pmc.currentCtx(), s.callback if tool == s._last_tool: return s._last_tool = tool if callback: callback(tool)
def rotateSelectedOrientsAroundAxis(axis, degrees=90, preserveChildren=True, preserveShapes=True, syncJointAxes=True): """ Rotate the selected nodes around the given axis If the node is a joint, its jointOrient will be rotated Args: axis: degress: preserveChildren: preserveShapes: syncJointAxes (bool): If True, joints will also have their translate and scale axes updated to match the new orientation """ # if currently on move tool, make sure its object space if pm.currentCtx() == pm.melGlobals['$gMove']: pm.manipMoveContext('Move', e=True, mode=0) rotation = pm.dt.Vector() rotation[axis] = degrees nodes = pm.selected() for node in nodes: rotateOrientOrTransform(node, rotation, preserveChildren, preserveShapes, syncJointAxes)
def smooth_skin_or_hik_full_body_key(): if is_skinning(): ctx = pm.currentCtx() pm.artAttrSkinPaintCtx(ctx, e=True, selectedattroper="smooth") pm.artAttrSkinPaintCtx(ctx, e=True, clear=True) else: pm.mel.HIKSetFullBodyKey()
def matchAttr(): # NOTE 获取当前使用的工具 ctx = pm.currentCtx() sel_list = pm.ls(sl=1) if ctx == "moveSuperContext": attr_list = ['tx', 'ty', 'tz'] elif ctx == "RotateSuperContext": attr_list = ['rx', 'ry', 'rz'] elif ctx == "scaleSuperContext": attr_list = ['sx', 'sy', 'sz'] else: return if len(sel_list) != 2: pm.headsUpMessage(u"请选择两个物体") pm.warning(u"请选择两个物体") driver, driven = sel_list for attr in attr_list: if not hasattr(driver, attr) or not hasattr(driven, attr): continue driver_attr = pm.Attribute("%s.%s" % (driver, attr)) driven_attr = pm.Attribute("%s.%s" % (driven, attr)) if driven_attr.isLocked() and not driven_attr.isKeyable(): continue driven_attr.set(driver_attr.get())
def onPaintSkinWeight(self): currentSelection, get_joint = self.getCurrentSelection( assertBone=False) pm.select(currentSelection) if pm.currentCtx() != 'artAttrSkinContext': mm.eval('artAttrSkinToolScript 3;') lastJoint = pm.artAttrSkinPaintCtx(pm.currentCtx(), query=True, influence=True) # artAttrSkinPaintCtx(currentCtx(), edit=True, influence=get_joint[0]) if get_joint: mm.eval(''' artAttrSkinToolScript 3; artSkinInflListChanging "%s" 0; artSkinInflListChanging "%s" 1; artSkinInflListChanged artAttrSkinPaintCtx; artAttrSkinPaintModePaintSelect 1 artAttrSkinPaintCtx;''' % (lastJoint, unicode(get_joint[0])))
def decorated_function(*args, **kwargs): currenttool = pm.currentCtx() selecttool = pm.melGlobals['gSelect'] if currenttool != selecttool: pm.setToolTo(selecttool) function(*args, **kwargs) pm.setToolTo(currenttool) else: function(*args, **kwargs)
def delete_history_or_remove_skinning(): if is_skinning(): ctx = pm.currentCtx() pm.artAttrSkinPaintCtx(ctx, e=True, selectedattroper="absolute") pm.artAttrSkinPaintCtx(ctx, e=True, opacity=1.0) pm.artAttrSkinPaintCtx(ctx, e=True, value=0.0) pm.artAttrSkinPaintCtx(ctx, e=True, clear=True) else: pm.mel.DeleteHistory()
def lock_unlock_All_Weight(self, lock=True): mesh = pm.selected()[0] node = skin.Skinning(mesh) if lock: node.lockAll_Weight() else: node.unlockAll_Weight() pm.select(mesh, r=1) if pm.currentCtx() != "artAttrSkinContext": mel.eval("ArtPaintSkinWeightsTool;")
def set_key_or_scale_skinweights(weight_value=1.1): if is_skinning(): ctx = pm.currentCtx() pm.artAttrSkinPaintCtx(ctx, e=True, selectedattroper="scale") if weight_value > 1: pm.artAttrSkinPaintCtx(ctx, e=True, maxvalue=weight_value) pm.artAttrSkinPaintCtx(ctx, e=True, value=weight_value) pm.artAttrSkinPaintCtx(ctx, e=True, clear=True) else: pm.mel.SetKey()
def onSetWeightClick(self): currentSelection, bones_list = self.getCurrentSelection() rul.skin_weight_setter(currentSelection, bones_list, skin_value=self.weightValue, normalized=self.normalizeToggle, hierachy=self.hierachyToggle) self.lastSelection = currentSelection # show Skin Paint Tools if pm.currentCtx() != 'artAttrSkinContext': mm.eval('artAttrSkinToolScript 3;') lastJoint = pm.artAttrSkinPaintCtx(pm.currentCtx(), query=True, influence=True) # artAttrSkinPaintCtx(currentCtx(), edit=True, influence=get_joint[0]) mm.eval(''' artAttrSkinToolScript 3; artSkinInflListChanging "%s" 0; artSkinInflListChanging "%s" 1; artSkinInflListChanged artAttrSkinPaintCtx; artAttrSkinPaintModePaintSelect 1 artAttrSkinPaintCtx;''' % (lastJoint, unicode(bones_list[0])))
def cycleManipulatorSpace(): """ Cycles through the different manipulator spaces. Usually parent, world, and object. """ validateSelect() current_context = pm.currentCtx() context_title = pm.contextInfo(current_context, t=True) if 'Move' in context_title: context_mode = pm.manipMoveContext('Move', q=True, mode=True) if context_mode == 0: pm.manipMoveContext('Move', edit=True, mode=context_mode + 1) pm.displayInfo('In Parent space.') elif context_mode == 1: pm.manipMoveContext('Move', edit=True, mode=context_mode + 1) pm.displayInfo('In World space.') else: pm.manipMoveContext('Move', edit=True, mode=0) pm.displayInfo('In Object space.') elif 'Rotate' in context_title: context_mode = pm.manipRotateContext('Rotate', q=True, mode=True) if context_mode == 0: pm.manipRotateContext('Rotate', edit=True, mode=context_mode + 1) pm.displayInfo('In World space.') elif context_mode == 1: pm.manipRotateContext('Rotate', edit=True, mode=context_mode + 1) pm.displayInfo('In Gimbal space.') else: pm.manipRotateContext('Rotate', edit=True, mode=0) pm.displayInfo('In Object space.') elif 'Scale' in context_title: context_mode = pm.manipScaleContext('Scale', q=True, mode=True) if context_mode == 0: pm.manipScaleContext('Scale', edit=True, mode=context_mode + 1) pm.displayInfo('In Parent space.') elif context_mode == 1: pm.manipScaleContext('Scale', edit=True, mode=context_mode + 1) pm.displayInfo('In World space.') else: pm.manipScaleContext('Scale', edit=True, mode=0) pm.displayInfo('In Object space.')
def floodBls(transform): pm.select(transform, r=1) if len(pm.ls(sl=1)) == 0: pm.warning('Select a Mesh!') # if we're not currently in the paint skin weights tool context, get us into it if pm.currentCtx() != "artAttrBlendShapeContext": mel.eval("ArtPaintBlendShapeWeightsTool;") # first get the current settings so that the user doesn't have to switch back currOp = pm.artAttrCtx(pm.currentCtx(), q=1, selectedattroper=1) currValue = pm.artAttrCtx(pm.currentCtx(), q=1, value=1) # flood the current selection to zero # first set our tool to the selected operation and value pm.artAttrCtx(pm.currentCtx(), e=1, selectedattroper="absolute") pm.artAttrCtx(pm.currentCtx(), e=1, value=0) pm.artAttrCtx(pm.currentCtx(), e=1, clear=1) # # set the tools back to the way you found them pm.artAttrCtx(pm.currentCtx(), e=1, selectedattroper=currOp) pm.artAttrCtx(pm.currentCtx(), e=1, value=currValue)
def select_influence_below_or_go_to_min_frame(weight_value=None): if is_skinning(): ctx = pm.currentCtx() if not weight_value: weight_value = pm.optionVar.get( k.OptionVars.SelectVerticesBelowInfluence, 0.01) pm.mel.artSkinSelectVertices("artAttrSkinPaintCtx", 0, 0) # Select affected vertices sel = pm.selected() target_joint = pm.artAttrSkinPaintCtx(ctx, q=True, influence=True) sel_mesh = sel[0].node().getTransform() skincluster = pm.PyNode(pm.mel.findRelatedSkinCluster(sel_mesh)) if not skincluster: pm.warning("No Skin Cluster found from selection") return get_data = skincluster.getPointsAffectedByInfluence(target_joint) weight_data = get_data[1] vert_data = [] if len(get_data[0]) > 0: for each in get_data[0][0]: vert_data.append(each.currentItemIndex()) sel_list = [] for vert, weight in zip(vert_data, weight_data): if weight < weight_value: sel_list.append(sel_mesh.name() + ".vtx[{}]".format(vert)) if not sel_list: sys.stdout.write( "No Vertices found below value: {}\n".format(weight_value)) deselect_skin_vertices_or_unsnap_vertices() return pm.select(sel_list, replace=True) else: pm.mel.GoToMinFrame()
def tglAttr(): # NOTE 获取当前使用的工具 ctx = pm.currentCtx() sel_list = pm.ls(sl=1) if ctx == "moveSuperContext": attr_list = ['tx', 'ty', 'tz'] elif ctx == "RotateSuperContext": attr_list = ['rx', 'ry', 'rz'] elif ctx == "scaleSuperContext": attr_list = ['sx', 'sy', 'sz'] else: return for sel in sel_list: for attr in attr_list: if not hasattr(sel, attr): continue attr = pm.Attribute("%s.%s" % (sel, attr)) attr.setKeyable(not attr.isKeyable()) attr.setLocked(not attr.isLocked())
def changeContext(): currentTool = pm.currentCtx() if currentTool == 'RotateSuperContext': # lockCheck_Rotate.setVisible(True) reset_Move.setVisible(False) lock_Move.setVisible(False) unlock_Move.setVisible(False) reset_Rotate.setVisible(True) lock_Rotate.setVisible(True) unlock_Rotate.setVisible(True) # lockCheck_Translate.setVisible(False) # rotateButton.setTool('RotateSuperContext') rotateButton.select() print 'カレントツール', currentTool elif currentTool == 'moveSuperContext': reset_Rotate.setVisible(False) lock_Rotate.setVisible(False) unlock_Rotate.setVisible(False) # lockCheck_Rotate.setVisible(False) reset_Move.setVisible(True) lock_Move.setVisible(True) unlock_Move.setVisible(True) # lockCheck_Translate.setVisible(True) # moveButton.setTool('moveSuperContext') moveButton.select() print 'カレントツール', currentTool else: reset_Rotate.setVisible(False) lock_Rotate.setVisible(False) unlock_Rotate.setVisible(False) # lockCheck_Rotate.setVisible(False) reset_Move.setVisible(False) lock_Move.setVisible(False) unlock_Move.setVisible(False)
def setTransformManipulatorMode(mode): context = pymel.currentCtx() if context == 'RotateSuperContext': if mode == 'world': mode = 1 elif mode == 'local': mode = 0 elif mode == 'trueValues': mode = 2 pymel.manipRotateContext('Rotate', edit=True, mode=mode) elif context == 'moveSuperContext': if mode == 'world': mode = 2 elif mode == 'local': mode = 0 elif mode == 'trueValues': mode = 1 pymel.manipMoveContext('Move', edit=True, mode=mode) elif context == 'scaleSuperContext': if mode == 'world': mode = 0 elif mode == 'local': mode = 0 elif mode == 'trueValues': mode = 0 pymel.manipScaleContext('Scale', edit=True, mode=mode)
def hairJiggle( nodes=[], prefix='jiggle', stretchable=True ): ''' update : 2015-04-27 # # 마야에서 기본으로 같은 기능을 하는 MakeCurvesDynamic 스크립트가 있으나 # 리턴 값이 없어 사용이 불가 # pm.runtime.MakeCurvesDynamic('curve1') # # makeCurvesDynamic 2 { "0", "1", "0", "1", "0"}; # $args[0] = surfaceAttach If true then connect the hairs to a surface(also selected) basing the uv on the nearest point to the first curve cv # $args[1] = snapToSurface If true and attaching to a surface then also snap the curve to the surface. # $args[2] = matchPosition If true then make the input curve a degree one so resulting output curve exactly matches the position. # $args[3] = createOutCurves If true then output curves are created # $args[4] = createPfxHair If true then hair is created. # ''' if nodes: pm.select(nodes) # get joints joints = pm.ls(sl=True, type='joint') if not joints: raise # get hairSystem hairSystem=None hairSystems = pm.ls(sl=True, dag=True, type='hairSystem') if hairSystems: hairSystem = hairSystems[-1] # get nucleus nucleus=None nucleuss = pm.ls(sl=True, dag=True, type='nucleus') if nucleuss: nucleus = nucleuss[-1] # store current state currentToolMode = pm.currentCtx() pm.setToolTo( 'selectSuperContext' ) sel = pm.selected() # # nucleus # if not nucleus and not hairSystem: nucleus = pm.createNode( 'nucleus' ) nucleus.rename( prefix+'_nucleus' ) pm.PyNode('time1').outTime >> nucleus.currentTime # # hairSystem # hairSystemTr = None if hairSystem: hairSystemTr = hairSystem.getParent() else: hairSystem = pm.createNode( 'hairSystem' ) hairSystemTr = hairSystem.getParent() hairSystemTr.rename( prefix+'_hairSys' ) # 새로 생성된 헤어와 뉴클리어스 연결 << connectAttr nextAvailable플래그로 해결해보려했으나.. 복잡.. 멜을 사용하는게 제일 편함. #pm.PyNode('time1').outTime >> hairSystem.currentTime #hairSystem.currentState >> nucleus.inputActive[0] #hairSystem.startState >> nucleus.inputActiveStart[0] #nucleus.outputObjects[0] >> hairSystem.nextState #nucleus.startFrame >> hairSystem.startFrame # 새로 생성된 헤어와 뉴클리어스 연결 pm.mel.assignNSolver( nucleus ) # default Value hairSystem.active.set( True ) # # follicle 생성 # follicle = pm.createNode( 'follicle' ) follicleTr = follicle.getParent() follicleTr.rename( prefix+'_follicle' ) # follicle 위치조정 pm.delete( pm.pointConstraint( joints[0], follicleTr ) ) pm.delete( pm.orientConstraint( joints[0], follicleTr, offset=(0, 90, 0) ) ) # follicle이 조인트, parent를 따라가도록설정 # Start Joint의 Parent가 없으면 현재 Start에 페어런트 검. parent = joints[0].getParent() const = None if parent: const = pm.parentConstraint( parent, follicleTr, mo=True) else: const = pm.parentConstraint( joints[0], follicleTr, mo=True) # 기본값 follicle.restPose.set(1) # same as start follicle.startDirection.set(1) # start Curve base follicle.degree.set(2) follicle.clumpWidth.set(5) # 폴리클 디스플레이 크기 # # curve Setting # # startCurve 생성 startCurve = jntToCrv( joints, degree=3, ep=True ) startCurve.setParent( follicleTr ) startCurve.rename( prefix+'_startCurve' ) # outputCurve 생성 outputCurveShape = pm.createNode( 'nurbsCurve' ) outputCurve = outputCurveShape.getParent() outputCurve.rename( prefix+'_outputCurve' ) # # DG # settableNum = 0 while True: if hairSystem.inputHair[ settableNum ].isSettable(): break settableNum +=1 startCurve.getShape().worldSpace >> follicle.startPosition follicle.outHair >> hairSystem.inputHair[ settableNum ] hairSystem.outputHair[ settableNum ] >> follicle.currentPosition pm.connectAttr( follicle+'.outCurve', outputCurveShape+'.create' ) # follicle.outCurve >> outputCurveShape.create # 이부분에서 다음 경고 발생: Warning: pymel.core.general : Could not create desired MFn. Defaulting to MFnDagNode. # # # # ikHandle # HDL, EFF = pm.ikHandle( solver='ikSplineSolver', startJoint=joints[0], endEffector=joints[-1], createCurve=False, curve=outputCurveShape, parentCurve=False ) HDL.rename( prefix+'_HDL') EFF.rename( prefix+'_EFF') # # # 그루핑 # rigGrp = pm.group(n=prefix+'_jointChainRig_grp#',em=True) rigGrp.v.set(False) pm.parent(follicleTr, HDL, outputCurve, rigGrp) # # # 스트레치 세팅 # if stretchable: # # 커브 리빌드, 익스텐드 # rdbCrv, rbd = pm.rebuildCurve( outputCurveShape, ch=True, replaceOriginal=False, rebuildType=0, # uniform endKnots=1, # 0 - uniform end knots, 1 - multiple end knots keepRange=0, # 0 - reparameterize the resulting curve from 0 to 1, 1 - keep the original curve parameterization, 2 - reparameterize the result from 0 to number of spans keepControlPoints=False, keepEndPoints=True, keepTangents=True, spans=len(joints), degree=3, tol=0.001 ) # # Locators on Curve # unit = 1.0 / (len(joints)-1) locOnCrvs = [] for i in range(len(joints)): param = unit * i xformOnCrv = pm.spaceLocator( n='xformOnCrv#') xformOnCrv.addAttr( 'parameter', sn='pr', dv=param, keyable=True ) xformOnCrv.addAttr( 'turnOnPercentage', sn='top', dv=False, at='bool', keyable=True ) xformOnCrv.addAttr( 'revRotation', sn='rot', keyable=True ) xformOnCrv.it.set(False) xformOnCrv.rename( 'xformOnCrv%02d'%i ) pntOnCrv = pm.PyNode( pm.pointOnCurve( rdbCrv.getShape(), parameter=param, ch=True ) ) pntOnCrv.turnOnPercentage.set(True) pntOnCrv.setAttr('parameter', keyable=True) pntOnCrv.setAttr('turnOnPercentage', keyable=True) pntOnCrv.rename( xformOnCrv+'_POC' ) xformOnCrv.parameter >> pntOnCrv.parameter xformOnCrv.turnOnPercentage >> pntOnCrv.turnOnPercentage pntOnCrv.position >> xformOnCrv.t locOnCrvs.append(xformOnCrv) # # distance Rig # distNodes = [] for i in range(len(locOnCrvs)-1): dist = pm.createNode( 'distanceDimShape' ) locOnCrvs[i].worldPosition[0] >> dist.startPoint locOnCrvs[i+1].worldPosition[0] >> dist.endPoint distNodes.append( dist ) # # ik핸들 커브 변경 # pm.ikHandle( HDL, e=True, curve=rdbCrv ) # # connect To Joint # for dist, jnt in zip(distNodes, joints[1:]): dist.distance >> jnt.tx # # 그루핑 # pm.parent(rdbCrv, locOnCrvs, [dist.getParent() for dist in distNodes], rigGrp) # # # restore state # pm.setToolTo( currentToolMode ) if sel: pm.select(sel) else: pm.select(cl=True)
def __init__(s, **kwargs): s.callback, s._last_tool = None, pmc.currentCtx() kwargs["e"] = ("PostToolChanged", s._changed) s.id = pmc.scriptJob(**kwargs)
def nclothAttrSmooth(iterations=1): for i in range(iterations): pm.mel.artAttrPaintOperation('artAttrCtx', 'Smooth') pm.artAttrCtx(pm.currentCtx(), clear=1, e=1)
def watch_tools(s): """ Track changes to tools """ curr_tool = pmc.currentCtx() if curr_tool != s.name: s.last_tool = curr_tool
def is_skinning(): state = False ctx = pm.currentCtx() if pm.contextInfo(ctx, q=True, c=True) == "artAttrSkin": return True return False