TB2 - Week 2


This week I continued to work on my City Generator.

After last week I wanted to add randomisation to my building generation. This would make the city seem a lot more natural.


First I experimented with the Random function within maya/python.  For example I used random.uniform (Line 7) to generate a random number between the 2 numbers the user inputs (BetweenA and BetweenB), this is then the value assigned to the variable xPosition. Finally the cmds.move command is used to move the polyCube to whatever that generated value is along the X axis. 

This basically creates a cube and moves it randomly a long the x axis every time the "SpawnCube" button is pressed.


I then tried to create a cube and change its width randomly every time the code is ran.


After the experimentation I moved back to my City Generator code and tried implementing the random module to help spawn the buildings with varying heights, as well as changing each cubes x and z position in order to spread out each building completely randomly. The for loop will take the value inputted by the user for the number of buildings and loop, creating one building with a random height, as well as x and z position until they all the buildings are created.


Next I added a basic cube as the foundation for the city to be built on.


I then worked on giving the user the ability to reset the ground foundation in case it is accidentally moved within the scene. If this SpawnGround() function is called, it selects the ground cube, deletes it and spawns another in its original position.

 

I also added cmds.text lines above each intField in order to tell the user what they need to input into each field, as before unless told they wouldn't have any idea what the intFields are for.


I had some trouble with the buildings scaling uniformly along the Y axis, up as well as down meaning most the buildings would be hidden beneath the floor. In order to fix this I changed the buildings from being created with a random height, to after being spawned, their pivot point is lowered and then scaled up. This has the effect of only scaling the cube upwards, reducing the amount of the building stuck out of view.


Here is a final view of what the user sees when spawning buildings at this stage.

I realised soon after that although my ground cube resetting code works well most of the time, if the cube is deleted some how it cannot be respawned. This causes issues as the user can then not respawn the ground unless they close the window and run the code again, making the process unpleasant.


My plan next week is to fix this as well as working on stopping the buildings from spawning in overlapping spaces as currently they can spawn anywhere within an area no matter whether another building is already intersecting with that space.

Leave a comment

Log in with itch.io to leave a comment.