Skip to content

Instantly share code, notes, and snippets.

@zephenryus
Created October 16, 2018 20:43
Show Gist options
  • Save zephenryus/d8fb0eca26c976567856419a70abe794 to your computer and use it in GitHub Desktop.
Save zephenryus/d8fb0eca26c976567856419a70abe794 to your computer and use it in GitHub Desktop.

Reading and Rendering the Terrain

Loading the Terrain Scene Data Into Memory

The first step is to decompile MainField.tscb into an array containing material data and area data.

The tscb file can be decompiled using the tscb file specification or a tscb tool.

The Material Data will be used later by .mate.stera files. The Area Data is used to layout .stera files across the world map.

In the Area Data array, there is an x and z value that specify where each base file is located on a 32×32 grid. To see how files are laid out look at my tscb map.

If you want to simply iterate through all possible files you can implement a z-order curve algorithm or using the Moser-de Bruijn sequence. Here is an implementation in python.

You would iterate through all values for each level of detail (0–8) from 0 to 4^zoomLevel and verifying that the file exists and place the data according to the z-order curve. Filenames are the hex string value of the integer used for iterating.

From the area data array fetch files with the base name and the available extensions. All areas have a hght.stera and mate.stera file associated and, depending on the extra_info_array, may have a grass.extm.stera and / or water.extm.stera file associated.

Files are stored in sarc archives and can be accessed via

unsigned int fileIndex
unsigned int lod
unsigned int sarcIndex = fileIndex / 4

string filename = hex(fileIndex) // 0 pad to 4 digits
string sarcname = hex(sarcIndex) // 0 pad to 4 digits

"Terrain/A/MainField/5{lod}0000{sarcName}.mate.sstera"
// Unpack sarc
"5{lod}0000{fileIndex}.mate" // Access file from within the unpacked sarc

Each file is then decompiled into array data that corresponds to a vertex on a mesh.

Height and Material data are applied to the same 256×256 vertex plane; water data is applied to its own 64×64 vertex plane; and grass is “painted” onto the height and material plane in 4×4 vertex blocks.

Information for decompiling each file type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment