Modeling, Scripting and Animating Gears

Annotation

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]

Introduction

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).

Fig. 01 id_fig01.png

Fig. 01 id_fig01.png

Learning Outcome

The objective of this tutorial is to introduce you to the following:

  • Getting Started and Creating the First Cog
  • i. Scene Setup and Timeline
    ii. Modelling a Cog
  • Creating the Prototype Cogs
  • i. Creating a Set of Cogs that Interlock
    ii. Customising the Cogs
    iii. Creating your First Gear Combination
    iv. Revision
  • Creating the Gear System
  • Creating the Door
  • i. Calculate the Size of the Teeth.
  • Animating the Gears
  • i. Creating the MELScript
    ii. Creating an Expression
    - The Expression Editor
    - Error Checking iii. Finishing Touches
    - Anticipation and Overlap (Roll Back and Forward)
    iv. All Stop..!! ...Weight
  • Door Driven
  • i. The Door as the Driver

    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).

    Fig. 02 id_fig02.png

    Fig. 02 id_fig02.png

    Name your project "gears". Click the Use Defaults button to set the Project Data Locations. Then click Accept (Fig.03).

    Fig. 03 id_fig03.png

    Fig. 03 id_fig03.png

    Getting Started and Creating the First Cog

    Set the timeline to 500 frames (Fig.04).

    Fig. 04 id_fig04.png

    Fig. 04 id_fig04.png

    Create a polygon cylinder (Polygons > Create > Polygon Primitives > Cylinder)(Fig.05).

    Fig. 05 id_fig05.png

    Fig. 05 id_fig05.png

    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

    Fig. 06 id_fig06.png

    Fig. 06 id_fig06.png

    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).

    Fig. 07 id_fig07.png

    Fig. 07 id_fig07.png

    Extrude the selected faces 4 units in the Z axis (Fig.08).

    Fig. 08 id_fig08.png

    Fig. 08 id_fig08.png

    Scale the teeth 0.8 units in the Local Scale X & Y axis (Fig.09).

    Fig. 09 id_fig09.png

    Fig. 09 id_fig09.png

    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!

    Fig. 10 d_fig10.png

    Fig. 10 d_fig10.png

    Fig. 11 d_fig11.png

    Fig. 11 d_fig11.png

    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).

    Fig. 12 d_fig12.png

    Fig. 12 d_fig12.png

    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).

    Fig. 13 d_fig13.png

    Fig. 13 d_fig13.png

    Rotate the four cogs 90° in the Z axis to stand them up. Delete History and Reset Transformation (Fig.14).

    Fig. 14 d_fig14.png

    Fig. 14 d_fig14.png

    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.

    Fig. 15 d_fig15.png

    Fig. 15 d_fig15.png

    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).

    Fig. 16 d_fig16.png

    Fig. 16 d_fig16.png

    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.

    Fig. 17 d_fig17.png

    Fig. 17 d_fig17.png

    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).

    Fig. 18 d_fig18.png

    Fig. 18 d_fig18.png

    Note: Remember to return to Object mode.

    Create a polygon cylinder for the connecting spindle (Fig.19).

    Fig. 19 d_fig19.png

    Fig. 19 d_fig19.png

    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).

    Fig. 20 d_fig20.png

    Fig. 20 d_fig20.png

    Select cog30 and cog10 and Parent [p] to gear01 (Fig.21).

    Fig. 21 d_fig21.png

    Fig. 21 d_fig21.png

    The first gear is complete!

    Revision

    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).

    Fig. 22 d_fig22.png

    Fig. 22 d_fig22.png

    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

    Fig.23

    Fig.23

    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).

    Fig. 24 d_fig24.png

    Fig. 24 d_fig24.png

    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).

    Fig. 25 d_fig25.png

    Fig. 25 d_fig25.png

    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).

    Fig. 26 d_fig26.png

    Fig. 26 d_fig26.png

    The circumference of a circle is calculated as: 2? * radius

    Where ? (Pi) = 3.14159, the circumference of cog20 is:

    = 2? * radius
    = (2*3.14159)*10
    = 62.831

    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

    Fig. 27 d_fig27.png

    Fig. 27 d_fig27.png

    Select the alternate faces. Extrude and scale them as indicated in Fig.28.

    Fig. 28 d_fig28.png

    Fig. 28 d_fig28.png

    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.

    Fig. 29 d_fig29.png

    Fig. 29 d_fig29.png

    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).

    Fig. 30 d_fig30.png

    Fig. 30 d_fig30.png

    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[2] - gear[5]). 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.

    Fig. 31 d_fig31.png

    Fig. 31 d_fig31.png

    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:

    gear02.rotateX=gear01.rotateX*-0.5;

    MELScript for gear03

    In Fig.32, cog10 is paired to cog40. When cog10 is rotated, cog40 will rotate at 1/4 the speed.

    Fig. 32 d_fig32.png

    Fig. 32 d_fig32.png

    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:

    gear03.rotateX=gear02.rotateX*-0.25;

    MELScript for gear04

    In Fig.33, cog20 is paired to cog30. When cog20 is rotated, cog30 will rotate at 2/3 the speed.

    Fig. 33 d_fig33.png

    Fig. 33 d_fig33.png

    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:

    gear04.rotateX=gear03.rotateX*-0.66;

    MELScript for gear05

    In Fig.34, cog10 is paired to cog30. When cog10 is rotated, cog30 will rotate at 1/3 the speed.

    Fig. 34 d_fig34.png

    Fig. 34 d_fig34.png

    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:

    gear05.rotateX=gear04.rotateX*-0.33;

    So here's the MELScript so far:

    gear02.rotateX=gear01.rotateX*-0.5;
    gear03.rotateX=gear02.rotateX*-0.25;
    gear04.rotateX=gear03.rotateX*-0.66;
    gear05.rotateX=gear04.rotateX*-0.33;

    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
    = (2*3.14159)*15
    = 94.248

    Therefore, rotating gear05 by 1° will translate door:

    = 94.248/360°
    = 0.2618

    Rotating gear05 by 90° will translate door:

    =90*0.2618

    Fig. 35 d_fig35.png

    Fig. 35 d_fig35.png

    The MELScript to translateY door, based on the rotation of gear05 is (Fig.36):

    door.translateY=gear05.rotateX*0.2618;

    So, the completed MELScript is:

    gear02.rotateX=gear01.rotateX*-0.5;
    gear03.rotateX=gear02.rotateX*-0.25;
    gear04.rotateX=gear03.rotateX*-0.66;
    gear05.rotateX=gear04.rotateX*-0.33;
    door.translateY=gear05.rotateX*0.2618;

    Creating an Expression

    Now that we've written the MELScript, the next step is to use it to create an expression.

    Fig. 36 d_fig36.png

    Fig. 36 d_fig36.png

    Open the Expression Editor (Window > Animation Editors > Expression Editor)(Fig.37).

    Enter the name "gearRotation" into the Expression Name field.

    Fig. 37 d_fig37.png

    Fig. 37 d_fig37.png

    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.

    Fig. 38 d_fig38.png

    Fig. 38 d_fig38.png

    Error Checking

    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).

    Fig. 39 d_fig39.png

    Fig. 39 d_fig39.png

    List the Expressions (Select Filter > By Expression Name). Then select gearRotation in the Selection listing (Fig.40).

    Fig. 40 d_fig40.png

    Fig. 40 d_fig40.png

    Finishing Touches

    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°

    Fig. 41 d_fig41.png

    Fig. 41 d_fig41.png

    All Stop..!!

    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).

    Fig. 42 d_fig42.png

    Fig. 42 d_fig42.png

    Play the animation.

    Door Driven

    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:

    gear_basic05.rotateX= door.translateY/0.2618;
    gear_basic04.rotateX= gear_basic05.rotateX*-3;
    gear_basic03.rotateX= gear_basic04.rotateX*-1.5;
    gear_basic02.rotateX= gear_basic03.rotateX*-4;
    gear_basic01.rotateX= gear_basic02.rotateX*-2;

    As explained previously, when gear05 is driving the door the translation of the door is calculated as:

    door.translateY=gear05.rotateX*0.2618;

    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:

    gear_basic05.rotateX= door.translateY/0.2618;

    Fig. 43 d_fig43.png

    Fig. 43 d_fig43.png

    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:

    gear_basic04.rotateX= gear_basic05.rotateX*-3;

    Fig. 44 d_fig44.png

    Fig. 44 d_fig44.png

    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:

    gear_basic03.rotateX= gear_basic04.rotateX*-1.5;

    Fig. 45 d_fig45.png

    Fig. 45 d_fig45.png

    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:

    gear_basic02.rotateX= gear_basic03.rotateX*-4;

    Fig. 46 d_fig46.png

    Fig. 46 d_fig46.png

    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:

    gear_basic01.rotateX= gear_basic02.rotateX*-2;

    Fig. 47 d_fig47.png

    Fig. 47 d_fig47.png

    Good luck and enjoy.

    Fetching comments...

    Post a comment