Skip to main content

s2_to_osmap

Function s2_to_osmap 

Source
pub fn s2_to_osmap(s2: S2Map, source_filename: &str) -> OpenStrandedMap
Expand description

Convert a parsed .s2 map into an .osmap (engine convention).

§Coordinate conversion

Blitz3D terrain setup: CreateTerrain(ter_size) — grid 0..ter_size in both X and Z ScaleEntity ter, Cworld_size, Cworld_height, Cworld_size — vertex spacing = 64 world units PositionEntity ter, -(64*ter_size/2), -(Cworld_height/2), -(64*ter_size/2) — centre at origin

So EntityX(h) returns a centred world coordinate in the range −ter_size×32 .. +ter_size×32.

.osmap stores positions in grid-cell units:

  • same orientation as the engine terrain mesh: +X right, +Z = north (= forward)
  • X and Z range = −ter_size/2 .. +ter_size/2 (grid cells, identical to engine’s grid)
  • Y = engine world Y (from norm_to_world)

Because the Blitz3D terrain is already centred, we simply divide by Cworld_size to get grid-cell units. No additional centering subtraction is needed, and Z is NOT negated (both the original and the engine use +Z forward).

The engine scales grid-cell XZ to world units by multiplying with the map’s step factor (step = 64.0 / terrain_size). For a 33×33 grid (terrain_size=32): step=2.0, world spans −32 .. +32.