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

What goes into a mesh

A render mesh is one binary file per object: a vertex buffer, an index buffer and a tree of geometries, LODs and materials that slice them into draw batches. Which of the three kinds a file is decides how the engine moves it: not at all, in rigid parts, or by bones.

BF22142Heroes

The three kinds#

KindFileMoves byUsed forNode record per LOD
static.staticmeshnever movesbuildings, props, walls, treesnode matrices (skipped by the loader)
bundled.bundledmeshrigid parts, each with its own matrixvehicles, weapons, flags' poles, particlespart count; BLENDINDICES byte 0 of a vertex = its part
skinned.skinnedmeshskeleton bones, two bones per vertexsoldiers, hero items, animated flagsrigs: per material the bone ids and inverse bind matrices

All three are read by bf2-mesh template.rs MeshFile::parse, which mirrors the RendDX9.dll readers line by line: the header (MeshTemplate::readHeader), the vertex declaration (D3D9 D3DVERTEXELEMENT9 entries), the vertex and 16-bit index arrays, then per geometry and LOD the bounds, the kind's node record and the materials (Material: alpha mode, effect file, technique, texture maps, vertex and index ranges). A geometry is a variant of the whole object (a vehicle's first-person, third-person and wreck), a LOD a cheaper copy for distance, a material one draw call.

bf2-mesh examples/mesh_json.rs on the three examples (vertex declaration: usage, index)
Static  v11: POSITION 0, NORMAL 0, BLENDINDICES 0, TEXCOORD 0, TEXCOORD 1, TANGENT 0
Bundled v10: POSITION 0, NORMAL 0, BLENDINDICES 0, TEXCOORD 0, TANGENT 0
Skinned v11: POSITION 0, NORMAL 0, BLENDWEIGHT 0, BLENDINDICES 0, TEXCOORD 0, TANGENT 0

Static: the village house#

townhousemedium_e_03 stands nine times in Heroes' village. Its CON pairs the render mesh and the collision mesh under one name, and its tweak sets the LOD distances:

