Animated Windmill

Part 2

Animation

In Part 1 we constructed the windmill model. In Part 2 we will animate the model.

The windmill will have the mill rotating slowly, and the vane and mill will oscillate laterally in the wind. This will need two distinct animation motions created in gmax. First make sure the System units are Metric as mentioned earlier, for animation to work correctly in Trainz.

Animation can be rotation and translation only – scalar (change of size of an object) is not supported by the export plugin.

The steps we will do are:

  • Align the objects’ axees to the World axis;
  • Place and link helpers;
  • Link all objects to helpers;
  • Set animation length;
  • Animate only the helpers, objects will follow;
  • Export animation .kin file.

Alignment

There were a number of different parts that make up the tower, mill and other objects. Decide which will be animated, and attach as many as you can into one object This will simplify the number of objects you are dealing with, and make the connection to helpers easier. For example, I suggest five final objects:

  • Tower: The tower legs, the diagonal and horizontal bracing, platform and the cap on top of the legs should be attached as the main stationary object;
  • Water_pipes: The water pipes and rod might need some adjustment later, so we will attach them as a second stationary object;
  • Mill: All the blades, rings and bearings should be attached as the rotating mill;
  • Oscillating_head: The vane and the top bearing will be attached as an oscillating object;
  • Tank: The water tank itself, as a stationary object.

Place all the objects as you want them at the start of the animation. If you decide to change this initial placement later after adding animation, it can be a problem correcting the animation.

  1. Select all the objects;
  2. Open the Hierarchy menu and select Affect Pivot Only;
  3. Click on the Align to the World button.

These steps are important to set up the animation correctly aligned. If not aligned, the animation may appear correct in gmax, but the objects will be scattered across the landscape in Trainz. You do not have to align the helpers, if they were placed in top view, they will be aligned automatically.

Notice how all the axes in the screenshot below are aligned. Click on the Effect Pivot Only button to turn it off.

Helpers

These are the dummies that are animated (note they are not the same as the “point” placed for the smoke attachment earlier). They are linked together to follow the animations of each other. You do not animate the objects themselves. Objects are linked to the helpers, and therefore follow the helper animation.

All helpers are placed in Top View. The main helper is usually called b.r.base or b.r.main and is placed on the origin. Notice the special notation that Trainz recognises, the b.r. must precede all helper point names.

  1. Select Top view;
  2. Select the Draw menu;
  3. Select the Helper menu;
  4. Click on the Dummy button;
  5. Anywhere in the top view, Left click and drag to make a small square, the helper;
  6. Name the point b.r.main

Select the helper just made, and move it to the origin (0,0,0) – remember you can right click on the co-ordinate arrows at the bottom of the screen. This is the main helper. EVERYTHING must be linked to a helper or it will not show in Trainz. Note:

  • Helpers are linked to each other and through to the b.r.main;
  • All static objects are linked to the b.r.main helper;
  • All objects to be moved are linked to their respective animated helpers.

I like to set the centers of rotation (centroid) for the mill and for the oscillating head, and then place helpers at these locations, easier to use co-ordinates rounded off (8.6 instead of 8.592).

Select the mill object, and the centroid is at X= 0, Y= -0.6, Z= 10.8. This is at the center of the mill and is a suitable rotation point. In top view draw a helper anywhere, name it b.r.mill and move it to these co-ordinates (you could also clone the b.r.main helper and rename the clone, instead of drawing a new helper).

For the oscillator on top of the tower, the centroid reads X= 0, Y= 0, Z= 10.6. This is a suitable point for the horizontal rotation. If the centroid were offset from the object center, you would use the Hierarchy menu and the Affect Pivot Only to move it to a suitable position. Again in top view, draw a helper anywhere, name it b.r.oscillator and move it to these co-ordinates. You should now have three small boxes as helpers, in the correct locations for animation.

Linking Helpers and Objects

The b.r.mill is to be linked to the b.r.oscillator which in turn is to be linked to b.r.main.

  1. Select the b.r.oscillator by clicking on it in the viewport, or pressing the H key and selecting it from the Select Objects menu;
  2. Click on the link symbol at the top, press the “H” key and the Select Parent menu box opens;
  3. Select the b.r.main;
  4. Click on the Link button at the bottom;
  5. Turn off the linking process by clicking on the Arrow at the top of the screen.

6. Select the b.r.mill by clicking on it in the viewport, or pressing the H key and selecting it from the Select Objects menu;
7. Click on the link symbol at the top, press the “H” key and the Select Parent menu opens;
8. Select the b.r.oscillator;
9. Click on the Link button at the bottom;
10. Turn off the linking process by clicking on the Arrow at the top of the screen.

The helpers are now linked correctly, and we can link the objects to those helpers. This is a similar process to the linking of the helpers above.

1. Select all the static objects, the tank, the water_pipe, and the tower by pressing the H key and selecting them from the Select Objects menu;
2. Click on the Link Symbol, then press the “H” key to open the Select Parent dialogue;
3. Select the b.r.main helper in the dialogue box;
4. Click on Link at the bottom of the box;
5. Click on the Arrow again to turn off the linking process.

Repeat this linking process for the mill, linking it to the b.r.mill, and then link the oscillating_head to the b.r.oscillator.

Note: Make sure you are looking at the correct screen, the Select Objects or the Select Parent screen, as appropriate.

Press the “H” key to display the Select Objects menu again, and click on the Display Subtree button to show the linking tree of the helpers and objects – see below.

Note that you do not have to link the a.water0 attachment point to a helper for it to work in Trainz. However, if you do want to have an attachment point move with a helper, you have to use a special notation – refer to the online TrainzDev Wiki for assistance.

http://online.ts2009.com/mediaWiki/index.php5/Attachment_Points

Remember to always click the Arrow key to turn off the linking process when finished, or you will only see the linking menu not the select menu.

Animating the Model

We can now animate the mill and oscillator. Now the mill head will swing slowly back and forth, and the mill blades will rotate a number of revolutions during that time. We can vary the final speed in the config.txt file with the animation-loop-speed tag, but in gmax we will select an animation of 300 frames – at 30 frames per second, this would give an oscillating time of 10 seconds. Let us decide that the mill blades will rotate 3 times over the 300 frames (every 100 frames). The animation must always return to the start position at the end of the cycle.

You should select carefully which animation should be done first, an animation is easiest if done in one plane at a time, that is, all the rotations of the mill blades should be entered for the full 300 frames before starting to oscillate the head. If the oscillations were done first, the mill blade would be rotating about a constantly changing axis, and near impossible to animate correctly.

Find the animation settings box at the bottom of the screen, step 1 below.

1. Click on the time button at the bottom to open the dialogue box above;
2. Enter 300 as the Length of the animation;
3. The default 30 fps is normal;
4. The playback button only affects speed in gmax, not Trainz, useful to slow things down when checking for smooth animation;
5. If you want to change the time length later, the Rescale time button will do this;
6. The Track bar is the display of key frames at the screen bottom (if the Track bar is not showing, go to Customise at the top, Show UI, Show Trackbar).

Important: You will notice the large Animate button on the bottom menu. This must be clicked red to record any animation of the helpers. If you move an object or a helper without this button being active (red) the animation will not be recorded, and the axis alignment could be destroyed.

Animating the Mill

There are a number of different tools in gmax to set up animation. This is one sequence:

1. Select the helper for the mill, b.r.mill;
2. Click the Animate button to change it Red;
3. Open the dropdown Animate menu (the one with the wheel symbol);
4. Click the Rotation button to create the first key frame at frame 0.

5. Click the rotation button at 5 above to show the screen at the right, with additional graph information on the key info and rotation parameters;
6. If you wish to delete a wrongly placed key, use the rotation button in 6 above;
7. This shows the current frame number.

Click the angle snap toggle  at the bottom of the screen, so any rotation is in 5 degree increments. This makes it easy to get correct angles. We decided to rotate the mill 360 degrees in each100 frames:

1. At the bottom menu type in 100 in the frame box;
2. The track bar display and the animation menu shows we have moved to frame 2 at 100;
3. In front view, and with the b.r.mill still selected, rotate it to the left, anti-clockwise;
4. This will register as a movement at frame 100, in my case I had rotated it 35 degrees;
5. In this box, type in the correct 360 instead of the 35. The initial rotation sets the direction.

The wheel should now rotate 360 degrees anticlockwise over 100 frames. Repeat these same steps at key frame 200 and 300, see steps 1 to 5 above but type in 200 and 300 to go to those key frames.

You can now turn off the red Animate button, and play the animation from frame 0. Because the mill blades are linked to the helper, they will follow the animation we have set for the helper. It should be smooth but if it is not, that would not be abnormal for a windmill. To smooth an animation you can insert extra intermediate key frames, or experiment with the tension values (25 to 50). These tighten up the rotation through the key frames, so it doesn’t drift as much.

