BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Level editor plan

The format research behind stage 3 of the web editor (milestone M11): what a level is made of in each of the three games, which bf2-rs function reads each file today, what an editor has to write back, and in which order to build the terrain, painter, road, lightmap and new-level tools.

BF22142Heroes
How this page was checked

Every statement about a file cites the bf2-rs reader (crate, file, function) or the retail file it was checked against. The counts come from small read-only scripts over the retail installs (retail/battlefield2 1.50, retail/battlefield2142, retail/battlefieldheroes-v1126), kept in analysis/scratch/editor/h18/ (list at the end). Anything marked unverified is an inference, not a measurement. The level folder itself is explained in Level authoring; this page assumes it. The assets a level places (meshes with their lightmap UVs, textures, materials, sounds, object templates) are shown with real Heroes files on What goes into a game asset.

The three games at a glance#

BF2 1.502142Heroes 1.126
Levels checked30 (mods/bf2, mods/xpack)20 (mods/bf2142)26 (mods/bfheroes; 11 snow / night variants mount a base level's archives, 9 of them use its heightmaps)
Primary heightmap513² or 1025², 16 bit, 2 m513² or 1025², 16 bit, 2 m257², 513² (2 m) or 1025² (1 m, Lunar), 16 bit
Terrain patches4×4 or 8×8 of 1284×4 or 8×8 of 1282×2, 4×4 or 8×8 of 128
Colour / light map per patch512² DXT1512² DXT11024² DXT1 (village), although patchColormapSize says 512
SimpleShadowmap*.rawall 30all 20none
AI navigation.qtr / .clb in 24 levelsin 7 levelsnone (bf2-rs generates it, bf2-ai navgen.rs, Not retail)
Level-only scriptstmp.con (15), map.desc (14)Weather.con (14)InitLogic.con (26), GameModes/*/GameLogicSettings.con (43), Weather.con (20)
Variants11 <base>_snow / _night levels mount the base level's archives from their Init.con (fileManager.mountArchive Levels/<base>/server.zip; bf2-engine level.rs run_level_load_tail, BFHeroes.exe@bfh126!0x005128f9)

Every Init.con of all 76 levels starts with rem *** Generated by BF2Editor ***, and all 76 StaticObjects.con have CRLF line ends: all three games were built with the same DICE editor generation.

Format matrix#

Columns: reader is the bf2-rs function that parses the file today; writer is what exists in bf2-rs (the bf2-terrain writers landed with H2002, notes/editor/formats.md); layout is the short form, with the full layout below or in the note named. "All N" means every retail file of that kind in the three installs was checked.

Terrain#

FileReader in bf2-rsWriterLayoutPer game, verified against
Heightdata.conbf2-terrain heightdata.rs parse + applyheightdata.rs write, from_clusterheightmapcluster.* / heightmap.* lines (below)Same commands in all three; cluster 3×3, setHeightmapSize = (w-1)*scale.x in all 76
HeightmapPrimary.rawheightmap.rs Heightmap::load_height_data_inHeightmap::write_height_dataw*h little-endian u16, row = z, values above 0xff00 clamp on load76/76 the exact length; no sample above 0xff00 in any file
HeightmapSecondary_<dir>.raw (8)samesamew*h u8; BF2 / 2142 257², Heroes 129² at 4 m528 files; one with 130 extra bytes (BF2 Devils_Perch _R1)
HeightmapPrimary.matheightmap.rs load_material_dataHeightmap::write_material_data(w*ms)*(h*ms) u8 material ids, ms = 1 everywhere76/76; a missing file fills 0 (BF2) or 99 (2142 and Heroes, load_height_data_in)
Terrain.conterrain_con.rs parse(text, editor)noneeditor branch: terrain.* settings; game branch: terrain.load terraindata.rawAll three identical in shape; the compiled file wins in game (5 fields of 3 BF2 levels differ, notes/formats/terrain.md)
terraindata.rawterraindata.rs parseterraindata.rs writeversion 26 stream (below)76/76 version 26, flag 1, 24-byte vertices; every byte consumed; re-serialised byte-identical by a 1:1 port of parse
Colormaps/tx<XX>x<ZZ>.dds, tx_s<i>.ddsterrain_con.rs patch_suffix, patch_texture, surrounding_texture; drawn by bf2-render terrain/mod.rsnoneDXT1 with mips512² (BF2, 2142), 1024² (Heroes village); some patches have none (BF2 Wake_Island_2007 22 of 64)
Detailmaps/tx<XX>x<ZZ>_<i>.ddsterrain_con.rs detail_texturenone256² 16-bit or DXT1, no mips (BF2, 2142); 512² 16-bit (Heroes)Strike_at_Karkand, Camp_Gibraltar, village
LowDetailmaps/tx*.dds, lowdetailtexture[low].ddsterrain/mod.rs (Terrain::loadLowDetailTexture RendDX9.dll!0x100db760)none256² DXT1; 512² 16-bitHeroes adds lowdetailtexturelow.dds
Undergrowth.cfg, .datundergrowth.rs parse_cfg, parse_datnonetext; binary v2 (notes/formats/terrain.md)All three; Heroes adds UndergrowthAtlas0_medium.dds + _medium.tai
Undergrowth.rawbytemap.rs ByteMap::parse (primary w*h)ByteMap::writeu8 material per heightmap sample76/76 the size of the primary heightmap
Overgrowth/Overgrowth.con, .raw, OvergrowthShadowmap.rawovergrowth.rs parse; ByteMap::parseByteMap::write (the maps)text; two u8 maps of w*h (0 / 0xff fill)Missing in BF2 Operation_Blue_Pearl, 2142 Operation_Shingle, Heroes Lunar
Overgrowth/OvergrowthCollision.conconsole (Object.create, Object.isOvergrowth 1)noneper-patch rem Patch: x, z + object lines (writer RendDX9.dll!0x100cb230)Heroes village: 130 lines, all rem or empty
SimpleShadowmap.raw, SimpleShadowmapIO.rawbytemap.rs simple_shadowmap_side, shadow_level, io_bit; bf2-render shadows.rsByteMap::write(cell/2)² u8, rows bottom-upBF2 30 levels, 2142 20, Heroes 0; files longer than read: BF2 17, 2142 9
*.tai (atlas index)tai.rs parsenone<file>\t\t<atlas>, idx, u, v, w, h lines96 BF2 files in the crate tests; three sample levels here

Water, sky, lighting, environment#

FileReader in bf2-rsWriterLayoutPer game, verified against
Water.conbf2-client commands.rs (renderer.water*), bf2-render water.rs; terrain_con.rs (terrain.waterSunIntensity)noneconsole linesAll three; Heroes village adds waterAlphaHeightMul and waterAlphaAdd to BF2 Strike_at_Karkand's set
sea levelheightmap.rs HeightmapCluster::set_sea_water_level (heightmapcluster.setSeaWaterLevel in Heightdata.con)noneone float4 levels of 2142 set -10000 (no sea, unverified meaning)
Sky.conbf2-client commands.rs (lightManager, skyDome, renderer, terrain, hemiMapManager), bf2-render lightmanager.rs, sky.rs, skyflare.rsnoneconsole lines with an editor branch (LightSettings.*, LightmapSettings.*)All three
Weather.conconsole tables (rainManager.*: bf2-con table_2142.rs, bfh-data console_rend.rs)noneconsole linesBF2 1 level, 2142 14, Heroes 20; Heroes village runs it without shipping it
groundhemi.ddshemiMapManager.setBaseHemiMap in Sky.con (bf2-client commands.rs)none1024² DXT5 (BF2, 2142), 512² DXT1 (Heroes)sample levels
Envmaps/EnvironmentMapInfo.emi, Envmaps/*.dds, Water/EnvMap.ddsmisc.rs parse_envmap_info; bf2-render envmap.rsnonetext + cube DDSAll three
lightWarpBundle.dds, lightWarpSkinned.ddsnone found (unverified who loads them)none256×16 32-bitHeroes only (26 levels)

Objects and game play#

FileReader in bf2-rsWriterLayoutPer game, verified against
StaticObjects.conbf2-con script.rs parse + the console; run by bf2-engine level.rs run_level_load_tailnone (stage 2: H1985)Object.create, Object.absolutePosition, Object.rotation, Object.setLightSourceMask; CRLFA run /objects/... template list: BF2 30/30 (in the editor branch on Strike_at_Karkand), 2142 6/20, Heroes 0/26; in game the templates come from GameLogic::loadTemplates (level.rs Abortable::LoadTemplates("Objects/"))
object template consbf2-objects template registry via bf2-connoneObjectTemplate.* / GeometryTemplate.*Not level files: Objects*_server.zip
GameModes/<mode>/<size>/GamePlayObjects.conbf2-engine level.rs gameplay_objects_path, choose_level_size; bf2-world control_point.rs, spawner.rs, spawn_manager.rs; bf2-client hud_combat_area.rsnonelevel-local ObjectTemplate.create ControlPoint / SpawnPoint / ObjectSpawner, Object.create, combatArea.*BF2 170 files, 2142 104, Heroes 44; sizes 16/32/64/128 (2142 adds 48, LEVEL_SIZES_2142)
GameModes/<mode>/<size>/GameLogicSettings.conbfh-server game_logic.rs, console.rs, tickets.rsnonegameLogic.setOverrideTickets, setTimeLimit, ...Heroes only, run after GamePlayObjects.con (BFHeroes.exe@bfh126!0x00517168)
InitLogic.conconsole (gameLogic.*, renderer.*, windManager.*)noneconsole linesHeroes only, run from Init.con
AmbientObjects.conbf2-world ambient.rs (Trigger, AmbientEffectArea)nonetemplate + object linesAll three
Triggerables.conrun by level.rs on the host only; objects in bf2-world triggerable.rsnoneconsole linesBF2 6, 2142 6, Heroes 1
Sounds.conbf2-audio eax.rs (sound.setReverb, console_args.rs)noneone reverb lineBF2 16, 2142 14, Heroes 1
Init.conbf2-engine level.rs (Init.con run, BF2142.exe!0x004cd740)noneeditor and game branches; teams, kits, setBeforeSpawnCameraAll 76

Roads#

FileReader in bf2-rsWriterLayoutPer game, verified against
CompiledRoads.conconsole: object.create, object.geometry.loadMesh, object.absolutepositionnonethree lines per road pieceAll three
Roads/<n>_compiled.meshbf2-mesh road.rs RoadMesh::parse; drawn by bf2-render roads.rsnoneversion 1.4 (below)BF2 980, 2142 1118, Heroes 177: all version 1.4, all consumed exactly; the stored position equals the .con position in 2270 of 2275
Splines/<template>_compiled.dat (Objects archive, not the level)bf2-geomdata road_spline.rs RoadSplineData::parsenone2 texture lines, f32 blend, 2 f32, u32 prio (notes/formats/road-splines.md)BF2 86, 2142 133, Heroes 8: all exact; every road object names an existing template
road editor files (RoadTemplate.*, splines)none (editor only; no binary has a RoadTemplate object, bf2-con tests/retail_scripts.rs)noneeditor branch of the template .conNot shipped as levels data

Lightmaps#

FileReader in bf2-rsWriterLayoutPer game, verified against
Lightmaps/tx<XX>x<ZZ>.dds (terrain)terrain/mod.rs (lightmap_base_name + patch_suffix)noneone per patch, DXT1 with mips, the colour-map size512² (BF2, 2142), 1024² (Heroes village); variants without them mount the base level's
Lightmaps/Objects/LightmapAtlas<n>.ddsbf2-client scene.rs lightmapsnone2048² DXT1, 11 mipsBF2 Strike_at_Karkand 21 atlases, 2142 Camp_Gibraltar 10, Heroes village 12
Lightmaps/Objects/LightmapAtlas.taitai.rs parse; misc.rs static_mesh_lightmap_name, parse_object_lightmap_namenonename <geometry>=NN=x=y=z with NN = geometry × 10 + LOD and the truncated world position51,340 / 42,509 / 32,652 entries; all but 6 parse
lightmap samples (.samples)nonenoneeditor inputNot in any retail archive of the three games
FileReader in bf2-rsWriterLayoutPer game, verified against
Info/<level>.descbf2-launcher levels.rs parse_desc; bf2-audio music.rs; bfh-server roles.rsnoneXML: <name>, <briefing>, <music>, <modes>All three
Info/*menuMap*.png, loadmap.pngno bf2-rs reader (menu images)noneBF2: DDS files named .png; 2142: real PNG 478×341 + 300×300 previews; Heroes: nonesample levels
GameModes/*/menuMap{Large,Small}.png (client)no bf2-rs readernonePNG 240² and 450²BF2, 2142
Hud/Minimap/ingameMap.dds (+ commanderMap, commanderMicroMap)bf2-hud render/map_markers.rs (Levels/<level>/Hud/Minimap/ingameMap)none512² DXT1 (BF2), 512² 32-bit (Heroes)Heroes ships only ingameMap
archive.md5bf2-fs checksum.rs; bf2-client content_check.rsnone<level> <ordinal> <md5> ×10All three; a pure server kicks a client whose level archives hash differently (kick 27)
loadCounter.dat, map.desc, tmp.conmisc.rs parse_load_counter (no binary reads it); none; consolenoneu32; XML; empty in Strike_at_KarkandloadCounter.dat BF2 13, 2142 5; map.desc BF2 14, 2142 2; tmp.con BF2 15, 2142 2, Heroes 2

AI#

FileReader in bf2-rsWriterLayoutPer game, verified against
AIPathFinding/<map>.qtrbf2-ai qtr.rs QtrFile::parsequadtree.rs QuadTree::save, save_islandsversion 3 quadtree (notes/formats/ai-navigation.md)BF2 24 levels, 2142 7, Heroes none
AIPathFinding/<map>.clbclb.rs ClbFile::parseclb.rs ClusterGraph::saveversion 5 cluster graphsame
AIPathFinding/AerialHeighMap.ahmahm.rs AerialHeightMap::parsenone16 m grid of obstacle heightsBF2 23, 2142 7
GameModes/*/AI/StrategicAreas.ai, AI/AI.ai, Strategies.aibf2-ai strategic_area.rs, ai_console.rs; order in level.rsnoneconsole linesBF2 26 levels, 2142 6, Heroes none
GTSData/Output/*, GTSData/Meshes/*qti.rs, vbf.rs, gts.rs, gts_text.rsgts.rs (layout)offline tool in- and output; the game loads none of itBF2 23, 2142 9
generated nav (Heroes)navgen.rsnavgen.rs → save_islandsthe same .qtr / .clbNot retail

Layouts the editor writes#

Heightdata.con and the raw heightmaps#

Heightdata.con (Heroes village, shipped, abridged)
heightmapcluster.create HeighmapCluster
heightmapcluster.setClusterSize 3
heightmapcluster.setHeightmapSize 512
heightmapcluster.addHeightmap Heightmap 0 0
heightmap.setSize 257 257
heightmap.setScale 2/0.0025/2
heightmap.setBitResolution 16
heightmap.setModified 1
heightmap.loadHeightData Levels/Village/HeightmapPrimary.raw
heightmap.setMaterialScale 1
heightmap.loadMaterialData Levels/Village/HeightmapPrimary.mat
heightmapcluster.addHeightmap Heightmap -1 -1
heightmap.setSize 129 129
heightmap.setScale 4/0.64/4
heightmap.setBitResolution 8
heightmap.loadHeightData Levels/Village/HeightmapSecondary_L1U1.raw
heightmapcluster.setSeaWaterLevel 12
  • The primary map is cell (0, 0); the eight secondaries surround it (L1U1, U1, R1U1, L1, R1, L1D1, D1, R1D1) at twice the spacing and 8 bit. setHeightmapSize is the world size of one cell, (w - 1) * scale.x.
  • Heights in metres are raw * scale.y; sampling is Heightmap::height_local (heightmap.rs, exact x87 port).
  • The retail writer of this file is bf2_w32ded.exe!0x006ae690 (notes/formats/terrain.md).

terraindata.raw#

The compiled render terrain (Terrain::load RendDX9.dll!0x100de6d0, written by TerrainEditable::compile RendDX9.dll!0x1010cd70; the field table is in notes/formats/terrain.md). In order: header (version 26, flag 1, world scales, the uninitialised 0xcdcdcdcd at +0x2c, min/max height, patch size 128, patches per side), the four texture base names as \n-terminated lines, far tiling, two colours, the water colour, the detail texture list, an 85-node LOD index tree, one shared index buffer, then per patch its bounds and 129² 24-byte vertices plus the per-detail-layer index blocks, then the surrounding (far) patches, then a 1365-node cull tree.

The 24-byte vertex (declaration RendDX9.dll!0x10219a58, bf2-render terrain/mod.rs). The version-26 writer is RendDX9.dll@bfh126!0x1015cda3, called per patch by TerrainEditable::saveTerrainData (RendDX9.dll@bfh126!0x10161947); BF2 1.50's own saveTerrainData (RendDX9.dll!0x1010cd70) still writes the pre-24 layout under a version-26 header, but its helpers compute the same values. bf2-terrain compile.rs (compile_patch) rebuilds every byte of every vertex of village (66,564 vertices), Strike_at_Karkand (266,256) and Camp_Gibraltar (1,065,024) from the level's heightmaps (tests/retail_compile.rs; the Python probe analysis/scratch/editor/h2/vertex_rebuild.py gives the same 100 % per field).

H(x, z) below is HeightmapCluster::getHeight at the vertex's world position, left in the x87 register: the primary map, and the secondary maps for the primary's last row and column and for the ring one sample outside it (the normals read it). The low bits depend on the editor's x87 precision: the BF2 levels were compiled at PC53 (the Windows default), the 2142 and Heroes levels at PC24 (Direct3D's default), compile::editor_precision.

BytesContentRule (exact on all three levels)
0selectoron a column x % 32 == 0 the row's z & 3, else on a row z % 32 == 0 the column's x & 3, else 0; 3 becomes 1. 32 is (int)(Terrain+0x88c / primaryWorldScale.x) (0x1015cda3). It indexes the shader's MORPHDELTAADDER
1..3z, x, 0patch-local row and column, then 0
4..7f32 height in raw units(float)(H * (float)(1 / scaleY)), a multiply by the reciprocal (QuadPatchEditable height fill RendDX9.dll!0x1019e410). So about a third of the village heights sit one float step below the integer sample (3507.9998 for 3508). The shipped files were not compiled from an older heightmap: every height follows today's HeightmapPrimary.raw and secondaries. Heroes 1.126's fill RendDX9.dll@bfh126!0x101f14ec divides instead, which would not reproduce its own levels
8..11, 12..15f32 morph delta, LOD 0 and 1RendDX9.dll!0x10109390 (RendDX9.dll@bfh126!0x1015c19e computes levels 0 and 1 only). With step = 2 << level, half = step / 2: at x % step == half, z % step == 0 the neighbours (x ± half, z); at x % step == half, z % step == half the diagonal (x + half, z - half), (x - half, z + half); at x % step == 0, z % step == half the neighbours (x, z ± half); every other vertex 0. mid = (float)((float)(((float)H(a) + H(b)) * (float)(1 / scaleY)) * 0.5), delta = (float)(H(x, z) / scaleY - mid), and 0 when mid == 0. The research's 42 % came from testing every vertex and the wrong heights
16..19f32 morph delta, LOD 20.0 (the array is zeroed and level 2 is never computed)
20..23normalPer cell (RendDX9.dll@bfh126!0x101e5c6f, BF2 RendDX9.dll!0x10188860): e1 = norm(step, H(x+1, z) - (float)H(x, z), 0), e2 = norm(0, H(x, z+1) - (float)H(x, z), step), face = norm(e2 × e1). Per vertex: norm((F(x-1, z) + F(x, z) + F(x, z-1) + F(x, z)) * 0.25), every += stored as float. Retail counts the face at (x, z) twice and never reads (x-1, z-1). norm is Vec3::normalize (0x100c8632: unchanged when the squared length is within FLT_EPSILON of 1, sqrt and its reciprocal stored as float). Packed (RendDX9.dll@bfh126!0x1007870f) as bytes [z, y, x, 0xff], each 0x7f - trunc(-127 * n)

Patch layers (one index block per detail layer the patch uses) decide which triangles each detail texture draws; a painter that changes detail coverage must rebuild them. The surrounding patches come from the secondary heightmaps (village writes none although it ships eight secondaries).

Road meshes#

Roads/<n>_compiled.mesh (RoadCompiled::load RendDX9.dll!0x1015b860, notes/formats/meshes.md): u16 minor 4, u16 major 1, vec3 position (= object.absoluteposition), f32 radius, vec3 bbox min / max, u32, u32 vertex count, 32-byte vertices (position relative to the road, uv0, uv1, f32 alpha), u32 index count, u16 indices, u32 chunk count

  • 24-byte chunks (index start, count, radius, centre). All 2275 retail meshes carry the chunk table.

Object lightmap names#

StaticMesh::initLightmaps (RendDX9.dll!0x100fc630, bf2-client scene.rs lightmaps) looks a static instance's lightmap up as <geometry>=NN=x=y=z with NN = geometry × 10 + LOD and x, y, z its world position truncated to integers (misc.rs object_lightmap_name). 58.7 % (BF2), 71.3 % (2142) and 64.9 % (Heroes) of the StaticObjects.con instances have an atlas entry at exactly their truncated position. Consequence for the editor: moving a static object across a metre boundary loses its baked lightmap (the lookup finds no entry; how the object then looks is unverified).

What the 2005 editor wrote, and what we can skip#

The BF2Editor wrote both the game files and its own editor-only files; the retail binaries still contain the writers (cited above). The game branch of each Init.con lists exactly what the game loads; everything else is editor state.

Editor wroteWe need it?Why
Heightdata.con, HeightmapPrimary.raw, .mat, secondariesYesphysics, server and client read them
Terrain.con editor branchWrite it, never read it in gamethe game reads terraindata.raw; keep the branch so the file stays a valid editor file
terraindata.rawYesthe client cannot draw the terrain without it
colour / detail / low-detail / light maps per patchYes (painter, lightmaps)client textures
Undergrowth.*, Overgrowth/*, SimpleShadowmap*.rawYes, regenerated after a sculptthey are sampled per heightmap texel
CompiledRoads.con + _compiled.meshYesthe game never sees the splines, only the meshes
road splines, RoadTemplate.*, Editor/StaticObjects.con, Editor/GamePlayObjects.con (run by the editor branch of Init.con)Skip, keep our own editor state in the overlaynone ships in any retail archive (0 files in 76 levels); the game branch never reads them
LevelSettings.*, LightSettings.*, LightmapSettings.* linesWrite them back unchangededitor branch only; harmless in game
GTSData/Meshes/*.gts, config.dat, CombatArea.dat, GTSData/Output/*Skipoffline navigation tool in- and output; the game loads only .qtr / .clb / .ahm (bf2-rs generates those with navgen.rs)
loadCounter.dat, map.desc, tmp.con, BaseDetailLayers.tga (2142 Camp_Gibraltar, 50 MB)Skipno bf2-rs reader; loadCounter.dat has no reader in any binary (notes/formats/terrain.md); the other two unverified
archive.md5Regenerate for a modded level or turn the pure check offbf2-fs checksum.rs: a changed archive fails the content check on a pure server

Stage 3: order and the hard problems#

Recommended order (each step usable on its own, each step's Check on Heroes village first):

  1. Writers first, no UI (part of H1988): heightmap raw / .mat writer, Heightdata.con writer, terraindata::write (the inverse of parse, byte-identical), byte-map writers. Pure Rust in bf2-terrain, proven by round-trip tests over all 76 levels.
  2. Sculpt (H1988): brush on the in-memory HeightmapCluster; the viewport redraws the touched patches; save writes the raw file and a recompiled terraindata.raw.
  3. Painter (H1989): colour maps first (DXT1 encode of one patch), then detail-layer coverage, then undergrowth / overgrowth byte maps.
  4. Roads + water (H1990): sea level and water settings are console lines (easy); roads need spline → mesh generation.
  5. Lightmaps (H1991): research plus a first bake; until it lands, edited levels keep the shipped lightmaps.
  6. New level wizard (H1992): last, because it is all of the above writing from scratch plus Init.con, .desc, a game mode folder and archive.md5.

The hard problems and what I recommend:

  • Terrain recompile after a sculpt (LOD, normals, bounds). The shipped terraindata.raw is a valid oracle: its vertices follow the shipped heightmaps byte for byte (bf2-terrain compile.rs, above). Recommendation: compile per patch (only patches a brush touched; a 129² patch is small) with compile::compile_patch, plus the patch bounds and the cull-tree boxes. A brush that touches a patch edge also changes the normals one sample into the neighbouring patch, so recompile those neighbours too. Untouched patches are copied byte for byte.
  • Undergrowth, overgrowth and water after a sculpt. Undergrowth and overgrowth take their ground height from the heightmap cluster when the level loads (bf2-render undergrowth.rs; bf2-client scene.rs passes HeightmapCluster::height to the overgrowth), so they follow the new ground without a rewrite; OvergrowthCollision.con holds fixed positions and must be regenerated from Overgrowth.raw (writer RendDX9.dll!0x100cb230, port it). SimpleShadowmap*.raw is derived data: rebuild it (BF2 / 2142 only). Water is a flat sea level plus console settings: nothing to regenerate, but warn when a sculpt goes below the sea level.
  • Road meshes. No spline data ships, so the editor owns the spline: a road is a polyline the user draws, draped on the heightmap, with the template's width and uv tiling; the mesh writer emits version 1.4 with the chunk table (the reader requires nothing more). Re-drape on save after a sculpt. Existing retail roads stay as meshes and can only be moved or deleted, not re-shaped.
  • Lightmap bake. The biggest unknown: the meaning of the terrain lightmap channels and the bake parameters (LightmapSettings.*) are unverified. Recommendation: H1991 first answers what each channel holds from the terrain shader (Shaders/TerrainShader, bf2-render terrain/mod.rs); the first editor bake is terrain-only (sun shadow from the heightmap plus sky occlusion) for edited patches, DXT1-encoded, Not retail. For moved static objects, rename their atlas entry to the new truncated position (one .tai edit) so they keep a lightmap.
  • The single-threaded page. The wasm engine runs on the page's main thread (no threads without cross-origin isolation, which the box does not promise: unverified). Keep every edit O(touched patches) and run bakes and full recompiles in a Web Worker with its own engine instance, sending back finished files for the overlay (OPFS). Never block a frame for more than one patch's work.

Round-trip contract#

The editor brief requires writers that round-trip the retail files. Which ones must be byte-identical:

WriterByte-identical?How the test proves it
HeightmapPrimary.raw, secondaries, .matYesdone (H2002): read → write → compare, 684/684 raw and 76/76 .mat byte-identical (bf2-terrain tests/retail_writers.rs; extra tail bytes kept with write::with_tail)
terraindata.rawYes (structural)done (H2002): parse → write → bytes equal, 76/76
byte maps (Undergrowth.raw, Overgrowth*.raw, SimpleShadowmap*.raw)Yesdone (H2002): 321/321 byte-identical, extra bytes kept
Heightdata.conYesdone (H2002): 76/76 byte-identical from the parsed commands and from the loaded cluster (heightdata::write, from_cluster)
Terrain.con, Water.con, Sky.con, CompiledRoads.con, StaticObjects.con, GamePlayObjects.conToken-identical, byte-identical when uneditedread → write → read gives the same token stream (the brief's rule); an unedited file is written back from its original bytes (CRLF everywhere)
_compiled.mesh, _compiled.datYesparse → write → bytes equal for all 2275 meshes and 227 templates
.taiYesparse → write equal for every atlas index
.qtr / .clbYessave_islands(parse(...)) equal to the retail file (today only a synthetic round trip, quadtree.rs save_round_trips_through_the_reader)
patch vertices of a recompiled terraindata.rawYescompile::compile_patch over every patch equals the shipped vertices (tests/retail_compile.rs: village, Strike_at_Karkand, Camp_Gibraltar)
other compiled output (patch bounds and layers, cull tree, a baked lightmap, a generated road mesh)Nosemantic tests: bounds contain every vertex, the level renders in the render harness, and an untouched patch is byte-identical to the shipped one

Open questions#

  • Whether every retail level used its game's x87 precision (PC53 for BF2, PC24 for 2142 and Heroes): measured on one level per game.
  • Meaning of the terrain lightmap channels and of the LightmapSettings.* bake settings.
  • Why Heroes village stores patchColormapSize 512 with 1024² colour maps (which one the renderer trusts).
  • How a static mesh without a lightmap entry is lit.
  • Whether the box can serve the editor cross-origin isolated (wasm threads).

Reproduce#

Read-only scripts (Python 3.12, PYTHONUTF8=1), in analysis/scratch/editor/h18/:

commands
python list_levels.py        # every file of Strike_at_Karkand / Camp_Gibraltar / village, grouped
python terrain_verify.py     # all 76 levels: heightmaps, .mat, Terrain.con, terraindata.raw parse + re-serialise, byte maps
python vertex_probe.py heroes village; python morph_probe2.py bf2 Strike_at_Karkand   # vertex heights, morph deltas, normals
python roads_verify.py       # all road meshes and spline templates
python lightmap_names.py     # atlas names vs StaticObjects.con positions
python dds_formats.py        # texture formats per kind; presence.py: which files each game ships

The vertex rules come from analysis/scratch/editor/h2/ (H2003):

commands
python vertex_rebuild.py     # every vertex of village, Strike_at_Karkand, Camp_Gibraltar: exact matches per field
cargo test -p bf2-terrain --test retail_compile -- --nocapture   # the same through bf2-terrain compile.rs

How it is tested#

This page is a plan with citations. A row marked done names its task, and the task's test program stands under crates/bf2-editor/tests; few of the page's addresses stand in a test's own text. The size limits it derives are held against every shipped level (terrain). A row not marked done has no test.

In the code#

The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):

CrateWhat it is
crates/bf2-renderthe wgpu renderer
crates/bf2-clientthe client's engine assembly as a library: boot, console, profiles, movies, join, level load, frame loop
crates/bf2-terrainterrain and level data formats
crates/bf2-conthe console script language: lexer, interpreter, command registry
crates/bf2-aibot AI: navigation data formats and pathfinding
crates/bf2-engineengine assembly shared by the programs: command line, start-up and level-load order, main loop timing, localization, settings
crates/bf2-worldthe runtime object world: objects from templates, object manager, hierarchy, tick order
crates/bf2-audiothe sound system: decoders, sound templates, mixing rules
Source: docs/dev/levels/editor-plan.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.