Buildings
For the buildings I wanted to be able to generate a group of buildings that had random height and shape, so what I started to look at first was generate a set of cubes that will generate within in a certain area and vary in height and appearance within the plane.
The piece of the script I ended up with was this:
#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 )
What this bit of the script allows me to do is create a plane which acts as the base and the roads of the city within a certain position, which it will then generate cubes that will use face extrusions to create different heights and details for the buildings within the perimeter of the base. However when the the code is executed a slider system has been added to the ui which allows you to increase the amount of buildings there are within the city along with the size of the base.
Programming for Computer Animation and VFX - Maya Python City
Status | Released |
Author | Aronne_Monk |
More posts
- FunctionsApr 24, 2023
- UI (Buttons & Sliders)Apr 24, 2023
- Day and Night CycleApr 24, 2023
- Snow SimulationApr 24, 2023
Leave a comment
Log in with itch.io to leave a comment.