TORCS Track Tutorial

Copyright (C) 2005 Christos Dimitrakakis (See License)
This document describes how to create a track for use in TORCS. Currently it outlines: necessary software, creating a basic track, adding shadows, controlling the mesh generation and adding a terrain relief file. More information, such as the meaning of fields in the xml track description will be added over time.

Necessary software

For basic track generation the trackgen utility in torcs is sufficient.

The included accc utility is used to combine various track elements in the final track description.

To use accc you will also need the stripe utility in your path.

The .xml file

Firstly, create a directory tracks/category/name where category is one of dirt, oval, road and name is the name of your track.

Create the track .xml file. You can take one of the available tracks to start with. The file shall contain one entry for the 3d description, which should be name.ac

Creating the basic .ac file

For initial testing of your track, issue the command trackgen -n name -c category. See that the track is OK by loading it with torcs.

Creating shading

To test shading, issue the command trackgen -a -E 1 -n name -c category from the top level directory. The track step and border step parameters in the Terrain Generation section of the xml file define the near-track and coarse terrain resolution. The terrain transition parameter controls the distance over which the mesh reaches the border step; zero retains the legacy spacing behavior. If terrain generation takes too long, increase the step values or shorten the transition. This will create an elevation file, name-elv.png

Terrain mesh resolution

The terrain settings are written below Graphic/Terrain Generation. For example:

<attnum name="track step" unit="m" val="10"/>
<attnum name="border margin" unit="m" val="150"/>
<attnum name="border step" unit="m" val="40"/>
<attnum name="terrain transition" unit="m" val="150"/>

track step controls sampling along the track and strongly influences terrain detail next to it. Dense points needed to follow the inside of a tight curve do not propagate a spacing smaller than the lesser of track step and border step. border step is the coarse target spacing far from the track. terrain transition is the distance over which spacing grows linearly from the local near-track value to the border step. It applies to terrain both inside and outside the closed track loop, including exterior pockets that are almost surrounded by track. If the parameter is omitted, it defaults to border margin. A value of zero or less disables the distance-based transition and retains legacy spacing.

With approximately 10 m spacing near the track and a 40 m border step, a 50 m transition reaches coarse terrain quickly and produces fewer triangles. A 150 m transition gives a moderate falloff: spacing is about 25 m at 75 m from the track. A 300 m transition preserves detail much farther away but increases triangle count and generation time. Use a longer transition when elevation-map features become visibly faceted; use a shorter transition when broad infields or exterior pockets are unnecessarily dense.

When trackgen detects a valid grade-separated crossing, it automatically divides the remaining terrain into connected domains. The projected road, bridge, socket, and floor geometry is excluded before each domain is sent to the terrain mesher. No crossing-specific terrain switch is required.

It is possible to create a simple shading scheme with the gimp. Open the image, select Filter &rarr Distorts &rarr Emboss. Select the parameters and apply the filter. Save the file as shadow2.rgb. If it is not a power of 2 in size, you have to resize it so that it has dimensions (x,y)=(2a, 2b)

However this scheme is not very good. It does produce soft shadows, but it is not much different than the light produced by the light source in the .xml file. A possibility is to do the following. After you Emboss the image, select Filters &rarr Blur &rarr Motion Blur. Select an angle that is 360 - a, where a is the angle that you have chosen for Emboss, if in the latter your elevation degrees was smaller than 90. If it was larger than 90, set angle to a. Select the appropriate length (between 10 and 50 is OK) and copy the image into a new buffer. Reopen the old image and place the new image as a layer on top of it. Now select either Multiply, or Darken Only and adjust the opacity to around 50. This should result in some shadows appearing to be cast from the sharper edges of your massif. Replace the previous shadows image with this one.

Now do cd tracks/category/name and issue the command

cp name.ac name-bak.ac
to have a backup of the original track description. This can then be used to generate a shading file that will use shadow2.rgb as a texture, with the following command:
 accc +shad name-bak.ac name-shade.ac

Now you can combine the two descriptions into one using

 accc -g name.ac -l0 name-bak.ac -l1 name-shade.ac -d3 1000 -d2 500 -d1 300 -S 300 -es
If the output is too much for your terminal you can always redirect it to /dev/null

Test your new track with torcs.

Creating elevation files

It is possible to create elevation files by issuing the command trackgen -a -E x -n name -c category, where x selects which elevation file should be generated.

         0: all elevatation files
         1: elevation file of terrain + track
         2: elevation file of terrain with track white
         3: track only
         4: track elevations with height steps
Each one of those will be useful for some purpose. I personally use 1 and 3. Number 3 can also be used to create a track preview. It can also be used to get an idea of where the track is so you can take this into account when changing the elevation map. The procedure is as follows:

Using either the track or terrain+track map as a template create a black and white image. The whiter a pixel is, the higher. Then save the images as elevation-map.png. You will then need to insert the following lines in the Terrain Geneartion section of name.xml

 <section name="Terrain Generation"/>
....
      <attstr name="elevation map" val="elevation-map.png"/>
      <attnum name="maximum altitude" val="30"/>
      <attnum name="minimum altitude" val="-30"/>
...
The maximum and mimimum altitude specify what the altitude corresponding to the brightest and darkest pixel in the image, respectively. You might need to fiddle around with that a bit until you get it right.

Of course, as seen in the previous section you can use the elevation map that you have created to generate shadows.

Other .xml attrributes

group size

The group size is used to split the terrain in smaller objects to help the scene graph make his job. If all the terrain is done in one object, it will never be culled and performance will be awful. This is done after the mesh generation, so it's not related to the mesh geometry.

relief file

<attstr name="relief file" val="track-relief.ac"/>

You can use additional ac3d files initially for setting altitude on the terrain. However the same points are also used in the generated mesh, thus possibly resulting in a better mesh. If a <track>-relief.ac file exists in the directory it will be used for the terrain generation by trackgen.

You can use additional ac3d files (see e-track-6-relief.ac in the sources) initially for setting altitude on the terrain but as the points are used in the generated mesh, it can be useful to give better mesh.

If a <track>-relief.ac file exists in the directory it will be used for the terrain generation by trackgen.

The mesh generator stops on closed polys, so if you want a hole in the mesh, you can draw closed polys, else you draw lines and they participate to the mesh.

If you supply the external border in the "relief" file, you can used the trackgen option "-B" to use it as external border instead of generating the default rectangular border. For a track with an automatic crossing, the exterior relief chain must enclose the complete track and crossing. Trackgen treats the largest enclosing exterior chain as closed, even when the AC3D line omits its final closing segment.

At an automatic crossing, relief lines are split where they meet terrain domain boundaries. Each resulting segment is applied only to the connected interior or exterior domain that contains it, so a relief line cannot fill through a bridge or floor footprint.

Lastly, you have to set properties to your lines and polys in the "relief" files : "interior" for the inner mesh and "exterior" for outer mesh.

Editing the .ac file

There are currently two ways to edit this file. One is to use AC3D, and the other is to use Blender which has an AC3D import/export filter. In either case, it might be necessary to remove things that TORCS does not recognise, from the ac3d output file. One such thing is surfaces with 2 vertices (refs 2 data blocks in the .ac file), and other unsupported ac3d features. These can be removed with a simple script if need be.
Christos Dimitrakakis, Eric Espie, Bernhard Wymann
Last modified: Sun Sep 11 12:09:27 CEST 2005