Legacy:New drivelines

This page covers the new driveline format introduced along SuperTuxKart 0.7

Concept of Quads and Drivelines

Drivelines are used to indicate to the AI where to drive and to determine the order of karts: if a kart is on the driveline, it is known how much of the track it has driven, and allows to compare the progress of karts. If a kart is off the driveline, the closest driveline point is picked to determine how far that kart has driven when comparing the distances of karts, and to determine where to drive to.

All places that a kart is allowed to drive on are marked by quads. Quads need not to be connected (though usually are). A sequence of quads together make a driveline, indicating in which order the AI should drive on the quads. Example:

New driveline.jpg

A driveline section is a sequences of quads connected to each other. These driveline sections are then connected to create the full drivelines for a track. In the example above there would be two driveline sections: the black main driveline creating the lap, and the driveline in red indicating a shortcut (or alternative path) for the karts.

In blender the quads of a driveline section are created from a simple mesh:

Driveline blender.jpg

The beginning of a driveline section is marked by two unconnected edges. The start point of a driveline is the middle point of the two end vertices of the edges. The end point is the middle point of the four vertices of the last quad. The edges connecting corresponding vertices from the left and right side are optional. So if you want to divide a quad into two (e.g. to better model the shape of the track, or to help the AI) you can just add the two vertices, you do not have to connect them. It is important though that both sides of the drivelines contain the same number of vertices (otherwise the quads can't be created properly). If you convert the main track as described in the track making tutorial the created mesh will automatically have the same number of points on each side.

There are two reasons why you might want to split a single driveline section into smaller driveline sections:

  1. A driveline section can be marked as 'insivisible', i.e. it will not be displayed in the minimap. This should be used for hidden shortcuts that need to be discovered by the player. This is done by giving the driveline the property 'invisible' with a non-zearo value.
  2. (not yet implemented): driveline section can be marked as 'disabled', meaning it will not be used (nor displayed) in the game. This can be used to force the AI to take a certain way and therefore make sure that the AI can drive on all possible paths.

The track export script distinguish between two kind of driveline sections:

Main driveline sections

The main driveline which indicates the 'main' way in which karts should drive. The quads of the main driveline must form a single lap. A driveline section is marked to be part of the main driveline by giving it the type "main-driveline".


The example above shows a single driveline section only. The order in which the main driveline sections are connected is determined as follows:

  1. The main driveline section with a start point closest to (0,0,0) is selected first.
  2. From all remaining main driveline sections the one with the start point closest to the end point of the last selected main driveline section is selected next.

The last step is then repeated till all main driveline sections are selected, and therefore the order in which the main driveline sections are connected is determined. The quads are then created from the separate driveline sections, and one quad is added from the last added driveline section to back to the first driveline section. This creates the main lap.

Note: Depending on experience we might either add quads to connect each driveline section, or not add the one driveline section between the last and the first section.

RV2Raa <a href="http://dqxrggsxhvlp.com/">dqxrggsxhvlp</a>, [url=http://yxwlknebhspj.com/]yxwlknebhspj[/url], [link=http://hizsnnzwkkjj.com/]hizsnnzwkkjj[/link], http://xjhykfqlpwuv.com/

Detailed concept: QuadGraph

While the description so far is exactly what is supported by the track exporter, the actual concept implemented in STK allows more complicated structure. This is done by maintaining two data structures: one containing the list of all quads, and one describing how the quads are connected with each other, the so called quad graph. The main difference between the two data structures is that one quad in the list of all quads can be used several times in the graph. The graph consists of nodes - as a default, each quad corresponds to a graph node with the same number - this is exactly what the track exporter assumes. But this is not necessary: A part of the track might not be used for a particular race (think of a city track where several different race tracks can be defined), or some quads might be used more than once (e.g. a figure 8 race track: the quad in the 'intersection' would be used twice)

The graph defines for each graph node which quad it belongs to, and which are the possible successors. Usually each quad will have exactly one successor, but in case of a shortcut or branch of the track it might have more than one.

Given the quad definitions from the picture, the following graphs could be defined: sgyKLJ <a href="http://xfpjoquklthg.com/">xfpjoquklthg</a>, [url=http://ictpunkgjgxs.com/]ictpunkgjgxs[/url], [link=http://kvhzlpyhsodw.com/]kvhzlpyhsodw[/link], http://vrinejfydvkc.com/

Reverse Loop

A graph with nodes 1 to 29, corresponding to the quads 1 to 29 and the graph:

1 → 29 → 28 → ... → 2 → 1.

This gives a similar simple loop as the one above, but it is driven in reverse (ie. counter-clockwise).

Simple Loop with Shortcut

Quad graph2.jpg

For this we need a graph with 34 nodes, corresponding to the 34 quads. The main loop will be defined as in example 1, but additionally we add:

 15 → 30 → 31 ... → 34 → 23

This allows the AI to pick any of the two ways (the criteria for which way is picked are not defined yet - atm it's a random selection).

XXXXXXXXX The numbers indicate the number of the quads. This part does not define in which order the quads should be driven, or if the shortcut is to be used or not, it only defines which part of the track can be used. YYYYYYYYYYYYY

A Loop Inside of the Track

The driveline structures also allows us to define a loop, i.e. forcing the AI to drive a circle before continuing, see picture:

Quad graph3.jpg

(note that this is most likely an absurd example only - for a track like this to be fair the player karts would have to do the same loop, which means there must be a mean to indicate this to the player, which we currently don't have).

To do this, we need additional graph nodes for the sections that are driven twice. So graph nodes 1 to 34 corresponds to the quads 1 to 34, and then additional graph nodes 35 to 43 which are mapped to the quads 15 to 23 (again). So the quads 15 to 23 have each two graph nodes associated with them, but each graph node still has exactly one quad. Then we can define the following graph:

1 → 2 → ... 14 → 15 → 16 → ... → 23 → 34 → 33 → ... → 30 → ...

This defines the first part of the loop: driving backwards on the shortcut to graph node 30 (which is quad 30). Then we use quad 15 for the second time, so we use the additional graph nodes here:

 ... 30 → 35 [15] → 36 [16] → ... → 43 [23] → 24 → 25 → ... → 29 → 1

In [] are the corresponding quad numbers for the graph nodes 35 to 43. By having the additional graph node layers the AI will simply follow the graph till the end (so there are no loops in the graph, except for starting a new lap), but the mappings of graph nodes to quads force the AI to drive a loop.

How to create drivelines with the track exporter

The track exporter is able to create quad and graph data structures from specific meshes in the track. While it can't handle all theoretical cases (e.g. a looped track as the last example above is not possible, to do this you have to manually edit the graph file), it can handle all kinds of shortcuts and alternative ways.

Creating the Main Driveline

First of all you need one mesh to be the main driveline. This is the main way the AI should be driving. The mesh can be created either by manually extruding ..., or by using curves (as described in the track making tutorial). Add a game logic property called 'type' and give it the value 'main-driveline'.

Driveline blender.jpg

This mesh must not be closed (see picture). To indicate the start point and therefore the direction in which the karts should be driving, add a single vertex with an edge to each of the two start points - see picture. The track exporter will export all the quads in this mesh including the implicit quad that connects the end to the beginning. Then it will add a graph describing this loop. Each track must have exactly one main driveline.

Note that the additional two vertices are completely ignored, they are only used to indicate where to start.

Creating a Shortcut or Alternative Way

If you want to add a shortcut (or alternative way), use a similar structure as for the main driveline, but give the game logic property 'type' the value 'driveline' (as opposed to main-driveline)

File:Driveline blender shortcut.jpg

The shortcut is added in the picture using again two vertices to indicate where the start point is. The export script will then automatically export the additional quads, and create the graph from the closest quad of the main driveline to the beginning of the shortcut, and from the end of the shortcut to the closest quad.

How to convert old drivelines to the new format

The old driveline format used two meshes - one for the left side, and one for the right side. To convert these to the new format:

  1. For each of the two drivelines remove the edge that crosses the starting line. So instead of having a loop you have two lines, each line having a starting point and an ending point indicating the direction in which the karts are driving (see picture above).
  2. Combine the two meshes into a single mesh.
  3. Create a new edge connecting the two starting points.
  4. Create a new edge connecting the two ending points.
  5. Select the two starting vertices, extrude them (vertices only), to indicate where the first quad to drive on is.
  6. Add the game logic property 'type', and set it to 'main-driveline'

Now you should be ready to export the track.

The file format

While it is not at all necessary to know or understand the file format used, here a short description which should help in debugging any problems, or modeling more complex graphs than the default one created by the exporter script.

The created .quad file is plain ASCII, e.g.:

<?xml version="1.0"?>
  <quad p0="15.575774,33.574879,0.000000" p1="-20.480236,11.145029,-0.000000" p2="-36.736404,14.047918,-0.000000" p3="-36.095619,34.736038,-0.000000"/>
  <quad p0="0:3" p1="0:2" p2="-89.494789,13.467787,-0.000000" p3="-90.163483,34.155022,-0.000000"/>
  <quad p0="1:3" p1="1:2" p2="-108.047676,9.295321,-0.000000" p3="-129.087753,34.263454,-0.000001"/>

A quad is defined by specifying four coordinates. This can be done either by using four 3d coordinates (as in the first quad line), or by referring to a point of an already defined quad: the latter case uses p0="Q:P" which means: use point P of quad Q as point 0 of the current quad.

Similarly the graph files are plain ASCII, too:

<?xml version="1.0"?>
  <node-list from-quad="0" to-quad="54"/>  
  <edge-loop from="0" to="54"/>

The first section described the mapping of quads to graph nodes - it will always be a 1:1 mapping, i.e. each quad will be used in exactly one graph node. Then the connection of the graph nodes are described. Besides defining a loop, a single edge can be defined as well: <edge from="15" to="23"/>