VMRJ

Panoramas:

Present your Trainz creations on the web

Just about every creator of Trainz content has the urge to show off his or her handsome scenery and rolling stock to its best advantage. TRS2004 makes capturing screen shots extremely easy -- just hit F5 to hide the controls, and Shift-PrintScrn to capture your screen as a Targa (.tga) format file. Unfortunately, the screen shot usually has to be cropped and compressed to allow display on your web site or on the many user forums. I've been using TRS2004 to recreate a historical railroad that once existed in Wisconsin, and wanted a way to show the locations along the line on my web site in a more interactive manner than just screen shots.

In the early 1990s Apple Computer initiated a method of creating immersive environments that are web-friendly. Called QTVR (QuickTime Virtual Reality), the method assembles a series of snapshots into a seamless, 360-degree panorama. A large number of inexpensive programs are now available that can "stitch" the images together and save the resulting panoramic image in any number of formats, including JPEG (see list of resources at end of article). A number of factors affect the quality of the stitching operation, including even (consistent) exposures around the series of images, a level plane of camera rotation, and equal degrees of rotation between each image. The number of images that are needed depends on the angle of view of the camera, and the stitching software's requirement for some overlap of adjacent images.

To get started with panoramas, you will need to set up a TRS2004 camera to capture a series of screen shots; an image processing program (Photoshop, Paint Shop Pro or the like) to convert the captured .tga images into a usable size and file format; a stitching program to assemble and save the panoramic image; and optionally, a script or program that can present the panoramic image as a scrollable or zoomable view.

Setting up the camera

The best panoramas are made from images shot at a series of equivalent rotations around a full circle. With a physical camera, the images can be captured using an indexed pan head on a tripod. In TRS2004 however, the camera is free to move to any angle, including tilting forward and back. So, how to constrain the TRS2004 camera to specific angles? Enter the cab interior cameras, which can be preset to any position and angle simply by entering the appropriate values in the config.txt file! This method is made feasible by Rich Blake (a.k.a. slugsmasher) and his InvisiCAB. A previous VMRJ article used the InvisiCAB as a "camera dolly" to present a walk-through tour of an architectural project. The InvisiCAB has no walls or body, and can be run on invisible tracks to allow constrained camera movement through a layout.

By modifying the InvisiCAB's config.txt file, we can create a series of interior cameras that are preset to every 10 degrees around a circle, or any set of rotations. In practice, the interior camera is set to a field of view of 65 degrees (defined in the TRS2004 config.txt file), so only 12 images at 30 degree intervals (and possibly fewer) are required to make the full circle. Stepping through the cameras is managed using the right- or left-bracket keys [ ], making capturing the images extremely quick and simple.

