W3D Format¶
Technical documentation for the Westwood 3D (W3D) file format.
Overview¶
W3D is a proprietary 3D model format developed by Westwood Studios, used in games like:
- Command & Conquer: Generals (2003)
- Command & Conquer: Generals - Zero Hour (2003)
- Earth & Beyond (2002)
- Command & Conquer: Renegade (2002)
Format Characteristics¶
- Binary format: Little-endian byte order
- Chunk-based: Hierarchical chunk structure
- Self-contained: Geometry, materials, animations in one file
- Extensible: Unknown chunks can be skipped
File Structure¶
┌─────────────────────────────────────┐
│ Chunk Header (8 bytes) │
│ - Type (4 bytes) │
│ - Size (4 bytes) │
├─────────────────────────────────────┤
│ Chunk Data │
│ - May contain sub-chunks │
├─────────────────────────────────────┤
│ Next Chunk Header │
├─────────────────────────────────────┤
│ ... │
└─────────────────────────────────────┘
Main Components¶
-
Meshes
Geometry with vertices, normals, UVs, and materials
-
Hierarchies
Skeleton bone structures for animation
-
Animations
Keyframe animation data
-
HLod
Level of Detail configuration
Sections¶
- Format Overview - Detailed format structure
- Chunk Types - Complete chunk type reference
- Meshes - Mesh data structures
- Hierarchies - Skeleton structures
- Animations - Animation formats
- HLod - Level of detail system
Quick Reference¶
Container Bit¶
The high bit of the chunk size indicates a container:
constexpr uint32_t CONTAINER_BIT = 0x80000000;
bool isContainer = (size & CONTAINER_BIT) != 0;
uint32_t dataSize = size & ~CONTAINER_BIT;
Common Chunk Types¶
| Chunk | ID | Description |
|---|---|---|
| MESH | 0x00000000 | Mesh container |
| HIERARCHY | 0x00000100 | Hierarchy container |
| ANIMATION | 0x00000200 | Animation container |
| HLOD | 0x00000700 | HLod container |
Name Format¶
Names are fixed-length, null-terminated:
Format Quirks¶
Important Implementation Notes
-
UV V-Flip: V coordinates are inverted compared to Vulkan
-
Quaternion Order: W3D stores (x,y,z,w), GLM expects (w,x,y,z)
-
Root Bone: Parent index
0xFFFFFFFFindicates root -
Per-Face UVs: UV indices are per-face, not per-vertex
- Requires "unrolling" meshes for modern rendering
Reference Implementation¶
The original W3D code can be found in:
Key files:
| File | Description |
|---|---|
w3d_file.h |
Format specification |
meshmdlio.cpp |
Mesh loading |
hlod.cpp |
HLod handling |
hanim.cpp |
Animation handling |
Versioning¶
W3D files include version numbers for compatibility: