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.
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.50 | 2142 | Heroes 1.126 | |
|---|---|---|---|
| Levels checked | 30 (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 heightmap | 513² or 1025², 16 bit, 2 m | 513² or 1025², 16 bit, 2 m | 257², 513² (2 m) or 1025² (1 m, Lunar), 16 bit |
| Terrain patches | 4×4 or 8×8 of 128 | 4×4 or 8×8 of 128 | 2×2, 4×4 or 8×8 of 128 |
| Colour / light map per patch | 512² DXT1 | 512² DXT1 | 1024² DXT1 (village), although patchColormapSize says 512 |
SimpleShadowmap*.raw | all 30 | all 20 | none |
| AI navigation | .qtr / .clb in 24 levels | in 7 levels | none (bf2-rs generates it, bf2-ai navgen.rs, Not retail) |
| Level-only scripts | tmp.con (15), map.desc (14) | Weather.con (14) | InitLogic.con (26), GameModes/*/GameLogicSettings.con (43), Weather.con (20) |
| Variants | 11 <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#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
Heightdata.con | bf2-terrain heightdata.rs parse + apply | heightdata.rs write, from_cluster | heightmapcluster.* / heightmap.* lines (below) | Same commands in all three; cluster 3×3, setHeightmapSize = (w-1)*scale.x in all 76 |
HeightmapPrimary.raw | heightmap.rs Heightmap::load_height_data_in | Heightmap::write_height_data | w*h little-endian u16, row = z, values above 0xff00 clamp on load | 76/76 the exact length; no sample above 0xff00 in any file |
HeightmapSecondary_<dir>.raw (8) | same | same | w*h u8; BF2 / 2142 257², Heroes 129² at 4 m | 528 files; one with 130 extra bytes (BF2 Devils_Perch _R1) |
HeightmapPrimary.mat | heightmap.rs load_material_data | Heightmap::write_material_data | (w*ms)*(h*ms) u8 material ids, ms = 1 everywhere | 76/76; a missing file fills 0 (BF2) or 99 (2142 and Heroes, load_height_data_in) |
Terrain.con | terrain_con.rs parse(text, editor) | none | editor branch: terrain.* settings; game branch: terrain.load terraindata.raw | All three identical in shape; the compiled file wins in game (5 fields of 3 BF2 levels differ, notes/formats/terrain.md) |
terraindata.raw | terraindata.rs parse | terraindata.rs write | version 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>.dds | terrain_con.rs patch_suffix, patch_texture, surrounding_texture; drawn by bf2-render terrain/mod.rs | none | DXT1 with mips | 512² (BF2, 2142), 1024² (Heroes village); some patches have none (BF2 Wake_Island_2007 22 of 64) |
Detailmaps/tx<XX>x<ZZ>_<i>.dds | terrain_con.rs detail_texture | none | 256² 16-bit or DXT1, no mips (BF2, 2142); 512² 16-bit (Heroes) | Strike_at_Karkand, Camp_Gibraltar, village |
LowDetailmaps/tx*.dds, lowdetailtexture[low].dds | terrain/mod.rs (Terrain::loadLowDetailTexture RendDX9.dll!0x100db760) | none | 256² DXT1; 512² 16-bit | Heroes adds lowdetailtexturelow.dds |
Undergrowth.cfg, .dat | undergrowth.rs parse_cfg, parse_dat | none | text; binary v2 (notes/formats/terrain.md) | All three; Heroes adds UndergrowthAtlas0_medium.dds + _medium.tai |
Undergrowth.raw | bytemap.rs ByteMap::parse (primary w*h) | ByteMap::write | u8 material per heightmap sample | 76/76 the size of the primary heightmap |
Overgrowth/Overgrowth.con, .raw, OvergrowthShadowmap.raw | overgrowth.rs parse; ByteMap::parse | ByteMap::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.con | console (Object.create, Object.isOvergrowth 1) | none | per-patch rem Patch: x, z + object lines (writer RendDX9.dll!0x100cb230) | Heroes village: 130 lines, all rem or empty |
SimpleShadowmap.raw, SimpleShadowmapIO.raw | bytemap.rs simple_shadowmap_side, shadow_level, io_bit; bf2-render shadows.rs | ByteMap::write | (cell/2)² u8, rows bottom-up | BF2 30 levels, 2142 20, Heroes 0; files longer than read: BF2 17, 2142 9 |
*.tai (atlas index) | tai.rs parse | none | <file>\t\t<atlas>, idx, u, v, w, h lines | 96 BF2 files in the crate tests; three sample levels here |
Water, sky, lighting, environment#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
Water.con | bf2-client commands.rs (renderer.water*), bf2-render water.rs; terrain_con.rs (terrain.waterSunIntensity) | none | console lines | All three; Heroes village adds waterAlphaHeightMul and waterAlphaAdd to BF2 Strike_at_Karkand's set |
| sea level | heightmap.rs HeightmapCluster::set_sea_water_level (heightmapcluster.setSeaWaterLevel in Heightdata.con) | none | one float | 4 levels of 2142 set -10000 (no sea, unverified meaning) |
Sky.con | bf2-client commands.rs (lightManager, skyDome, renderer, terrain, hemiMapManager), bf2-render lightmanager.rs, sky.rs, skyflare.rs | none | console lines with an editor branch (LightSettings.*, LightmapSettings.*) | All three |
Weather.con | console tables (rainManager.*: bf2-con table_2142.rs, bfh-data console_rend.rs) | none | console lines | BF2 1 level, 2142 14, Heroes 20; Heroes village runs it without shipping it |
groundhemi.dds | hemiMapManager.setBaseHemiMap in Sky.con (bf2-client commands.rs) | none | 1024² DXT5 (BF2, 2142), 512² DXT1 (Heroes) | sample levels |
Envmaps/EnvironmentMapInfo.emi, Envmaps/*.dds, Water/EnvMap.dds | misc.rs parse_envmap_info; bf2-render envmap.rs | none | text + cube DDS | All three |
lightWarpBundle.dds, lightWarpSkinned.dds | none found (unverified who loads them) | none | 256×16 32-bit | Heroes only (26 levels) |
Objects and game play#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
StaticObjects.con | bf2-con script.rs parse + the console; run by bf2-engine level.rs run_level_load_tail | none (stage 2: H1985) | Object.create, Object.absolutePosition, Object.rotation, Object.setLightSourceMask; CRLF | A 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 cons | bf2-objects template registry via bf2-con | none | ObjectTemplate.* / GeometryTemplate.* | Not level files: Objects*_server.zip |
GameModes/<mode>/<size>/GamePlayObjects.con | bf2-engine level.rs gameplay_objects_path, choose_level_size; bf2-world control_point.rs, spawner.rs, spawn_manager.rs; bf2-client hud_combat_area.rs | none | level-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.con | bfh-server game_logic.rs, console.rs, tickets.rs | none | gameLogic.setOverrideTickets, setTimeLimit, ... | Heroes only, run after GamePlayObjects.con (BFHeroes.exe@bfh126!0x00517168) |
InitLogic.con | console (gameLogic.*, renderer.*, windManager.*) | none | console lines | Heroes only, run from Init.con |
AmbientObjects.con | bf2-world ambient.rs (Trigger, AmbientEffectArea) | none | template + object lines | All three |
Triggerables.con | run by level.rs on the host only; objects in bf2-world triggerable.rs | none | console lines | BF2 6, 2142 6, Heroes 1 |
Sounds.con | bf2-audio eax.rs (sound.setReverb, console_args.rs) | none | one reverb line | BF2 16, 2142 14, Heroes 1 |
Init.con | bf2-engine level.rs (Init.con run, BF2142.exe!0x004cd740) | none | editor and game branches; teams, kits, setBeforeSpawnCamera | All 76 |
Roads#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
CompiledRoads.con | console: object.create, object.geometry.loadMesh, object.absoluteposition | none | three lines per road piece | All three |
Roads/<n>_compiled.mesh | bf2-mesh road.rs RoadMesh::parse; drawn by bf2-render roads.rs | none | version 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::parse | none | 2 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) | none | editor branch of the template .con | Not shipped as levels data |
Lightmaps#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
Lightmaps/tx<XX>x<ZZ>.dds (terrain) | terrain/mod.rs (lightmap_base_name + patch_suffix) | none | one per patch, DXT1 with mips, the colour-map size | 512² (BF2, 2142), 1024² (Heroes village); variants without them mount the base level's |
Lightmaps/Objects/LightmapAtlas<n>.dds | bf2-client scene.rs lightmaps | none | 2048² DXT1, 11 mips | BF2 Strike_at_Karkand 21 atlases, 2142 Camp_Gibraltar 10, Heroes village 12 |
Lightmaps/Objects/LightmapAtlas.tai | tai.rs parse; misc.rs static_mesh_lightmap_name, parse_object_lightmap_name | none | name <geometry>=NN=x=y=z with NN = geometry × 10 + LOD and the truncated world position | 51,340 / 42,509 / 32,652 entries; all but 6 parse |
lightmap samples (.samples) | none | none | editor input | Not in any retail archive of the three games |
Menus, minimap, server-side#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
Info/<level>.desc | bf2-launcher levels.rs parse_desc; bf2-audio music.rs; bfh-server roles.rs | none | XML: <name>, <briefing>, <music>, <modes> | All three |
Info/*menuMap*.png, loadmap.png | no bf2-rs reader (menu images) | none | BF2: DDS files named .png; 2142: real PNG 478×341 + 300×300 previews; Heroes: none | sample levels |
GameModes/*/menuMap{Large,Small}.png (client) | no bf2-rs reader | none | PNG 240² and 450² | BF2, 2142 |
Hud/Minimap/ingameMap.dds (+ commanderMap, commanderMicroMap) | bf2-hud render/map_markers.rs (Levels/<level>/Hud/Minimap/ingameMap) | none | 512² DXT1 (BF2), 512² 32-bit (Heroes) | Heroes ships only ingameMap |
archive.md5 | bf2-fs checksum.rs; bf2-client content_check.rs | none | <level> <ordinal> <md5> ×10 | All three; a pure server kicks a client whose level archives hash differently (kick 27) |
loadCounter.dat, map.desc, tmp.con | misc.rs parse_load_counter (no binary reads it); none; console | none | u32; XML; empty in Strike_at_Karkand | loadCounter.dat BF2 13, 2142 5; map.desc BF2 14, 2142 2; tmp.con BF2 15, 2142 2, Heroes 2 |
AI#
| File | Reader in bf2-rs | Writer | Layout | Per game, verified against |
|---|---|---|---|---|
AIPathFinding/<map>.qtr | bf2-ai qtr.rs QtrFile::parse | quadtree.rs QuadTree::save, save_islands | version 3 quadtree (notes/formats/ai-navigation.md) | BF2 24 levels, 2142 7, Heroes none |
AIPathFinding/<map>.clb | clb.rs ClbFile::parse | clb.rs ClusterGraph::save | version 5 cluster graph | same |
AIPathFinding/AerialHeighMap.ahm | ahm.rs AerialHeightMap::parse | none | 16 m grid of obstacle heights | BF2 23, 2142 7 |
GameModes/*/AI/StrategicAreas.ai, AI/AI.ai, Strategies.ai | bf2-ai strategic_area.rs, ai_console.rs; order in level.rs | none | console lines | BF2 26 levels, 2142 6, Heroes none |
GTSData/Output/*, GTSData/Meshes/* | qti.rs, vbf.rs, gts.rs, gts_text.rs | gts.rs (layout) | offline tool in- and output; the game loads none of it | BF2 23, 2142 9 |
| generated nav (Heroes) | navgen.rs | navgen.rs → save_islands | the same .qtr / .clb | Not retail |
Layouts the editor writes#
Heightdata.con and the raw heightmaps#
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.setHeightmapSizeis the world size of one cell,(w - 1) * scale.x. - Heights in metres are
raw * scale.y; sampling isHeightmap::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.
| Bytes | Content | Rule (exact on all three levels) |
|---|---|---|
| 0 | selector | on 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..3 | z, x, 0 | patch-local row and column, then 0 |
| 4..7 | f32 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..15 | f32 morph delta, LOD 0 and 1 | RendDX9.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..19 | f32 morph delta, LOD 2 | 0.0 (the array is zeroed and level 2 is never computed) |
| 20..23 | normal | Per 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 wrote | We need it? | Why |
|---|---|---|
Heightdata.con, HeightmapPrimary.raw, .mat, secondaries | Yes | physics, server and client read them |
Terrain.con editor branch | Write it, never read it in game | the game reads terraindata.raw; keep the branch so the file stays a valid editor file |
terraindata.raw | Yes | the client cannot draw the terrain without it |
| colour / detail / low-detail / light maps per patch | Yes (painter, lightmaps) | client textures |
Undergrowth.*, Overgrowth/*, SimpleShadowmap*.raw | Yes, regenerated after a sculpt | they are sampled per heightmap texel |
CompiledRoads.con + _compiled.mesh | Yes | the 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 overlay | none ships in any retail archive (0 files in 76 levels); the game branch never reads them |
LevelSettings.*, LightSettings.*, LightmapSettings.* lines | Write them back unchanged | editor branch only; harmless in game |
GTSData/Meshes/*.gts, config.dat, CombatArea.dat, GTSData/Output/* | Skip | offline 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) | Skip | no bf2-rs reader; loadCounter.dat has no reader in any binary (notes/formats/terrain.md); the other two unverified |
archive.md5 | Regenerate for a modded level or turn the pure check off | bf2-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):
- Writers first, no UI (part of H1988):
heightmapraw /.matwriter,Heightdata.conwriter,terraindata::write(the inverse ofparse, byte-identical), byte-map writers. Pure Rust inbf2-terrain, proven by round-trip tests over all 76 levels. - Sculpt (H1988): brush on the in-memory
HeightmapCluster; the viewport redraws the touched patches; save writes the raw file and a recompiledterraindata.raw. - Painter (H1989): colour maps first (DXT1 encode of one patch), then detail-layer coverage, then undergrowth / overgrowth byte maps.
- Roads + water (H1990): sea level and water settings are console lines (easy); roads need spline → mesh generation.
- Lightmaps (H1991): research plus a first bake; until it lands, edited levels keep the shipped lightmaps.
- New level wizard (H1992): last, because it is all of the above writing from scratch plus
Init.con,.desc, a game mode folder andarchive.md5.
The hard problems and what I recommend:
- Terrain recompile after a sculpt (LOD, normals, bounds). The shipped
terraindata.rawis a valid oracle: its vertices follow the shipped heightmaps byte for byte (bf2-terraincompile.rs, above). Recommendation: compile per patch (only patches a brush touched; a 129² patch is small) withcompile::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-renderundergrowth.rs;bf2-clientscene.rspassesHeightmapCluster::heightto the overgrowth), so they follow the new ground without a rewrite;OvergrowthCollision.conholds fixed positions and must be regenerated fromOvergrowth.raw(writerRendDX9.dll!0x100cb230, port it).SimpleShadowmap*.rawis 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-renderterrain/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.taiedit) 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:
| Writer | Byte-identical? | How the test proves it |
|---|---|---|
HeightmapPrimary.raw, secondaries, .mat | Yes | done (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.raw | Yes (structural) | done (H2002): parse → write → bytes equal, 76/76 |
byte maps (Undergrowth.raw, Overgrowth*.raw, SimpleShadowmap*.raw) | Yes | done (H2002): 321/321 byte-identical, extra bytes kept |
Heightdata.con | Yes | done (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.con | Token-identical, byte-identical when unedited | read → 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.dat | Yes | parse → write → bytes equal for all 2275 meshes and 227 templates |
.tai | Yes | parse → write equal for every atlas index |
.qtr / .clb | Yes | save_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.raw | Yes | compile::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) | No | semantic 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
villagestorespatchColormapSize 512with 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/:
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 shipsThe vertex rules come from analysis/scratch/editor/h2/ (H2003):
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.rsHow 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):
| Crate | What it is |
|---|---|
crates/bf2-render | the wgpu renderer |
crates/bf2-client | the client's engine assembly as a library: boot, console, profiles, movies, join, level load, frame loop |
crates/bf2-terrain | terrain and level data formats |
crates/bf2-con | the console script language: lexer, interpreter, command registry |
crates/bf2-ai | bot AI: navigation data formats and pathfinding |
crates/bf2-engine | engine assembly shared by the programs: command line, start-up and level-load order, main loop timing, localization, settings |
crates/bf2-world | the runtime object world: objects from templates, object manager, hierarchy, tick order |
crates/bf2-audio | the sound system: decoders, sound templates, mixing rules |
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.