def makeVColorMask(obj,obj_v_len): #?J???[?Z?b?g??擾 pm.polyColorSet(obj, currentColorSet=True, colorSet= 'colorSet_for_cartoonBlur' ) temp = pm.polyColorSet( query=True, currentColorSet=True ) vColorMask = [ 1 - (sum(pm.polyColorPerVertex( obj.vtx[i],q=True,r=True,g=True,b=True ))/3 ) for i in range(0,obj_v_len) ] print(vColorMask) return vColorMask
def NumColorSets(): ColorSets = pm.polyColorSet( query=True, allColorSets=True ) # If there are No Color Sets, Return 0, if there is Exactly 1, Return 1, if there are at least 2, Return 2. if ColorSets == None: return 0 elif len(ColorSets) == 1: return 1 elif len(ColorSets) > 1: return 2
def makeVtxColorSet(obj): #???2????ColorSet?????m?F colSetLis = pm.polyColorSet(obj, query=1, allColorSets=1) if type(colSetLis) == list and u'colorSet_for_cartoonBlur' in pm.polyColorSet(obj, query=1, allColorSets=1): pm.polyColorSet( colorSet = 'colorSet_for_cartoonBlur', delete = 1) pm.confirmDialog( title="CartoonBlur", message="Vertex color set 'colorSet_for_cartoonBlur' is already exsist./Overwrited") pm.polyColorSet(obj, create = 1, rpt = "RGB", colorSet = 'colorSet_for_cartoonBlur') pm.polyColorPerVertex (obj, rgb = (1.0,1.0,1.0) ) pm.confirmDialog( title="CartoonBlur", message="???_?J???[?fcolorSet_for_cartoonBlur?f??????h??????????G?t?F?N?g???????????B\n?????x????????????????x???????????????????o?O????????")
def CreateColorSet( IntIndex ): i = IntIndex colorSetName = 'colorSet%d' % i print colorSetName pm.polyColorSet( create=True, colorSet = colorSetName )
def GenerateVertexColor( StrNoiseOpt, FMax, FMin ): NoiseFunction = StrNoiseOpt Min = FMin Max = FMax # Check that a Valid Selection has been made Selected = pm.ls( selection = True ) if len(Selected) == 0: return "No Objects Selected" elif len(Selected) > 1: return "More Than One Object Selected" # If there is a Valid Selection elif len(Selected) == 1: # Get the Selection's Shape SelectionShape = Selected[0].getShape() # Check if the Object Type is a Polygon Mesh bIsValidObjType = pm.objectType( SelectionShape, isType='mesh' ) # If it is Not, Exit the Function and tell the User if bIsValidObjType != True: return "Selected Object is Not a Polygon Mesh" # If Everything in Valid, Execute The Script else: # Check Number of Color Sets IntNumOfColorSets = NumColorSets() if IntNumOfColorSets == 0: # Create 2 Color Sets, Set the first one to .5 # and Run the Noise Function on the Second for i in range(2): CreateColorSet(i+1) # If the Current Color Set is colorSet1 set it to 0.5 Grey if pm.polyColorSet( query=True, colorSet=True, currentColorSet=True ) == 'colorSet1': SetMiddleGrey( Selected[0] ) # Else If it is not the Current Color Set, Set to the Current and Set it's Color to 0.5 Grey elif pm.polyColorSet( query=True, colorSet=True, currentColorSet=True ) != 'colorSet1': pm.polyColorSet( currentColorSet=True, colorSet='colorSet1' ) SetMiddleGrey( Selected[0] ) pm.polyColorSet( currentColorSet=True, colorSet='colorSet2' ) if pm.polyColorSet( query=True, currentColorSet=True, colorSet=True ) == 'colorSet1': return "Unable To Set Current Color Set to colorSet2" else: if NoiseFunction == 'Simple': SimpleNoise( Selected[0], Min, Max ) return "Random Noise for 'colorSet2' Was Set for %s" % Selected[0].name() else: return "Invalid Noise Function Sepcified" elif IntNumOfColorSets == 1: # Create 'colorSet2' CreateColorSet(2) # Set 'colorSet2' as the Active Color Set if it's not the Active Color Set if pm.polyColorSet( query=True, currentColorSet=True, colorSet=True ) != 'colorSet2': pm.polyColorSet( currentColorSet=True, colorSet='colorSet2' ) # Run Noise Function if NoiseFunction == 'Simple': SimpleNoise( Selected[0], Min, Max ) return "Random Noise for 'colorSet2' Was Set for %s" % Selected[0].name() else: return "Invalid Noise Function Sepcified" elif IntNumOfColorSets == 2: # List All Color Sets AllColorSets = pm.polyColorSet( query=True, allColorSets=True ) # Check for 'colorSet2" if 'colorSet2' in AllColorSets: if pm.polyColorSet( query=True, currentColorSet=True, colorSet=True ) != 'colorSet2': pm.polyColorSet( currentColorSet=True, colorSet='colorSet2' ) # Run the Noise Function SimpleNoise( Selected[0], Min, Max ) return "Random Noise for 'colorSet2' Was Set for %s" % Selected[0].name() # if it does not exist Create 'colorSet2' CreateColorSet(2) # Set 'colorSet2' as the Active Color Set if it's not the Active Color Set if pm.polyColorSet( query=True, currentColorSet=True, colorSet=True ) != 'colorSet2': pm.polyColorSet( currentColorSet=True, colorSet='colorSet2' ) # Run the Noise Function if NoiseFunction == 'Simple': SimpleNoise( Selected[0], Min, Max ) return "Random Noise for 'colorSet2' Was Set for %s" % Selected[0].name() else: return "Invalid Noise Function Sepcified" else: return "Unknown Error Occurred"