Tony's tutorial Page

I'm making a slight disinction between the "artwork" on the artwork page, and the technical parts on the this page.

Wooden Trains (Tutorial)       2:14 PM - Dec 26, 2008

Download kit here: woodTrains.zip (3MB)

This is the technical side of the wooden trains work that appears on the artwork page.

I wanted to make the trains ride along the tracks and make the track layout fairly flexible. This meant making the track scripting system update somewhat automatically, making functional switch tracks, and making off-ramps and on-ramps that would let the train go "off road" and drive around on the train table.

I also (despite working with Maya since 2001) hadn't really ever had the need of building a control window, so this was also an exercise in building a control panel.

Icons need to be stored in /maya/prefs/2008/icons


This is a simple track layout. It looks pretty, but the train doesn't use the render geometry to move. It's only the clever rigger lining up the system that preserves the illusion of consistency.


This is the actual train system. The blue curves and locators are the track. The black locators and joints are the train. The locators of the train are lined up with the axles of the wheels of each car. The car geometry is constrained to these locators, which are then moves along the curves from piece to piece.


Each track piece consists of the geometry shape, two locators, and a NURBS curve.

The locators have a string attribute added called "other track". Once the track is all linked up, this attribute will hold the name of the locator on the matching piece of track that lines up with this locator. This lets the train script know what the next piece of track is that the train will roll onto when it rolls off of this current piece of track.

The NURBS curve is the path that the train follows. All of the curves are parameterized from 0 to 1 regardless of their distance. The train rolls along the curve for one track piece until it hits the end then it quickly swaps to the near end of the curve of the next track piece and continues rolling.


Each train car is constrained to a locator for each axle of the train car. These axles have several extra attributes.
CurrTrackParamVal stores how far along the current track (from 0 to 1) this locator is.
DistFromFront stores how far in world space distance this axle is from the front of the train. This is used with the script for setting the train on the track initially, and doesn't change as the train moves along.
FacingZeroToOneDir stores whether or not this axle is is pointed along the current track in the direction of the curve's parameterization from 0 to 1. That is, if the train is moving forward, should this axle's CurrTrackParamVal be going towards 1 or towards 0? This is necessary because the train can easily travel both ways across a single track piece.
CurrTrackCurve stores the name of the NURBS curve for the current track piece that this locator/axle is currently on.
IsLastAxle is used for switch tracks. Once the last axle of the train travels across the beginning of a switch track, the switch can toggle to another direction without disrupting the train's movement.


CurrTrack is deprecated from an earlier script, and I need to get rid of it.

Download kit here: woodTrains.zip (3MB)

 
tony@kaap.us | WebSite by KaapFamily.net  |  Valid CSS  |  Valid HTML