Ejemplo n.º 1
0
	def syncSelection( self ):
		'''
		syncs the list selection with the existing paint skin weights UI
		'''
		cur = cmd.artAttrSkinPaintCtx( cmd.currentCtx(), q=True, inf=True )
		if cur is None:
			return

		self.UI_tsl.clearSelection()
		self.UI_tsl.selectByValue( cur )
Ejemplo n.º 2
0
    def syncSelection(self):
        '''
		syncs the list selection with the existing paint skin weights UI
		'''
        cur = cmd.artAttrSkinPaintCtx(cmd.currentCtx(), q=True, inf=True)
        if cur is None:
            return

        self.UI_tsl.clearSelection()
        self.UI_tsl.selectByValue(cur)
Ejemplo n.º 3
0
def switchInfluence():

    obj = cmds.ls(sl=True)[0]

    history = cmds.listHistory(obj, pdo=1, il=2)
    skinCluster = ''

    for node in history:
        if cmds.nodeType(node) == 'skinCluster':
            skinCluster = node

    joints = cmds.skinCluster(skinCluster, q=True, inf=True)

    unlockedJoints = []

    for joint in joints:
        lock = cmds.getAttr('%s.liw' % joint)
        if not lock:
            unlockedJoints.append(joint)

    currentItem = cmds.artAttrSkinPaintCtx('artAttrSkinPaintCtx1',
                                           q=True,
                                           inf=True)
    try:
        i = unlockedJoints.index(currentItem)
    except:
        i = 0
    i += 1
    if i == len(unlockedJoints):
        i = 0

    cmds.artAttrSkinPaintCtx('artAttrSkinPaintCtx1',
                             e=True,
                             inf=unlockedJoints[i])

    mel.eval('artSkinInflListChanging %s 0' % currentItem)
    mel.eval('artSkinInflListChanging %s 1' % unlockedJoints[i])
    mel.eval('artSkinInflListChanged artAttrSkinPaintCtx')

    om.MGlobal.displayInfo('Paint Weights on %s' % unlockedJoints[i])
Ejemplo n.º 4
0
def switchInfluence(): 

    obj = cmds.ls(sl = True)[0]
    
    history = cmds.listHistory(obj)
    skinCluster = ''
    
    for node in history:
        if cmds.nodeType(node) == 'skinCluster':
            skinCluster = node
               
    joints = cmds.skinCluster(skinCluster,q = True,inf = True)
    
    unlockedJoints = []
    
    for joint in joints:
        lock = cmds.getAttr('%s.liw'%joint)
        if not lock:
            unlockedJoints.append(joint)
    
    currentItem = cmds.artAttrSkinPaintCtx('artAttrSkinPaintCtx1',q = True,inf = True)
    try:
        i = unlockedJoints.index(currentItem)
    except:
        i = 0    
    i += 1
    if i == len(unlockedJoints):
        i = 0
    
    
    cmds.artAttrSkinPaintCtx('artAttrSkinPaintCtx1',e = True,inf = unlockedJoints[i])
    
    mel.eval('artSkinInflListChanging %s 0'%currentItem)
    mel.eval('artSkinInflListChanging %s 1'%unlockedJoints[i])
    mel.eval('artSkinInflListChanged artAttrSkinPaintCtx')
    
    print 'Paint Weights on %s'%unlockedJoints[i]
Ejemplo n.º 5
0
def smoothFlood(skinCluster, iterations=1):
    '''
	Smooth flood all influences
	@param geometry: The geometry connected to the skinCluster to smooth
	@type geometry: str
	@param iterations: Number of smooth iterations
	@type iterations: int
	'''
    # Check zero iterations
    if not iterations: return

    # Get current tool
    currentTool = mc.currentCtx()

    # Select geometry
    geometry = glTools.utils.deformer.getAffectedGeometry(skinCluster).keys()
    mc.select(geometry)

    # Get skinCluster influence list
    influenceList = mc.skinCluster(skinCluster, q=True, inf=True)

    # Unlock influence weights
    for influence in influenceList:
        mc.setAttr(influence + '.lockInfluenceWeights', 0)

    # Initialize paint context
    skinPaintTool = 'artAttrSkinContext'
    if not mc.artAttrSkinPaintCtx(skinPaintTool, ex=True):
        mc.artAttrSkinPaintCtx(skinPaintTool,
                               i1='paintSkinWeights.xpm',
                               whichTool='skinWeights')
    mc.setToolTo(skinPaintTool)
    mc.artAttrSkinPaintCtx(skinPaintTool, edit=True, sao='smooth')

    # Smooth Weights
    for i in range(iterations):
        print(skinCluster + ': Smooth Iteration - ' + str(i + 1))
        for influence in influenceList:
            # Lock current influence weights
            mc.setAttr(influence + '.lockInfluenceWeights', 1)
            # Smooth Flood
            mm.eval('artSkinSelectInfluence artAttrSkinPaintCtx "' +
                    influence + '" "' + influence + '"')
            mc.artAttrSkinPaintCtx(skinPaintTool, e=True, clear=True)
            # Unlock current influence weights
            mc.setAttr(influence + '.lockInfluenceWeights', 0)

    # Reset current tool
    mc.setToolTo(currentTool)
