Wednesday, 12 February 2014

Python Scripting - Final Script for Leaning Tower of Pisa

This is the final script. I have managed to make the arches more prominent. 

Final Script+Model
 Boolean was rather tough but with the help from a teacher, I managed to do the arches. I have added the things that I want to cut together in the boolean. For example: MC.polyBoo10p("levels","cuts").

Final Model before Batch Render

Leaning Tower of Pisa


Python Scripting - Cutting to make Archs

Before cutting polygons to make archs, I have created more circles on other levels. To do so, I created another function and copied and pasted from the Arch() function. 
But this time round, I have added for each in range into the function. Since I have 6 levels, I duplicate the group of cylinders 6 times and move them accordingly like what I did for Levels(). 

Cutting polygons in Maya is called Difference, while python commands, it is called polyBoo10p.


Boolean polygons
  1. MC.polyUnite is to combine objects together into one.
  2. MC.select is to select items.
  3. MC.polyBoo10p is to create boolean(difference).

Booleans
The cutting is not deep enough and I have to move the cylinders inwards before cutting to get the arches. 




Python Scripting - Making levels

Making of levels was not that difficult. Actually, it was quite easy to do. 

There are 8 levels for Leaning Tower of Pisa. That includes 6 middle levels, 1 big bottom level and 1 top level. For this script, it runs 6 platforms for the 6 middle levels. 
Index differs one level from another. Since range is 6, it applies to 6 levels. The spacing represents the spacing in between 2 platforms. 

Levels Completed!


Python Scripting - Making columns on more levels

For this post, it will be all about duplicating pillars.

Creating Columns

In order to create more columns for the other 6 levels of the Leaning Tower of Pisa, I have added more parameters into the BigColumns function. There are 8 parameters in total and I have added 4 more parameters from the previous. They are scaleY(height of columns), moveZ(movement in Z-axis), rotateX(rotation around X-axis) and scaleXZ(size of columns). I need the other 6 levels to have 18 pillars and the bottom level to have 10 pillars. Just simply put in the variables into the parameters. 

Final Level Scripting

Python Scripting - Rotation of circles solution

After many attempts, I have finally managed to make the circles rotate around the building. Not the best solution, but it works!

Step 1: Creates a cylinder and rotate it -90 degree+ (-5 degree for leaning tower) so that it smacks and stays there on the cylinder. 

Step 2: Group and duplicate then include the number of circles that you want and make them rotate in the Y-axis. Use of equation is "each*36". This is the angle between two circles. It is derived from a complete rotation, (360 degree)/number of circles. In this case, I need 10 circles, so 360 degree/10 equates to 36 degree. 
Step 3: Group them again so that they move, scale and rotate together. 


Rotation of Circles Complete

Python Scripting - Creating Archs(Part 1) and Railings

After creating the columns, it is time to create archs. I have made a new function for the archs. Making the archs was difficult and tedious. I had many problems with creating the archs such as the circles were not placed in the right positions that I want. To make the archs, I have to create circles around the structure and cut them into the cylinder. In this script, the circles are obviously wrongly placed.

Rotation Scripting FAIL

Creating the Railings

I have also made railings for the Leaning Tower of Pisa. To do so, I have created another function. The first thing was to make the circular shapes for the railing bar. I have used a pipe to create the railings. In order to make the railings look circular, I have added poly.smooth below. The main reason why I used poly.smooth is there is no subdivisions to make the pipe circular. For the poles, I made them into a circular formation using the same math equations that were used before. As usual, I have made lists and append for both Railingbars and Poles. After which, I just grouped(MC.group) them together and duplicated(MC.duplicate) once more to produce another railing.

Python Scripting - Simplify columns script

The previous script was kind of messy so I had to put some parameters into the BigColumns function. There are four parameters: NumOfPillars(Number of pillars), SpaceFromCenter(Space from pivot(0,0,0) for columns), Height(height movement in Y-axis) and gap(Space from pivot(0,0,0) for small rings). At the end in the myCreation function, I can just add in the numbers that I want for the 4 attributes. 

Simplified Version Script
I have also grouped the columns together with the torus so that they will move together in height. So first off, I have to create lists and append for both pillars and torus. After which, I grouped them together and move, rotate or scale however I want.  :)

Python Scripting - Columns Rotation

The rotation of the columns was a problem initially but I managed to fix the problem with teacher's help. :) The equation was the main problem. :/ Instead of using math.pi inside the move axis, I have to use math.cos and math.sin for aX and aZ respectively. The spacing or gap is to control the space from the pivot(0,0,0) which is the center. (2 math.pi)/10 simply represents 360 degree divided by the number of columns. I have also did the same thing to the torus.

Columns Rotation Solution

Main Structure with columns rotation

And finally! The columns are rotating around the structure. ^^

Python Scripting - Main Structure

When I first started out, maya scripting was quite tough to understand. For this assignment, I have chosen to do the Leaning Tower of Pisa. The first thing I did was to do the basic main structure for the tower which is made up of cylinders.
Main Structure Script

Making cylinders were kind of tough at first but it was fun during the process. As you can see from the picture above, I have broken down the script into 3 functions. The first function makes the middle and the top cylinders, the second scripts the base platform at the bottom and the last makes the columns. The base platform was rather hard to get it work at first but I managed to do it. I have added "index += 1", gap and height so that the steps inclines upwards in the Y-axis individually. To make the shape of the base platform stand out, I have added "index*10" in both the X and Z axis(scale) so the steps decrease in size.

Making columns and creating a master function

In order to make the whole script run, I needed to add another function called "myCreation". Under myCreation, I have added the above functions. However, I had a problem with the columns and needed to change the equation. I wanted to make an equation to allow the number of columns I want to rotate around the the main structure of the tower. So the equation simply didn't work out.