Friday, 26 August 2016

Those I76 Level Heightmaps, in 3D

So, since we can extract heightfield information for the level terrain then there's an obvious thing we can do, which is try and convert the heightfields to .obj format as a mesh, and look at them in Blender to get a nice 3D view of the whole level.

Anyway, this is actually simple: take the heightmap, and walk through it dumping out the co-ordinate as x & y, and the height value as z, prefixing these values with a "v" to generate vector values in an obj file format-

      QString s = "v " + QString::number(x) + " "+ QString::number(y) + " "  + QString::number(z);
This gives us the basic height map as a set of points in an obj "importable to blender" format.

Then, since obj files can support faces that are quads we can simply walk through the heightfield and form a quad  with the lower edge from two values in this row, then the values from the next row as the upper edge, i.e. for each pixel we take this pixel, the next X pixel, and the go up one Y interval to the next row and take the two adjacent pixels to form the edges points of the quad.

  int fcount =1;
  int fh = fcount + (w*128);

...and then, for points in the heightmap...

        QString s = "f " + QString::number(fcount) + " "+ QString::number(fcount + 1) + " "  + QString::number(fh+1)+ " "  + QString::number(fh);

We need to watch out for going over the boundaries of the heightmap in the outer loops (i.e the upper X & Y values), but that's all.

So this is the output for the crater.

The slight discontinuity (around the zone edges) on the inside of the crater walls is odd - for a while I assumed it was a fault in the export or rendering, but going into the game on that map there *is* actually a slight step there which you can see when you drive along it, so  I suspect it's either an artefact of the level editor, or possibly a deliberate step to help vehicles get up the slope (although it's a bit too regular for that to be likely).

The Z-scaling is fairly arbitrary - I just played with the Z scale in blender for these screen shots rather than work out a mapping.

Looking at something larger, here's trip level 1.

And here's a close up of a section (which matches the mesh from the introductory image to this post)

Which is kinda neat. You can see the nice smooth, editor generated, slopes of the hills, and the blocky "looks kind of manual" cliff edges. Some of the "pits" cut into the terrain look strange, but having driven around in the game level they do appear to be there as deliberate (and annoying) traps to catch you if you go too far off the line that Taurus gives you. The LOD in the game does actually help these look less abrupt, which is actually quite a clever example of using the engine limitations when you think about it.

And that'll do for today.