Ejemplo n.º 6
0
def smoothFlood(skinCluster,iterations=1):
	'''
	Smooth flood all influences
	@param geometry: The geometry connected to the skinCluster to smooth
	@type geometry: str
	@param iterations: Number of smooth iterations
	@type iterations: int
	'''
	# Check zero iterations
	if not iterations: return
	
	# Get current tool
	currentTool = mc.currentCtx()
	
	# Select geometry
	geometry = glTools.utils.deformer.getAffectedGeometry(skinCluster).keys()
	mc.select(geometry)
	
	# Get skinCluster influence list
	influenceList = mc.skinCluster(skinCluster,q=True,inf=True)
	
	# Unlock influence weights
	for influence in influenceList: mc.setAttr(influence+'.lockInfluenceWeights',0)
	
	# Initialize paint context
	skinPaintTool = 'artAttrSkinContext'
	if not mc.artAttrSkinPaintCtx(skinPaintTool,ex=True):
		mc.artAttrSkinPaintCtx(skinPaintTool,i1='paintSkinWeights.xpm',whichTool='skinWeights')
	mc.setToolTo(skinPaintTool)
	mc.artAttrSkinPaintCtx(skinPaintTool,edit=True,sao='smooth')
	
	# Smooth Weights
	for i in range(iterations):
		print(skinCluster+': Smooth Iteration - '+str(i+1))
		for influence in influenceList:
			# Lock current influence weights
			mc.setAttr(influence+'.lockInfluenceWeights',1)
			# Smooth Flood
			mm.eval('artSkinSelectInfluence artAttrSkinPaintCtx "'+influence+'" "'+influence+'"')
			mc.artAttrSkinPaintCtx(skinPaintTool,e=True,clear=True)
			# Unlock current influence weights
			mc.setAttr(influence+'.lockInfluenceWeights',0)
	
	# Reset current tool
	mc.setToolTo(currentTool)
Ejemplo n.º 7
0
def switchInfluence():    
    sel = cmds.ls(sl = True)
    influenceList = cmds.skinCluster(sel, query = True, influence = True)
    unlockedList = []
    for num in influenceList:
        lockValue = cmds.getAttr('%s.liw'%num)
        if lockValue == False:
            unlockedList.append(num)
    #find selected influence
    currentCtx1 = cmds.currentCtx()
    currentInf = cmds.artAttrSkinPaintCtx(currentCtx1, query = True, inf = True)
    #Check for thing in index
    if currentInf in unlockedList:
        #find index
        index = unlockedList.index(currentInf)
    
        myJoint = unlockedList[(index -1)]
        mel.eval('artSkinSelectInfluence("artAttrSkinPaintCtx", "%s")'% myJoint)
    else:
        error("HappyBirthday Claytor")
Ejemplo n.º 8
0
    def smoothBetweenSelectedJoints(self):
        '''
		performs a flood smooth between the selected joints
		'''

        #grab initial state
        initialLockState = [cmd.getAttr('%s.liw' % j) for j in self.UI_tsl]
        initMode = cmd.artAttrSkinPaintCtx(cmd.currentCtx(), q=True, sao=True)
        initOpacity = cmd.artAttrSkinPaintCtx(cmd.currentCtx(),
                                              q=True,
                                              opacity=True)
        initValue = cmd.artAttrSkinPaintCtx(cmd.currentCtx(),
                                            q=True,
                                            value=True)

        self.setLockStateForAll(True, False)
        self.setLockStateForSelected(False, False)

        #perform the smooth
        cmd.artAttrSkinPaintCtx(cmd.currentCtx(), e=True, sao='smooth')
        j = self.iterSelected().next()
        if j is not None:
            cmd.artAttrSkinPaintCtx(cmd.currentCtx(),
                                    e=True,
                                    value=1,
                                    opacity=1,
                                    clear=True)

        #restore state
        cmd.artAttrSkinPaintCtx(cmd.currentCtx(), e=True, sao=initMode)
        cmd.artAttrSkinPaintCtx(cmd.currentCtx(), e=True, opacity=initOpacity)
        cmd.artAttrSkinPaintCtx(cmd.currentCtx(), e=True, value=initValue)
        for j, state in zip(self.UI_tsl, initialLockState):
            cmd.setAttr('%s.liw' % j, state)
Ejemplo n.º 9
0
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!")
Ejemplo n.º 10
0
	def smoothBetweenSelectedJoints( self ):
		'''
		performs a flood smooth between the selected joints
		'''

		#grab initial state
		initialLockState = [ cmd.getAttr( '%s.liw' % j ) for j in self.UI_tsl ]
		initMode = cmd.artAttrSkinPaintCtx( cmd.currentCtx(), q=True, sao=True )
		initOpacity = cmd.artAttrSkinPaintCtx( cmd.currentCtx(), q=True, opacity=True )
		initValue = cmd.artAttrSkinPaintCtx( cmd.currentCtx(), q=True, value=True )

		self.setLockStateForAll( True, False )
		self.setLockStateForSelected( False, False )


		#perform the smooth
		cmd.artAttrSkinPaintCtx( cmd.currentCtx(), e=True, sao='smooth' )
		j = self.iterSelected().next()
		if j is not None:
			cmd.artAttrSkinPaintCtx( cmd.currentCtx(), e=True, value=1, opacity=1, clear=True )


		#restore state
		cmd.artAttrSkinPaintCtx( cmd.currentCtx(), e=True, sao=initMode )
		cmd.artAttrSkinPaintCtx( cmd.currentCtx(), e=True, opacity=initOpacity )
		cmd.artAttrSkinPaintCtx( cmd.currentCtx(), e=True, value=initValue )
		for j, state in zip( self.UI_tsl, initialLockState ):
			cmd.setAttr( '%s.liw' % j, state )
Ejemplo n.º 11
0
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!")