def enableRitalin(enable = True): global RitalinEnabled global resetTumbleToolToCOI if enable == True: if RitalinEnabled == False: if (cmds.tumbleCtx ("tumbleContext", query = True, localTumble = true)) == 1: cmds.tumbleCtx ("tumbleContext", edit = True, localTumble = 0) resetTumbleToolToCOI = True else: resetTumbleToolToCOI = False cleanRitalinScriptJobs() #The dragRelease event is king, it always gets fired when the user presses the mouse button or moves the mouse with the button pressed - exactly what we need Job1 = cmds.scriptJob(runOnce = False, killWithScene = False, event =('DragRelease', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)")) RitalinScriptJobs.append(Job1) #Due to a bug in Maya we need to run the following event at least once to ensure that the DragRelease event gets triggered above. Otherwise it never kicks in :-( #Also, to prevent the undo/redo queue from getting overwritten we only do store selected components when there are no commands to redo, #which is only the case if the selction change was due to user-action rather than undo/redo... Job2 = cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)")) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job2) Job3 = cmds.scriptJob(runOnce = False, killWithScene = False, event =('Undo', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)")) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job3) Job4 = cmds.scriptJob(runOnce = False, killWithScene = False, event =('Redo', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)")) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job4) setCamRotatePivots() if enable == False: #print ("Attempting to disable Ritalin - Deleting script Jobs") if resetTumbleToolToCOI == True: cmds.tumbleCtx ("tumbleContext", edit = True, localTumble = 1) cleanRitalinScriptJobs()
def switch(self, onOff): utilMod.killScriptJobs("G.tumbleOnObjectsScriptJobs") if onOff: cmds.tumbleCtx("tumbleContext", edit=True, localTumble=0) #scriptJob G.tumbleOnObjectsScriptJobs.append( cmds.scriptJob(runOnce=False, killWithScene=False, event=('DragRelease', self.update))) G.tumbleOnObjectsScriptJobs.append( cmds.scriptJob(runOnce=False, killWithScene=False, event=('SelectionChanged', self.update))) G.tumbleOnObjectsScriptJobs.append( cmds.scriptJob(runOnce=False, killWithScene=False, event=('timeChanged', self.update))) self.update() else: cmds.tumbleCtx("tumbleContext", edit=True, localTumble=self.currentLocalTumble)
def setDefaultConfig(self): #STATIC PREFS # tumble config #cmds.tumbleCtx( 'tumbleContext', edit=True, alternateContext=True, tumbleScale=1.0, localTumble=0, autoOrthoConstrain=False, orthoLock=False) cmds.tumbleCtx('tumbleContext', edit=True, alternateContext=True, tumbleScale=1.0, localTumble=0) cmds.dollyCtx('dollyContext', edit=True, alternateContext=True, scale=1.0, localDolly=True, centerOfInterestDolly=False) #timeline ticks display G.playBackSliderPython = G.playBackSliderPython or mel.eval( '$aTools_playBackSliderPython=$gPlayBackSlider') cmds.timeControl(G.playBackSliderPython, edit=True, showKeys="mainChannelBox", showKeysCombined=True, animLayerFilterOptions="active") #tickDrawSpecial Color cmds.displayRGBColor('timeSliderTickDrawSpecial', 1, 1, .4) #CUSTOMIZABLE PREFS for loopPref in PREFS: name = loopPref["name"] self.setPref(name, True)
def switch(self, onOff): utilMod.killScriptJobs("G.tumbleOnObjectsScriptJobs") if onOff: cmds.tumbleCtx ("tumbleContext", edit=True, localTumble=0) #scriptJob G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('DragRelease', self.update ))) G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.update ))) G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('timeChanged', self.update ))) self.update() else: cmds.tumbleCtx ("tumbleContext", edit=True, localTumble=self.currentLocalTumble)
def __init__(self): self.currentLocalTumble = cmds.tumbleCtx ("tumbleContext", query=True, localTumble=True) self.unitMultiplier = {"mm": 0.1, "cm": 1.0, "m" : 100.0, "in": 2.54, "ft": 30.48, "yd": 91.44}
def setDefaultConfig(self): #STATIC PREFS # tumble config #cmds.tumbleCtx( 'tumbleContext', edit=True, alternateContext=True, tumbleScale=1.0, localTumble=0, autoOrthoConstrain=False, orthoLock=False) cmds.tumbleCtx( 'tumbleContext', edit=True, alternateContext=True, tumbleScale=1.0, localTumble=0) cmds.dollyCtx( 'dollyContext', edit=True, alternateContext=True, scale=1.0, localDolly=True, centerOfInterestDolly=False) #timeline ticks display G.playBackSliderPython = G.playBackSliderPython or mel.eval('$aTools_playBackSliderPython=$gPlayBackSlider') cmds.timeControl(G.playBackSliderPython, edit=True, showKeys="mainChannelBox", showKeysCombined=True, animLayerFilterOptions="active") #tickDrawSpecial Color cmds.displayRGBColor('timeSliderTickDrawSpecial',1,1,.4) #CUSTOMIZABLE PREFS for loopPref in PREFS: name = loopPref["name"] self.setPref(name, True)
def checkTumble(): if mc.tumbleCtx('tumbleContext', query=True, localTumble=1) == False: mc.tumbleCtx('tumbleContext', edit=True, localTumble=1) else: mc.warning("Tumble already about Center of Interest")
def setCamRotatePivots(oObjects = []): global RitalinEnabled global RitalinHonorInfluenceJoints Units = cmds.currentUnit(query = True, linear = True) #Unfortunately Maya is too stupid to set the rotion pivot according to the currently set unit type in the scene. #It always uses cm internally, so we need a Unit Multiplier (UM) depending on the active unit type for correction in case units are not set to cm if Units == "mm": UM = 0.1 elif Units == "cm": UM = 1.0 elif Units == "m": UM = 100.0 elif Units == "in": UM = 2.54 elif Units == "ft": UM = 30.48 elif Units == "yd": UM = 91.44 Cams = cmds.ls( dag = true, cameras = True ) if RitalinEnabled == True: CheckPaintTool = True Continue = False ComputeCenterAlreadyDone = False if len(oObjects) == 0: #print("No Objects given to compute BB for, using current selection instead!") Selec = cmds.ls( selection = True ) else: Selec = oObjects CheckPaintTool = False #In case there are objects given to compute BB center for we don't need to check for the paint tool, we already know what to compute BB for if len(Selec) > 0: #We have objects to work with? X = 0.0; Y = 0.0; Z = 0.0 if CheckPaintTool: #print ("Checking paint tool...") #Let's find out if we are in skin weights paint mode currCtx = cmds.currentCtx(); #print ("Current Context is: " + str(currCtx)) currTool = "" try: #contextInfo operations are buggy in Maya 2011, we need to try.. :-( currTool = cmds.contextInfo (currCtx, t = True); #print ("Current Tool is: " + str(currTool)) except: #print ("Fail") pass if RitalinHonorInfluenceJoints == True: #In case we are painting skin weights we can ignore everything and just concentrate on the currently active skin joint if currTool == "artAttrSkin" or currTool == "Paint Skin Weights Tool": whichTool = cmds.artAttrSkinPaintCtx (currCtx, query = True, whichTool = True) #print ("Tool name is: " + str(whichTool)) if whichTool == "skinWeights": #Yes, we are in skin paint weights mode #print ("We are in paint skin weights mode...") influenceJoint = "" #Find the currently active joint for which weights are being painted influenceJoint = cmds.artAttrSkinPaintCtx (currCtx, query = true, influence = true) #print("Currently painting joint: " + str(influenceJoint)) if influenceJoint != "": influenceJoint += (".rotatePivot") BB = cmds.exactWorldBoundingBox (influenceJoint) X = ((BB[0] + BB[3])/2) Y = ((BB[1] + BB[4])/2) Z = ((BB[2] + BB[5])/2) ComputeCenterAlreadyDone = True Continue = True if ComputeCenterAlreadyDone == False: #Standard computation in case we are not in paintSkinWeights mode or don't care if we are Joints = [] stdObjects = [] specialTransformTypes = ["selectHandle", "rotatePivot", "scalePivot", "Axis"] for o in Selec: if (cmds.nodeType (o) == "joint"): #Maya can't compute BB of joints (API bug?) so we have to work around this by dealing with joint's rotatePivots instead #print ("Selected node is of type joint") isSpecialType = False for Type in specialTransformTypes: if o.find (Type) > -1: #print ("Selected node is of a special Transform Type") stdObjects.append(o) isSpecialType = True break if isSpecialType == False: #print ("Selected node is not of special TransformType, appending directly") stdObjects.append(o + ".rotatePivot") elif (cmds.nodeType (o) == "transform"): #Maya does not take shape nodes of selected objects into account automatically, we must supply such nodes directly #to compute BB of e.g. skinned objects or objects whose pivots have been moved far from their geometric centers #print ("Selected node is of type transform") Shapes = (cmds.ls(o, dagObjects = True, shapes = True, noIntermediate = True)) #Lets get all the shape nodes associated with the transform if len(Shapes) > 0: for shp in Shapes: #print ("Shape is of type " + cmds.nodeType(shp)) #print ("Shape name: " + shp) shpName = str(shp) stdObjects.append(shpName) else: #We have a transform without a shape? stdObjects.append(o) else: #print ("Node must be a subcomponent") stdObjects.append(o) if len(stdObjects) > 0: BB = cmds.exactWorldBoundingBox (stdObjects) #Do standard BB computation X = ((BB[0] + BB[3])/2) Y = ((BB[1] + BB[4])/2) Z = ((BB[2] + BB[5])/2) Continue = True #Finally let'S do the actual tumble pivot setting on the cameras if Continue == True : cmds.tumbleCtx ("tumbleContext", edit = True, localTumble = 0) #Set the tumble tool to honor the cameras tumble pivot X = X * UM Y = Y * UM Z = Z * UM for cam in Cams: try: #finally set the tumble pivot of the camera to the coordinates we have calculated before cmds.setAttr (cam + ".tumblePivot", X, Y, Z) except: Warning("Ritalin: Setting camera tumble pivot on " + cam + "failed!")
def switchObjectTumble(): headsUpDisplayMessage(message='Tumble object focus: '+str(not cmds.tumbleCtx('tumbleContext', objectTumble=True, q=True))) cmds.tumbleCtx('tumbleContext', ac=True, objectTumble=not cmds.tumbleCtx('tumbleContext', objectTumble=True, q=True), e=True)
def setCamRotatePivots(oObjects=[]): global RitalinEnabled global RitalinHonorInfluenceJoints Units = cmds.currentUnit(query=True, linear=True) #Unfortunately Maya is too stupid to set the rotion pivot according to the currently set unit type in the scene. #It always uses cm internally, so we need a Unit Multiplier (UM) depending on the active unit type for correction in case units are not set to cm if Units == "mm": UM = 0.1 elif Units == "cm": UM = 1.0 elif Units == "m": UM = 100.0 elif Units == "in": UM = 2.54 elif Units == "ft": UM = 30.48 elif Units == "yd": UM = 91.44 Cams = cmds.ls(dag=true, cameras=True) if RitalinEnabled == True: CheckPaintTool = True Continue = False ComputeCenterAlreadyDone = False if len(oObjects) == 0: #print("No Objects given to compute BB for, using current selection instead!") Selec = cmds.ls(selection=True) else: Selec = oObjects CheckPaintTool = False #In case there are objects given to compute BB center for we don't need to check for the paint tool, we already know what to compute BB for if len(Selec) > 0: #We have objects to work with? X = 0.0 Y = 0.0 Z = 0.0 if CheckPaintTool: #print ("Checking paint tool...") #Let's find out if we are in skin weights paint mode currCtx = cmds.currentCtx() #print ("Current Context is: " + str(currCtx)) currTool = "" try: #contextInfo operations are buggy in Maya 2011, we need to try.. :-( currTool = cmds.contextInfo(currCtx, t=True) #print ("Current Tool is: " + str(currTool)) except: #print ("Fail") pass if RitalinHonorInfluenceJoints == True: #In case we are painting skin weights we can ignore everything and just concentrate on the currently active skin joint if currTool == "artAttrSkin" or currTool == "Paint Skin Weights Tool": whichTool = cmds.artAttrSkinPaintCtx(currCtx, query=True, whichTool=True) #print ("Tool name is: " + str(whichTool)) if whichTool == "skinWeights": #Yes, we are in skin paint weights mode #print ("We are in paint skin weights mode...") influenceJoint = "" #Find the currently active joint for which weights are being painted influenceJoint = cmds.artAttrSkinPaintCtx( currCtx, query=true, influence=true) #print("Currently painting joint: " + str(influenceJoint)) if influenceJoint != "": influenceJoint += (".rotatePivot") BB = cmds.exactWorldBoundingBox(influenceJoint) X = ((BB[0] + BB[3]) / 2) Y = ((BB[1] + BB[4]) / 2) Z = ((BB[2] + BB[5]) / 2) ComputeCenterAlreadyDone = True Continue = True if ComputeCenterAlreadyDone == False: #Standard computation in case we are not in paintSkinWeights mode or don't care if we are Joints = [] stdObjects = [] specialTransformTypes = [ "selectHandle", "rotatePivot", "scalePivot", "Axis" ] for o in Selec: if (cmds.nodeType(o) == "joint"): #Maya can't compute BB of joints (API bug?) so we have to work around this by dealing with joint's rotatePivots instead #print ("Selected node is of type joint") isSpecialType = False for Type in specialTransformTypes: if o.find(Type) > -1: #print ("Selected node is of a special Transform Type") stdObjects.append(o) isSpecialType = True break if isSpecialType == False: #print ("Selected node is not of special TransformType, appending directly") stdObjects.append(o + ".rotatePivot") elif (cmds.nodeType(o) == "transform"): #Maya does not take shape nodes of selected objects into account automatically, we must supply such nodes directly #to compute BB of e.g. skinned objects or objects whose pivots have been moved far from their geometric centers #print ("Selected node is of type transform") Shapes = ( cmds.ls(o, dagObjects=True, shapes=True, noIntermediate=True) ) #Lets get all the shape nodes associated with the transform if len(Shapes) > 0: for shp in Shapes: #print ("Shape is of type " + cmds.nodeType(shp)) #print ("Shape name: " + shp) shpName = str(shp) stdObjects.append(shpName) else: #We have a transform without a shape? stdObjects.append(o) else: #print ("Node must be a subcomponent") stdObjects.append(o) if len(stdObjects) > 0: BB = cmds.exactWorldBoundingBox( stdObjects) #Do standard BB computation X = ((BB[0] + BB[3]) / 2) Y = ((BB[1] + BB[4]) / 2) Z = ((BB[2] + BB[5]) / 2) Continue = True #Finally let'S do the actual tumble pivot setting on the cameras if Continue == True: cmds.tumbleCtx( "tumbleContext", edit=True, localTumble=0 ) #Set the tumble tool to honor the cameras tumble pivot X = X * UM Y = Y * UM Z = Z * UM for cam in Cams: try: #finally set the tumble pivot of the camera to the coordinates we have calculated before cmds.setAttr(cam + ".tumblePivot", X, Y, Z) except: Warning("Ritalin: Setting camera tumble pivot on " + cam + "failed!")
def enableRitalin(enable=True): global RitalinEnabled global resetTumbleToolToCOI if enable == True: if RitalinEnabled == False: if (cmds.tumbleCtx("tumbleContext", query=True, localTumble=true)) == 1: cmds.tumbleCtx("tumbleContext", edit=True, localTumble=0) resetTumbleToolToCOI = True else: resetTumbleToolToCOI = False cleanRitalinScriptJobs() #The dragRelease event is king, it always gets fired when the user presses the mouse button or moves the mouse with the button pressed - exactly what we need Job1 = cmds.scriptJob( runOnce=False, killWithScene=False, event= ('DragRelease', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)" )) RitalinScriptJobs.append(Job1) #Due to a bug in Maya we need to run the following event at least once to ensure that the DragRelease event gets triggered above. Otherwise it never kicks in :-( #Also, to prevent the undo/redo queue from getting overwritten we only do store selected components when there are no commands to redo, #which is only the case if the selction change was due to user-action rather than undo/redo... Job2 = cmds.scriptJob( runOnce=False, killWithScene=False, event= ('SelectionChanged', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)" )) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job2) Job3 = cmds.scriptJob( runOnce=False, killWithScene=False, event= ('Undo', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)" )) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job3) Job4 = cmds.scriptJob( runOnce=False, killWithScene=False, event= ('Redo', "cmds.undoInfo (swf = False); setCamRotatePivots(); cmds.undoInfo (swf = True)" )) #if cmds.undoInfo(q = true, redoName = True) == '': RitalinScriptJobs.append(Job4) setCamRotatePivots() if enable == False: #print ("Attempting to disable Ritalin - Deleting script Jobs") if resetTumbleToolToCOI == True: cmds.tumbleCtx("tumbleContext", edit=True, localTumble=1) cleanRitalinScriptJobs()