예제 #1
0
def makeFountainPark(wxd, treeShaders, daytime, lightGeom):
    '''
    Creates a park with a fountain in the middle.
    
    wxd: A tuple containing the width and the depth of the park.
    treeShaders: A list of shaders for the tree crowns.
    daytime: Boolean variable which is true if it is day and false if it is night.
    lightGeom: Tuple containing the object name and node name for a polygonal object,
               in this case a street light.
    On exit: A park with trees (placeTreesInSquare(...)), fences (makeFence(...)) 
             and street lights (trafficLight.placeLight(...)) has been created and
             a fountain has been created in the middle of the park using 
             makeFountain(...). Everything has been combined into a single polygonal 
             object except the lights, which are instead parented to this object. 
             The park object is returned as a tuple containing the object name and 
             node name.
    '''
    # Make fences around the park.
    fence1 = makeFence((-wxd[0]/2.0,wxd[1]/2.0), (-1,wxd[1]/2.0), "x")
    fence2 = makeFence((1,wxd[1]/2.0), (wxd[0]/2.0,wxd[1]/2.0), "x")
    fence3 = makeFence((wxd[0]/2.0,wxd[1]/2.0), (wxd[0]/2.0,1), "z")
    fence4 = makeFence((wxd[0]/2.0,-1), (wxd[0]/2.0,-wxd[1]/2.0), "z")
    fence5 = makeFence((wxd[0]/2.0,-wxd[1]/2.0), (1,-wxd[1]/2.0), "x")
    fence6 = makeFence((-1,-wxd[1]/2.0), (-wxd[0]/2.0,-wxd[1]/2.0), "x")
    fence7 = makeFence((-wxd[0]/2.0,-wxd[1]/2.0), (-wxd[0]/2.0,-1), "z")
    fence8 = makeFence((-wxd[0]/2.0,1), (-wxd[0]/2.0,wxd[1]/2.0), "z")
    fountain = makeFountain()
    # Place squares with grass and trees around the paths.
    square1 = placeTreesInSquare(((-wxd[0]/2.0, -wxd[1]/2.0), (-1,-1)), treeShaders)
    square2 = placeTreesInSquare(((-wxd[0]/2.0, 1),(-1, wxd[1]/2.0)), treeShaders)
    square3 = placeTreesInSquare(((1, -wxd[1]/2.0),(wxd[0]/2.0, -1)), treeShaders)
    square4 = placeTreesInSquare(((1,1),(wxd[0]/2.0, wxd[1]/2.0)), treeShaders)
    park = cmds.polyUnite(fence1, fence2, fence3, fence4, fence5, fence6, fence7,
                          fence8, fountain, square1, square2, square3, square4)
    cmds.delete(park, ch = True)
    # Create and place instances of street lights
    light1 = cmds.instance(lightGeom[0])
    trafficLight.placeLight(light1[0], (-1.5,-0.9), daytime)
    light2 = cmds.instance(lightGeom[0])
    trafficLight.placeLight(light2[0], (-1.5,0.9), daytime)
    light3 = cmds.instance(lightGeom[0])
    trafficLight.placeLight(light3[0], (1.5,-0.9), daytime)
    light4 = cmds.instance(lightGeom[0])
    trafficLight.placeLight(light4[0], (1.5,0.9), daytime)
    cmds.parent((light1[0],light2[0],light3[0],light4[0]),park[0])
    return park
예제 #2
0
def makePark(wxd, treeShaders, daytime, lightGeom):
    '''
    Creates a park block with trees, paths, fences and street lights.
    
    wxd: A tuple containing the width and the depth of the park.
    treeShaders: A list of shaders for the tree crowns.
    daytime: Boolean variable which is true if it is day and false if it is night.
    lightGeom: Tuple containing the object name and node name for a polygonal object,
               in this case a street light.
    On exit: A park with three randomly placed paths has been created and street 
             lights placed using trafficLights.placeLights(...) at the intersection of 
             these paths. Trees and fences have also been created using 
             placeTreesInSquare(...) and makeFence(...). Everything has been combined 
             into a single polygonal object except the lights, which are instead parented
             to this object. The park object is returned as a tuple containing the 
             object name and node name.
    '''
    # Decide if the first path should be horisontal (along the x-axis) or vertical (along the z-axis).
    dir = random.choice(["horisontal", "vertical"]) 
    if dir == "horisontal":
        path1 = random.uniform(-wxd[1]/2 + 2, wxd[1]/2 - 2) # z-coordinate for the first path.
        path2 = random.uniform(-wxd[0]/2 + 2, wxd[0]/2 - 2) # x-coordinate for the second path.
        path3 = random.uniform(-wxd[0]/2 + 2, wxd[0]/2 - 2) # x-coordinate for the third path.
        # Place squares with grass and trees around the paths.
        square1 = placeTreesInSquare(((-wxd[0]/2.0, -wxd[1]/2.0), (path2 - 0.5, path1 - 1)), treeShaders)
        square2 = placeTreesInSquare(((-wxd[0]/2.0, path1 + 1), (path3 - 0.5, wxd[1]/2.0)), treeShaders)
        square3 = placeTreesInSquare(((path2 + 0.5, -wxd[1]/2.0), (wxd[0]/2.0, path1 - 1)), treeShaders)
        square4 = placeTreesInSquare(((path3 + 0.5, path1 + 1), (wxd[0]/2.0, wxd[1]/2.0)), treeShaders)
        # Make fences around the park.
        fence1 = makeFence((-wxd[0]/2.0,-wxd[1]/2.0), (path2 -0.5,-wxd[1]/2.0), "x")
        fence2 = makeFence((path2 + 0.5,-wxd[1]/2.0), (wxd[0]/2.0,-wxd[1]/2.0), "x")
        fence3 = makeFence((wxd[0]/2.0,-wxd[1]/2.0), (wxd[0]/2.0,path1 - 1), "z")
        fence4 = makeFence((wxd[0]/2.0,path1 + 1), (wxd[0]/2.0,wxd[1]/2.0), "z")
        fence5 = makeFence((wxd[0]/2.0,wxd[1]/2.0), (path3 + 0.5,wxd[1]/2.0), "x")
        fence6 = makeFence((path3 - 0.5,wxd[1]/2.0), (-wxd[0]/2.0,wxd[1]/2.0), "x")
        fence7 = makeFence((-wxd[0]/2.0,wxd[1]/2.0), (-wxd[0]/2.0,path1 + 1), "z")
        fence8 = makeFence((-wxd[0]/2.0,path1 - 1), (-wxd[0]/2.0,-wxd[1]/2.0), "z")
        # Create and place instances of street lights
        light1 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light1[0], (path3 - 1.5,path1 + 0.9), daytime)
        light2 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light2[0], (path3 + 1.5,path1 + 0.9), daytime)
        light3 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light3[0], (path2 - 1.5,path1 - 0.9), daytime)
        light4 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light4[0], (path2 + 1.5,path1 - 0.9), daytime)
    if dir == "vertical":
        path1 = random.uniform(-wxd[0]/2 + 2, wxd[0]/2 - 2) # x-coordinate for the first path.
        path2 = random.uniform(-wxd[1]/2 + 2, wxd[1]/2 - 2) # z-coordinate for the second path.
        path3 = random.uniform(-wxd[1]/2 + 2, wxd[1]/2 - 2) # z-coordinate for the third path.
        # Place squares with grass and trees around the paths.
        square1 = placeTreesInSquare(((-wxd[0]/2.0, -wxd[1]/2.0), (path1 - 1, path2 - 0.5)), treeShaders)
        square2 = placeTreesInSquare(((-wxd[0]/2.0, path2 + 0.5), (path1 - 1, wxd[1]/2.0)), treeShaders)
        square3 = placeTreesInSquare(((path1 + 1, -wxd[1]/2.0), (wxd[0]/2.0, path3 - 0.5)), treeShaders)
        square4 = placeTreesInSquare(((path1 + 1, path3 + 0.5), (wxd[0]/2.0, wxd[1]/2.0)), treeShaders)
        # Make fences around the park.
        fence1 = makeFence((-wxd[0]/2.0,-wxd[1]/2.0), (path1 -1,-wxd[1]/2.0), "x")
        fence2 = makeFence((path1 + 1,-wxd[1]/2.0), (wxd[0]/2.0,-wxd[1]/2.0), "x")
        fence3 = makeFence((wxd[0]/2.0,-wxd[1]/2.0), (wxd[0]/2.0,path3 - 0.5), "z")
        fence4 = makeFence((wxd[0]/2.0,path3 + 0.5), (wxd[0]/2.0,wxd[1]/2.0), "z")
        fence5 = makeFence((wxd[0]/2.0,wxd[1]/2.0), (path1 + 1,wxd[1]/2.0), "x")
        fence6 = makeFence((path1 - 1,wxd[1]/2.0), (-wxd[0]/2.0,wxd[1]/2.0), "x")
        fence7 = makeFence((-wxd[0]/2.0,wxd[1]/2.0), (-wxd[0]/2.0,path2 + 0.5), "z")
        fence8 = makeFence((-wxd[0]/2.0,path2 - 0.5), (-wxd[0]/2.0,-wxd[1]/2.0), "z")
        # Create and place instances of street lights
        light1 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light1[0], (path1 + 0.9,path3 - 1.5), daytime)
        light2 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light2[0], (path1 + 0.9,path3 + 1.5), daytime)
        light3 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light3[0], (path1 - 0.9,path2 - 1.5), daytime)
        light4 = cmds.instance(lightGeom[0])
        trafficLight.placeLight(light4[0], (path1 - 0.9,path2 + 1.5), daytime)
    park = cmds.polyUnite(square1,square2,square3,square4,fence1, fence2, fence3,
                          fence4, fence5, fence6, fence7, fence8)
    cmds.delete(park, ch = True)
    cmds.parent((light1[0],light2[0],light3[0],light4[0]),park[0])
    return park