Rookie Awards 2024 - Open for Entries!
Train Generator Script
Share

Train Generator Script

Alexandra Cuthbert
by BackgroundWhimsy on 15 Dec 2022

Project 1 of 2 for CSANM 258: Scripting for Animation, completed in March 2022.

1 320 0
Round of applause for our sponsors

Scripting for Animation was a class that took what I knew about programming and applied it to the animation tools I'd used in some of my other classes. The goal was to teach us how to make tools for automating certain aspects of the animating process, so our first project was to write a Python script for Maya that would generate a Train and some Tracks.

I've always been the kind of person who likes working to exact specifications and measurements, so I did my best to base the default values of the script on a real 4-4-0 American steam locomotive. I chose that train in particular because I'm a fan of The General by Buster Keaton, and the titular train in the film was a 4-4-0 type engine. That is to say, it had four leading wheels, four driving wheels, and no trailing wheels.

Finding references and specs for the rails and ties in the track was easy, but finding the same information for the engine and boxcars was unexpectedly difficult. I did the best I could with what I could find, and even then the specs I had were only found because I asked a friend to help me search. So, I can't claim that my model is 100% to-scale, but I can say that it was as closely based on the real thing as I could manage at the time.

This was meant to be a tool to help animators block out a train with simple shapes so they could get a feel for the general size and proportions before they spent time actually modeling it. Therefore, I didn't bother to actually sit down and model any of my train's components, and spent my time blocking out the shapes with properly-sized cubes and cylinders instead.

The full Python script with all the code for building the train, the tracks, and the UI ended up just over 1200 lines. That was definitely not the intended scale of the project when it was assigned, but since this class was meant to serve as an introduction to programming for the students on the art side of the animation program, Computer Science majors like me had a lot of extra time and leeway to pursue additional goals. 

So, my Train Script didn't just make a train. It gave the user the option to switch between a simple and complex version of both the train and the tracks, and to specify the dimensions of just about everything. The User Interface had tabs to separate the train controls from the track controls, and the script would check to see if an instance of the train or the track had already been created in the scene. During the tool's initialization it would set up all the necessary shaders for all the components, or revert any pre-existing shaders of the same names back to the default values. The complex models for each of the components were cached the first time they were created to save time when making a lot of them, and the object hierarchies for the train and tracks were maintained as each component was built up and attached to the others.

Even the User Interface was an extra feature. It wasn't a requirement to provide the user with controls like this, but I did it because I wanted to learn how to set up a tool UI similar to the ones already included with Maya. There were one or two things I got stuck on since the documentation for the different widgets wasn't as thoroughly labeled as I would have liked, but in the end I found what I was looking for and overall I'm pretty happy with how this project turned out.


Comments (0)

This project doesn't have any comments yet.