Modeling, Scripting and Animating Gears
Shortcut keys are indicated by , e.g:
Move Tool = [w]
Rotate Tool = [e]
Duplicate = [Ctrl]+[d]
Parent = [p]
Middle Mouse Button = [MMB]
Right Mouse Button = [RMB]
This tutorial covers an in-depth practical approach to developing a completely automated gear system. The tutorial will show you how to do everything from modeling gears that successfully interlock, to coding (MELScript) the system (Fig.01)(Video.01 - 02).
The objective of this tutorial is to introduce you to the following:
ii. Modelling a Cog
ii. Customising the Cogs
iii. Creating your First Gear Combination
ii. Creating an Expression
- The Expression Editor
- Error Checking iii. Finishing Touches
- Anticipation and Overlap (Roll Back and Forward)
iv. All Stop..!! ...Weight
Setting up the Project
The Project folder contains all the source files used in the scene, which are organised into sub-folders. This allows your scene to source for all the appropriate files and references in an organised manner.
Create a New Project (File > Project > New):
1. Name the Project
2. Location to Save the Project
3. Set Folder Names
Name the Project: only use lower case characters, obvious names with no spaces.
Location of Project: The default location is set to Documents Folder, but if you are not working on your own computer it's better to save it to the Desktop. You can copy the Project folder to your portable device when you have finished this tutorial. Do not save your project to your portable drive (thumb drive) at this stage or the performance will lag (Fig.02).
Name your project "gears". Click the Use Defaults button to set the Project Data Locations. Then click Accept (Fig.03).
Getting Started and Creating the First Cog
Set the timeline to 500 frames (Fig.04).
Create a polygon cylinder (Polygons > Create > Polygon Primitives > Cylinder)(Fig.05).
Select the cylinder and modify values by opening the Channel Box. In the Shape Node, set the values to the following (Fig.06):
• Radius: 10
• Height: 5
• Subdivision Axis: 20
Note: Make sure the cylinder is positioned at the Origin (0,0,0).
Creating the Cog Teeth
There are 20 faces around the circumference of the cylinder. In Component mode, select 10 alternate faces and extrude them to create the teeth (Polygons > Edit Mesh > Extrude)(Fig.07).
Extrude the selected faces 4 units in the Z axis (Fig.08).
Scale the teeth 0.8 units in the Local Scale X & Y axis (Fig.09).
Rotate the cog 90° on the Z axis to stand it up. Delete History and Reset Transformation (Fig.10 - 11). And the first cog is complete!
Note: It is important to remember this cog has 20 segments (10 teeth) and a radius of 10 units. It is important to remember that all future cogs will be multiples of these numbers.
This means a cog twice the size will have 40 segments, a radius of 20 units and 20 teeth. A cog half the size will have 10 segments, a radius of 5 units and 5 teeth. If you follow this simple rule, the gears will easily fit together and it will be easier to calculate the rotation values.
Now you understand how a cog is created, delete the first cog and we'll start again.
Creating the Prototype Cogs
Now that you know how to create a basic cog, create four new cogs (small, medium, large and extra large). These cogs will form the basis of your gear system by matching them together in different combinations (Fig.12).
Check they have the correct Radius and Subdivision values, and then rename them.
Select and extrude the alternate faces around the circumference to create the teeth (Fig.13).
Rotate the four cogs 90° in the Z axis to stand them up. Delete History and Reset Transformation (Fig.14).
You now have your four basic prototype cogs, ready to create the gear system. All the other cogs in the system will be duplicates of these four prototypes.
Creating your First Gear Combination
The next objective is to create a gear combination. This requires two different sized cogs connected to a spindle (cylinder), as indicated in Fig.15.
The example in Fig.13 combines cog10 (10 teeth) with cog30 (30 teeth).
Duplicate cog10 and cog30 - Ctrl + [d]. Then align them using the Move tool [w] with
Point Snap [v] pressed (Fig.16).
Before we proceed with the tutorial, this is a convenient time to consider the size of the cogs and relationship between them. Look at Fig.16. The radius of cog30 (large) is three times bigger than cog10 (small). Likewise, the number of teeth on cog30 is three times as many as cog10.
The most important value for us in this tutorial is this circumference. The circumference of cog30 is three times the length of cog10. This means that if both cogs rotate 360° over the same time period, the teeth on cog30 will have covered three times the distance as the teeth on cog10, and therefore the teeth on cog30 are moving three times faster than cog10.
Note: "cog30 is three times faster than cog10" is the same as "cog10 is 3 times slower than cog30".
In Fig.17, cog10 and cog30 are both rotated 90° over 25 frames - both are rotating at the same speed. However, the distance covered by the teeth on cog30 is clearly further than the teeth on cog10. Therefore the teeth on cog30 are moving three times faster than the teeth on cog10.
Customizing the Cogs
As the objective of this tutorial is rigging, the modeling aspect is kept to a minimum - the cogs are very simple. However, to make things more visually interesting in this tutorial, it's a good idea to customize the cogs as you create the gear system.
In Component mode [RMB], select the vertices of each cog and move [w] them to customize the thickness of each cog (Fig.18).
Note: Remember to return to Object mode.
Create a polygon cylinder for the connecting spindle (Fig.19).
Don't forget to Delete History and Freeze Transformations after you have positioned and resized the spindle (cylinder). Then rename the spindle cylinder "gear01" (Fig.20).
Select cog30 and cog10 and Parent [p] to gear01 (Fig.21).
The first gear is complete!
Before you start creating the other gears, it is a good idea to revise the relationship between the cogs. Here are the four prototype cogs you created earlier (Fig.22).
The image below contains three simple gear setups. Consider the following very carefully (Fig.23):
(a) cog40 is rotating four times slower than cog10
(a) cog10 is rotating four times faster than cog40
(b) cog10 is rotating three times faster than cog30
(b) cog30 is rotating three times slower than cog10
(c) cog20 is rotating two times faster than cog40
(c) cog40 is rotating two times slower than cog20
Creating the Gear System
Following the method outlined previously, create the remaining four gears ([B] - [E]), and rename them "gear02" to "gear05". The aim is to rotate gear01 [A], which will cause the door [F] to move up and down.
Move [w] the gears into a suitable starting position, so that the cogs interlock with each other. You'll also need to individually rotate [e] cogs to achieve this. Do not rotate the spindle/parent objects (gear01 - gear05), only the cogs (Fig.24).
Note: Take note that gear05 [E] only has one cog: cog30.
Creating the Door
I added the door to this tutorial because up to this point it is all pretty easy. So, the aim of the door is to complicate matters slightly and challenge you.
The reason the door is slightly complicated is because it needs teeth to interlock with cogs. The problem is you don't know the actual size of the teeth... yet.
Start by making a polygon cube (Polygons > Create Polygon Primitives > Cube)(Fig.25).
Calculate the Size of the Teeth
If we take cog20 as an example, it is a cylinder with a radius of 10 units and 20 teeth (subdivisions). We can discover the size of the teeth by calculating the circumference of cog20 and dividing it by 20 (Fig.26).
The circumference of a circle is calculated as: 2? * radius
Where ? (Pi) = 3.14159, the circumference of cog20 is:
= 2? * radius
Therefore, the size of the teeth is 62.831/20 = 3.14155 units each.
A door with 10 teeth (subdivisions) would be 31.1415 units in height.
A door with 50 teeth (subdivisions) would be 157.077 units in height.
And a door with 20 teeth (subdivisions) would be 62.831 units in height.
Select pCube1 and modify values by opening the Channel Box. In the Shape Node, set the values to as follows (Fig.27):
• Width: 10
• Height: 62.831
• Depth: 40
• Subdivision Axis: 20
Select the alternate faces. Extrude and scale them as indicated in Fig.28.
Delete History and Reset Transformation. Rename pCube1 as "door".
The gear system should now be set up as indicated in Fig.29, containing five gears ([A] - [E]) and a door. The aim is to rotate gear01 [A] and cause door [F] to translate (move) up and down.
You're now ready to start animating.
Animating the Gears
The objective of this tutorial is to create a simple Gear system that is simple to animate and easily modified. It would be far too tedious and time consuming to keyframe the rotation of gear01 - gear05 + TranslateY of door. It would be even more tedious to modify it several times if your supervisor required it.
For that reason, we'll create a system that only requires the animator (you) to animate gear01.
Select gear01 and create the following 2 keyframes (Fig.30).
Play the animation and check that gear01 rotates 10 times.
Creating the MELScript
MELScript is the programming language used in Maya. An expression is a MELScript that runs every frame and allows you to create animation.
The next step is to write a MELScript that calculates the rotation value for each gear (gear - gear). We'll start by creating and explaining the MELScript first, and then show you how to use the Expression Editor later in the tutorial.
MELScript for gear02
In Fig.31, cog10 is paired to cog20. When cog10 is rotated, cog20 will rotate at 1/2 the speed.
This can be summarized as a ratio: cog10/cog20=0.5 (10/20=0.5). The MELScript to rotate gear02 by 1/2 the rotation value of gear01, in the opposite direction is:
MELScript for gear03
In Fig.32, cog10 is paired to cog40. When cog10 is rotated, cog40 will rotate at 1/4 the speed.
This can be summarized as a ratio: cog10/cog40=0.25 (10/40=0.25). The MELScript to rotate gear03 by 1/4 the rotation value of gear02, in the opposite direction is:
MELScript for gear04
In Fig.33, cog20 is paired to cog30. When cog20 is rotated, cog30 will rotate at 2/3 the speed.
This can be summarized as a ratio: cog20/cog30=0.66 (20/30=0.66). The MELScript to rotate gear04 by 2/3 the rotation value of gear03, in the opposite direction is:
MELScript for gear05
In Fig.34, cog10 is paired to cog30. When cog10 is rotated, cog30 will rotate at 1/3 the speed.
This can be summarized as a ratio: cog10/cog30=0.33 (10/30=0.33). The MELScript to rotate gear05 by 1/3 the rotation value of gear04, in the opposite direction is:
So here's the MELScript so far:
Finally, the difficult part - gear05 lifting the door.
gear05 contains a single cog30. For each degree cog30 rotates, the door will translate in the Y axis. If we calculate the circumference of cog30 and divide by 360°, we'll know how much to translate the door in the Y axis.
Here's a quick breakdown of this process (Fig.35):
1. Rotating cog30 360° will translate door the same distance as the circumference of cog30.
2. Therefore, we can assume that by rotating cog30 1°, door will translate circumference/360.
The circumference of a circle is calculated as: 2? * radius
Where ? (Pi) = 3.14159, the circumference of cog30 is:
= 2? * radius
Therefore, rotating gear05 by 1° will translate door:
Rotating gear05 by 90° will translate door:
The MELScript to translateY door, based on the rotation of gear05 is (Fig.36):
So, the completed MELScript is:
Creating an Expression
Now that we've written the MELScript, the next step is to use it to create an expression.
Open the Expression Editor (Window > Animation Editors > Expression Editor)(Fig.37).
Enter the name "gearRotation" into the Expression Name field.
Type the MELScript code into the Expression: field. Click Create to Compile and Save the expression (Fig.38).
If you have followed the tutorial correctly, you have finished. Play the animation and the gears should all by rotating and synced together.
However, if you have made a typo in the MELScript and it produces an Error or incorrect results, you'll need to edit the expression. Open the Expression Editor (Fig.39).
List the Expressions (Select Filter > By Expression Name). Then select gearRotation in the Selection listing (Fig.40).
Up to now, the animation in this tutorial is very simple - gear01 rotates 10 times (3600°) over 20 seconds (500 frames).
Add some anticipation to the start and overlap to the end of the rotation for gear01 (Fig.41):
• Frame 1: Start Position: 0°
• Frame 25: Roll backwards to anticipate: -90°
• Frame 450: End of 10 rotations: 3600°
• Frame 500: Roll backwards to rest position: 3560°
To help create the illusion of weight in the way the gears rotate, they should come to a complete start and stop at each key frame. Select gear_basic01, and in the Channel Box, select RotateX. Open the Graph Editor (Window > Animation Editors > Graph Editor).
Select all four keyframe markers (small black dots) and set the tangents to Flat Tangent. This will ensure the animation comes to a compete start and stop at each keyframe - indicating weight (Fig.42).
Play the animation.
In the previous section of this tutorial, the gear01 was the driving force for the animation.
In the next section the project is reversed to make the door the driving force:
As explained previously, when gear05 is driving the door the translation of the door is calculated as:
In Fig.43 the driver is reversed from [gear05 > door], to [door > gear05]. Therefore, the rotation of gear05 is calculated as door.translateY/0.2618;
The MELScript to rotate gear05 is:
In Fig.44, cog30 is paired to cog10. When cog30 is rotated, cog10 will rotate at three times the speed.
This can be summarized as a ratio: cog30/cog10=3 (30/10=3). The MELScript to rotate gear04 by three times the rotation value of gear05, in the opposite direction is:
In Fig.45, cog30 is paired to cog20. When cog30 is rotated, cog20 will rotate at 1.5 times the speed.
This can be summarized as a ratio: cog30/cog20=1.5 (30/20=1.5). The MELScript to rotate gear03 by 1.5 times the rotation value of gear04, in the opposite direction is:
In Fig.46, cog40 is paired to cog10. When cog40 is rotated, cog10 will rotate at four times the speed. This can be summarized as a ratio: cog40/cog10=4 (40/10=4). The MELScript to rotate gear02 by four times the rotation value of gear03, in the opposite direction is:
In Fig.47, cog20 is paired to cog10. When cog20 is rotated, cog10 will rotate at two times the speed. This can be summarized as a ratio: cog20/cog10=2 (20/10=2). The MELScript to rotate gear01 by 2 times the rotation value of gear02, in the opposite direction is:
Good luck and enjoy.