Terra Firma

Terra Firma works in 4 layers.

  1. The API gives the viewer a terrain definition: overall width, height, tile grid, terrain mode, and metadata. That comes through terra_firma.js.
  2. The height source turns any world-space (x, z) into a height. Structural terrain does that procedurally, and real terrain does it from DEM tiles in height-sources.js.
  3. The renderer builds one shared global sample grid for the whole terrain in terrain.js. From that grid it computes:
    • heights
    • normals
    • hypsometric vertex colors
    • per-tile mesh geometry

Because every tile reads from the same global sample grid, the borders line up and the terrain stays seamless.

  1. Three.js draws those tile meshes with lighting in main.js. The material is still vertex-colored terrain, lit by the scene lights.


what does the API have, what is it doing, and where is it getting its from?

At the simplest level, the Terra Firma API does 2 jobs:

  1. It tells the viewer what terrain exists and which one to load.
  2. It tells the viewer how that terrain is defined: size, mode, tiles, metadata, and where to find DEM files for real terrain.

The two API endpoints are registered in terra_firma.js. They are:

Where it gets the data from:

What those tables hold:

What the API is doing between DB and viewer:

One important distinction: the API does not send the full DEM height arrays inline. For real terrain, the API sends metadata plus tile URLs, and then the browser fetches the actual DEM tile JSON files from the static media folder, like the files under pittsburgh-real tiles.

So the data flow is:

For the two current terrains seeded in SQL:


The DB is the authoritative catalog for Terra Firma terrain definitions. It is not generating the mesh itself, and it is not storing the full DEM arrays inline. It stores the structured terrain metadata that tells the system what terrains exist and how to load them.

What DB it is:

What tables it uses:

What TerraFirma.Terrain does:

So this table answers:

What TerraFirma.TerrainTile does:

So this table answers:

What the DB is doing in the system:

What the DB is not doing:

Where the DB gets its data from:
There are really 2 sources feeding Terra Firma overall.

  1. Seeded/manual terrain metadata into SQL
    • The schema and seed data come from Build-Linea-TerraFirma.sql
    • That script:
      • creates the schema/tables
      • inserts or updates structural-pilot
      • inserts or updates pittsburgh-real
      • inserts all tile rows for both terrains

So the DB gets its Terra Firma rows from that SQL bootstrap script.

  1. DEM-derived tile files on disk
    • For real terrain, the DB only stores the path to each tile’s height file in HeightDataPath
    • The actual elevation numbers come from JSON files under:
    • Those files are produced by the DEM ingest script:

So for pittsburgh-real, the DB is not the origin of the terrain heights. The DB is the registry and metadata layer pointing to the height assets.

End-to-end for real terrain:

End-to-end for structural terrain:

So the short version is: