def makeWindowShaders(daytime, glow, environment): ''' Creates shaders for windows. daytime: Boolean variable which is true if it is day and false if it is night. glow: Boolean variable which specifies if all windows will glow if daytime is false, or if some windows will be dark. environment: Triple containing the colour value the environment windows will be given if daytime is true. On exit: A list of shaders is returned. If daytime is true this list contains only one shader. ''' shaderList = [] if daytime == True: windowShader = tools.makeShader((environment[0],environment[1],environment[2]), "glassMaterial") cmds.setAttr("glassMaterial.reflectivity",1.000) cmds.setAttr("glassMaterial.eccentricity",0.291) cmds.setAttr("glassMaterial.specularColor",0.863,0.863,0.863) shaderList.append(windowShader) else: if glow == False: for i in range(1): windowShader = tools.makeShader((0,0,0),"glassMaterial") cmds.setAttr(windowShader[0] + ".reflectivity",1.000) shaderList.append(windowShader) for i in range(4): windowShader = tools.makeShader((1.0,0.75,0),"glassMaterial") inc = random.uniform(0.1,0.6) incR = inc * 1 incG = inc * 0.922 incB = inc * 0.399 cmds.setAttr(windowShader[0] + ".glowIntensity", 0.05) cmds.setAttr(windowShader[0] + ".incandescence", incR,incG,incB) shaderList.append(windowShader) return shaderList
def makeNecessaryShaders(daytime): ''' Creates shaders that are needed for the city. daytime: Boolean variable which is true if it is day and false if it is night. On exit: Shaders for streets, pavement, parks, traffic lights and street lights have been created. ''' streetShader = tools.makeShader((0.145,0.145,0.145), "streetMaterial", "lambert") pavementShader = tools.makeShader((0.701,0.628,0.594), "pavementMaterial", "lambert") park.makeParkShaders() trafficLight.makeLightShaders(daytime)
def makeParkShaders(): ''' Creates the shaders that are necessary for creating parks. On exit: Shaders for fences, fountains and grass has been created. ''' fountainShader = tools.makeShader((0.691,0.683,0.596), "fountainMaterial") cmds.setAttr("fountainMaterial.reflectivity",0) cmds.setAttr("fountainMaterial.specularColor",0.179,0.179,0.179) grassShader = tools.makeShader((0.043,0.392,0.008), "grassMaterial") cmds.setAttr("grassMaterial.reflectivity",0) cmds.setAttr("grassMaterial.specularColor",0.137,0.137,0.137) fenceShader = tools.makeShader((0.373,0.269,0.168), "fenceMaterial") cmds.setAttr("fenceMaterial.reflectivity",0) cmds.setAttr("fenceMaterial.specularColor",0.137,0.137,0.137)
def makeTreeShaders(num): ''' Creates a number of shaders suitable for trees. num: The number of different green coloured shaders that will be created. On exit: Creates a shader for the tree trunk, and returns a list with the specified number of shaders with different green colours. ''' trunkShader = tools.makeShader((0.124,0.043,0.000), "trunkMaterial") cmds.setAttr("trunkMaterial.reflectivity", 0) cmds.setAttr("trunkMaterial.specularColor", 0, 0, 0) l =[] for i in range(num): hue = random.randint(75, 120) saturation = random.uniform(0.6, 1) value = random.uniform(0.15, 0.6) RGB = tools.convertToRgb((hue, saturation, value)) treeShader = tools.makeShader((RGB[0], RGB[1], RGB[2]), "treeMaterial") cmds.setAttr(treeShader[0] + ".reflectivity", 0) cmds.setAttr(treeShader[0] + ".specularColor", 0, 0, 0) l.append(treeShader) return l
def makeLightShaders(daytime): ''' Creates shaders for traffic lights and street lights. daytime: Boolean variable which is true if it is day and false if it is night. On exit: Shaders for the traffic and street lights have been created, and appropriate names have been given to them. ''' blackMetal = tools.makeShader((0.090, 0.090, 0.090), "blackMetal") cmds.setAttr("blackMetal.reflectivity", 0) green = tools.makeShader((0.0, 0.4, 0.0), "green") red = tools.makeShader((0.6, 0.0, 0.0), "red") yellow = tools.makeShader((0.6,0.6,0.0), "yellow") greenLight = tools.makeShader((0.0, 1.0, 0.0), "greenLight") redLight = tools.makeShader(( 1.0, 0.0, 0.0), "redLight") yellowLight = tools.makeShader((1.0,1.0,0.0), "yellowLight") whiteLight = tools.makeShader((0.474, 0.487, 0.334), "whiteLight") cmds.setAttr("whiteLight.reflectivity", 0) cmds.setAttr("green.reflectivity", 0) cmds.setAttr("red.reflectivity", 0) cmds.setAttr("yellow.reflectivity", 0) cmds.setAttr("greenLight.reflectivity", 0) cmds.setAttr("redLight.reflectivity", 0) cmds.setAttr("yellowLight.reflectivity", 0) if daytime == False: cmds.setAttr("whiteLight.incandescence", 0.4,0.4,0.4) cmds.setAttr("whiteLight.glowIntensity", 0.3) cmds.setAttr("greenLight.incandescence", 0.0,0.812,0.0) cmds.setAttr("greenLight.glowIntensity", 0.3) cmds.setAttr("redLight.incandescence", 1.0, 0.0, 0.0) cmds.setAttr("redLight.glowIntensity", 0.3) cmds.setAttr("yellowLight.incandescence", 0.725, 0.532, 0.0) cmds.setAttr("yellowLight.glowIntensity", 0.3) else: cmds.setAttr("whiteLight.transparency", 0.7,0.7,0.7) cmds.setAttr("greenLight.incandescence", 0.0,0.128,0.0) cmds.setAttr("greenLight.glowIntensity", 0.1) cmds.setAttr("redLight.incandescence", 1.0, 0.118, 0.118) cmds.setAttr("redLight.glowIntensity", 0.1) cmds.setAttr("yellowLight.incandescence", 0.12, 0.09, 0.0) cmds.setAttr("yellowLight.glowIntensity", 0.1)
def makeHouseShaders(num, colourRange): ''' Creates a number of shaders for houses. num: The number of shaders that will be created. colourRange: A tuple containing two triples with hsv colour values. These colour values gives the range for the hue, saturation and value the shaders will have. On exit: The specified number of shaders have been created and added to a list. All the shaders have colours within the given colour range. The list is returned. ''' shaderList = [] for i in range(num): hue = tools.getRandomValue((colourRange[0][0]/360.0,colourRange[1][0]/360.0)) saturation = tools.getRandomValue((colourRange[0][1],colourRange[1][1])) value = tools.getRandomValue((colourRange[0][2],colourRange[1][2])) RGB = tools.convertToRgb((hue*360, saturation, value)) shader = tools.makeShader((RGB[0], RGB[1], RGB[2])) cmds.setAttr(shader[0] + ".reflectivity", 0.000) cmds.setAttr(shader[0] + ".specularColor", 0.120, 0.120, 0.120) shaderList.append(shader) return shaderList