Understanding Static Meshes

Static Meshes

* Materials, Textures and UVs

Static meshes have to use the custom BF2StaticMesh2 Material in order to be
exported correctly. This material type combines multiple textures, each with
a distinct UV channel.

* Base Layer

The Base layer (UV Channel 1) is used for basic coloring purposes. As such, UVs
are usually simple. The textures themselves are usually simple, are mostly
a uniform base with small variations.

* Detail Layer (+NDetail)

The Detail layer (UV Channel 2) is used for surface details such as wood or
masonry patterns. Therefore, there should be no stretched or otherwise
distorted UVs if possible.

The NDetail layer (also UV Channel 2) is used for normalmaps (tangent)
of the textures in the Detail layer.

* Dirt Layer

The Dirt Layer (UV Channel 3) can be used to add (little surprise) dirt effects
and fake ambient occlusion effects on objects. It is mixed together with the
base and detail layers.

* Crack Layer (+NCrack)

The Crack layer (UV Channel 4) can be used to add wear and weathering to
objects. Textures in this slot will be rendered above the other layers,
depending on the texture's alpha channel. Faces mapped to transparent parts of
the crack texture will remain unchanged.

The NDetail layer (also UV Channel 4) is used for normalmaps (tangent)
of the textures in the Detail layer.

Layers can be left empty as required/desired, however only the following
combinations of layers are allowed:

* Base
\* Base, Detail
\* Base, NDetail
\* Base, Detail, Dirt
\* Base, Detail, NDetail
\* Base, Detail, Dirt, NDetail
\* Base, Detail, Crack, NDetail, NCrack
\* Base, Detail, Dirt, Crack, NDetail, NCrack
* Alpha Channels

Alpha Channels in texture slots represent either specular or transparency.

If "Alpha Test" is selected, the detail layer's alpha channel is used for
transparency, which will affect all layers. Otherwise the detail layer's alpha
channel is used for specular.

If "Alpha Test" is selected without a detail layer, the base layer's alpha
channel is used for transparency instead, which will also affect all layers.

Alpha Channels in Crack textures are always used for transparency (affecting
only the crack texture).

* Lightmap UVs

UV Channel 5 is used for lightmaps. They can either be mapped manually, or be
auto-generated during export. See [Advanced Lightmap Tutorial](AdvLightmaps.md)
for a tutorial on creating custom lightmaps in 3ds max.

In order to lightmap levels with the BF2Editor, .samples files are necessary,
which are generated during export. These have fixed resolution that are
specified during export.
The resolution for an object can be set in the main exporter window. The chosen
size is applied to `lod0`, with each additional lod lightmap being halved by 2.
It is also possible to assign custom lightmap sizes for each lod using the
LodSettings dialog.

* Export

In order to export a staticmesh, the scene has to conform to a number of rules
with regard to hierarchy and node names.

* Hierarchy

Helper nodes are used to define the hierarchy. A complete hierachy should look
like the following:

* a point dummy with name starting like `root\_staticmesh\_` followed by the mesh name
  \* a point dummy with name `geom0`
      \* a point dummy with name `lod0`
          \* the actual mesh, either as EditablePoly or EditableMesh
              \* a Point Dummy with the same name as the mesh, suffixed with \_\_Anchor
              \* a Point Dummy with name `nonvis\_`
                  \* col0, the projectile collision mesh
                  \* col1, the vehicle collision mesh
                  \* col2, the soldier collision mesh
                  \* col3, the AI collision mesh
              \* a Point Dummy with name `occ`
                  the occlusion mesh
      \* additional point dummies with names `lod1`, `lod2`, etc. as required
          \* lod meshes with the same name as the `lod0` mesh
  \* additional point dummies with names `geom1` etc.
      \* followed by the same hierachy as under `geom0`

Every static mesh needs to have at least a `root\_staticmesh\_`, `geom0`, `lod0`
and a visible geometry.

Other nodes can be added or omitted as required:

* An anchor is recommended for static meshes
  Anchors tell BF2Editor where a mesh should "snap" to the ground.

* occlusion mesh is recommended for very large objects
  Usually a simple bounding box, anything behind the occlusion mesh is not
  rendered.
* LODs

LOD meshes are recommended for better performance.
A LOD Generator included in the Utilities Dialog can be used to automatically
create 3 lods with multi-res modifiers.

The distance at which each LOD becomes visible can be set in the LodSettings
Dialog available from the main exporter window.

* COLs

On each col, a MultiMaterial made up of standard materials is used, with each
material given a different color to allow easy identification on the object.
Each Material has to be given a recognizable name. This name will be used
to identify the material in the BF2Editor where the actual material ids
will be assigned (the given name doesn't actually assign any materials).

Material ids can also be specified directly in 3ds Max by adding `||ID`
to each material name, where `ID` is the appropriate ID as taken from
`Common/Material/materialManagerSettings.con`

* col0 is required if the mesh is to block projectiles

  col0 meshes are usually identical to the visual mesh, with material ids
  assigned to correspond with the respective surfaces (e.g. wood, metal, ...)
  The materials are responsible for impact effects (sounds and decals)

* col1 is required if the mesh is supposed to block vehicles
  col1 meshes are simplified, very low-poly representations of the visual
  mesh so the engine knows where vehicles are supposed to collide. Assigned
  Materials are responsible for impact characteristics, and vehicle traction.

* col2 is required if the mesh is supposed to block soldiers
  col2 meshes are more detailed than col1 meshes so that soldiers can
  properly walk in, on and around the objects. Assigned materials are
  responsible for footstep sounds, impact characteristics and soldier
  traction.

* col3 is required if the mesh is supposed to be walked into by bots

  By default, all objects are represented by their bounding box in col3,
  meaning bots cannot enter them. Open statics to be used by AI therefore
  require a custom col3.
  A col3 has to be completely "watertight", i.e. there cannot be any open
  edges. Use the STL-check modifier to find problem areas.
* Import

Existing .staticmesh files can be re-imported back into 3ds Max using the Mesh
Importer in the Utilities Window. Only the visual mesh will be imported,
collision meshes have to be imported seperately. Before another export can take
place, the imported hierachies will have to be combined and fixed up.

There are drawbacks to importing meshes:
\* all polygons will have been converted to tris
\* smoothing group information will be lost (though normals should be intact)
\* there will be non-welded duplicated vertices and edges in the mesh

* Usage
* SimpleObject

The most common use for static meshes is a SimpleObject. (This is also the
default object type when the export node has no type specified.)

They are placed as single objects onto levels.

Static meshes for SimpleObject require only `geom0`

* Bundle

Bundles serve the same purpose as SimpleObjects, with the added ability to
include child objects (e.g. windows, ladders, smoke effects, etc).

* DestroyableObject

DestroyableObjects are represented by staticmeshes that contain two seperate
geometries: `geom0` contains the intact geometry,

`geom1` contains the destroyed geometry. (Both geoms require their own collision meshes)