Oscillating the Head

The head of the windmill will oscillate in the wind, but it should not be regular, and should pause in some positions until the wind changes. Make a random animation but return to the start position after 300 frames. Plan the animation before starting. The mill is connected to the oscillator helper, so it will swing with the oscillator, following the helpers.

Let the head swing as follows:

1. Right (anticlockwise) 0 to 30 frames, -10 degrees;
2. Pause for 30 to 80 frames;
3. Swing left (clockwise) over 80 to 110 frames to plus 5 degrees;
4. Pause 110 to 180 frames;
5. Swing another 5 degrees left over 180 to 200 frames;
6. Pause 200 to 260 frames;
7. Then swing back to the start (frame 300), from 260 to 300 frames.

Animate the oscillator helper using the following steps, it is similar to how we animated the mill blades. Look at the top view and as before,

1. Select the helper for the oscillator, b.r.oscillator;
2. Click the Animate button to change it Red;
3. Open the dropdown Animate menu;
4. Click the Rotation button to create the first key frame at frame 0.

5. Type in 30 in the frame box on the bottom of the screen;
6. Rotate the helper so the mill and oscillator swing to the right 10 degrees. You can type in the correct value in the angle entry box, or watch it change while you rotate the helper, then stop the rotation at 10 degrees.

7. Type in 80 in the frame box at the bottom of the screen;
8. Click the Rotation button to create a key at the same position as in step 7 above, you do not need to rotate the helper.
9. Type in 110 in the frame box at the bottom of the screen;
10. Rotate the helper so the oscillator rotates back to the left, 15 degrees to create the key.

Here are the first four key frame setting displays from the steps above:

Note:

  • When you want to pause the rotation and make one key identical to the previous key, you just click the rotation button.
  • When you want to rotate, you rotate the helper in the direction required, and specify the correct angle change in the box. This initial rotation sets up the correct direction. The angles in the entry boxes are angle changes from the previous key frame, not cumulative angle changes, and they do not have a sign to denote direction.

Repeat the above steps for the remaining key positions, here are the setting displays:

The oscillations sometimes look like they are on rubber bands, a bit sloppy, especially if they are large movements over short time frames, they can overshoot the required positions. For the mill this makes the movement more natural and fluid.

You can vary the tension in the Key Info box. The curved graph gives loose control at 25 and changes to the pointed curve (tighter control) at 50. Select any number in between these values to experiment. When you use translation in animation (linear movement say), there are different controls on how the movement passes through the key frame points.

The animation should be working correctly, if not you may have to delete some of the key frames, or even unlink helpers or objects, or delete the helpers and start again in extreme cases. If when you get the animation into Trainz, it is scattered across the landscape, the axis alignment was incorrect at the start of the animation setup. If any of the objects fail to appear in Trainz, it is likely you have forgotten to link all objects to a helper, or the linking is broken. These are the keys for unlinking or deleting a key frame:

Linear Animation – Lifting the Rod

To be complete, we really should introduce some linear animation, the vertical lift rod that raises the water is operated on a crank from the mill and goes up and down. The rod itself would be hard to see, so lets make a rusty coupler in the length of rod, so that will be obvious when it moves up and down. We have however attached the rod to the water pipe earlier and made it a stationary object attached to b.r.main.

It is easy to separate it, and then attach it to a new helper that goes up and down. Select the water_pipe object then:

1. Use the Modify menu;
2. Select the polygon option;
3. Select all the polygons on the galvanised rod;
4. Detach the polygons as a new object;
5. Give it a name “rod” again.

We need to make a rusty coupler as part of the rod, about 6 metres above the ground, so we can actually see the animation action of the rod. Construct a small cylinder with a diameter a little larger than the rod, texture and map it rust, then attach it to the rod as one object.

1. Select the rod;
2. Open the modify menu;
3. Select the Attach List;
4. Choose the newly created cylinder from the list;
5. Click on attach. You may be asked to match material Ids, click yes.

Animating the Rod and Coupler

In top view construct a helper b.r.rod near the centre of the rod (about 6m up from the ground), link the b.r.rod to the b.r.main, then link the rod itself to the b.r.rod, similar to previous linking steps.

Because the rod was part of the water_pipe, and has not been rotated during the detaching process, its axis will be aligned to the World axis already. The mill rotates three times over the 300 frames, and the rod goes down and up for each rotation. Consider the position of the b.r.rod to be at the top of the stroke, and it will move down 0.3m, then back up over 100 frames, this will be repeated three times for the full animation cycle.

To animate the rod helper, make sure the animation is at frame zero (in entry box at the bottom of the screen), and make sure the Animate button is clicked to make it red:

1. Select the b.r.rod helper;
2. Open the animation menu;
3. Check you have selected the correct helper, b.r.rod;
4. Click the Position button to set the initial Key frame;
5. This shows we are on Key frame1;
6. Note the height of the helper is 6 metres at the start;

To move the helper and therefore the rod, we will have key frames at every 50 frames, the heights alternate from 6.0m to 5.7m and back again. Setting these frames and heights is quite easy, and we will use the bottom frame and height entry boxes this time instead of the animate menu down the side of the screen.

1. In the frame box at the bottom type in 50;
2. In the Z axis box (vertical dimensions) type in 5.7 as the new height at 50 frames.

The action of typing in a new dimension sets the key frame, with a value of 5.7m and you will see the helper move down 0.3 metres.

3. In the frame box at the bottom type in 100;
4. In the Z axis box (vertical dimensions) type in 6.0 as the new height at 100 frames.

Now the rod has completed one of the three cycles and it is back at the top of its travel. Repeat the above steps for frames at 150, 200, 250 and 300 with the 5.7 or 6.0m heights entered correctly.

Click the Animate button to turn it off and run the animation from the buttons at the bottom of the screen. The animation should look smooth and the rusty coupler should travel up and down with the lift rod.

Adjusting Linear Animation Smoothmess and Performance

The rod should not move up and down in a linear motion, as it is driven by a crank on the mill. It should slow down as it approaches the top or bottom of the motion. Looking at the animation just created it seems to do this. The way an animation tracks through a key frame was discussed earlier, as an elastic band, accelerating into or out of the frame, or sharp changes of direction. These properties are set by the animation controllers, you will have noticed the graphical diagram in the Key Info box of the Animate menu.

The one shown is the default value and gives a smooth flow through the key frame. This is usually satisfactory for most of your animation. However, if you move a helper and hence an object over large distances and short time frames, then alter the trajectory sharply, the animation can wander all over the place, or overshoot. Right click on one of the graphs above, and you can see the other options to alter the behaviour into and out of each key frame, you should refer to the Help file for an understanding of each option.

Exporting the Model

Make a temporary directory to export the model, for later import into Trainz. Export the model as mill.im from the file export menu (File .. Export .. mill.im .. Save).

Exporting the Textures

To export the textures used on the model use the Resource Collector option.

1. Click the tools symbol;
2. Select the resource collector button;
3. We need to define the paths, so click the Browse button;
4. Click on the Use Path button in the dialogue box that opens;
5. Click on the Begin button.

All the textures used should now be found in the same folder as the mill.im model. Verify that the textures match the texture.txt file names, delete any texture files that are not required.

After many exports, when the model is finished, you should delete all the texture.txt and the texture files, and export and gather for a final time – you may have changed your textures during the model development, and have obsolete textures left in the directory.

Exporting the Animation

Open the File ..Export box and export the animation as anim.kin. A dialogue box will open asking how many animation frames to export, click ok to export the full 300 frames.

The Config.txt File

For the correct config.txt file see the downloadable model for this tutorial. A typical file for the windmill will look like this:

You should only use a vanilla text editor such as Notepad to create config.txt files, MS Word is not suitable, the quote character “ for example, is not the correct quote ” code recognised by Trainz.

The important parts for the mill model in the mesh table are:

  • The auto-create 1 tag makes the windmill show as soon as it is placed in Surveyor;
  • The anim anim.kin tag locates the correct animation file;
  • The animation-loop-speed 1 tag plays the animation at normal speed, if you want to vary the speed, use 0.5 for slower, or 2 for faster, for instance, instead of the 1.

Comments

I hope you can find something useful in the tutorial.

Making the Model

The construction of the windmill is covered in Part 1 of the tutorial, see link below:

Ian Manion (Vulcan) May 2008

The full tutorial is available for download as a pdf see link below: 

The model files (gmax and ingame files) are also available for download see link below:

Amendment Notes and Comments

18/05/08 Initial issue.

15/06/12 Additional info in the linking process steps