w3d_file.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /Commando/Code/ww3d/w3d_file.h 56 8/12/98 11:16a Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Library *
  24. * *
  25. * $Archive:: /Commando/Code/ww3d/w3d_file.h $*
  26. * *
  27. * $Author:: Greg_h $*
  28. * *
  29. * $Modtime:: 8/11/98 4:15p $*
  30. * *
  31. * $Revision:: 56 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef W3D_FILE_H
  37. #define W3D_FILE_H
  38. #include "always.h"
  39. #ifndef BITTYPE_H
  40. #include "bittype.h"
  41. #endif
  42. /********************************************************************************
  43. VERSION NUMBERS:
  44. Each Major chunk type will contain a "header" as its first
  45. sub-chunk. The first member of this header will be a Version
  46. number formatted so that its major revision number is the
  47. high two bytes and its minor revision number is the lower two
  48. bytes.
  49. Version 1.0:
  50. MESHES - contained the following chunks:
  51. W3D_CHUNK_MESH_HEADER, // header for a mesh
  52. W3D_CHUNK_VERTICES, // array of vertices
  53. W3D_CHUNK_VERTEX_NORMALS, // array of normals
  54. W3D_CHUNK_SURRENDER_NORMALS, // array of surrender normals (one per vertex as req. by surrender)
  55. W3D_CHUNK_TEXCOORDS, // array of texture coordinates
  56. W3D_CHUNK_MATERIALS, // array of materials
  57. W3D_CHUNK_TRIANGLES, // array of triangles
  58. W3D_CHUNK_SURRENDER_TRIANGLES,// array of surrender format tris
  59. W3D_CHUNK_MESH_USER_TEXT, // Name of owning hierarchy, text from the MAX comment field
  60. HIERARCHY TREES - contained the following chunks:
  61. W3D_CHUNK_HIERARCHY_HEADER,
  62. W3D_CHUNK_PIVOTS,
  63. W3D_CHUNK_PIVOT_FIXUPS,
  64. HIERARCHY ANIMATIONS - contained the following chunks:
  65. W3D_CHUNK_ANIMATION_HEADER,
  66. W3D_CHUNK_ANIMATION_CHANNEL,
  67. MESH CONNECTIONS - (blueprint for a hierarchical model) contained these chunks:
  68. Version 2.0:
  69. MESHES:
  70. - Mesh header now contains the hierarchy model name. The mesh name will be built
  71. as <HModelName>.<MeshName> instead of the old convention: <HTreeName>.<Meshname>
  72. - The material chunk is replaced with a new material structure which contains
  73. some information for animating materials.
  74. - Vertex Influences link vertices of a mesh to bones in a hierarchy, this is
  75. the information needed for skinning.
  76. - Damage chunks added. A damage chunk contains a new set of materials, a set
  77. of vertex offsets, and a set of vertex colors.
  78. Added the following chunks:
  79. W3D_CHUNK_VERTEX_COLORS,
  80. W3D_CHUNK_VERTEX_INFLUENCES,
  81. W3D_CHUNK_DAMAGE,
  82. W3D_CHUNK_DAMAGE_HEADER,
  83. W3D_CHUNK_DAMAGE_MATERIALS,
  84. W3D_CHUNK_DAMAGE_VERTICES,
  85. W3D_CHUNK_DAMAGE_COLORS,
  86. W3D_CHUNK_MATERIALS2,
  87. MESH CONNECTIONS: Hierarchy models can now contain skins and collision meshes
  88. in addition to the normal meshes.
  89. W3D_CHUNK_COLLISION_CONNECTION, // collision meshes connected to the hierarchy
  90. W3D_CHUNK_SKIN_CONNECTION, // skins connected to the hierarchy
  91. W3D_CHUNK_CONNECTION_AUX_DATA // extension of the connection header
  92. Dec 12, 1997
  93. Changed MESH_CONNECTIONS chunks into HMODEL chunks because the name
  94. mesh connections was becoming more and more inappropriate... This was only
  95. a data structure naming change so no-one other than the coders are affected
  96. Added W3D_CHUNK_LODMODEL. An LOD Model contains a set of names for
  97. render objects, each with a specified distance range.
  98. Feb 6, 1998
  99. Added W3D_CHUNK_SECTMESH and its sub-chunks. This will be the file
  100. format for the terrain geometry exported from POV's Atlas tool.
  101. March 29, 1998 : Version 3.0
  102. - New material chunk which supports the new features of the 3D engine
  103. - Modified HTrees to always have a root transform to remove all of the
  104. special case -1 bone indexes.
  105. - Added new mesh types, A mesh can now be categorized as: normal,
  106. aligned, skin, collision, or shadow.
  107. June 22, 1998
  108. Removed the "SECTMESH" chunks which were never implemented or used.
  109. Adding a new type of object: The 'Tilemap'. This simple-sounding object
  110. is a binary partition tree of tiles where tiles are rectangular regions of
  111. space. In each leaf to the tree, a mesh is referenced. The tile map is
  112. made of several chunks:
  113. - W3D_CHUNK_TILEMAP
  114. - W3D_CHUNK_TILEMAP_HEADER
  115. - W3D_CHUNK_TILES
  116. - W3D_CHUNK_MESH
  117. - W3D_CHUNK_MESH
  118. ...
  119. - W3D_CHUNK_PARTITION_TREE
  120. - W3D_CHUNK_PARTITION_TREE_HEADER
  121. - W3D_CHUNK_PARTITION_TREE_NODES
  122. - W3D_CHUNK_TILE_INSTANCES
  123. - W3D_CHUNK_TILE_INSTANCE
  124. ********************************************************************************/
  125. #define W3D_MAKE_VERSION(major,minor) (((major) << 16) | (minor))
  126. #define W3D_GET_MAJOR_VERSION(ver) ((ver)>>16)
  127. #define W3D_GET_MINOR_VERSION(ver) ((ver) & 0xFFFF)
  128. #define W3D_CURRENT_VERSION W3D_MAKE_VERSION(3,0)
  129. /********************************************************************************
  130. CHUNK TYPES FOR ALL 3D DATA
  131. All 3d data is stored in chunks similar to an IFF file. Each
  132. chunk will be headed by an ID and size field.
  133. All structures defined in this header file are prefixed with
  134. W3d to prevent naming conflicts with in-game structures which
  135. may be slightly different than the on-disk structures.
  136. ********************************************************************************/
  137. enum {
  138. W3D_CHUNK_MESH = 0, // Mesh definition (.WTM file)
  139. W3D_CHUNK_MESH_HEADER, // header for a mesh
  140. W3D_CHUNK_VERTICES, // array of vertices
  141. W3D_CHUNK_VERTEX_NORMALS, // array of normals
  142. W3D_CHUNK_SURRENDER_NORMALS, // array of surrender normals (one per vertex as req. by surrender)
  143. W3D_CHUNK_TEXCOORDS, // array of texture coordinates
  144. W3D_CHUNK_MATERIALS, // array of materials
  145. O_W3D_CHUNK_TRIANGLES, // array of triangles (obsolete)
  146. O_W3D_CHUNK_QUADRANGLES, // array of quads (obsolete)
  147. W3D_CHUNK_SURRENDER_TRIANGLES,// array of surrender format tris
  148. O_W3D_CHUNK_POV_TRIANGLES, // POV format triangles (obsolete)
  149. O_W3D_CHUNK_POV_QUADRANGLES, // POV format quads (obsolete)
  150. W3D_CHUNK_MESH_USER_TEXT, // Name of owning hierarchy, text from the MAX comment field
  151. W3D_CHUNK_VERTEX_COLORS, // Pre-set vertex coloring
  152. W3D_CHUNK_VERTEX_INFLUENCES, // Mesh Deformation vertex connections
  153. W3D_CHUNK_DAMAGE, // Mesh damage, new set of materials, vertex positions, vertex colors
  154. W3D_CHUNK_DAMAGE_HEADER, // Header for the damage data, tells what is coming
  155. W3D_CHUNK_DAMAGE_VERTICES, // Array of modified vertices (W3dMeshDamageVertexStruct's)
  156. W3D_CHUNK_DAMAGE_COLORS, // Array of modified vert colors (W3dMeshDamageColorStruct's)
  157. O_W3D_CHUNK_DAMAGE_MATERIALS, // (OBSOLETE) Damage materials simply wrapped with MATERIALS3 or higher
  158. W3D_CHUNK_MATERIALS2, // array of version 2 materials (with animation frame counts)
  159. W3D_CHUNK_MATERIALS3, // array of version 3 materials (all new surrender features supported)
  160. W3D_CHUNK_MATERIAL3, // Each version 3 material wrapped with this chunk ID
  161. W3D_CHUNK_MATERIAL3_NAME, // Name of the material (array of chars, null terminated)
  162. W3D_CHUNK_MATERIAL3_INFO, // contains a W3dMaterial3Struct, general material info
  163. W3D_CHUNK_MATERIAL3_DC_MAP, // wraps the following two chunks, diffuse color texture
  164. W3D_CHUNK_MAP3_FILENAME, // filename of the texture
  165. W3D_CHUNK_MAP3_INFO, // a W3dMap3Struct
  166. W3D_CHUNK_MATERIAL3_DI_MAP, // diffuse illimination map, same format as other maps
  167. W3D_CHUNK_MATERIAL3_SC_MAP, // specular color map, same format as other maps
  168. W3D_CHUNK_MATERIAL3_SI_MAP, // specular illumination map, same format as other maps
  169. W3D_CHUNK_MESH_HEADER3, // New improved mesh header
  170. W3D_CHUNK_TRIANGLES, // New improved triangles chunk
  171. W3D_CHUNK_PER_TRI_MATERIALS, // Multi-Mtl meshes - An array of uint16 material id's
  172. W3D_CHUNK_HIERARCHY = 0x100, // hierarchy tree definition (.WHT file)
  173. W3D_CHUNK_HIERARCHY_HEADER,
  174. W3D_CHUNK_PIVOTS,
  175. W3D_CHUNK_PIVOT_FIXUPS, // only needed by the exporter...
  176. W3D_CHUNK_ANIMATION = 0x200, // hierarchy animation data (.WHA file)
  177. W3D_CHUNK_ANIMATION_HEADER,
  178. W3D_CHUNK_ANIMATION_CHANNEL,
  179. W3D_CHUNK_BIT_CHANNEL, // channel of boolean values (e.g. visibility)
  180. W3D_CHUNK_HMODEL = 0x300, // blueprint for a hierarchy model
  181. W3D_CHUNK_HMODEL_HEADER, // usually found at end of a .WTM file
  182. W3D_CHUNK_NODE, // render objects connected to the hierarchy
  183. W3D_CHUNK_COLLISION_NODE, // collision meshes connected to the hierarchy
  184. W3D_CHUNK_SKIN_NODE, // skins connected to the hierarchy
  185. W3D_CHUNK_HMODEL_AUX_DATA, // extension of the connection header
  186. W3D_CHUNK_SHADOW_NODE, // shadow object connected to the hierarchy
  187. W3D_CHUNK_LODMODEL = 0x400, // blueprint for an LOD model. This is simply a
  188. W3D_CHUNK_LODMODEL_HEADER, // collection of 'n' render objects, ordered in terms
  189. W3D_CHUNK_LOD, // of their expected rendering costs.
  190. W3D_CHUNK_TILEMAP = 0x600, // Tile Map definition.
  191. W3D_CHUNK_TILEMAP_NAME,
  192. W3D_CHUNK_TILEMAP_HEADER,
  193. W3D_CHUNK_TILEMAP_TILE_INSTANCES,
  194. W3D_CHUNK_TILEMAP_PARTITION_TREE,
  195. W3D_CHUNK_TILEMAP_PARTITION_NODE,
  196. };
  197. struct W3dChunkHeader
  198. {
  199. uint32 ChunkType; // Type of chunk (see above enumeration)
  200. uint32 ChunkSize; // Size of the chunk, (not including the chunk header)
  201. };
  202. /********************************************************************************
  203. WTM ( Westwood Triangle Mesh )
  204. Each mesh will be contained within a WTM_CHUNK_MESH within
  205. this chunk will be the following chunks:
  206. The header will be the first chunk and it tells general
  207. information about the mesh such as how many triangles there
  208. are, how many vertices, the bounding box, center
  209. of mass, inertia matrix, etc.
  210. The vertex array is an array of Vectors giving the object
  211. space location of each vertex
  212. The normal array is an array of all of the unique vertex
  213. normal vectors needed by the mesh. This allows for vertices
  214. with multiple normals so that we can duplicate the effect
  215. of the smoothing groups in 3dsMax.
  216. The surrender normal array is an array of vertex normals which
  217. correspond 1to1 with the vertices. This is because the current
  218. version of surrender can only handle one vertex normal per vertex.
  219. In this case, the application should skip the normal array chunk
  220. and read the surrender normal chunk into its SR_VERTs
  221. The texture coord array is all of the unique texture coordinates
  222. for the mesh. This allows triangles to share vertices but not
  223. necessarily share texture coordinates.
  224. The material array is a list of the names and rgb colors of
  225. all of the unique materials used by the mesh. All triangles will
  226. have a material index into this list.
  227. The triangle array is all of the triangles which make up the
  228. mesh. Each triangle has 3 indices to its vertices, vertex normals,
  229. and texture coordinates. Each also has a material id and the
  230. coefficients for its plane equation.
  231. The Surrender Triangle array is all of the triangles in a slightly
  232. different format. Surrender triangles contain their u-v coordinates
  233. so there is no indirection and no possibility for sharing. To
  234. make the importer faster, the triangles will also be stored in this
  235. format. The application can read whichever chunk it wants to.
  236. The mesh user text chunk is a NULL-terminated text buffer.
  237. ********************************************************************************/
  238. #define W3D_NAME_LEN 16
  239. /////////////////////////////////////////////////////////////////////////////////////////////
  240. // vector
  241. /////////////////////////////////////////////////////////////////////////////////////////////
  242. struct W3dVectorStruct
  243. {
  244. float32 X; // X,Y,Z coordinates
  245. float32 Y;
  246. float32 Z;
  247. };
  248. /////////////////////////////////////////////////////////////////////////////////////////////
  249. // quaternion
  250. /////////////////////////////////////////////////////////////////////////////////////////////
  251. struct W3dQuaternionStruct
  252. {
  253. float32 Q[4];
  254. };
  255. /////////////////////////////////////////////////////////////////////////////////////////////
  256. // texture coordinate
  257. /////////////////////////////////////////////////////////////////////////////////////////////
  258. struct W3dTexCoordStruct
  259. {
  260. float32 U; // U,V coordinates
  261. float32 V;
  262. };
  263. /////////////////////////////////////////////////////////////////////////////////////////////
  264. // rgb color, one byte per channel, padded to an even 4 bytes
  265. /////////////////////////////////////////////////////////////////////////////////////////////
  266. struct W3dRGBStruct
  267. {
  268. uint8 R;
  269. uint8 G;
  270. uint8 B;
  271. uint8 pad;
  272. };
  273. /////////////////////////////////////////////////////////////////////////////////////////////
  274. // Version 1.0 Material, array of these are found inside the W3D_CHUNK_MATERIALS chunk.
  275. /////////////////////////////////////////////////////////////////////////////////////////////
  276. struct W3dMaterialStruct
  277. {
  278. char MaterialName[W3D_NAME_LEN]; // name of the material (NULL terminated)
  279. char PrimaryName[W3D_NAME_LEN]; // primary texture name (NULL terminated)
  280. char SecondaryName[W3D_NAME_LEN]; // secondary texture name (NULL terminated)
  281. uint32 RenderFlags; // Rendering flags
  282. uint8 Red; // Rgb colors
  283. uint8 Green;
  284. uint8 Blue;
  285. };
  286. /////////////////////////////////////////////////////////////////////////////////////////////
  287. // Version 2.0 Material, array of these are found inside the W3D_CHUNK_MATERIALS2 chunk.
  288. /////////////////////////////////////////////////////////////////////////////////////////////
  289. struct W3dMaterial2Struct
  290. {
  291. char MaterialName[W3D_NAME_LEN]; // name of the material (NULL terminated)
  292. char PrimaryName[W3D_NAME_LEN]; // primary texture name (NULL terminated)
  293. char SecondaryName[W3D_NAME_LEN]; // secondary texture name (NULL terminated)
  294. uint32 RenderFlags; // Rendering flags
  295. uint8 Red; // Rgb colors
  296. uint8 Green;
  297. uint8 Blue;
  298. uint8 Alpha;
  299. uint16 PrimaryNumFrames; // number of animated frames (if 1, not animated)
  300. uint16 SecondaryNumFrames; // number of animated frames (if 1, not animated)
  301. char Pad[12]; // expansion room
  302. };
  303. /////////////////////////////////////////////////////////////////////////////////////////////
  304. // MATERIAL ATTRIBUTES (version 3.0 onward)
  305. /////////////////////////////////////////////////////////////////////////////////////////////
  306. // Use alpha enables alpha channels, etc, Use sorting causes display lists using
  307. // this material to be sorted (even with z-buf, translucent materials need to be sorted)
  308. #define W3DMATERIAL_USE_ALPHA 0x00000001
  309. #define W3DMATERIAL_USE_SORTING 0x00000002
  310. // Hints for render devices that cannot support all features
  311. #define W3DMATERIAL_HINT_DIT_OVER_DCT 0x00000010
  312. #define W3DMATERIAL_HINT_SIT_OVER_SCT 0x00000020
  313. #define W3DMATERIAL_HINT_DIT_OVER_DIG 0x00000040
  314. #define W3DMATERIAL_HINT_SIT_OVER_SIG 0x00000080
  315. #define W3DMATERIAL_HINT_FAST_SPECULAR_AFTER_ALPHA 0x00000100
  316. // Last byte is for PSX: Translucency type and a lighting disable flag.
  317. #define W3DMATERIAL_PSX_MASK 0xFF000000
  318. #define W3DMATERIAL_PSX_TRANS_MASK 0x07000000
  319. #define W3DMATERIAL_PSX_TRANS_NONE 0x00000000
  320. #define W3DMATERIAL_PSX_TRANS_100 0x01000000
  321. #define W3DMATERIAL_PSX_TRANS_50 0x02000000
  322. #define W3DMATERIAL_PSX_TRANS_25 0x03000000
  323. #define W3DMATERIAL_PSX_TRANS_MINUS_100 0x04000000
  324. #define W3DMATERIAL_PSX_NO_RT_LIGHTING 0x08000000
  325. /////////////////////////////////////////////////////////////////////////////////////////////
  326. // MAPPING TYPES (version 3.0 onward)
  327. /////////////////////////////////////////////////////////////////////////////////////////////
  328. #define W3DMAPPING_UV 0
  329. #define W3DMAPPING_ENVIRONMENT 1
  330. /////////////////////////////////////////////////////////////////////////////////////////////
  331. // Version 3.0 Material, A W3D_CHUNK_MATERIALS3 chunk will wrap a bunch of
  332. // W3D_CHUNK_MATERIAL3 chunks. Inside each chunk will be a name chunk, an 'info' chunk which
  333. // contains the following struct, and one or more map chunks. a mesh with 2 materials might
  334. // look like:
  335. //
  336. // W3D_CHUNK_MATERIALS3 <-- simply a wrapper around the array of mtls
  337. // W3D_CHUNK_MATERIAL3 <-- a wrapper around each material
  338. // W3D_CHUNK_STRING <-- name of the material
  339. // W3D_CHUNK_MATERIAL3_INFO <-- standard material properties, a W3dMaterial3Struct
  340. // W3D_CHUNK_MATERIAL3_DC_MAP <-- a map, W3dMap3Struct
  341. // W3D_CHUNK_STRING <-- filename of the map
  342. // W3D_CHUNK_MAP_INFO <-- map parameters
  343. // W3D_CHUNK_MATERIAL3_SC_MAP
  344. // W3D_CHUNK_STRING <-- filename of the map
  345. // W3D_CHUNK_MAP_INFO
  346. // W3D_CHUNK_MATERIAL3
  347. // W3D_CHUNK_MATERIAL3_NAME
  348. // W3D_CHUNK_MATERIAL3_INFO
  349. // W3D_CHUNK_MATERIAL3_SI_MAP
  350. //
  351. /////////////////////////////////////////////////////////////////////////////////////////////
  352. struct W3dMaterial3Struct
  353. {
  354. uint32 Attributes; // flags,hints,etc.
  355. W3dRGBStruct DiffuseColor; // diffuse color
  356. W3dRGBStruct SpecularColor; // specular color
  357. W3dRGBStruct EmissiveCoefficients; // emmissive coefficients, default to 0,0,0
  358. W3dRGBStruct AmbientCoefficients; // ambient coefficients, default to 1,1,1
  359. W3dRGBStruct DiffuseCoefficients; // diffuse coeficients, default to 1,1,1
  360. W3dRGBStruct SpecularCoefficients; // specular coefficients, default to 0,0,0
  361. float32 Shininess; // how tight the specular highlight will be, 1 - 1000 (default = 1)
  362. float32 Opacity; // how opaque the material is, 0.0 = invisible, 1.0 = fully opaque (default = 1)
  363. float32 Translucency; // how much light passes through the material. (default = 0)
  364. float32 FogCoeff; // effect of fog (0.0=not fogged, 1.0=fogged) (default = 1)
  365. };
  366. /////////////////////////////////////////////////////////////////////////////////////////////
  367. // A map, only occurs as part of a material, will be preceeded by its name.
  368. /////////////////////////////////////////////////////////////////////////////////////////////
  369. struct W3dMap3Struct
  370. {
  371. uint16 MappingType; // Mapping type, will be one of the above #defines (e.g. W3DMAPPING_UV)
  372. uint16 FrameCount; // Number of frames (1 if not animated)
  373. float32 FrameRate; // Frame rate, frames per second in floating point
  374. };
  375. /////////////////////////////////////////////////////////////////////////////////////////////
  376. // A triangle, occurs inside the W3D_CHUNK_SURRENDER_TRIANGLES chunk
  377. /////////////////////////////////////////////////////////////////////////////////////////////
  378. struct W3dSurrenderTriStruct
  379. {
  380. uint32 Vindex[3]; // vertex, vert normal, and texture coord indexes (all use same index)
  381. W3dTexCoordStruct TexCoord[3]; // texture coordinates (OBSOLETE!!!)
  382. uint32 MaterialIdx; // material index
  383. W3dVectorStruct Normal; // Face normal
  384. uint32 Attributes; // collision flags, sort method, etc
  385. W3dRGBStruct Gouraud[3]; // Pre-set shading values (OBSOLETE!!!)
  386. };
  387. /////////////////////////////////////////////////////////////////////////////////////////////
  388. // A triangle, occurs inside the W3D_CHUNK_TRIANGLES chunk
  389. // This is NEW for Version 3.
  390. /////////////////////////////////////////////////////////////////////////////////////////////
  391. struct W3dTriStruct
  392. {
  393. uint32 Vindex[3]; // vertex,vnormal,texcoord,color indices
  394. uint32 Attributes; // attributes bits
  395. W3dVectorStruct Normal; // plane normal
  396. float32 Dist; // plane distance
  397. };
  398. /////////////////////////////////////////////////////////////////////////////////////////////
  399. // Flags for the Mesh Attributes member
  400. /////////////////////////////////////////////////////////////////////////////////////////////
  401. #define W3D_MESH_FLAG_NONE 0x00000000 // plain ole normal mesh
  402. #define W3D_MESH_FLAG_COLLISION_BOX 0x00000001 // mesh is a collision box (should be 8 verts, should be hidden, etc)
  403. #define W3D_MESH_FLAG_SKIN 0x00000002 // skin mesh
  404. #define W3D_MESH_FLAG_SHADOW 0x00000004 // intended to be projected as a shadow
  405. #define W3D_MESH_FLAG_ALIGNED 0x00000008 // always aligns with camera
  406. #define W3D_MESH_FLAG_COLLISION_TYPE_MASK 0x00000FF0 // mask for the collision type bits
  407. #define W3D_MESH_FLAG_COLLISION_TYPE_SHIFT 4 // shifting to get to the collision type bits
  408. #define W3D_MESH_FLAG_COLLISION_TYPE_PHYSICAL 0x00000010 // physical collisions
  409. #define W3D_MESH_FLAG_COLLISION_TYPE_PROJECTILE 0x00000020 // projectiles (rays) collide with this
  410. #define W3D_MESH_FLAG_HIDDEN 0x00001000 // this mesh is hidden by default
  411. /////////////////////////////////////////////////////////////////////////////////////////////
  412. // Original (Obsolete) Mesh Header
  413. /////////////////////////////////////////////////////////////////////////////////////////////
  414. struct W3dMeshHeaderStruct
  415. {
  416. uint32 Version; // Currently version 0x100
  417. char MeshName[W3D_NAME_LEN]; // name of the mesh (Null terminated)
  418. uint32 Attributes;
  419. //
  420. // Counts, these can be regarded as an inventory of what is to come in the file.
  421. //
  422. uint32 NumTris; // number of triangles (OBSOLETE!)
  423. uint32 NumQuads; // number of quads; (OBSOLETE!)
  424. uint32 NumSrTris; // number of triangles
  425. uint32 NumPovTris; // (NOT USED)
  426. uint32 NumPovQuads; // (NOT USED)
  427. uint32 NumVertices; // number of unique vertices
  428. uint32 NumNormals; // number of unique normals (OBSOLETE!)
  429. uint32 NumSrNormals; // number of surrender normals (MUST EQUAL NumVertices or 0)
  430. uint32 NumTexCoords; // number of unique texture coords (MUST EQUAL NumVertices or 0)
  431. uint32 NumMaterials; // number of unique materials needed
  432. uint32 NumVertColors; // number of vertex colors (MUST EQUAL NumVertices or 0)
  433. uint32 NumVertInfluences;// vertex influences(MUST EQUAL NumVertices or 0)
  434. uint32 NumDamageStages; // number of damage offset chunks
  435. uint32 FutureCounts[5]; // reserve space for future counts (set to zero).
  436. //
  437. // LOD controls
  438. //
  439. float32 LODMin; // min LOD distance
  440. float32 LODMax; // max LOD distance
  441. //
  442. // Collision / rendering quick-rejection
  443. //
  444. W3dVectorStruct Min; // Min corner of the bounding box
  445. W3dVectorStruct Max; // Max corner of the bounding box
  446. W3dVectorStruct SphCenter; // Center of bounding sphere
  447. float32 SphRadius; // Bounding sphere radius
  448. //
  449. // Default transformation
  450. //
  451. W3dVectorStruct Translation;
  452. float32 Rotation[9];
  453. //
  454. // Physics Properties
  455. //
  456. W3dVectorStruct MassCenter; // Center of mass in object space
  457. float32 Inertia[9]; // Inertia tensor (relative to MassCenter)
  458. float32 Volume; // volume of the object
  459. //
  460. // Name of possible hierarchy this mesh should be attached to
  461. //
  462. char HierarchyTreeName[W3D_NAME_LEN];
  463. char HierarchyModelName[W3D_NAME_LEN];
  464. uint32 FutureUse[24]; // Reserved for future use
  465. };
  466. /////////////////////////////////////////////////////////////////////////////////////////////
  467. // Version 3 Mesh Header, trimmed out some of the junk that was in the
  468. // previous versions.
  469. /////////////////////////////////////////////////////////////////////////////////////////////
  470. #define W3D_VERTEX_CHANNEL_LOCATION 0x00000001 // object-space location of the vertex
  471. #define W3D_VERTEX_CHANNEL_NORMAL 0x00000002 // object-space normal for the vertex
  472. #define W3D_VERTEX_CHANNEL_TEXCOORD 0x00000004 // texture coordinate
  473. #define W3D_VERTEX_CHANNEL_COLOR 0x00000008 // vertex color
  474. #define W3D_VERTEX_CHANNEL_BONEID 0x00000010 // per-vertex bone id for skins
  475. #define W3D_FACE_CHANNEL_FACE 0x00000001 // basic face info, W3dTriStruct...
  476. struct W3dMeshHeader3Struct
  477. {
  478. uint32 Version;
  479. uint32 Attributes;
  480. char MeshName[W3D_NAME_LEN];
  481. char HierarchyModelName[W3D_NAME_LEN];
  482. //
  483. // Counts, these can be regarded as an inventory of what is to come in the file.
  484. //
  485. uint32 NumTris; // number of triangles
  486. uint32 NumVertices; // number of unique vertices
  487. uint32 NumMaterials; // number of unique materials
  488. uint32 NumDamageStages; // number of damage offset chunks
  489. uint32 FutureCounts[3]; // future counts
  490. uint32 VertexChannels; // bits for presence of types of per-vertex info
  491. uint32 FaceChannels; // bits for presence of types of per-face info
  492. //
  493. // Bounding volumes
  494. //
  495. W3dVectorStruct Min; // Min corner of the bounding box
  496. W3dVectorStruct Max; // Max corner of the bounding box
  497. W3dVectorStruct SphCenter; // Center of bounding sphere
  498. float32 SphRadius; // Bounding sphere radius
  499. };
  500. //
  501. // Vertex Influences. For "skins" each vertex can be associated with a
  502. // different bone.
  503. //
  504. struct W3dVertInfStruct
  505. {
  506. uint16 BoneIdx;
  507. uint8 Pad[6];
  508. };
  509. //
  510. // Mesh Damage. This can include a new set of materials for the mesh,
  511. // new positions for certain vertices in the mesh, and new vertex
  512. // colors for certain vertices.
  513. //
  514. struct W3dMeshDamageStruct
  515. {
  516. uint32 NumDamageMaterials; // number of materials to replace
  517. uint32 NumDamageVerts; // number of vertices to replace
  518. uint32 NumDamageColors; // number of vertex colors to replace
  519. uint32 DamageIndex; // what index is this damage chunk assigned to
  520. uint32 FutureUse[4];
  521. };
  522. struct W3dMeshDamageVertexStruct
  523. {
  524. uint32 VertexIndex;
  525. W3dVectorStruct NewVertex;
  526. };
  527. struct W3dMeshDamageColorStruct
  528. {
  529. uint32 VertexIndex;
  530. W3dRGBStruct NewColor;
  531. };
  532. /********************************************************************************
  533. WHT ( Westwood Hierarchy Tree )
  534. A hierarchy tree defines a set of coordinate systems which are connected
  535. hierarchically. The header defines the name, number of pivots, etc.
  536. The pivots chunk will contain a W3dPivotStructs for each node in the
  537. tree.
  538. The W3dPivotFixupStruct contains a transform for each MAX coordinate
  539. system and our version of that same coordinate system (bone). It is
  540. needed when the user exports the base pose using "Translation Only".
  541. These are the matrices which go from the MAX rotated coordinate systems
  542. to a system which is unrotated in the base pose. These transformations
  543. are needed when exporting a hierarchy animation with the given hierarchy
  544. tree file.
  545. Another explanation of these kludgy "fixup" matrices:
  546. What are the "fixup" matrices? These are the transforms which
  547. were applied to the base pose when the user wanted to force the
  548. base pose to use only matrices with certain properties. For
  549. example, if we wanted the base pose to use translations only,
  550. the fixup transform for each node is a transform which when
  551. multiplied by the real node's world transform, yeilds a pure
  552. translation matrix. Fixup matrices are used in the mesh
  553. exporter since all vertices must be transformed by their inverses
  554. in order to make things work. They also show up in the animation
  555. exporter because they are needed to make the animation work with
  556. the new base pose.
  557. ********************************************************************************/
  558. struct W3dHierarchyStruct
  559. {
  560. uint32 Version;
  561. char Name[W3D_NAME_LEN]; // Name of the hierarchy
  562. uint32 NumPivots;
  563. W3dVectorStruct Center;
  564. };
  565. struct W3dPivotStruct
  566. {
  567. char Name[W3D_NAME_LEN]; // Name of the node (UR_ARM, LR_LEG, TORSO, etc)
  568. uint32 ParentIdx; // 0xffffffff = root pivot; no parent
  569. W3dVectorStruct Translation; // translation to pivot point
  570. W3dVectorStruct EulerAngles; // orientation of the pivot point
  571. W3dQuaternionStruct Rotation; // orientation of the pivot point
  572. };
  573. struct W3dPivotFixupStruct
  574. {
  575. float32 TM[4][3]; // this is a direct dump of a MAX 3x4 matrix
  576. };
  577. /********************************************************************************
  578. WHA (Westwood Hierarchy Animation)
  579. A Hierarchy Animation is a set of data defining deltas from the base
  580. position of a hierarchy tree. Translation and Rotation channels can be
  581. attached to any node of the hierarchy tree which the animation is
  582. associated with.
  583. ********************************************************************************/
  584. struct W3dAnimHeaderStruct
  585. {
  586. uint32 Version;
  587. char Name[W3D_NAME_LEN];
  588. char HierarchyName[W3D_NAME_LEN];
  589. uint32 NumFrames;
  590. uint32 FrameRate;
  591. };
  592. enum
  593. {
  594. ANIM_CHANNEL_X = 0,
  595. ANIM_CHANNEL_Y,
  596. ANIM_CHANNEL_Z,
  597. ANIM_CHANNEL_XR,
  598. ANIM_CHANNEL_YR,
  599. ANIM_CHANNEL_ZR,
  600. ANIM_CHANNEL_Q
  601. };
  602. struct W3dAnimChannelStruct
  603. {
  604. uint16 FirstFrame;
  605. uint16 LastFrame;
  606. uint16 VectorLen; // length of each vector in this channel
  607. uint16 Flags; // channel type.
  608. uint16 Pivot; // pivot affected by this channel
  609. uint16 pad;
  610. float32 Data[1]; // will be (LastFrame - FirstFrame + 1) * VectorLen long
  611. };
  612. enum
  613. {
  614. BIT_CHANNEL_VIS = 0, // turn meshes on and off depending on anim frame.
  615. };
  616. struct W3dBitChannelStruct
  617. {
  618. uint16 FirstFrame; // all frames outside "First" and "Last" are assumed = DefaultVal
  619. uint16 LastFrame;
  620. uint16 Flags; // channel type.
  621. uint16 Pivot; // pivot affected by this channel
  622. uint8 DefaultVal; // default state when outside valid range.
  623. uint8 Data[1]; // will be (LastFrame - FirstFrame + 1) / 8 long
  624. };
  625. /********************************************************************************
  626. (HModel - Hiearchy Model)
  627. A Hierarchy Model is a set of render objects which should be attached to
  628. bones in a hierarchy tree. There can be multiple objects per node
  629. in the tree. Or there may be no objects attached to a particular bone.
  630. ********************************************************************************/
  631. struct W3dHModelHeaderStruct
  632. {
  633. uint32 Version;
  634. char Name[W3D_NAME_LEN]; // Name of this connection set (NULL terminated)
  635. char HierarchyName[W3D_NAME_LEN]; // Name of hierarchy associated with these connections (NULL terminated)
  636. uint16 NumConnections;
  637. };
  638. struct W3dHModelAuxDataStruct
  639. {
  640. uint32 Attributes;
  641. uint32 MeshCount;
  642. uint32 CollisionCount;
  643. uint32 SkinCount;
  644. uint32 ShadowCount;
  645. uint32 FutureCounts[7];
  646. float32 LODMin;
  647. float32 LODMax;
  648. uint32 FutureUse[32];
  649. };
  650. struct W3dHModelNodeStruct
  651. {
  652. // Note: the full name of the Render object is expected to be: <HModelName>.<RenderObjName>
  653. char RenderObjName[W3D_NAME_LEN];
  654. uint16 PivotIdx;
  655. };
  656. /********************************************************************************
  657. (LODModel - Level-Of-Detail Model)
  658. An LOD Model is a set of render objects which are interchangeable and
  659. designed to be different resolution versions of the same object.
  660. ********************************************************************************/
  661. struct W3dLODModelHeaderStruct
  662. {
  663. uint32 Version;
  664. char Name[W3D_NAME_LEN]; // Name of this LOD Model
  665. uint16 NumLODs;
  666. };
  667. struct W3dLODStruct
  668. {
  669. char RenderObjName[2*W3D_NAME_LEN];
  670. float32 LODMin; // "artist" inspired switching distances
  671. float32 LODMax;
  672. };
  673. /********************************************************************************
  674. TileMap
  675. ********************************************************************************/
  676. struct W3dTileMapHeaderStruct
  677. {
  678. uint32 Version;
  679. uint32 TileInstanceCount;
  680. };
  681. #define W3D_TILE_ROTATION_0 0x00
  682. #define W3D_TILE_ROTATION_90 0x01
  683. #define W3D_TILE_ROTATION_180 0x02
  684. #define W3D_TILE_ROTATION_270 0x03
  685. struct W3dTileInstanceStruct
  686. {
  687. char RenderObjName[2*W3D_NAME_LEN];
  688. uint32 Rotation;
  689. W3dVectorStruct Position;
  690. };
  691. #define W3D_TILEMAP_PARTITION_FLAGS_PARTITION 0x0001
  692. #define W3D_TILEMAP_PARTITION_FLAGS_LEAF 0x0002
  693. #define W3D_TILEMAP_PARTITION_FLAGS_XNORMAL 0x0004
  694. #define W3D_TILEMAP_PARTITION_FLAGS_YNORMAL 0x0008
  695. #define W3D_TILEMAP_PARTITION_FLAGS_ZNORMAL 0x0010
  696. #define W3D_TILEMAP_PARTITION_FLAGS_FRONT_CHILD 0x0020
  697. #define W3D_TILEMAP_PARTITION_FLAGS_BACK_CHILD 0x0040
  698. struct W3dTileMapPartitionStruct
  699. {
  700. uint16 Flags; // type of node, type of plane, flags for presence of children.
  701. uint16 InstanceIndex; // if Type==LEAF, this field will store the tile instance index.
  702. float32 Dist; // distance along plane axis.
  703. W3dVectorStruct Min; // min corner of the bounding box
  704. W3dVectorStruct Max; // max corner of the bounding box
  705. };
  706. #endif