Objects/StaticObjects_server.zip buildings/townhousemedium_e_03/*.con, *.tweak (retail)
GeometryTemplate.create StaticMesh townhousemedium_e_03
CollisionManager.createTemplate townhousemedium_e_03
ObjectTemplate.create SimpleObject townhousemedium_e_03
ObjectTemplate.collisionMesh townhousemedium_e_03
ObjectTemplate.geometry townhousemedium_e_03
GeometryTemplate.setSubGeometryLodDistance 0 0 15
GeometryTemplate.setSubGeometryLodDistance 0 1 30
GeometryTemplate.setSubGeometryLodDistance 0 2 70
The house's four LODs: 2449, 1497, 827 and 328 triangles. The renderer switches at the distances above (bf2-render objlod.rs: entry j of setSubGeometryLodDistance, scaled by the geometry quality option).
The house's four LODs: 2449, 1497, 827 and 328 triangles. The renderer switches at the distances above (bf2-render objlod.rs: entry j of setSubGeometryLodDistance, scaled by the geometry quality option).

LOD selection (bf2-render objlod.rs): the distance to the object minus its radius is compared with the switch distances times the quality option (0.5 / 0.8 / 1.0) and renderer.globalStaticMeshLodDistanceScale; distances the tweak does not set default to steps of 25 m (bundled: 50 m).

LOD 0 as wireframe and per material batch (one material here), the separate .collisionmesh with its collision types, and the lightmap UV set: every triangle its own place in the lightmap, no overlaps.
LOD 0 as wireframe and per material batch (one material here), the separate .collisionmesh with its collision types, and the lightmap UV set: every triangle its own place in the lightmap, no overlaps.
  • Collision mesh. A second file, meshes/<name>.collisionmesh, read by bf2-collision CollisionMesh::parse: geometries, sub-geometries and LODs again, but each LOD is a collision type (0-2 projectile / vehicle / soldier by community naming, 3 the AI navigation mesh), with per-face materials that ObjectTemplate.mapMaterial maps to the game's material ids, and an optional BSP for fast ray tests. The house has two: type 0 with 1551 faces and a coarse type 1.
  • Lightmap UVs. Static meshes carry one more TEXCOORD set than their textures need; the last set places the triangle in the level's lightmap atlas (bf2-mesh MeshFile::texcoords doc, bf2-render staticmesh.rs). The tweak's doNotGenerateLightmaps 0 keeps the house in the editor's lightmap bake (the bake itself: level editor plan).

Bundled: the Heroes jeep#

bri_jeep_willys.bundledmesh: three geometries. Geometry 0 is a one-triangle stand-in, geometry 1 the drivable jeep in 11 parts, geometry 2 the wreck (one part). Colour = part index.
bri_jeep_willys.bundledmesh: three geometries. Geometry 0 is a one-triangle stand-in, geometry 1 the drivable jeep in 11 parts, geometry 2 the wreck (one part). Colour = part index.

A bundled mesh moves in rigid parts: the vertex's first BLENDINDICES byte names its part, and the engine passes one matrix per part (setPartTransform; bf2-render bundledmesh.rs module doc). The jeep's steering wheel, wheels and suspension are parts of geometry 1; the CON's RotationalBundle and Spring children turn and move them. With more than one geometry the renderer's default is geometry 1 (bf2-render bundledmesh.rs, "Default geom").

The jeep's LOD chain (geometry 1): 2721, 1784, 901 and 232 triangles.
The jeep's LOD chain (geometry 1): 2721, 1784, 901 and 232 triangles.

Skinned: a hero body#

A royal hero's six default items in the bind pose, each its own .skinnedmesh: coloured per item, then per skeleton bone (rig bone id of the vertex's first blend index), front and side.
A royal hero's six default items in the bind pose, each its own .skinnedmesh: coloured per item, then per skeleton bone (rig bone id of the vertex's first blend index), front and side.

A Heroes hero has no body mesh of its own: the customization manager builds one from the player's items, each a skinned mesh under Objects/Items/<British|German>/<item>/Meshes/ (bfh-client hero_mesh.rs, notes/bfheroes client.md "Tints and mesh rules"). Each vertex has two bone indices and one weight (BLENDWEIGHT x for the first bone, 1 - x for the second; bf2-mesh MeshFile::blend_weights). A material's rig lists the skeleton bone ids its indices refer to and the inverse bind pose per bone; the renderer draws bone id with rig matrix * skeleton[id] (bf2-mesh RigBone, bf2-render skinned.rs). The skeleton itself is the soldier's .ske (british_male_soldier.ske), shared by every item, which is why items made separately fit together; how it is posed is on animations.

How it is tested#

  • Every shipped mesh parses (crates/bf2-mesh/tests/retail.rs): every render mesh in every archive is read, the parse must consume all bytes and its ranges must be consistent.
  • Written back identical (write_heroes.rs): for every static, bundled and skinned mesh of the Heroes install, writing the parsed mesh gives the file back byte for byte.
  • Without an install (synthetic.rs): hand-built files exercise every version branch of the readers.
  • The viewer's mesh on this wiki is a shape of the wiki's own, decoded by the collision crate's decoder; the wiki's test compares the committed JSON with the script's shape.

Where it is read and drawn#

Stepbf2-rs
parse the three kindsbf2-mesh template.rs MeshFile::parse, decl.rs vertex elements
collisionbf2-collision lib.rs CollisionMesh::parse
LOD choicebf2-render objlod.rs, skinned.rs select_lod
drawbf2-render staticmesh.rs, bundledmesh.rs, skinned.rs (shader choice: materials)
hero bodiesbfh-client hero_mesh.rs

The draw order and passes are on the render pipeline page; the textures the materials name are on textures; the archives the files come from on archives.

Source: docs/dev/assets/mesh.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.