Get started by visiting the Download Station (http://www.auran.com/TRS2004/DLS.php) and fetching the InvisiCAB pack. This contains four required items: InvisiCAB (KUID:86661:15710), invisible interior (KUID:86661:55710), silent horn (KUID:86661:54710) and silent engine (KUID:86661:53710). I found that the InvisiCAB had to be put into my /World/Custom/Trains directory in order for it to show up in the Railyard and in Surveyor. While downloading, you may also want to fetch MAN6 Invisible Track (KUID:63290:38102), unless you want your viewer to feel like they are standing between the rails!

Next, you need to modify the config.txt file of the invisible interior (KUID 86661:55710). Find the folder named "kuid 86661 55710" and open the config.txt file. Be sure to use a text editor such as Notepad or WordPad, not a word processor such as MS Word. A few lines down, you'll see the camera definitions:

camera 0,0,0.5
cameralist {
camera0 0,0,0.5
camera1 -0.3,-2,0.7
camera2 0.3,5,0.7
camera3 1,-5,1
}
cameradefault 0

The cameradefault value tells TRS what entry in the cameralist to use when first entering the cab. The values after each camera name are X, Y and Z positions in meters, and the horizontal angle in radians. TRS uses positive values from 0 to pi for 0 to 180 degrees, and -pi (negative pi) to 0 for 180 to 360 degrees. The horizontal angle is relative to the InvisiCABs heading, so if you want to start with 0 at true north you need be sure your invisible track is laid straight north-south and the InvisiCAB is placed on the track facing north. For simulating the viewpoint of a person standing on the ground, the Z value should be eye-height, or about 1.7 meters (67 inches). Interesting "birds-eye" views could be made by placing the camera at 100 meters.

Here is a series of cameras to paste into the config.txt in place of the above section. This defines 12 cameras at 30 degree intervals at 1.7 meter height. The radians were calculated as (degrees * 0.01745) using a spreadsheet function. After pasting, save the config.txt and launch TRS2004.

Camera 0,0,1.7
cameralist {
camera0 0,0,1.7,0
camera1 0,0,1.7,-0.5235
camera2 0,0,1.7,-1.047
camera3 0,0,1.7,-1.5705
camera4 0,0,1.7,-2.094
camera5 0,0,1.7,-2.6175
camera6 0,0,1.7,3.141
camera7 0,0,1.7,2.6175
camera8 0,0,1.7,2.094
camera9 0,0,1.7,1.5705
camera10 0,0,1.7,1.047
camera11 0,0,1.7,0.5235
}
cameradefault 0

For your convenience, we’ve included a replacement config.txt file for your use. Just rename the existing config.txt file to something innocuous that you can find later if you want to reuse it (e.g., original_config.txt) and copy the new config.txt file into the same location as the old one.

Get the new config.txt file here.

Placing the InvisiCAB and capturing images

Start Surveyor and load your layout. Consider from what vantage point you want your panorama to be centered. Keep in mind that the stitching software needs some objects in the images in order to find the image overlaps and stitch correctly. Once you have found the most photogenic site, lay a short stretch of invisible track. Switch to Consist mode and place the InvisiCAB on the track. Note the orientation of the InvisiCAB and switch its direction if necessary. (Some panorama presentation software can also display a map or overhead view alongside the panorama, which is helpful for orienting the viewer. In this case, heading the InvisiCAB due north allows you to capture an overhead map view using the external camera).

Save your layout, and hit Ctrl-F2 to switch into Driver. If you have a lot of consists in your layout, you may need to look through the train list in Driver (lower left of screen). InvisiCAB is easy to find because there is no picture of the cab. Just a white rectangle!

Click on the InvisiCAB and choose Cab view. Turn off the online Help function by placing the cursor in the upper left area of the screen to display a menu and then clicking on the right-most icon (this prevents any track switches from displaying their red-green direction arrows). Now hit F5 to hide the interface elements, and your screen should be filled with a gorgeous view of your layout.

Practice using the [ and ] bracket keys to change your view. The camera swings over and slows to a stop, so you need to be careful to wait before capturing a screen shot. When you are comfortable with the camera controls, get the camera back to the default heading -- easiest if you exit the cab and re-enter. Be wary of zooming or pitching (up/down) -- zoom may throw off the stitching operation, and TRS2004 seems to remember the pitch for each individual camera position.

Capture the screen (Shift-PrintScrn), then hit ] to move clockwise (most stitching software expects a left-to-right or clockwise series of images, but the software can easily reverse the order of your images if you capture in the wrong order). Let the camera settle, then capture again. Continue in this way all the way around the circle -- 12 captures in total. Whew -- now for the fun part!

Rescaling and converting images

The screens you captured will typically be 800 x 600 pixels or 1024 x 768 pixels -- the usual screen resolution used in TRS2004. Depending on your computer and the intended use of the panorama, this is probably larger than necessary and could take a long time for the stitching software to process. Also, none of the stitching programs that I investigated for this project were able to work with the Targa format files saved by TRS2004. So I used Photoshop to scale the screenshots down and to save as JPEG format, which my stitching program could understand. An advantage of Photoshop is the ability to batch process files. So once you convert the first image you can apply that action to all the rest of the screen shots. Another useful program for batch conversions from .tga to some other format is IrfanView, available free at http://www.irfanview.com. IrfanView, however, does not batch process size changes.

I chose 512 x 364 pixels as the image size and used a medium JPEG compression level. For other panoramas, I saved the full size screen shots as top-quality JPEG (10 in PhotoShop). This compressed the 3-megabyte .tga images down to about 500 kilobytes. You may need to experiment with the image format, because degradation of your image quality can occur at several steps along the path to the final panoramic image. All the screen shots were converted and saved into a single folder using the original filenames -- conveniently numbered in order of creation by TRS2004.

Stitching the panorama

Although the general process of stitching the images is easily described, the details will vary along with the quality of the results, depending on the particular software package used. I tried several demo packages that typically are fully functional but will save the final image with a watermark on it -- so don't be shy about trying them out. Some packages include viewer software, screensaver software, or web/html display generation, so think about the possible uses you have for the panoramas.

When you are ready to make your great panorama, you will need to supply a few pieces of information to the software to increase the quality of the stitching process. Most important is the focal length of the camera lens used. This allows the software to calculate the field of view and the expected overlap between adjacent images. The software uses this information to warp the images and correct for lens distortions, then merges the images and blends the overlapping areas. For us, the calculation of focal length is very easy, because the camera field of view is defined in the TRS2004 TrainzOptions file as "cabinfov=65" (at least if you didn't apply any zoom before capturing your screen shots -- otherwise, go back into TRS2004 and recapture your images). Using a bit of high-school trigonometry, I arrived at a focal length of 34.01 mm (actually this is the "35 mm lens equivalent focal length" -- more in-depth explanations can be found at http://www.panoramafactory.com). Plugging this value into the software, and the fact that 12 images covered the full 360 degrees, resulted in a ~50% overlap of neighboring images.

So, load your processed image series (figure 1) into the stitching software and let 'er rip. Sometimes the software will have trouble aligning two images, in which case you may have to manually adjust the overlap. At the end of the stitching the initial panoramic image will be presented, usually with the option to proceed or to go back and tweak the parameters for a better stitch. I ran into a few problems where the images had no foreground detail. Usually a simple right or left overlap adjustment solved the problem. Another area that may cause problems is the sky. The clouds in TRS2004 can move mighty fast, so the clouds in the beginning image probably won't line up nicely with the last image. You can try setting the sky to a plain, noncloudy type, or use your image processing program to edit the final panorama to blend the clouds to your liking.

Input

Figure 1. Input.

Figure 2 shows a stitch where two images had different brightness levels -- the region of overlap is between the brighter left image and darker right image.

Raw stitch

Figure 2. Raw stitch.

The final step is blending the images, which will smooth the differences between the adjacent images. Figure 3 shows the blend of figure 2 -- the brightness change is now much less distinct. If this is still too noticeable, your software may allow you to go back and adjust the brightness and contrast of the initial images for a better match.

After blend

Figure 3. After blend.

At this point you will have a very wide image, which you can save in JPEG format. If you just view it in your web browser it will probably be scaled down to fit the width of your screen. If your stitching software has the capability to generate a web page with html code, you are nearly done. Other packages are also available to allow display of the finished panorama within a web site; my favorite is a package that uses JavaScript to display the panorama and a map view, with the map indicating the direction of the view. Hot spots can also be placed on the panorama, making it "clickable" to jump to other panoramas or to other web pages. The possibilities are limited only by your imagination!

pano 1

Pano 2

Pano 3

Pano 4

Samples.

Resources

TRS2004 Downloads

  • InvisiCAB by Rich Blake (kuid:86661:15710)</li>
  • MAN6 Invisible Rail by Max Nelson (elvenor; kuid:63290:38102)
  • Tropical March Sky by Roger Cabo (www.trainzland.de.vu KUID 60349: 21006)

Conversion software

Stitching software (only a fraction of what is available; no endorsement implied)

Panorama display

Scott

Article and screen shots ©2004 Scott Monsma. All rights reserved.