Functions


When it came down to the execution and organisation for the script to create the city I decided to use two separate functions so that when it interacts with the UI it would not be significant amount of code.

The following layout I used for the two separate functions was this:

def Clouds(slider):

    

    cloud_range = cmds.intSlider(slider, query = True, value = True)

    

    Sphere_List = []

    #creating the clouds for the emitters to attatch to.

    for i in range(-cloud_range,cloud_range+1):

        for j in range(-cloud_range,cloud_range+1):

            cloud = cmds.polySphere(sx=20, sy=20, r=0.5)

            cmds.move( j*4+15, 16, i*4+15 )

            Sphere_List.append(cloud[0])

            

    #the emitters that generate the snow.

    particles = cmds.particle( p=((-1, 5, 2), (2, 2, 2), (3, 3, 3)), n='particles' )

    cmds.move( 0, 16, 0 )

    emitters = cmds.emitter(Sphere_List, r=20, mxd=3, n='emitter', type = "surface" )

    cmds.move( 0, 20, 0 )

    cmds.connectDynamic( particles, em = emitters )  

    #Hide command to hide the clouds to make the snow generation look more natural.

    cmds.hide(Sphere_List)

    #buildings and base creation.

def createCity(width_slider):

    

    width_slider_value = cmds.intSlider(width_slider, query = True, value = True)

    

    cmds.polyPlane(h = width_slider_value*3, w = width_slider_value*3)

    cmds.move(width_slider_value*1.1,0,width_slider_value*1.1)

    #Day and Night Cycle creation using a directional light with it turning clockwise and keying it every few frames to create the turning motion.

    light = cmds.directionalLight(i = 10)

    for i in range(25):

        cmds.currentTime( i*15, edit=True )

        cmds.setKeyframe("directionalLight1",v=i*15, at="rotateX")

    

    #The slider that dictates the size of the base and amaount of buildings. 

    for i in range(0,width_slider_value):

        for y in range(0,width_slider_value):

            cmds.polyCube( n = "base")

            cmds.move(i*3 , 0 , y*3)

            random_height = random.uniform(2,10)

            

            for z in range(1,int(random_height)):

          #the range of how the buildings are created my face extrusion      

                cube_name = "pCube%r_%r_%r" % (i,y, z)

                cmds.polyCube(n = cube_name )

                cmds.move(i*3 , z , y*3)

                cmds.polyExtrudeFacet( cube_name+ ".f[0]", kft=False, lt=(-0.5,-0.1,-0.1), off = 1 )

                cmds.polyExtrudeFacet( cube_name+ ".f[2]", kft=False, lt=(-0.5,-0.1,-0.1), off = 1 )

                cmds.polyExtrudeFacet( cube_name+ ".f[4]", kft=False, lt=(-0.1,-0.1,-0.1), off = 1 )

                cmds.polyExtrudeFacet( cube_name+ ".f[5]", kft=False, lt=(-0.1,-0.1,-0.1), off = 1 )

With this I sectioned of the code for the city and the weather simulation and linked them to the UI with the individual buttons and sliders so that you can execute different aspects of the city individually with some features to change the properties of the city and particle simulation.

Leave a comment

Log in with itch.io to leave a comment.