Skip to content

Polyline item

skzk edited this page Mar 4, 2025 · 15 revisions

Roads and various other items in the game are procedurally generated by drawing a spline through the nodes of the items and creating geometry along that path.

To my great annoyance, the rotation of a node and the length of the path between the two nodes of an item are cached in the map files. If you don't get them right, the game will initially create the items with your inaccurate values, and to fix them, you need to open the properties dialog of each node and click Cancel. This will recalculate the node's rotation and the cached lengths of its attached items.

Function

The spline function used is a Hermite spline. The tangents of each piece are calculated as follows:

  1. Calculate the distance d between the two control nodes.

  2. Rotate the vector (0, 0, -d) by the rotation of the start and end node respectively.

Length

I don't know which method the game uses to approximate the length of the spline – I decompiled it and now I just plug my numbers in and the right number comes out, but all this SIMD math is a black box to me.

Rotation

The rotation value of the two nodes of a polyline item can either be set manually using the Free Rotation flag, or the game can calculate it automatically like this:

  • For a node with only one "neighbor" in either direction, its rotation is simply the angles between the direction vector of the polyline segment and the ground plane.

  • For a node p1 with a "neighbor" in both directions: convert the direction p1-p0 to its rotation, then average it with the rotation of p2.

Clone this wiki locally