w3d_file.h 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  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: /VSS_Sync/ww3d2/w3d_file.h 20 10/26/01 3:12p Vss_sync $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Library *
  24. * *
  25. * $Archive:: /VSS_Sync/ww3d2/w3d_file.h $*
  26. * *
  27. * $Author:: Vss_sync $*
  28. * *
  29. * $Modtime:: 10/26/01 2:56p $*
  30. * *
  31. * $Revision:: 20 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #if defined(_MSC_VER)
  37. #pragma once
  38. #endif
  39. #ifndef W3D_FILE_H
  40. #define W3D_FILE_H
  41. #include "always.h"
  42. #include "bittype.h"
  43. #include "iostruct.h"
  44. #include <limits.h>
  45. /********************************************************************************
  46. NAMING CONVENTIONS:
  47. Typical render object name is 15 characters + NULL
  48. Meshes have 31 + NULL character name formed from the concatenation of the "container"
  49. model name and the mesh's name: "ContainerName.MeshName"
  50. Animations have 31 + NULL character names formed from the concatenation of the Hierarchy tree
  51. name with the animation name: "AnimationName.HierarchyName"
  52. Textures have unlimited name length.
  53. Typically you can determine which 'W3D' file a render object came from by looking
  54. at its name. If the name contains a '.' then the filename is the string before
  55. the '.' and if not, then the render object name is the name of the file.
  56. VERSION NUMBERS:
  57. Each Major chunk type will contain a "header" as its first
  58. sub-chunk. The first member of this header will be a Version
  59. number formatted so that its major revision number is the
  60. high two bytes and its minor revision number is the lower two
  61. bytes.
  62. Version 1.0:
  63. MESHES - contained the following chunks:
  64. W3D_CHUNK_MESH_HEADER, // header for a mesh
  65. W3D_CHUNK_VERTICES, // array of vertices
  66. W3D_CHUNK_VERTEX_NORMALS, // array of normals
  67. W3D_CHUNK_SURRENDER_NORMALS, // array of surrender normals (one per vertex as req. by surrender)
  68. W3D_CHUNK_TEXCOORDS, // array of texture coordinates
  69. W3D_CHUNK_MATERIALS, // array of materials
  70. W3D_CHUNK_TRIANGLES, // array of triangles
  71. W3D_CHUNK_SURRENDER_TRIANGLES,// array of surrender format tris
  72. W3D_CHUNK_MESH_USER_TEXT, // Name of owning hierarchy, text from the MAX comment field
  73. HIERARCHY TREES - contained the following chunks:
  74. W3D_CHUNK_HIERARCHY_HEADER,
  75. W3D_CHUNK_PIVOTS,
  76. W3D_CHUNK_PIVOT_FIXUPS,
  77. HIERARCHY ANIMATIONS - contained the following chunks:
  78. W3D_CHUNK_ANIMATION_HEADER,
  79. W3D_CHUNK_ANIMATION_CHANNEL,
  80. MESH CONNECTIONS - (blueprint for a hierarchical model) contained these chunks:
  81. Version 2.0:
  82. MESHES:
  83. - Mesh header now contains the hierarchy model name. The mesh name will be built
  84. as <HModelName>.<MeshName> instead of the old convention: <HTreeName>.<Meshname>
  85. - The material chunk is replaced with a new material structure which contains
  86. some information for animating materials.
  87. - Vertex Influences link vertices of a mesh to bones in a hierarchy, this is
  88. the information needed for skinning.
  89. - Damage chunks added. A damage chunk contains a new set of materials, a set
  90. of vertex offsets, and a set of vertex colors.
  91. Added the following chunks:
  92. W3D_CHUNK_VERTEX_COLORS,
  93. W3D_CHUNK_VERTEX_INFLUENCES,
  94. W3D_CHUNK_DAMAGE,
  95. W3D_CHUNK_DAMAGE_HEADER,
  96. W3D_CHUNK_DAMAGE_MATERIALS,
  97. W3D_CHUNK_DAMAGE_VERTICES,
  98. W3D_CHUNK_DAMAGE_COLORS,
  99. W3D_CHUNK_MATERIALS2,
  100. MESH CONNECTIONS: Hierarchy models can now contain skins and collision meshes
  101. in addition to the normal meshes.
  102. W3D_CHUNK_COLLISION_CONNECTION, // collision meshes connected to the hierarchy
  103. W3D_CHUNK_SKIN_CONNECTION, // skins connected to the hierarchy
  104. W3D_CHUNK_CONNECTION_AUX_DATA // extension of the connection header
  105. Dec 12, 1997
  106. Changed MESH_CONNECTIONS chunks into HMODEL chunks because the name
  107. mesh connections was becoming more and more inappropriate... This was only
  108. a data structure naming change so no-one other than the coders are affected
  109. Added W3D_CHUNK_LODMODEL. An LOD Model contains a set of names for
  110. render objects, each with a specified distance range.
  111. Feb 6, 1998
  112. Added W3D_CHUNK_SECTMESH and its sub-chunks. This will be the file
  113. format for the terrain geometry exported from POV's Atlas tool.
  114. March 29, 1998 : Version 3.0
  115. - New material chunk which supports the new features of the 3D engine
  116. - Modified HTrees to always have a root transform to remove all of the
  117. special case -1 bone indexes.
  118. - Added new mesh types, A mesh can now be categorized as: normal,
  119. aligned, skin, collision, or shadow.
  120. June 22, 1998
  121. Removed the "SECTMESH" chunks which were never implemented or used.
  122. Adding a new type of object: The 'Tilemap'. This simple-sounding object
  123. is a binary partition tree of tiles where tiles are rectangular regions of
  124. space. In each leaf to the tree, a mesh is referenced. The tile map is
  125. made of several chunks:
  126. - W3D_CHUNK_TILEMAP
  127. - W3D_CHUNK_TILEMAP_HEADER
  128. - W3D_CHUNK_TILES
  129. - W3D_CHUNK_MESH
  130. - W3D_CHUNK_MESH
  131. ...
  132. - W3D_CHUNK_PARTITION_TREE
  133. - W3D_CHUNK_PARTITION_TREE_HEADER
  134. - W3D_CHUNK_PARTITION_TREE_NODES
  135. - W3D_CHUNK_TILE_INSTANCES
  136. - W3D_CHUNK_TILE_INSTANCE
  137. October 19, 1998
  138. Created the w3d_obsolete.h header file and moved everything that I could into
  139. it. This header was getting so messy that even I couldn't understand it so
  140. hopefully this helps a little...
  141. Updating the mesh format as part of the conversion to Surrender1.40. Some
  142. of the new features in this mesh format are:
  143. - per pass, per stage U-V coordinate arrays
  144. - per pass vertex diffuse color arrays
  145. - per pass vertex specular color arrays
  146. - per pass vertex pre-calced diffuse illumination arrays
  147. In addition, the way you describe the materials for a mesh has *completely*
  148. changed. The new system separates the concepts of VertexMaterial, Texture
  149. and Shader. A VertexMaterial defines the parameters which control the
  150. gradient calculations for vertices. Textures you know about. Shaders
  151. define how the gradients (diffuse and specular) are combined with the texture
  152. and the frame buffer. In addition, a mesh can have several passes; each
  153. pass having VertexMaterials, Textures and Shaders
  154. - new chunk to describe a shader, contains a W3dShaderStruct
  155. - new chunk to describe a vertex material, contains a W3dVertexMaterialStruct
  156. - textures use the old 'Map3' chunk still
  157. - new chunk to describe a "pass" for the mesh
  158. - new chunk to tie up all of these vertex materials, shaders, and textures
  159. - new chunks for specifying per-poly, per-pass arrays of texture, shader, and
  160. vertex material indices.
  161. The culling system changed a bit requiring some re-working of the "Tilemap"
  162. so I have removed the tilemap chunks. At this point in time, all of the AABTree
  163. building is being done at run-time. Once we get the editor a little farther
  164. along, we'll define some new chunks for this stuff.
  165. At this point in time, meshes look like the following. I've placed an asterisk
  166. next to the new chunk types.
  167. W3D_CHUNK_MESH
  168. W3D_CHUNK_MESH_HEADER3
  169. W3D_CHUNK_MESH_USER_TEXT
  170. W3D_CHUNK_VERTICES
  171. W3D_CHUNK_VERTEX_NORMALS
  172. W3D_CHUNK_VERTEX_INFLUENCES
  173. W3D_CHUNK_TRIANGLES
  174. * W3D_CHUNK_VERTEX_SHADE_INDICES
  175. * W3D_CHUNK_MATERIAL_INFO // how many passes, vertex mtls, shaders, and textures...
  176. * W3D_CHUNK_SHADERS // array of W3dShaderStruct's
  177. * W3D_CHUNK_VERTEX_MATERIALS
  178. * W3D_CHUNK_VERTEX_MATERIAL
  179. * W3D_CHUNK_VERTEX_MATERIAL_NAME
  180. * W3D_CHUNK_VERTEX_MATERIAL_INFO
  181. ...
  182. * W3D_CHUNK_TEXTURES
  183. * W3D_CHUNK_TEXTURE
  184. * W3D_CHUNK_TEXTURE_NAME
  185. * W3D_CHUNK_TEXTURE_INFO
  186. ...
  187. * W3D_CHUNK_MATERIAL_PASS
  188. * W3D_CHUNK_VERTEX_MATERIAL_IDS
  189. * W3D_CHUNK_SHADER_IDS
  190. * W3D_CHUNK_DCG
  191. * W3D_CHUNK_DIG
  192. * W3D_CHUNK_SCG
  193. * W3D_CHUNK_TEXTURE_STAGE
  194. * W3D_CHUNK_TEXTURE_IDS
  195. * W3D_CHUNK_STAGE_TEXCOORDS
  196. Added a Collection chunk type. When we export a bunch of independent meshes
  197. (turning off the hierarchy and animation options) this chunk will be added
  198. on to the end of the file. It lists by name each render object that was
  199. defined in the file. Presumably the run-time asset manager will be able
  200. to give you a "collection" render object which will be named the same as
  201. the w3d file that it came from and will contain the name or an actual instance
  202. of each of the meshes. This is a feature that was added for the Commando
  203. level editor.
  204. Added the W3D_CHUNK_POINTS chunk. This is used to implement "snap points"
  205. for the level editor. It is just an array of points that were found in
  206. the max scene (helper object->point). We make these points co-incide in
  207. the level editor to snap objects together. This chunk can occur inside a
  208. mesh, hmodel, or collection chunk. When it does, the points should simply
  209. be associated with the model being defined.
  210. August 5, 1999
  211. Adding Null Object exporting
  212. March 28, 2000
  213. Adding Merge objects to collections. We already have "Proxy" objects which ask
  214. the level editor to instatiate an object at a given transform. Now we will
  215. have "Merge" objects which mean a copy of the named model should be merged in
  216. with this model. This is used in the case of building interiors. We can create
  217. a building interior and lightmap it as a separate collection, then "merge" it
  218. with the level collection (multiple times even) and the tool will pre-transform
  219. the meshes and add them to the collection.
  220. March 31, 2000
  221. Changed W3D_CHUNK_MERGE_NODE to W3D_CHUNK_TRANSFORM_NODE. Same data - slightly
  222. different application. Now the information will indicate how a w3d asset with the
  223. same name as that in the node should pre-transform itself relative to the object
  224. that contains the transform node.
  225. April 07, 2000
  226. Added W3D_CHUNK_LIGHTSCAPE, W3D_CHUNK_LIGHTSCAPE_LIGHT and W3D_CHUNK_LIGHT_TRANSFORM.
  227. These chunks form part of the output of new Westwood light file type (.wlt).
  228. July 10, 2000
  229. Added W3D_CHUNK_VERTEX_MAPPER_ARGS1 and renamed W3D_CHUNK_VERTEX_MAPPER_ARGS to
  230. W3D_CHUNK_VERTEX_MAPPER_ARGS0. These are the mapper args for the first and second
  231. texture stages. The choice of mapper for the second stage has been added to the
  232. 'Attributes' field in W3dVertexMaterialStruct.
  233. August 5, 2000
  234. Added W3D_CHUNK_LIGHT_GLARE and its sub-chunks. Light glares are going to
  235. be a new 'geometry type' which simply define points where light glare effects
  236. should be placed. The application will supply a callback to the WW3D code
  237. which indicates the visibilty of any light glares in the view frustum.
  238. June 5, 2001
  239. (gth) Adding line rendering options to particle systems today. This involves a
  240. new line-properties chunk and a RenderMode variable added to the InfoV2 struct.
  241. ********************************************************************************/
  242. #define W3D_MAKE_VERSION(major,minor) (((major) << 16) | (minor))
  243. #define W3D_GET_MAJOR_VERSION(ver) ((ver)>>16)
  244. #define W3D_GET_MINOR_VERSION(ver) ((ver) & 0xFFFF)
  245. #define W3D_NAME_LEN 16
  246. /********************************************************************************
  247. CHUNK TYPES FOR ALL 3D DATA
  248. All 3d data is stored in chunks similar to an IFF file. Each
  249. chunk will be headed by an ID and size field.
  250. All structures defined in this header file are prefixed with
  251. W3d to prevent naming conflicts with in-game structures which
  252. may be slightly different than the on-disk structures.
  253. Oct 19,1998: Moved obsolete chunk id's to w3d_obsolete.h, added many
  254. new chunk types.
  255. ********************************************************************************/
  256. enum {
  257. W3D_CHUNK_MESH =0x00000000, // Mesh definition
  258. W3D_CHUNK_VERTICES =0x00000002, // array of vertices (array of W3dVectorStruct's)
  259. W3D_CHUNK_VERTEX_NORMALS =0x00000003, // array of normals (array of W3dVectorStruct's)
  260. W3D_CHUNK_MESH_USER_TEXT =0x0000000C, // Text from the MAX comment field (Null terminated string)
  261. W3D_CHUNK_VERTEX_INFLUENCES =0x0000000E, // Mesh Deformation vertex connections (array of W3dVertInfStruct's)
  262. W3D_CHUNK_MESH_HEADER3 =0x0000001F, // mesh header contains general info about the mesh. (W3dMeshHeader3Struct)
  263. W3D_CHUNK_TRIANGLES =0x00000020, // New improved triangles chunk (array of W3dTriangleStruct's)
  264. W3D_CHUNK_VERTEX_SHADE_INDICES =0x00000022, // shade indexes for each vertex (array of uint32's)
  265. W3D_CHUNK_PRELIT_UNLIT =0x00000023, // optional unlit material chunk wrapper
  266. W3D_CHUNK_PRELIT_VERTEX =0x00000024, // optional vertex-lit material chunk wrapper
  267. W3D_CHUNK_PRELIT_LIGHTMAP_MULTI_PASS =0x00000025, // optional lightmapped multi-pass material chunk wrapper
  268. W3D_CHUNK_PRELIT_LIGHTMAP_MULTI_TEXTURE =0x00000026, // optional lightmapped multi-texture material chunk wrapper
  269. W3D_CHUNK_MATERIAL_INFO =0x00000028, // materials information, pass count, etc (contains W3dMaterialInfoStruct)
  270. W3D_CHUNK_SHADERS =0x00000029, // shaders (array of W3dShaderStruct's)
  271. W3D_CHUNK_VERTEX_MATERIALS =0x0000002A, // wraps the vertex materials
  272. W3D_CHUNK_VERTEX_MATERIAL =0x0000002B,
  273. W3D_CHUNK_VERTEX_MATERIAL_NAME =0x0000002C, // vertex material name (NULL-terminated string)
  274. W3D_CHUNK_VERTEX_MATERIAL_INFO =0x0000002D, // W3dVertexMaterialStruct
  275. W3D_CHUNK_VERTEX_MAPPER_ARGS0 =0x0000002E, // Null-terminated string
  276. W3D_CHUNK_VERTEX_MAPPER_ARGS1 =0x0000002F, // Null-terminated string
  277. W3D_CHUNK_TEXTURES =0x00000030, // wraps all of the texture info
  278. W3D_CHUNK_TEXTURE =0x00000031, // wraps a texture definition
  279. W3D_CHUNK_TEXTURE_NAME =0x00000032, // texture filename (NULL-terminated string)
  280. W3D_CHUNK_TEXTURE_INFO =0x00000033, // optional W3dTextureInfoStruct
  281. W3D_CHUNK_MATERIAL_PASS =0x00000038, // wraps the information for a single material pass
  282. W3D_CHUNK_VERTEX_MATERIAL_IDS =0x00000039, // single or per-vertex array of uint32 vertex material indices (check chunk size)
  283. W3D_CHUNK_SHADER_IDS =0x0000003A, // single or per-tri array of uint32 shader indices (check chunk size)
  284. W3D_CHUNK_DCG =0x0000003B, // per-vertex diffuse color values (array of W3dRGBAStruct's)
  285. W3D_CHUNK_DIG =0x0000003C, // per-vertex diffuse illumination values (array of W3dRGBStruct's)
  286. W3D_CHUNK_SCG =0x0000003E, // per-vertex specular color values (array of W3dRGBStruct's)
  287. W3D_CHUNK_TEXTURE_STAGE =0x00000048, // wrapper around a texture stage.
  288. W3D_CHUNK_TEXTURE_IDS =0x00000049, // single or per-tri array of uint32 texture indices (check chunk size)
  289. W3D_CHUNK_STAGE_TEXCOORDS =0x0000004A, // per-vertex texture coordinates (array of W3dTexCoordStruct's)
  290. W3D_CHUNK_PER_FACE_TEXCOORD_IDS =0x0000004B, // indices to W3D_CHUNK_STAGE_TEXCOORDS, (array of Vector3i)
  291. W3D_CHUNK_DEFORM =0x00000058, // mesh deform or 'damage' information.
  292. W3D_CHUNK_DEFORM_SET =0x00000059, // set of deform information
  293. W3D_CHUNK_DEFORM_KEYFRAME =0x0000005A, // a keyframe of deform information in the set
  294. W3D_CHUNK_DEFORM_DATA =0x0000005B, // deform information about a single vertex
  295. W3D_CHUNK_PS2_SHADERS =0x00000080, // Shader info specific to the Playstation 2.
  296. W3D_CHUNK_AABTREE =0x00000090, // Axis-Aligned Box Tree for hierarchical polygon culling
  297. W3D_CHUNK_AABTREE_HEADER, // catalog of the contents of the AABTree
  298. W3D_CHUNK_AABTREE_POLYINDICES, // array of uint32 polygon indices with count=mesh.PolyCount
  299. W3D_CHUNK_AABTREE_NODES, // array of W3dMeshAABTreeNode's with count=aabheader.NodeCount
  300. W3D_CHUNK_HIERARCHY =0x00000100, // hierarchy tree definition
  301. W3D_CHUNK_HIERARCHY_HEADER,
  302. W3D_CHUNK_PIVOTS,
  303. W3D_CHUNK_PIVOT_FIXUPS, // only needed by the exporter...
  304. W3D_CHUNK_ANIMATION =0x00000200, // hierarchy animation data
  305. W3D_CHUNK_ANIMATION_HEADER,
  306. W3D_CHUNK_ANIMATION_CHANNEL, // channel of vectors
  307. W3D_CHUNK_BIT_CHANNEL, // channel of boolean values (e.g. visibility)
  308. W3D_CHUNK_COMPRESSED_ANIMATION =0x00000280, // compressed hierarchy animation data
  309. W3D_CHUNK_COMPRESSED_ANIMATION_HEADER, // describes playback rate, number of frames, and type of compression
  310. W3D_CHUNK_COMPRESSED_ANIMATION_CHANNEL, // compressed channel, format dependent on type of compression
  311. W3D_CHUNK_COMPRESSED_BIT_CHANNEL, // compressed bit stream channel, format dependent on type of compression
  312. W3D_CHUNK_MORPH_ANIMATION =0x000002C0, // hierarchy morphing animation data (morphs between poses, for facial animation)
  313. W3D_CHUNK_MORPHANIM_HEADER, // W3dMorphAnimHeaderStruct describes playback rate, number of frames, and type of compression
  314. W3D_CHUNK_MORPHANIM_CHANNEL, // wrapper for a channel
  315. W3D_CHUNK_MORPHANIM_POSENAME, // name of the other anim which contains the poses for this morph channel
  316. W3D_CHUNK_MORPHANIM_KEYDATA, // morph key data for this channel
  317. W3D_CHUNK_MORPHANIM_PIVOTCHANNELDATA, // uin32 per pivot in the htree, indicating which channel controls the pivot
  318. W3D_CHUNK_HMODEL =0x00000300, // blueprint for a hierarchy model
  319. W3D_CHUNK_HMODEL_HEADER, // Header for the hierarchy model
  320. W3D_CHUNK_NODE, // render objects connected to the hierarchy
  321. W3D_CHUNK_COLLISION_NODE, // collision meshes connected to the hierarchy
  322. W3D_CHUNK_SKIN_NODE, // skins connected to the hierarchy
  323. OBSOLETE_W3D_CHUNK_HMODEL_AUX_DATA, // extension of the hierarchy model header
  324. OBSOLETE_W3D_CHUNK_SHADOW_NODE, // shadow object connected to the hierarchy
  325. W3D_CHUNK_LODMODEL =0x00000400, // blueprint for an LOD model. This is simply a
  326. W3D_CHUNK_LODMODEL_HEADER, // collection of 'n' render objects, ordered in terms
  327. W3D_CHUNK_LOD, // of their expected rendering costs. (highest is first)
  328. W3D_CHUNK_COLLECTION =0x00000420, // collection of render object names
  329. W3D_CHUNK_COLLECTION_HEADER, // general info regarding the collection
  330. W3D_CHUNK_COLLECTION_OBJ_NAME, // contains a string which is the name of a render object
  331. W3D_CHUNK_PLACEHOLDER, // contains information about a 'dummy' object that will be instanced later
  332. W3D_CHUNK_TRANSFORM_NODE, // contains the filename of another w3d file that should be transformed by this node
  333. W3D_CHUNK_POINTS =0x00000440, // array of W3dVectorStruct's. May appear in meshes, hmodels, lodmodels, or collections.
  334. W3D_CHUNK_LIGHT =0x00000460, // description of a light
  335. W3D_CHUNK_LIGHT_INFO, // generic light parameters
  336. W3D_CHUNK_SPOT_LIGHT_INFO, // extra spot light parameters
  337. W3D_CHUNK_NEAR_ATTENUATION, // optional near attenuation parameters
  338. W3D_CHUNK_FAR_ATTENUATION, // optional far attenuation parameters
  339. W3D_CHUNK_EMITTER =0x00000500, // description of a particle emitter
  340. W3D_CHUNK_EMITTER_HEADER, // general information such as name and version
  341. W3D_CHUNK_EMITTER_USER_DATA, // user-defined data that specific loaders can switch on
  342. W3D_CHUNK_EMITTER_INFO, // generic particle emitter definition
  343. W3D_CHUNK_EMITTER_INFOV2, // generic particle emitter definition (version 2.0)
  344. W3D_CHUNK_EMITTER_PROPS, // Key-frameable properties
  345. OBSOLETE_W3D_CHUNK_EMITTER_COLOR_KEYFRAME, // structure defining a single color keyframe
  346. OBSOLETE_W3D_CHUNK_EMITTER_OPACITY_KEYFRAME, // structure defining a single opacity keyframe
  347. OBSOLETE_W3D_CHUNK_EMITTER_SIZE_KEYFRAME, // structure defining a single size keyframe
  348. W3D_CHUNK_EMITTER_LINE_PROPERTIES, // line properties, used by line rendering mode
  349. W3D_CHUNK_EMITTER_ROTATION_KEYFRAMES, // rotation keys for the particles
  350. W3D_CHUNK_EMITTER_FRAME_KEYFRAMES, // frame keys (u-v based frame animation)
  351. W3D_CHUNK_EMITTER_BLUR_TIME_KEYFRAMES, // length of tail for line groups
  352. W3D_CHUNK_AGGREGATE =0x00000600, // description of an aggregate object
  353. W3D_CHUNK_AGGREGATE_HEADER, // general information such as name and version
  354. W3D_CHUNK_AGGREGATE_INFO, // references to 'contained' models
  355. W3D_CHUNK_TEXTURE_REPLACER_INFO, // information about which meshes need textures replaced
  356. W3D_CHUNK_AGGREGATE_CLASS_INFO, // information about the original class that created this aggregate
  357. W3D_CHUNK_HLOD =0x00000700, // description of an HLod object (see HLodClass)
  358. W3D_CHUNK_HLOD_HEADER, // general information such as name and version
  359. W3D_CHUNK_HLOD_LOD_ARRAY, // wrapper around the array of objects for each level of detail
  360. W3D_CHUNK_HLOD_SUB_OBJECT_ARRAY_HEADER, // info on the objects in this level of detail array
  361. W3D_CHUNK_HLOD_SUB_OBJECT, // an object in this level of detail array
  362. W3D_CHUNK_HLOD_AGGREGATE_ARRAY, // array of aggregates, contains W3D_CHUNK_SUB_OBJECT_ARRAY_HEADER and W3D_CHUNK_SUB_OBJECT_ARRAY
  363. W3D_CHUNK_HLOD_PROXY_ARRAY, // array of proxies, used for application-defined purposes, provides a name and a bone.
  364. W3D_CHUNK_BOX =0x00000740, // defines an collision box render object (W3dBoxStruct)
  365. W3D_CHUNK_SPHERE,
  366. W3D_CHUNK_RING,
  367. W3D_CHUNK_NULL_OBJECT =0x00000750, // defines a NULL object (W3dNullObjectStruct)
  368. W3D_CHUNK_LIGHTSCAPE =0x00000800, // wrapper for lights created with Lightscape.
  369. W3D_CHUNK_LIGHTSCAPE_LIGHT, // definition of a light created with Lightscape.
  370. W3D_CHUNK_LIGHT_TRANSFORM, // position and orientation (defined as right-handed 4x3 matrix transform W3dLightTransformStruct).
  371. W3D_CHUNK_DAZZLE =0x00000900, // wrapper for a glare object. Creates halos and flare lines seen around a bright light source
  372. W3D_CHUNK_DAZZLE_NAME, // null-terminated string, name of the dazzle (typical w3d object naming: "container.object")
  373. W3D_CHUNK_DAZZLE_TYPENAME, // null-terminated string, type of dazzle (from dazzle.ini)
  374. W3D_CHUNK_SOUNDROBJ =0x00000A00, // description of a sound render object
  375. W3D_CHUNK_SOUNDROBJ_HEADER, // general information such as name and version
  376. W3D_CHUNK_SOUNDROBJ_DEFINITION, // chunk containing the definition of the sound that is to play
  377. };
  378. struct W3dChunkHeader
  379. {
  380. uint32 ChunkType; // Type of chunk (see above enumeration)
  381. uint32 ChunkSize; // Size of the chunk, (not including the chunk header)
  382. };
  383. /////////////////////////////////////////////////////////////////////////////////////////////
  384. // vector
  385. /////////////////////////////////////////////////////////////////////////////////////////////
  386. typedef IOVector3Struct W3dVectorStruct;
  387. /////////////////////////////////////////////////////////////////////////////////////////////
  388. // quaternion
  389. /////////////////////////////////////////////////////////////////////////////////////////////
  390. typedef IOQuaternionStruct W3dQuaternionStruct;
  391. /////////////////////////////////////////////////////////////////////////////////////////////
  392. // texture coordinate
  393. /////////////////////////////////////////////////////////////////////////////////////////////
  394. struct W3dTexCoordStruct
  395. {
  396. bool operator == (W3dTexCoordStruct t)
  397. {
  398. return ((U == t.U) && (V == t.V));
  399. }
  400. float32 U; // U,V coordinates
  401. float32 V;
  402. };
  403. /////////////////////////////////////////////////////////////////////////////////////////////
  404. // rgb color, one byte per channel, padded to an even 4 bytes
  405. /////////////////////////////////////////////////////////////////////////////////////////////
  406. struct W3dRGBStruct
  407. {
  408. W3dRGBStruct () {}
  409. W3dRGBStruct (uint8 r, uint8 g, uint8 b)
  410. {
  411. R = r;
  412. G = g;
  413. B = b;
  414. }
  415. void Set (uint8 r, uint8 g, uint8 b)
  416. {
  417. R = r;
  418. G = g;
  419. B = b;
  420. }
  421. void Set (float r, float g, float b)
  422. {
  423. R = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, r) * ((float) (UCHAR_MAX + 1)));
  424. G = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, g) * ((float) (UCHAR_MAX + 1)));
  425. B = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, b) * ((float) (UCHAR_MAX + 1)));
  426. }
  427. bool operator == (W3dRGBStruct c)
  428. {
  429. return ((R == c.R) && (G == c.G) && (B == c.B));
  430. }
  431. bool operator != (W3dRGBStruct c)
  432. {
  433. return (!(*this == c));
  434. }
  435. W3dRGBStruct operator += (W3dRGBStruct c)
  436. {
  437. R = MIN (((unsigned) R) + ((unsigned) c.R), (unsigned) UCHAR_MAX);
  438. G = MIN (((unsigned) G) + ((unsigned) c.G), (unsigned) UCHAR_MAX);
  439. B = MIN (((unsigned) B) + ((unsigned) c.B), (unsigned) UCHAR_MAX);
  440. return (*this);
  441. }
  442. W3dRGBStruct operator *= (W3dRGBStruct c)
  443. {
  444. R = (((unsigned) R) * ((unsigned) c.R)) / ((unsigned) UCHAR_MAX);
  445. G = (((unsigned) G) * ((unsigned) c.G)) / ((unsigned) UCHAR_MAX);
  446. B = (((unsigned) B) * ((unsigned) c.B)) / ((unsigned) UCHAR_MAX);
  447. return (*this);
  448. }
  449. unsigned Get_Color()
  450. {
  451. return (R<<24)|(G<<16)|(B<<8);
  452. }
  453. uint8 R;
  454. uint8 G;
  455. uint8 B;
  456. uint8 pad;
  457. };
  458. struct W3dRGBAStruct
  459. {
  460. uint8 R;
  461. uint8 G;
  462. uint8 B;
  463. uint8 A;
  464. };
  465. /////////////////////////////////////////////////////////////////////////////////////////////
  466. // MATERIALS
  467. //
  468. // Surrender 1.40 significantly changed the way that materials are described. To
  469. // accomodate this, the w3d file format has changed since there are new features and
  470. // optimizations that we want to take advangage of.
  471. //
  472. // The VertexMaterial defines parameters which control the calculation of the primary
  473. // and secondary gradients. The shader defines how those gradients are combined with
  474. // the texel and the frame buffer contents.
  475. //
  476. /////////////////////////////////////////////////////////////////////////////////////////////
  477. struct W3dMaterialInfoStruct
  478. {
  479. uint32 PassCount; // how many material passes this render object uses
  480. uint32 VertexMaterialCount; // how many vertex materials are used
  481. uint32 ShaderCount; // how many shaders are used
  482. uint32 TextureCount; // how many textures are used
  483. };
  484. #define W3DVERTMAT_USE_DEPTH_CUE 0x00000001
  485. #define W3DVERTMAT_ARGB_EMISSIVE_ONLY 0x00000002
  486. #define W3DVERTMAT_COPY_SPECULAR_TO_DIFFUSE 0x00000004
  487. #define W3DVERTMAT_DEPTH_CUE_TO_ALPHA 0x00000008
  488. #define W3DVERTMAT_STAGE0_MAPPING_MASK 0x00FF0000
  489. #define W3DVERTMAT_STAGE0_MAPPING_UV 0x00000000
  490. #define W3DVERTMAT_STAGE0_MAPPING_ENVIRONMENT 0x00010000
  491. #define W3DVERTMAT_STAGE0_MAPPING_CHEAP_ENVIRONMENT 0x00020000
  492. #define W3DVERTMAT_STAGE0_MAPPING_SCREEN 0x00030000
  493. #define W3DVERTMAT_STAGE0_MAPPING_LINEAR_OFFSET 0x00040000
  494. #define W3DVERTMAT_STAGE0_MAPPING_SILHOUETTE 0x00050000
  495. #define W3DVERTMAT_STAGE0_MAPPING_SCALE 0x00060000
  496. #define W3DVERTMAT_STAGE0_MAPPING_GRID 0x00070000
  497. #define W3DVERTMAT_STAGE0_MAPPING_ROTATE 0x00080000
  498. #define W3DVERTMAT_STAGE0_MAPPING_SINE_LINEAR_OFFSET 0x00090000
  499. #define W3DVERTMAT_STAGE0_MAPPING_STEP_LINEAR_OFFSET 0x000A0000
  500. #define W3DVERTMAT_STAGE0_MAPPING_ZIGZAG_LINEAR_OFFSET 0x000B0000
  501. #define W3DVERTMAT_STAGE0_MAPPING_WS_CLASSIC_ENV 0x000C0000
  502. #define W3DVERTMAT_STAGE0_MAPPING_WS_ENVIRONMENT 0x000D0000
  503. #define W3DVERTMAT_STAGE0_MAPPING_GRID_CLASSIC_ENV 0x000E0000
  504. #define W3DVERTMAT_STAGE0_MAPPING_GRID_ENVIRONMENT 0x000F0000
  505. #define W3DVERTMAT_STAGE0_MAPPING_RANDOM 0x00100000
  506. #define W3DVERTMAT_STAGE0_MAPPING_EDGE 0x00110000
  507. #define W3DVERTMAT_STAGE0_MAPPING_BUMPENV 0x00120000
  508. #define W3DVERTMAT_STAGE1_MAPPING_MASK 0x0000FF00
  509. #define W3DVERTMAT_STAGE1_MAPPING_UV 0x00000000
  510. #define W3DVERTMAT_STAGE1_MAPPING_ENVIRONMENT 0x00000100
  511. #define W3DVERTMAT_STAGE1_MAPPING_CHEAP_ENVIRONMENT 0x00000200
  512. #define W3DVERTMAT_STAGE1_MAPPING_SCREEN 0x00000300
  513. #define W3DVERTMAT_STAGE1_MAPPING_LINEAR_OFFSET 0x00000400
  514. #define W3DVERTMAT_STAGE1_MAPPING_SILHOUETTE 0x00000500
  515. #define W3DVERTMAT_STAGE1_MAPPING_SCALE 0x00000600
  516. #define W3DVERTMAT_STAGE1_MAPPING_GRID 0x00000700
  517. #define W3DVERTMAT_STAGE1_MAPPING_ROTATE 0x00000800
  518. #define W3DVERTMAT_STAGE1_MAPPING_SINE_LINEAR_OFFSET 0x00000900
  519. #define W3DVERTMAT_STAGE1_MAPPING_STEP_LINEAR_OFFSET 0x00000A00
  520. #define W3DVERTMAT_STAGE1_MAPPING_ZIGZAG_LINEAR_OFFSET 0x00000B00
  521. #define W3DVERTMAT_STAGE1_MAPPING_WS_CLASSIC_ENV 0x00000C00
  522. #define W3DVERTMAT_STAGE1_MAPPING_WS_ENVIRONMENT 0x00000D00
  523. #define W3DVERTMAT_STAGE1_MAPPING_GRID_CLASSIC_ENV 0x00000E00
  524. #define W3DVERTMAT_STAGE1_MAPPING_GRID_ENVIRONMENT 0x00000F00
  525. #define W3DVERTMAT_STAGE1_MAPPING_RANDOM 0x00001000
  526. #define W3DVERTMAT_STAGE1_MAPPING_EDGE 0x00001100
  527. #define W3DVERTMAT_STAGE1_MAPPING_BUMPENV 0x00001200
  528. #define W3DVERTMAT_PSX_MASK 0xFF000000
  529. #define W3DVERTMAT_PSX_TRANS_MASK 0x07000000
  530. #define W3DVERTMAT_PSX_TRANS_NONE 0x00000000
  531. #define W3DVERTMAT_PSX_TRANS_100 0x01000000
  532. #define W3DVERTMAT_PSX_TRANS_50 0x02000000
  533. #define W3DVERTMAT_PSX_TRANS_25 0x03000000
  534. #define W3DVERTMAT_PSX_TRANS_MINUS_100 0x04000000
  535. #define W3DVERTMAT_PSX_NO_RT_LIGHTING 0x08000000
  536. struct W3dVertexMaterialStruct
  537. {
  538. W3dVertexMaterialStruct(void) {}
  539. bool operator == (W3dVertexMaterialStruct vm)
  540. {
  541. return ( Attributes == vm.Attributes
  542. && Ambient == vm.Ambient
  543. && Diffuse == vm.Diffuse
  544. && Specular == vm.Specular
  545. && Emissive == vm.Emissive
  546. && Shininess == vm.Shininess
  547. && Opacity == vm.Opacity
  548. && Translucency == vm.Translucency);
  549. }
  550. bool operator != (W3dVertexMaterialStruct vm)
  551. {
  552. return (!(*this == vm));
  553. }
  554. uint32 Attributes; // bitfield for the flags defined above
  555. W3dRGBStruct Ambient;
  556. W3dRGBStruct Diffuse;
  557. W3dRGBStruct Specular;
  558. W3dRGBStruct Emissive;
  559. float32 Shininess; // how tight the specular highlight will be, 1 - 1000 (default = 1)
  560. float32 Opacity; // how opaque the material is, 0.0 = invisible, 1.0 = fully opaque (default = 1)
  561. float32 Translucency; // how much light passes through the material. (default = 0)
  562. };
  563. inline void W3d_Vertex_Material_Reset(W3dVertexMaterialStruct * vmat)
  564. {
  565. vmat->Attributes = 0;
  566. vmat->Ambient.R = vmat->Ambient.G = vmat->Ambient.B = 255;
  567. vmat->Diffuse.R = vmat->Diffuse.G = vmat->Diffuse.B = 255;
  568. vmat->Specular.R = vmat->Specular.G = vmat->Specular.B = 0;
  569. vmat->Emissive.R = vmat->Emissive.G = vmat->Emissive.B = 0;
  570. vmat->Shininess = 1.0f;
  571. vmat->Opacity = 1.0f;
  572. vmat->Translucency = 0.0f;
  573. }
  574. // W3dShaderStruct bits. These control every setting in the shader. Use the helper functions
  575. // to set them and test them more easily.
  576. enum
  577. {
  578. W3DSHADER_DEPTHCOMPARE_PASS_NEVER = 0, // pass never (i.e. always fail depth comparison test)
  579. W3DSHADER_DEPTHCOMPARE_PASS_LESS, // pass if incoming less than stored
  580. W3DSHADER_DEPTHCOMPARE_PASS_EQUAL, // pass if incoming equal to stored
  581. W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL, // pass if incoming less than or equal to stored (default)
  582. W3DSHADER_DEPTHCOMPARE_PASS_GREATER, // pass if incoming greater than stored
  583. W3DSHADER_DEPTHCOMPARE_PASS_NOTEQUAL, // pass if incoming not equal to stored
  584. W3DSHADER_DEPTHCOMPARE_PASS_GEQUAL, // pass if incoming greater than or equal to stored
  585. W3DSHADER_DEPTHCOMPARE_PASS_ALWAYS, // pass always
  586. W3DSHADER_DEPTHCOMPARE_PASS_MAX, // end of enumeration
  587. W3DSHADER_DEPTHMASK_WRITE_DISABLE = 0, // disable depth buffer writes
  588. W3DSHADER_DEPTHMASK_WRITE_ENABLE, // enable depth buffer writes (default)
  589. W3DSHADER_DEPTHMASK_WRITE_MAX, // end of enumeration
  590. W3DSHADER_ALPHATEST_DISABLE = 0, // disable alpha testing (default)
  591. W3DSHADER_ALPHATEST_ENABLE, // enable alpha testing
  592. W3DSHADER_ALPHATEST_MAX, // end of enumeration
  593. W3DSHADER_DESTBLENDFUNC_ZERO = 0, // destination pixel doesn't affect blending (default)
  594. W3DSHADER_DESTBLENDFUNC_ONE, // destination pixel added unmodified
  595. W3DSHADER_DESTBLENDFUNC_SRC_COLOR, // destination pixel multiplied by fragment RGB components
  596. W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_COLOR, // destination pixel multiplied by one minus (i.e. inverse) fragment RGB components
  597. W3DSHADER_DESTBLENDFUNC_SRC_ALPHA, // destination pixel multiplied by fragment alpha component
  598. W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_ALPHA, // destination pixel multiplied by fragment inverse alpha
  599. W3DSHADER_DESTBLENDFUNC_SRC_COLOR_PREFOG, // destination pixel multiplied by fragment RGB components prior to fogging
  600. W3DSHADER_DESTBLENDFUNC_MAX, // end of enumeration
  601. W3DSHADER_PRIGRADIENT_DISABLE = 0, // disable primary gradient (same as OpenGL 'decal' texture blend)
  602. W3DSHADER_PRIGRADIENT_MODULATE, // modulate fragment ARGB by gradient ARGB (default)
  603. W3DSHADER_PRIGRADIENT_ADD, // add gradient RGB to fragment RGB, copy gradient A to fragment A
  604. W3DSHADER_PRIGRADIENT_BUMPENVMAP, // environment-mapped bump mapping
  605. W3DSHADER_PRIGRADIENT_MAX, // end of enumeration
  606. W3DSHADER_SECGRADIENT_DISABLE = 0, // don't draw secondary gradient (default)
  607. W3DSHADER_SECGRADIENT_ENABLE, // add secondary gradient RGB to fragment RGB
  608. W3DSHADER_SECGRADIENT_MAX, // end of enumeration
  609. W3DSHADER_SRCBLENDFUNC_ZERO = 0, // fragment not added to color buffer
  610. W3DSHADER_SRCBLENDFUNC_ONE, // fragment added unmodified to color buffer (default)
  611. W3DSHADER_SRCBLENDFUNC_SRC_ALPHA, // fragment RGB components multiplied by fragment A
  612. W3DSHADER_SRCBLENDFUNC_ONE_MINUS_SRC_ALPHA, // fragment RGB components multiplied by fragment inverse (one minus) A
  613. W3DSHADER_SRCBLENDFUNC_MAX, // end of enumeration
  614. W3DSHADER_TEXTURING_DISABLE = 0, // no texturing (treat fragment initial color as 1,1,1,1) (default)
  615. W3DSHADER_TEXTURING_ENABLE, // enable texturing
  616. W3DSHADER_TEXTURING_MAX, // end of enumeration
  617. W3DSHADER_DETAILCOLORFUNC_DISABLE = 0, // local (default)
  618. W3DSHADER_DETAILCOLORFUNC_DETAIL, // other
  619. W3DSHADER_DETAILCOLORFUNC_SCALE, // local * other
  620. W3DSHADER_DETAILCOLORFUNC_INVSCALE, // ~(~local * ~other) = local + (1-local)*other
  621. W3DSHADER_DETAILCOLORFUNC_ADD, // local + other
  622. W3DSHADER_DETAILCOLORFUNC_SUB, // local - other
  623. W3DSHADER_DETAILCOLORFUNC_SUBR, // other - local
  624. W3DSHADER_DETAILCOLORFUNC_BLEND, // (localAlpha)*local + (~localAlpha)*other
  625. W3DSHADER_DETAILCOLORFUNC_DETAILBLEND, // (otherAlpha)*local + (~otherAlpha)*other
  626. W3DSHADER_DETAILCOLORFUNC_MAX, // end of enumeration
  627. W3DSHADER_DETAILALPHAFUNC_DISABLE = 0, // local (default)
  628. W3DSHADER_DETAILALPHAFUNC_DETAIL, // other
  629. W3DSHADER_DETAILALPHAFUNC_SCALE, // local * other
  630. W3DSHADER_DETAILALPHAFUNC_INVSCALE, // ~(~local * ~other) = local + (1-local)*other
  631. W3DSHADER_DETAILALPHAFUNC_MAX, // end of enumeration
  632. W3DSHADER_DEPTHCOMPARE_DEFAULT = W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL,
  633. W3DSHADER_DEPTHMASK_DEFAULT = W3DSHADER_DEPTHMASK_WRITE_ENABLE,
  634. W3DSHADER_ALPHATEST_DEFAULT = W3DSHADER_ALPHATEST_DISABLE,
  635. W3DSHADER_DESTBLENDFUNC_DEFAULT = W3DSHADER_DESTBLENDFUNC_ZERO,
  636. W3DSHADER_PRIGRADIENT_DEFAULT = W3DSHADER_PRIGRADIENT_MODULATE,
  637. W3DSHADER_SECGRADIENT_DEFAULT = W3DSHADER_SECGRADIENT_DISABLE,
  638. W3DSHADER_SRCBLENDFUNC_DEFAULT = W3DSHADER_SRCBLENDFUNC_ONE,
  639. W3DSHADER_TEXTURING_DEFAULT = W3DSHADER_TEXTURING_DISABLE,
  640. W3DSHADER_DETAILCOLORFUNC_DEFAULT = W3DSHADER_DETAILCOLORFUNC_DISABLE,
  641. W3DSHADER_DETAILALPHAFUNC_DEFAULT = W3DSHADER_DETAILALPHAFUNC_DISABLE,
  642. };
  643. enum PS2_SHADER_SETTINGS {
  644. PSS_SRC = 0,
  645. PSS_DEST,
  646. PSS_ZERO,
  647. PSS_SRC_ALPHA = 0,
  648. PSS_DEST_ALPHA,
  649. PSS_ONE,
  650. // From combo box. To match the PC default gradient.
  651. PSS_PRIGRADIENT_DECAL = 0,
  652. PSS_PRIGRADIENT_MODULATE,
  653. PSS_PRIGRADIENT_HIGHLIGHT,
  654. PSS_PRIGRADIENT_HIGHLIGHT2,
  655. // Actual PS2 numbers.
  656. PSS_PS2_PRIGRADIENT_MODULATE = 0,
  657. PSS_PS2_PRIGRADIENT_DECAL,
  658. PSS_PS2_PRIGRADIENT_HIGHLIGHT,
  659. PSS_PS2_PRIGRADIENT_HIGHLIGHT2,
  660. PSS_DEPTHCOMPARE_PASS_NEVER = 0,
  661. PSS_DEPTHCOMPARE_PASS_LESS,
  662. PSS_DEPTHCOMPARE_PASS_ALWAYS,
  663. PSS_DEPTHCOMPARE_PASS_LEQUAL,
  664. };
  665. struct W3dShaderStruct
  666. {
  667. W3dShaderStruct(void) {}
  668. uint8 DepthCompare;
  669. uint8 DepthMask;
  670. uint8 ColorMask; // now obsolete and ignored
  671. uint8 DestBlend;
  672. uint8 FogFunc; // now obsolete and ignored
  673. uint8 PriGradient;
  674. uint8 SecGradient;
  675. uint8 SrcBlend;
  676. uint8 Texturing;
  677. uint8 DetailColorFunc;
  678. uint8 DetailAlphaFunc;
  679. uint8 ShaderPreset; // now obsolete and ignored
  680. uint8 AlphaTest;
  681. uint8 PostDetailColorFunc;
  682. uint8 PostDetailAlphaFunc;
  683. uint8 pad[1];
  684. };
  685. struct W3dPS2ShaderStruct
  686. {
  687. uint8 DepthCompare;
  688. uint8 DepthMask;
  689. uint8 PriGradient;
  690. uint8 Texturing;
  691. uint8 AlphaTest;
  692. uint8 AParam;
  693. uint8 BParam;
  694. uint8 CParam;
  695. uint8 DParam;
  696. uint8 pad[3];
  697. };
  698. inline void W3d_Shader_Reset(W3dShaderStruct * s) {
  699. s->DepthCompare = W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL;
  700. s->DepthMask = W3DSHADER_DEPTHMASK_WRITE_ENABLE;
  701. s->ColorMask = 0; // obsolete
  702. s->DestBlend = W3DSHADER_DESTBLENDFUNC_ZERO;
  703. s->FogFunc = 0; // obsolete
  704. s->PriGradient = W3DSHADER_PRIGRADIENT_MODULATE;
  705. s->SecGradient = W3DSHADER_SECGRADIENT_DISABLE;
  706. s->SrcBlend = W3DSHADER_SRCBLENDFUNC_ONE;
  707. s->Texturing = W3DSHADER_TEXTURING_DISABLE;
  708. s->DetailColorFunc = W3DSHADER_DETAILCOLORFUNC_DISABLE;
  709. s->DetailAlphaFunc = W3DSHADER_DETAILALPHAFUNC_DISABLE;
  710. s->ShaderPreset = 0; // obsolete
  711. s->AlphaTest = W3DSHADER_ALPHATEST_DISABLE;
  712. s->PostDetailColorFunc = W3DSHADER_DETAILCOLORFUNC_DISABLE;
  713. s->PostDetailAlphaFunc = W3DSHADER_DETAILALPHAFUNC_DISABLE;
  714. s->pad[0] = 0;
  715. }
  716. inline void W3d_Shader_Set_Depth_Compare(W3dShaderStruct * s,int val) { s->DepthCompare = val; }
  717. inline void W3d_Shader_Set_Depth_Mask(W3dShaderStruct * s,int val) { s->DepthMask = val; }
  718. inline void W3d_Shader_Set_Dest_Blend_Func(W3dShaderStruct * s,int val) { s->DestBlend = val; }
  719. inline void W3d_Shader_Set_Pri_Gradient(W3dShaderStruct * s,int val) { s->PriGradient = val; }
  720. inline void W3d_Shader_Set_Sec_Gradient(W3dShaderStruct * s,int val) { s->SecGradient = val; }
  721. inline void W3d_Shader_Set_Src_Blend_Func(W3dShaderStruct * s,int val) { s->SrcBlend = val; }
  722. inline void W3d_Shader_Set_Texturing(W3dShaderStruct * s,int val) { s->Texturing = val; }
  723. inline void W3d_Shader_Set_Detail_Color_Func(W3dShaderStruct * s,int val) { s->DetailColorFunc = val; }
  724. inline void W3d_Shader_Set_Detail_Alpha_Func(W3dShaderStruct * s,int val) { s->DetailAlphaFunc = val; }
  725. inline void W3d_Shader_Set_Alpha_Test(W3dShaderStruct * s,int val) { s->AlphaTest = val; }
  726. inline void W3d_Shader_Set_Post_Detail_Color_Func(W3dShaderStruct * s,int val) { s->PostDetailColorFunc = val; }
  727. inline void W3d_Shader_Set_Post_Detail_Alpha_Func(W3dShaderStruct * s,int val) { s->PostDetailAlphaFunc = val; }
  728. // These functions use the existing W3dShaderStruct unused members to store PS2 specific parameters.
  729. // At mesh save time, if a PS2 material was used, a separate PS2 material chunk is saved out.
  730. // If W3dShaderStruct is changed this should still work because it is only used for the PS2 stuff.
  731. inline void W3d_Shader_Set_PS2_Param_A(W3dShaderStruct *s, int val) {s->ColorMask = val;}
  732. inline void W3d_Shader_Set_PS2_Param_B(W3dShaderStruct *s, int val) {s->FogFunc = val;}
  733. inline void W3d_Shader_Set_PS2_Param_C(W3dShaderStruct *s, int val) {s->ShaderPreset = val;}
  734. inline void W3d_Shader_Set_PS2_Param_D(W3dShaderStruct *s, int val) {s->pad[0] = val;}
  735. inline int W3d_Shader_Get_PS2_Param_A(const W3dShaderStruct *s) {return (s->ColorMask);}
  736. inline int W3d_Shader_Get_PS2_Param_B(const W3dShaderStruct *s) {return (s->FogFunc);}
  737. inline int W3d_Shader_Get_PS2_Param_C(const W3dShaderStruct *s) {return (s->ShaderPreset);}
  738. inline int W3d_Shader_Get_PS2_Param_D(const W3dShaderStruct *s) {return (s->pad[0]);}
  739. inline int W3d_Shader_Get_PS2_Param_A(const W3dPS2ShaderStruct *s) {return (s->AParam);}
  740. inline int W3d_Shader_Get_PS2_Param_B(const W3dPS2ShaderStruct *s) {return (s->BParam);}
  741. inline int W3d_Shader_Get_PS2_Param_C(const W3dPS2ShaderStruct *s) {return (s->CParam);}
  742. inline int W3d_Shader_Get_PS2_Param_D(const W3dPS2ShaderStruct *s) {return (s->DParam);}
  743. inline int W3d_Shader_Get_Depth_Compare(const W3dPS2ShaderStruct * s) { return s->DepthCompare; }
  744. inline int W3d_Shader_Get_Depth_Mask(const W3dPS2ShaderStruct * s) { return s->DepthMask; }
  745. inline int W3d_Shader_Get_Pri_Gradient(const W3dPS2ShaderStruct * s) { return s->PriGradient; }
  746. inline int W3d_Shader_Get_Texturing(const W3dPS2ShaderStruct * s) { return s->Texturing; }
  747. inline int W3d_Shader_Get_Alpha_Test(const W3dPS2ShaderStruct * s) { return s->AlphaTest; }
  748. inline int W3d_Shader_Get_Depth_Compare(const W3dShaderStruct * s) { return s->DepthCompare; }
  749. inline int W3d_Shader_Get_Depth_Mask(const W3dShaderStruct * s) { return s->DepthMask; }
  750. inline int W3d_Shader_Get_Dest_Blend_Func(const W3dShaderStruct * s) { return s->DestBlend; }
  751. inline int W3d_Shader_Get_Pri_Gradient(const W3dShaderStruct * s) { return s->PriGradient; }
  752. inline int W3d_Shader_Get_Sec_Gradient(const W3dShaderStruct * s) { return s->SecGradient; }
  753. inline int W3d_Shader_Get_Src_Blend_Func(const W3dShaderStruct * s) { return s->SrcBlend; }
  754. inline int W3d_Shader_Get_Texturing(const W3dShaderStruct * s) { return s->Texturing; }
  755. inline int W3d_Shader_Get_Detail_Color_Func(const W3dShaderStruct * s) { return s->DetailColorFunc; }
  756. inline int W3d_Shader_Get_Detail_Alpha_Func(const W3dShaderStruct * s) { return s->DetailAlphaFunc; }
  757. inline int W3d_Shader_Get_Alpha_Test(const W3dShaderStruct * s) { return s->AlphaTest; }
  758. inline int W3d_Shader_Get_Post_Detail_Color_Func(const W3dShaderStruct * s) { return s->PostDetailColorFunc; }
  759. inline int W3d_Shader_Get_Post_Detail_Alpha_Func(const W3dShaderStruct * s) { return s->PostDetailAlphaFunc; }
  760. /////////////////////////////////////////////////////////////////////////////////////////////
  761. // Texture Animation parameters
  762. // May occur inside a texture chunk if its needed
  763. /////////////////////////////////////////////////////////////////////////////////////////////
  764. #define W3DTEXTURE_PUBLISH 0x0001 // this texture should be "published" (indirected so its changeable in code)
  765. #define W3DTEXTURE_RESIZE_OBSOLETE 0x0002 // this texture should be resizeable (OBSOLETE!!!)
  766. #define W3DTEXTURE_NO_LOD 0x0004 // this texture should not have any LOD (mipmapping or resizing)
  767. #define W3DTEXTURE_CLAMP_U 0x0008 // this texture should be clamped on U
  768. #define W3DTEXTURE_CLAMP_V 0x0010 // this texture should be clamped on V
  769. #define W3DTEXTURE_ALPHA_BITMAP 0x0020 // this texture's alpha channel should be collapsed to one bit
  770. // Specify desired no. of mip-levels to be generated.
  771. #define W3DTEXTURE_MIP_LEVELS_MASK 0x00c0
  772. #define W3DTEXTURE_MIP_LEVELS_ALL 0x0000 // generate all mip-levels
  773. #define W3DTEXTURE_MIP_LEVELS_2 0x0040 // generate up to 2 mip-levels (NOTE: use W3DTEXTURE_NO_LOD to generate just 1 mip-level)
  774. #define W3DTEXTURE_MIP_LEVELS_3 0x0080 // generate up to 3 mip-levels
  775. #define W3DTEXTURE_MIP_LEVELS_4 0x00c0 // generate up to 4 mip-levels
  776. // Hints to describe the intended use of the various passes / stages
  777. // This will go into the high byte of Attributes.
  778. #define W3DTEXTURE_HINT_SHIFT 8 // number of bits to shift up
  779. #define W3DTEXTURE_HINT_MASK 0x0000ff00 // mask for shifted hint value
  780. #define W3DTEXTURE_HINT_BASE 0x0000 // base texture
  781. #define W3DTEXTURE_HINT_EMISSIVE 0x0100 // emissive map
  782. #define W3DTEXTURE_HINT_ENVIRONMENT 0x0200 // environment/reflection map
  783. #define W3DTEXTURE_HINT_SHINY_MASK 0x0300 // shinyness mask map
  784. #define W3DTEXTURE_TYPE_MASK 0x1000
  785. #define W3DTEXTURE_TYPE_COLORMAP 0x0000 // Color map.
  786. #define W3DTEXTURE_TYPE_BUMPMAP 0x1000 // Grayscale heightmap (to be converted to bumpmap).
  787. // Animation types
  788. #define W3DTEXTURE_ANIM_LOOP 0x0000
  789. #define W3DTEXTURE_ANIM_PINGPONG 0x0001
  790. #define W3DTEXTURE_ANIM_ONCE 0x0002
  791. #define W3DTEXTURE_ANIM_MANUAL 0x0003
  792. struct W3dTextureInfoStruct
  793. {
  794. W3dTextureInfoStruct(void) {}
  795. uint16 Attributes; // flags for this texture
  796. uint16 AnimType; // animation logic
  797. uint32 FrameCount; // Number of frames (1 if not animated)
  798. float32 FrameRate; // Frame rate, frames per second in floating point
  799. };
  800. /////////////////////////////////////////////////////////////////////////////////////////////
  801. // A triangle, occurs inside the W3D_CHUNK_TRIANGLES chunk
  802. // This was introduced with version 3.0 of the file format
  803. /////////////////////////////////////////////////////////////////////////////////////////////
  804. struct W3dTriStruct
  805. {
  806. uint32 Vindex[3]; // vertex,vnormal,texcoord,color indices
  807. uint32 Attributes; // attributes bits
  808. W3dVectorStruct Normal; // plane normal
  809. float32 Dist; // plane distance
  810. };
  811. /////////////////////////////////////////////////////////////////////////////////////////////
  812. // Flags for the Triangle Attributes member
  813. /////////////////////////////////////////////////////////////////////////////////////////////
  814. typedef enum
  815. {
  816. SURFACE_TYPE_LIGHT_METAL = 0,
  817. SURFACE_TYPE_HEAVY_METAL,
  818. SURFACE_TYPE_WATER,
  819. SURFACE_TYPE_SAND,
  820. SURFACE_TYPE_DIRT,
  821. SURFACE_TYPE_MUD,
  822. SURFACE_TYPE_GRASS,
  823. SURFACE_TYPE_WOOD,
  824. SURFACE_TYPE_CONCRETE,
  825. SURFACE_TYPE_FLESH,
  826. SURFACE_TYPE_ROCK,
  827. SURFACE_TYPE_SNOW,
  828. SURFACE_TYPE_ICE,
  829. SURFACE_TYPE_DEFAULT,
  830. SURFACE_TYPE_GLASS,
  831. SURFACE_TYPE_CLOTH,
  832. SURFACE_TYPE_TIBERIUM_FIELD,
  833. SURFACE_TYPE_FOLIAGE_PERMEABLE,
  834. SURFACE_TYPE_GLASS_PERMEABLE,
  835. SURFACE_TYPE_ICE_PERMEABLE,
  836. SURFACE_TYPE_CLOTH_PERMEABLE,
  837. SURFACE_TYPE_ELECTRICAL,
  838. SURFACE_TYPE_FLAMMABLE,
  839. SURFACE_TYPE_STEAM,
  840. SURFACE_TYPE_ELECTRICAL_PERMEABLE,
  841. SURFACE_TYPE_FLAMMABLE_PERMEABLE,
  842. SURFACE_TYPE_STEAM_PERMEABLE,
  843. SURFACE_TYPE_WATER_PERMEABLE,
  844. SURFACE_TYPE_TIBERIUM_WATER,
  845. SURFACE_TYPE_TIBERIUM_WATER_PERMEABLE,
  846. SURFACE_TYPE_UNDERWATER_DIRT,
  847. SURFACE_TYPE_UNDERWATER_TIBERIUM_DIRT,
  848. SURFACE_TYPE_MAX // NOTE: if you add a surface type, add it to the SurfaceEffects.INI file!
  849. } W3D_SURFACE_TYPES;
  850. const char * const SURFACE_TYPE_STRINGS[SURFACE_TYPE_MAX] =
  851. {
  852. "Light Metal",
  853. "Heavy Metal",
  854. "Water",
  855. "Sand",
  856. "Dirt",
  857. "Mud",
  858. "Grass",
  859. "Wood",
  860. "Concrete",
  861. "Flesh",
  862. "Rock",
  863. "Snow",
  864. "Ice",
  865. "Default",
  866. "Glass",
  867. "Cloth",
  868. "Tiberium Field",
  869. "Foliage Permeable",
  870. "Glass Permeable",
  871. "Ice Permeable",
  872. "Cloth Permeable",
  873. "Electrical",
  874. "Electrical Permeable",
  875. "Flammable",
  876. "Flammable Permeable",
  877. "Steam",
  878. "Steam Permeable",
  879. "Water Permeable",
  880. "Tiberium Water",
  881. "Tiberium Water Permeable",
  882. "Underwater Dirt",
  883. "Underwater Tiberium Dirt",
  884. };
  885. /////////////////////////////////////////////////////////////////////////////////////////////
  886. // Flags for the Mesh Attributes member
  887. /////////////////////////////////////////////////////////////////////////////////////////////
  888. #define W3D_MESH_FLAG_NONE 0x00000000 // plain ole normal mesh
  889. #define W3D_MESH_FLAG_COLLISION_BOX 0x00000001 // (obsolete as of 4.1) mesh is a collision box (should be 8 verts, should be hidden, etc)
  890. #define W3D_MESH_FLAG_SKIN 0x00000002 // (obsolete as of 4.1) skin mesh
  891. #define W3D_MESH_FLAG_SHADOW 0x00000004 // (obsolete as of 4.1) intended to be projected as a shadow
  892. #define W3D_MESH_FLAG_ALIGNED 0x00000008 // (obsolete as of 4.1) always aligns with camera
  893. #define W3D_MESH_FLAG_COLLISION_TYPE_MASK 0x00000FF0 // mask for the collision type bits
  894. #define W3D_MESH_FLAG_COLLISION_TYPE_SHIFT 4 // shifting to get to the collision type bits
  895. #define W3D_MESH_FLAG_COLLISION_TYPE_PHYSICAL 0x00000010 // physical collisions
  896. #define W3D_MESH_FLAG_COLLISION_TYPE_PROJECTILE 0x00000020 // projectiles (rays) collide with this
  897. #define W3D_MESH_FLAG_COLLISION_TYPE_VIS 0x00000040 // vis rays collide with this mesh
  898. #define W3D_MESH_FLAG_COLLISION_TYPE_CAMERA 0x00000080 // camera rays/boxes collide with this mesh
  899. #define W3D_MESH_FLAG_COLLISION_TYPE_VEHICLE 0x00000100 // vehicles collide with this mesh (and with physical collision meshes)
  900. #define W3D_MESH_FLAG_HIDDEN 0x00001000 // this mesh is hidden by default
  901. #define W3D_MESH_FLAG_TWO_SIDED 0x00002000 // render both sides of this mesh
  902. #define OBSOLETE_W3D_MESH_FLAG_LIGHTMAPPED 0x00004000 // obsolete lightmapped mesh
  903. // NOTE: retained for backwards compatibility - use W3D_MESH_FLAG_PRELIT_* instead.
  904. #define W3D_MESH_FLAG_CAST_SHADOW 0x00008000 // this mesh casts shadows
  905. #define W3D_MESH_FLAG_GEOMETRY_TYPE_MASK 0x00FF0000 // (introduced with 4.1)
  906. #define W3D_MESH_FLAG_GEOMETRY_TYPE_NORMAL 0x00000000 // (4.1+) normal mesh geometry
  907. #define W3D_MESH_FLAG_GEOMETRY_TYPE_CAMERA_ALIGNED 0x00010000 // (4.1+) camera aligned mesh
  908. #define W3D_MESH_FLAG_GEOMETRY_TYPE_SKIN 0x00020000 // (4.1+) skin mesh
  909. #define OBSOLETE_W3D_MESH_FLAG_GEOMETRY_TYPE_SHADOW 0x00030000 // (4.1+) shadow mesh OBSOLETE!
  910. #define W3D_MESH_FLAG_GEOMETRY_TYPE_AABOX 0x00040000 // (4.1+) aabox OBSOLETE!
  911. #define W3D_MESH_FLAG_GEOMETRY_TYPE_OBBOX 0x00050000 // (4.1+) obbox OBSOLETE!
  912. #define W3D_MESH_FLAG_GEOMETRY_TYPE_CAMERA_ORIENTED 0x00060000 // (4.1+) camera oriented mesh (points _towards_ camera)
  913. #define W3D_MESH_FLAG_PRELIT_MASK 0x0F000000 // (4.2+)
  914. #define W3D_MESH_FLAG_PRELIT_UNLIT 0x01000000 // mesh contains an unlit material chunk wrapper
  915. #define W3D_MESH_FLAG_PRELIT_VERTEX 0x02000000 // mesh contains a precalculated vertex-lit material chunk wrapper
  916. #define W3D_MESH_FLAG_PRELIT_LIGHTMAP_MULTI_PASS 0x04000000 // mesh contains a precalculated multi-pass lightmapped material chunk wrapper
  917. #define W3D_MESH_FLAG_PRELIT_LIGHTMAP_MULTI_TEXTURE 0x08000000 // mesh contains a precalculated multi-texture lightmapped material chunk wrapper
  918. #define W3D_MESH_FLAG_SHATTERABLE 0x10000000 // this mesh is shatterable.
  919. #define W3D_MESH_FLAG_NPATCHABLE 0x20000000 // it is ok to NPatch this mesh
  920. /********************************************************************************
  921. Meshes
  922. Version 3 Mesh Header, trimmed out some of the junk that was in the
  923. previous versions.
  924. ********************************************************************************/
  925. #define W3D_CURRENT_MESH_VERSION W3D_MAKE_VERSION(4,2)
  926. #define W3D_VERTEX_CHANNEL_LOCATION 0x00000001 // object-space location of the vertex
  927. #define W3D_VERTEX_CHANNEL_NORMAL 0x00000002 // object-space normal for the vertex
  928. #define W3D_VERTEX_CHANNEL_TEXCOORD 0x00000004 // texture coordinate
  929. #define W3D_VERTEX_CHANNEL_COLOR 0x00000008 // vertex color
  930. #define W3D_VERTEX_CHANNEL_BONEID 0x00000010 // per-vertex bone id for skins
  931. #define W3D_FACE_CHANNEL_FACE 0x00000001 // basic face info, W3dTriStruct...
  932. // boundary values for W3dMeshHeaderStruct::SortLevel
  933. #define SORT_LEVEL_NONE 0
  934. #define MAX_SORT_LEVEL 32
  935. #define SORT_LEVEL_BIN1 20
  936. #define SORT_LEVEL_BIN2 15
  937. #define SORT_LEVEL_BIN3 10
  938. struct W3dMeshHeader3Struct
  939. {
  940. uint32 Version;
  941. uint32 Attributes;
  942. char MeshName[W3D_NAME_LEN];
  943. char ContainerName[W3D_NAME_LEN];
  944. //
  945. // Counts, these can be regarded as an inventory of what is to come in the file.
  946. //
  947. uint32 NumTris; // number of triangles
  948. uint32 NumVertices; // number of unique vertices
  949. uint32 NumMaterials; // number of unique materials
  950. uint32 NumDamageStages; // number of damage offset chunks
  951. sint32 SortLevel; // static sorting level of this mesh
  952. uint32 PrelitVersion; // mesh generated by this version of Lightmap Tool
  953. uint32 FutureCounts[1]; // future counts
  954. uint32 VertexChannels; // bits for presence of types of per-vertex info
  955. uint32 FaceChannels; // bits for presence of types of per-face info
  956. //
  957. // Bounding volumes
  958. //
  959. W3dVectorStruct Min; // Min corner of the bounding box
  960. W3dVectorStruct Max; // Max corner of the bounding box
  961. W3dVectorStruct SphCenter; // Center of bounding sphere
  962. float32 SphRadius; // Bounding sphere radius
  963. };
  964. //
  965. // Vertex Influences. For "skins" each vertex can be associated with a
  966. // different bone.
  967. //
  968. struct W3dVertInfStruct
  969. {
  970. uint16 BoneIdx;
  971. uint8 Pad[6];
  972. };
  973. //
  974. // Deform information. Each mesh can have sets of keyframes of
  975. // deform info associated with it.
  976. //
  977. struct W3dMeshDeform
  978. {
  979. uint32 SetCount;
  980. uint32 AlphaPasses;
  981. uint32 reserved[3];
  982. };
  983. //
  984. // Deform set information. Each set is made up of a series
  985. // of keyframes.
  986. //
  987. struct W3dDeformSetInfo
  988. {
  989. uint32 KeyframeCount;
  990. uint32 flags;
  991. uint32 reserved[1];
  992. };
  993. #define W3D_DEFORM_SET_MANUAL_DEFORM 0x00000001 // set is isn't applied during sphere or point tests.
  994. //
  995. // Deform keyframe information. Each keyframe is made up of
  996. // a set of per-vert deform data.
  997. //
  998. struct W3dDeformKeyframeInfo
  999. {
  1000. float32 DeformPercent;
  1001. uint32 DataCount;
  1002. uint32 reserved[2];
  1003. };
  1004. //
  1005. // Deform data. Contains deform information about a vertex
  1006. // in the mesh.
  1007. //
  1008. struct W3dDeformData
  1009. {
  1010. uint32 VertexIndex;
  1011. W3dVectorStruct Position;
  1012. W3dRGBAStruct Color;
  1013. uint32 reserved[2];
  1014. };
  1015. //
  1016. // AABTree header. Each mesh can have an associated Axis-Aligned-Bounding-Box tree
  1017. // which is used for collision detection and certain rendering algorithms (like
  1018. // texture projection.
  1019. //
  1020. struct W3dMeshAABTreeHeader
  1021. {
  1022. uint32 NodeCount;
  1023. uint32 PolyCount;
  1024. uint32 Padding[6];
  1025. };
  1026. //
  1027. // AABTree Node. This is a node in the AABTree.
  1028. // If the MSB of FrontOrPoly0 is 1, then the node is a leaf and contains Poly0 and PolyCount
  1029. // else, the node is not a leaf and contains indices to its front and back children. This matches
  1030. // the format used by AABTreeClass in WW3D.
  1031. //
  1032. struct W3dMeshAABTreeNode
  1033. {
  1034. W3dVectorStruct Min; // min corner of the box
  1035. W3dVectorStruct Max; // max corner of the box
  1036. uint32 FrontOrPoly0; // index of the front child or poly0 (if MSB is set, then leaf and poly0 is valid)
  1037. uint32 BackOrPolyCount; // index of the back child or polycount
  1038. };
  1039. /********************************************************************************
  1040. WHT ( Westwood Hierarchy Tree )
  1041. A hierarchy tree defines a set of coordinate systems which are connected
  1042. hierarchically. The header defines the name, number of pivots, etc.
  1043. The pivots chunk will contain a W3dPivotStructs for each node in the
  1044. tree.
  1045. The W3dPivotFixupStruct contains a transform for each MAX coordinate
  1046. system and our version of that same coordinate system (bone). It is
  1047. needed when the user exports the base pose using "Translation Only".
  1048. These are the matrices which go from the MAX rotated coordinate systems
  1049. to a system which is unrotated in the base pose. These transformations
  1050. are needed when exporting a hierarchy animation with the given hierarchy
  1051. tree file.
  1052. Another explanation of these kludgy "fixup" matrices:
  1053. What are the "fixup" matrices? These are the transforms which
  1054. were applied to the base pose when the user wanted to force the
  1055. base pose to use only matrices with certain properties. For
  1056. example, if we wanted the base pose to use translations only,
  1057. the fixup transform for each node is a transform which when
  1058. multiplied by the real node's world transform, yeilds a pure
  1059. translation matrix. Fixup matrices are used in the mesh
  1060. exporter since all vertices must be transformed by their inverses
  1061. in order to make things work. They also show up in the animation
  1062. exporter because they are needed to make the animation work with
  1063. the new base pose.
  1064. ********************************************************************************/
  1065. #define W3D_CURRENT_HTREE_VERSION W3D_MAKE_VERSION(4,1)
  1066. struct W3dHierarchyStruct
  1067. {
  1068. uint32 Version;
  1069. char Name[W3D_NAME_LEN]; // Name of the hierarchy
  1070. uint32 NumPivots;
  1071. W3dVectorStruct Center;
  1072. };
  1073. struct W3dPivotStruct
  1074. {
  1075. char Name[W3D_NAME_LEN]; // Name of the node (UR_ARM, LR_LEG, TORSO, etc)
  1076. uint32 ParentIdx; // 0xffffffff = root pivot; no parent
  1077. W3dVectorStruct Translation; // translation to pivot point
  1078. W3dVectorStruct EulerAngles; // orientation of the pivot point
  1079. W3dQuaternionStruct Rotation; // orientation of the pivot point
  1080. };
  1081. struct W3dPivotFixupStruct
  1082. {
  1083. float32 TM[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1084. };
  1085. /********************************************************************************
  1086. WHA (Westwood Hierarchy Animation)
  1087. A Hierarchy Animation is a set of data defining deltas from the base
  1088. position of a hierarchy tree. Translation and Rotation channels can be
  1089. attached to any node of the hierarchy tree which the animation is
  1090. associated with.
  1091. ********************************************************************************/
  1092. #define W3D_CURRENT_HANIM_VERSION W3D_MAKE_VERSION(4,1)
  1093. #define W3D_CURRENT_COMPRESSED_HANIM_VERSION W3D_MAKE_VERSION(0,1)
  1094. #define W3D_CURRENT_MORPH_HANIM_VERSION W3D_MAKE_VERSION(0,1)
  1095. struct W3dAnimHeaderStruct
  1096. {
  1097. uint32 Version;
  1098. char Name[W3D_NAME_LEN];
  1099. char HierarchyName[W3D_NAME_LEN];
  1100. uint32 NumFrames;
  1101. uint32 FrameRate;
  1102. };
  1103. struct W3dCompressedAnimHeaderStruct
  1104. {
  1105. uint32 Version;
  1106. char Name[W3D_NAME_LEN];
  1107. char HierarchyName[W3D_NAME_LEN];
  1108. uint32 NumFrames;
  1109. uint16 FrameRate;
  1110. uint16 Flavor;
  1111. };
  1112. enum
  1113. {
  1114. ANIM_CHANNEL_X = 0,
  1115. ANIM_CHANNEL_Y,
  1116. ANIM_CHANNEL_Z,
  1117. ANIM_CHANNEL_XR,
  1118. ANIM_CHANNEL_YR,
  1119. ANIM_CHANNEL_ZR,
  1120. ANIM_CHANNEL_Q,
  1121. ANIM_CHANNEL_TIMECODED_X,
  1122. ANIM_CHANNEL_TIMECODED_Y,
  1123. ANIM_CHANNEL_TIMECODED_Z,
  1124. ANIM_CHANNEL_TIMECODED_Q,
  1125. ANIM_CHANNEL_ADAPTIVEDELTA_X,
  1126. ANIM_CHANNEL_ADAPTIVEDELTA_Y,
  1127. ANIM_CHANNEL_ADAPTIVEDELTA_Z,
  1128. ANIM_CHANNEL_ADAPTIVEDELTA_Q,
  1129. };
  1130. //
  1131. // Flavor Enumerations
  1132. //
  1133. enum
  1134. {
  1135. ANIM_FLAVOR_TIMECODED = 0,
  1136. ANIM_FLAVOR_ADAPTIVE_DELTA,
  1137. ANIM_FLAVOR_VALID
  1138. };
  1139. // Begin Classic Structures
  1140. struct W3dAnimChannelStruct
  1141. {
  1142. uint16 FirstFrame;
  1143. uint16 LastFrame;
  1144. uint16 VectorLen; // length of each vector in this channel
  1145. uint16 Flags; // channel type.
  1146. uint16 Pivot; // pivot affected by this channel
  1147. uint16 pad;
  1148. float32 Data[1]; // will be (LastFrame - FirstFrame + 1) * VectorLen long
  1149. };
  1150. enum
  1151. {
  1152. BIT_CHANNEL_VIS = 0, // turn meshes on and off depending on anim frame.
  1153. BIT_CHANNEL_TIMECODED_VIS,
  1154. };
  1155. struct W3dBitChannelStruct
  1156. {
  1157. uint16 FirstFrame; // all frames outside "First" and "Last" are assumed = DefaultVal
  1158. uint16 LastFrame;
  1159. uint16 Flags; // channel type.
  1160. uint16 Pivot; // pivot affected by this channel
  1161. uint8 DefaultVal; // default state when outside valid range.
  1162. uint8 Data[1]; // will be (LastFrame - FirstFrame + 1) / 8 long
  1163. };
  1164. // End Classic Structures
  1165. // Begin Time Coded Structures
  1166. // A time code is a uint32 that prefixes each vector
  1167. // the MSB is used to indicate a binary (non interpolated) movement
  1168. #define W3D_TIMECODED_BINARY_MOVEMENT_FLAG 0x80000000
  1169. struct W3dTimeCodedAnimChannelStruct
  1170. {
  1171. uint32 NumTimeCodes; // number of time coded entries
  1172. uint16 Pivot; // pivot affected by this channel
  1173. uint8 VectorLen; // length of each vector in this channel
  1174. uint8 Flags; // channel type.
  1175. uint32 Data[1]; // will be (NumTimeCodes * ((VectorLen * sizeof(uint32)) + sizeof(uint32)))
  1176. };
  1177. // The bit channel is encoded right into the MSB of each time code
  1178. #define W3D_TIMECODED_BIT_MASK 0x80000000
  1179. struct W3dTimeCodedBitChannelStruct
  1180. {
  1181. uint32 NumTimeCodes; // number of time coded entries
  1182. uint16 Pivot; // pivot affected by this channel
  1183. uint8 Flags; // channel type.
  1184. uint8 DefaultVal; // default state when outside valid range.
  1185. uint32 Data[1]; // will be (NumTimeCodes * sizeof(uint32))
  1186. };
  1187. // End Time Coded Structures
  1188. // Begin AdaptiveDelta Structures
  1189. struct W3dAdaptiveDeltaAnimChannelStruct
  1190. {
  1191. uint32 NumFrames; // number of frames of animation
  1192. uint16 Pivot; // pivot effected by this channel
  1193. uint8 VectorLen; // num Channels
  1194. uint8 Flags; // channel type
  1195. float Scale; // Filter Table Scale
  1196. uint32 Data[1]; // OpCode Data Stream
  1197. };
  1198. // End AdaptiveDelta Structures
  1199. /********************************************************************************
  1200. HMorphAnimClass
  1201. This is an animation format which describes morphs between poses in another
  1202. animation. It is used for Renegade's facial animation system. There is
  1203. a normal anim which defines the pose for each phoneme and then a "Morph Anim"
  1204. which defines the transitions between phonemes over time. In addition there
  1205. is the concept of multiple morph channels in a morph anim. Each "channel"
  1206. controls a set of pivots in the skeleton and has its own set of morph keys
  1207. and poses. This lets us have one set of poses for expressions and another
  1208. for phonemes (a bone is only moved in one or the other anims though)
  1209. The chunks used to describe a "morph" anim are as follows:
  1210. W3D_CHUNK_MORPH_ANIMATION =0x000002C0, // wrapper for the entire anim
  1211. W3D_CHUNK_MORPHANIM_HEADER, // W3dMorphAnimHeaderStruct describes playback rate, number of frames, and type of compression
  1212. W3D_CHUNK_MORPHANIM_CHANNEL, // wrapper for a channel
  1213. W3D_CHUNK_MORPHANIM_POSENAME, // name of the other anim which contains the poses for this morph channel
  1214. W3D_CHUNK_MORPHANIM_KEYDATA, // array of W3dMorphAnimKeyStruct's (use chunk length to determine how many)
  1215. W3D_CHUNK_MORPHANIM_PIVOTCHANNELDATA, // uin32 per pivot in the htree, indicating which channel controls the pivot
  1216. ********************************************************************************/
  1217. struct W3dMorphAnimHeaderStruct
  1218. {
  1219. uint32 Version;
  1220. char Name[W3D_NAME_LEN];
  1221. char HierarchyName[W3D_NAME_LEN];
  1222. uint32 FrameCount;
  1223. float32 FrameRate;
  1224. uint32 ChannelCount;
  1225. };
  1226. struct W3dMorphAnimKeyStruct
  1227. {
  1228. uint32 MorphFrame;
  1229. uint32 PoseFrame;
  1230. };
  1231. /********************************************************************************
  1232. HModel - Hiearchical Model
  1233. A Hierarchy Model is a set of render objects which should be attached to
  1234. bones in a hierarchy tree. There can be multiple objects per node
  1235. in the tree. Or there may be no objects attached to a particular bone.
  1236. (gth) 09/22/2000 - Simplified the HModel file format. The W3DHModelAuxDataStruct
  1237. was un-needed and moved to w3d_obsolete.h. The safe way to parse previous
  1238. and current HModel formats is this:
  1239. - Read in the header from W3D_CHUNK_HMODEL_HEADER
  1240. - Allocate space for 'NumConnections' nodes that will follow
  1241. - Read in the rest of the chunks
  1242. - Create a sub-object for W3D_CHUNK_NODE, W3D_CHUNK_COLLISION_NODE, or
  1243. W3D_CHUNK_SKIN_NODE.
  1244. - Skip the OBSOLETE_W3D_CHUNK_HMODEL_AUX_DATA and OBSOLETE_W3D_CHUNK_SHADOW_NODE
  1245. ********************************************************************************/
  1246. #define W3D_CURRENT_HMODEL_VERSION W3D_MAKE_VERSION(4,2)
  1247. struct W3dHModelHeaderStruct
  1248. {
  1249. uint32 Version;
  1250. char Name[W3D_NAME_LEN]; // Name of this model
  1251. char HierarchyName[W3D_NAME_LEN]; // Name of the hierarchy tree this model uses
  1252. uint16 NumConnections;
  1253. };
  1254. struct W3dHModelNodeStruct
  1255. {
  1256. // Note: the full name of the Render object is expected to be: <HModelName>.<RenderObjName>
  1257. char RenderObjName[W3D_NAME_LEN];
  1258. uint16 PivotIdx;
  1259. };
  1260. /********************************************************************************
  1261. (LODModel - Level-Of-Detail Model)
  1262. An LOD Model is a set of render objects which are interchangeable and
  1263. designed to be different resolution versions of the same object.
  1264. ********************************************************************************/
  1265. struct W3dLODModelHeaderStruct
  1266. {
  1267. uint32 Version;
  1268. char Name[W3D_NAME_LEN]; // Name of this LOD Model
  1269. uint16 NumLODs;
  1270. };
  1271. struct W3dLODStruct
  1272. {
  1273. char RenderObjName[2*W3D_NAME_LEN];
  1274. float32 LODMin; // "artist" inspired switching distances
  1275. float32 LODMax;
  1276. };
  1277. /********************************************************************************
  1278. Collection
  1279. A collection chunk is generated when the user exports a bunch of meshes.
  1280. The collection will be named with the root name of the w3d file and will
  1281. contain a string chunk for the name of each render object in the collection.
  1282. A collection may also contain a "Snap Points" chunk.
  1283. W3D_CHUNK_COLLECTION
  1284. W3D_CHUNK_COLLECTION_HEADER
  1285. W3D_CHUNK_SNAP_POINTS
  1286. W3D_CHUNK_COLLECTION_OBJ_NAME
  1287. W3D_CHUNK_COLLECTION_OBJ_NAME
  1288. W3D_CHUNK_COLLECTION_OBJ_NAME
  1289. ...
  1290. ********************************************************************************/
  1291. #define W3D_CURRENT_COLLECTION_VERSION W3D_MAKE_VERSION(4,2)
  1292. struct W3dCollectionHeaderStruct
  1293. {
  1294. uint32 Version;
  1295. char Name[W3D_NAME_LEN];
  1296. uint32 RenderObjectCount;
  1297. uint32 pad[2];
  1298. };
  1299. /*
  1300. ** Placeholder chunks. Also known as "PROXIES". These are used by the Renegade
  1301. ** level editor to instruct the editor to instance a particular named object
  1302. */
  1303. #define W3D_CURRENT_PLACEHOLDER_VERSION W3D_MAKE_VERSION(1,0)
  1304. //
  1305. // Note: This structure is follwed directly by an array of char's 'name_len' in length
  1306. // which specify the name of the placeholder object in our Commando-level editor.
  1307. //
  1308. struct W3dPlaceholderStruct
  1309. {
  1310. uint32 version;
  1311. float32 transform[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1312. uint32 name_len;
  1313. };
  1314. /*
  1315. ** Transform chunks. These chunks refer to other W3D files which should be transformed by
  1316. ** this file. This feature is used to allow user to (for example) lightmap the interior
  1317. ** of a building once and then just transform that into all of our levels that use it.
  1318. */
  1319. #define W3D_CURRENT_TRANSFORM_VERSION W3D_MAKE_VERSION(1,0)
  1320. //
  1321. // Note: This structure is followed directly by an array of char's 'name_len' in length
  1322. // which specifies the name of the file to apply the transform to.
  1323. //
  1324. struct W3dTransformNodeStruct
  1325. {
  1326. uint32 version;
  1327. float32 transform[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1328. uint32 name_len;
  1329. };
  1330. /********************************************************************************
  1331. Lights
  1332. The following structs are used to define lights in the w3d file. Currently
  1333. we have point lights, directional lights, and spot lights.
  1334. ********************************************************************************/
  1335. #define W3D_CURRENT_LIGHT_VERSION W3D_MAKE_VERSION(1,0)
  1336. #define W3D_LIGHT_ATTRIBUTE_TYPE_MASK 0x000000FF
  1337. #define W3D_LIGHT_ATTRIBUTE_POINT 0x00000001
  1338. #define W3D_LIGHT_ATTRIBUTE_DIRECTIONAL 0x00000002
  1339. #define W3D_LIGHT_ATTRIBUTE_SPOT 0x00000003
  1340. #define W3D_LIGHT_ATTRIBUTE_CAST_SHADOWS 0x00000100
  1341. struct W3dLightStruct
  1342. {
  1343. uint32 Attributes;
  1344. uint32 Unused; // Old exclusion bit deprecated
  1345. W3dRGBStruct Ambient;
  1346. W3dRGBStruct Diffuse;
  1347. W3dRGBStruct Specular;
  1348. float32 Intensity;
  1349. };
  1350. struct W3dSpotLightStruct
  1351. {
  1352. W3dVectorStruct SpotDirection;
  1353. float32 SpotAngle;
  1354. float32 SpotExponent;
  1355. };
  1356. struct W3dLightAttenuationStruct
  1357. {
  1358. float32 Start;
  1359. float32 End;
  1360. };
  1361. struct W3dLightTransformStruct
  1362. {
  1363. float32 Transform [3][4];
  1364. };
  1365. /********************************************************************************
  1366. Particle emitters
  1367. The following structs are used to define emitters in the w3d file.
  1368. ********************************************************************************/
  1369. #define W3D_CURRENT_EMITTER_VERSION 0x00020000
  1370. //
  1371. // This enum contains valid defines for the Type field
  1372. // of the W3dEmitterUserInfoStruct. The programmer
  1373. // can add entries here that their specific loader
  1374. // can switch on to determine what type the emitter is.
  1375. //
  1376. // NOTE: Please add a string the the EMITTER_TYPE_NAMES
  1377. // array when you add an entry to the enum.
  1378. //
  1379. enum
  1380. {
  1381. EMITTER_TYPEID_DEFAULT = 0,
  1382. EMITTER_TYPEID_COUNT
  1383. };
  1384. //
  1385. // The definition of this string array can be found in
  1386. // Part_Ldr.cpp. Please update this array accordingly.
  1387. //
  1388. extern const char *EMITTER_TYPE_NAMES[EMITTER_TYPEID_COUNT];
  1389. struct W3dEmitterHeaderStruct
  1390. {
  1391. uint32 Version;
  1392. char Name[W3D_NAME_LEN];
  1393. };
  1394. struct W3dEmitterUserInfoStruct
  1395. {
  1396. uint32 Type; // One of the EMITTER_TYPEID_ enum's defined above
  1397. uint32 SizeofStringParam; // Size (in bytes) of the following string data
  1398. char StringParam[1]; // Array of bytes. Where "count = SizeofStringParam"
  1399. };
  1400. struct W3dEmitterInfoStruct
  1401. {
  1402. char TextureFilename[260];
  1403. float32 StartSize;
  1404. float32 EndSize;
  1405. float32 Lifetime;
  1406. float32 EmissionRate;
  1407. float32 MaxEmissions;
  1408. float32 VelocityRandom;
  1409. float32 PositionRandom;
  1410. float32 FadeTime;
  1411. float32 Gravity;
  1412. float32 Elasticity;
  1413. W3dVectorStruct Velocity;
  1414. W3dVectorStruct Acceleration;
  1415. W3dRGBAStruct StartColor;
  1416. W3dRGBAStruct EndColor;
  1417. };
  1418. struct W3dVolumeRandomizerStruct
  1419. {
  1420. uint32 ClassID;
  1421. float32 Value1;
  1422. float32 Value2;
  1423. float32 Value3;
  1424. uint32 reserved[4];
  1425. };
  1426. #define W3D_EMITTER_RENDER_MODE_TRI_PARTICLES 0
  1427. #define W3D_EMITTER_RENDER_MODE_QUAD_PARTICLES 1
  1428. #define W3D_EMITTER_RENDER_MODE_LINE 2
  1429. #define W3D_EMITTER_RENDER_MODE_LINEGRP_TETRA 3
  1430. #define W3D_EMITTER_RENDER_MODE_LINEGRP_PRISM 4
  1431. #define W3D_EMITTER_FRAME_MODE_1x1 0
  1432. #define W3D_EMITTER_FRAME_MODE_2x2 1
  1433. #define W3D_EMITTER_FRAME_MODE_4x4 2
  1434. #define W3D_EMITTER_FRAME_MODE_8x8 3
  1435. #define W3D_EMITTER_FRAME_MODE_16x16 4
  1436. struct W3dEmitterInfoStructV2
  1437. {
  1438. uint32 BurstSize;
  1439. W3dVolumeRandomizerStruct CreationVolume;
  1440. W3dVolumeRandomizerStruct VelRandom;
  1441. float32 OutwardVel;
  1442. float32 VelInherit;
  1443. W3dShaderStruct Shader;
  1444. uint32 RenderMode; // render as particles or lines?
  1445. uint32 FrameMode; // chop the texture into a grid of smaller squares?
  1446. uint32 reserved[6];
  1447. };
  1448. // W3D_CHUNK_EMITTER_PROPS
  1449. // Contains a W3dEmitterPropertyStruct followed by a number of color keyframes,
  1450. // opacity keyframes, and size keyframes
  1451. struct W3dEmitterPropertyStruct
  1452. {
  1453. uint32 ColorKeyframes;
  1454. uint32 OpacityKeyframes;
  1455. uint32 SizeKeyframes;
  1456. W3dRGBAStruct ColorRandom;
  1457. float32 OpacityRandom;
  1458. float32 SizeRandom;
  1459. uint32 reserved[4];
  1460. };
  1461. struct W3dEmitterColorKeyframeStruct
  1462. {
  1463. float32 Time;
  1464. W3dRGBAStruct Color;
  1465. };
  1466. struct W3dEmitterOpacityKeyframeStruct
  1467. {
  1468. float32 Time;
  1469. float32 Opacity;
  1470. };
  1471. struct W3dEmitterSizeKeyframeStruct
  1472. {
  1473. float32 Time;
  1474. float32 Size;
  1475. };
  1476. // W3D_CHUNK_EMITTER_ROTATION_KEYFRAMES
  1477. // Contains a W3dEmitterRotationHeaderStruct followed by a number of
  1478. // rotational velocity keyframes.
  1479. struct W3dEmitterRotationHeaderStruct
  1480. {
  1481. uint32 KeyframeCount;
  1482. float32 Random; // random initial rotational velocity (rotations/sec)
  1483. float32 OrientationRandom; // random initial orientation (rotations, 1.0=360deg)
  1484. uint32 Reserved[1];
  1485. };
  1486. struct W3dEmitterRotationKeyframeStruct
  1487. {
  1488. float32 Time;
  1489. float32 Rotation; // rotational velocity in rotations/sec
  1490. };
  1491. // W3D_CHUNK_EMITTER_FRAME_KEYFRAMES
  1492. // Contains a W3dEmitterFrameHeaderStruct followed by a number of
  1493. // frame keyframes (sub-texture indexing)
  1494. struct W3dEmitterFrameHeaderStruct
  1495. {
  1496. uint32 KeyframeCount;
  1497. float32 Random;
  1498. uint32 Reserved[2];
  1499. };
  1500. struct W3dEmitterFrameKeyframeStruct
  1501. {
  1502. float32 Time;
  1503. float32 Frame;
  1504. };
  1505. // W3D_CHUNK_EMITTER_BLUR_TIME_KEYFRAMES
  1506. // Contains a W3dEmitterFrameHeaderStruct followed by a number of
  1507. // frame keyframes (sub-texture indexing)
  1508. struct W3dEmitterBlurTimeHeaderStruct
  1509. {
  1510. uint32 KeyframeCount;
  1511. float32 Random;
  1512. uint32 Reserved[1];
  1513. };
  1514. struct W3dEmitterBlurTimeKeyframeStruct
  1515. {
  1516. float32 Time;
  1517. float32 BlurTime;
  1518. };
  1519. // W3D_CHUNK_EMITTER_LINE_PROPERTIES
  1520. // Contains a W3dEmitterLinePropertiesStruct.
  1521. // Emiter Line Flags (used in the Flags field of W3dEmitterLinePropertiesStruct):
  1522. #define W3D_ELINE_MERGE_INTERSECTIONS 0x00000001 // Merge intersections
  1523. #define W3D_ELINE_FREEZE_RANDOM 0x00000002 // Freeze random (note: offsets are in camera space)
  1524. #define W3D_ELINE_DISABLE_SORTING 0x00000004 // Disable sorting (even if shader has alpha-blending)
  1525. #define W3D_ELINE_END_CAPS 0x00000008 // Draw end caps on the line
  1526. #define W3D_ELINE_TEXTURE_MAP_MODE_MASK 0xFF000000 // Must cover all possible TextureMapMode values
  1527. #define W3D_ELINE_TEXTURE_MAP_MODE_OFFSET 24 // By how many bits do I need to shift the texture mapping mode?
  1528. #define W3D_ELINE_UNIFORM_WIDTH_TEXTURE_MAP 0x00000000 // Entire line uses one row of texture (constant V)
  1529. #define W3D_ELINE_UNIFORM_LENGTH_TEXTURE_MAP 0x00000001 // Entire line uses one row of texture stretched length-wise
  1530. #define W3D_ELINE_TILED_TEXTURE_MAP 0x00000002 // Tiled continuously over line
  1531. #define W3D_ELINE_DEFAULT_BITS (W3D_ELINE_MERGE_INTERSECTIONS | (W3D_ELINE_UNIFORM_WIDTH_TEXTURE_MAP << W3D_ELINE_TEXTURE_MAP_MODE_OFFSET))
  1532. struct W3dEmitterLinePropertiesStruct
  1533. {
  1534. uint32 Flags;
  1535. uint32 SubdivisionLevel;
  1536. float32 NoiseAmplitude;
  1537. float32 MergeAbortFactor;
  1538. float32 TextureTileFactor;
  1539. float32 UPerSec;
  1540. float32 VPerSec;
  1541. uint32 Reserved[9];
  1542. };
  1543. /********************************************************************************
  1544. Aggregate objects
  1545. The following structs are used to define aggregates in the w3d file. An
  1546. 'aggregate' is simply a 'shell' that contains references to a hierarchy
  1547. model and subobjects to attach to its bones.
  1548. ********************************************************************************/
  1549. #define W3D_CURRENT_AGGREGATE_VERSION 0x00010003
  1550. const int MESH_PATH_ENTRIES = 15;
  1551. const int MESH_PATH_ENTRY_LEN = (W3D_NAME_LEN * 2);
  1552. struct W3dAggregateHeaderStruct
  1553. {
  1554. uint32 Version;
  1555. char Name[W3D_NAME_LEN];
  1556. };
  1557. struct W3dAggregateInfoStruct
  1558. {
  1559. char BaseModelName[W3D_NAME_LEN*2];
  1560. uint32 SubobjectCount;
  1561. };
  1562. struct W3dAggregateSubobjectStruct
  1563. {
  1564. char SubobjectName[W3D_NAME_LEN*2];
  1565. char BoneName[W3D_NAME_LEN*2];
  1566. };
  1567. //
  1568. // Structures for version 1.1 and newer
  1569. //
  1570. struct W3dTextureReplacerHeaderStruct
  1571. {
  1572. uint32 ReplacedTexturesCount;
  1573. };
  1574. struct W3dTextureReplacerStruct
  1575. {
  1576. char MeshPath[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN];
  1577. char BonePath[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN];
  1578. char OldTextureName[260];
  1579. char NewTextureName[260];
  1580. W3dTextureInfoStruct TextureParams;
  1581. };
  1582. //
  1583. // Flags used in the W3dAggregateMiscInfo structure
  1584. //
  1585. const int W3D_AGGREGATE_FORCE_SUB_OBJ_LOD = 0x00000001;
  1586. //
  1587. // Structures for version 1.2 and newer
  1588. //
  1589. struct W3dAggregateMiscInfo
  1590. {
  1591. uint32 OriginalClassID;
  1592. uint32 Flags;
  1593. uint32 reserved[3];
  1594. };
  1595. /********************************************************************************
  1596. HLod (Hierarchical LOD Model)
  1597. This is a hierarchical model which has multiple arrays of models which can
  1598. be switched for LOD purposes.
  1599. Relevant Chunks:
  1600. ----------------
  1601. W3D_CHUNK_HLOD =0x00000700, // description of an HLod object (see HLodClass)
  1602. W3D_CHUNK_HLOD_HEADER, // general information such as name and version
  1603. W3D_CHUNK_HLOD_LOD_ARRAY, // wrapper around the array of objects for each level of detail
  1604. W3D_CHUNK_HLOD_SUB_OBJECT_ARRAY_HEADER, // info on the objects in this level of detail array
  1605. W3D_CHUNK_HLOD_SUB_OBJECT, // an object in this level of detail array
  1606. W3D_CHUNK_HLOD_AGGREGATE_ARRAY, // array of aggregates, contains W3D_CHUNK_SUB_OBJECT_ARRAY_HEADER and W3D_CHUNK_SUB_OBJECT_ARRAY
  1607. W3D_CHUNK_HLOD_PROXY_ARRAY, // array of proxies, used for application-defined purposes
  1608. An HLOD is the basic hierarchical model format used by W3D. It references
  1609. an HTree for its hierarchical structure and animation data and several arrays
  1610. of sub-objects; one for each LOD in the model. In addition, it can contain
  1611. an array of "aggregates" which are references to external W3D objects to
  1612. be automatically attached into it. And it can have a list of "proxy" objects
  1613. which can be used for application purposes such as instantiating game objects
  1614. at the specified transform.
  1615. ********************************************************************************/
  1616. #define W3D_CURRENT_HLOD_VERSION W3D_MAKE_VERSION(1,0)
  1617. #define NO_MAX_SCREEN_SIZE WWMATH_FLOAT_MAX
  1618. struct W3dHLodHeaderStruct
  1619. {
  1620. uint32 Version;
  1621. uint32 LodCount;
  1622. char Name[W3D_NAME_LEN];
  1623. char HierarchyName[W3D_NAME_LEN]; // name of the hierarchy tree to use (\0 if none)
  1624. };
  1625. struct W3dHLodArrayHeaderStruct
  1626. {
  1627. uint32 ModelCount;
  1628. float32 MaxScreenSize; // if model is bigger than this, switch to higher lod.
  1629. };
  1630. struct W3dHLodSubObjectStruct
  1631. {
  1632. uint32 BoneIndex;
  1633. char Name[W3D_NAME_LEN*2];
  1634. };
  1635. /********************************************************************************
  1636. Collision Boxes
  1637. Collision boxes are meant to be used for, you guessed it, collision detection.
  1638. For this reason, they only contain a minimal amount of rendering information
  1639. (a color).
  1640. Axis Aligned - This is a bounding box which is *always* aligned with the world
  1641. coordinate system. So, the center point is to be transformed by whatever
  1642. transformation matrix is being used but the extents always point down the
  1643. world space x,y, and z axes. (in effect, you are translating the center).
  1644. Oriented - This is an oriented 3D box. It is aligned with the coordinate system
  1645. it is in. So its extents always point along the local coordinate system axes.
  1646. ********************************************************************************/
  1647. #define W3D_BOX_CURRENT_VERSION W3D_MAKE_VERSION(1,0)
  1648. #define W3D_BOX_ATTRIBUTE_ORIENTED 0x00000001
  1649. #define W3D_BOX_ATTRIBUTE_ALIGNED 0x00000002
  1650. #define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_MASK 0x00000FF0 // mask for the collision type bits
  1651. #define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_SHIFT 4 // shifting to get to the collision type bits
  1652. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PHYSICAL 0x00000010 // physical collisions
  1653. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PROJECTILE 0x00000020 // projectiles (rays) collide with this
  1654. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VIS 0x00000040 // vis rays collide with this mesh
  1655. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_CAMERA 0x00000080 // cameras collide with this mesh
  1656. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VEHICLE 0x00000100 // vehicles collide with this mesh
  1657. struct W3dBoxStruct
  1658. {
  1659. uint32 Version; // file format version
  1660. uint32 Attributes; // box attributes (above #define's)
  1661. char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<boxname>
  1662. W3dRGBStruct Color; // color to use when drawing the box
  1663. W3dVectorStruct Center; // center of the box
  1664. W3dVectorStruct Extent; // extent of the box
  1665. };
  1666. /********************************************************************************
  1667. NULL Objects
  1668. Null objects are used by the LOD system to make meshes dissappear at lower
  1669. levels of detail.
  1670. ********************************************************************************/
  1671. #define W3D_NULL_OBJECT_CURRENT_VERSION W3D_MAKE_VERSION(1,0)
  1672. struct W3dNullObjectStruct
  1673. {
  1674. uint32 Version; // file format version
  1675. uint32 Attributes; // object attributes (currently un-used)
  1676. uint32 pad[2]; // pad space
  1677. char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<boxname>
  1678. };
  1679. /********************************************************************************
  1680. Dazzle Objects
  1681. The only data needed to instantiate a dazzle object is the type-name of
  1682. the dazzle to use. The dazzle is always assumed to be at the pivot point
  1683. of the bone it is attached to (you should enable Export_Transform) for
  1684. dazzles. If the dazzle-type (from dazzle.ini) is directional, then the
  1685. coordinate-system of the bone will define the direction.
  1686. ********************************************************************************/
  1687. /********************************************************************************
  1688. Sound render objects
  1689. The following structs are used to define sound render object in the w3d file.
  1690. These objects are used to trigger a sound effect in the world. When the object
  1691. is shown, its associated sound is added to the world and played, when the object
  1692. is hidden, the associated sound is stopped and removed from the world.
  1693. ********************************************************************************/
  1694. #define W3D_CURRENT_SOUNDROBJ_VERSION 0x00010000
  1695. //
  1696. // Note: This structure is follwed directly by a chunk (W3D_CHUNK_SOUNDROBJ_DEFINITION)
  1697. // that contains an embedded AudibleSoundDefinitionClass's storage. See audibledound.h
  1698. // for details.
  1699. //
  1700. struct W3dSoundRObjHeaderStruct
  1701. {
  1702. uint32 Version;
  1703. char Name[W3D_NAME_LEN];
  1704. uint32 Flags;
  1705. uint32 Padding[8];
  1706. };
  1707. /*
  1708. ** Include the obsolete structures and chunk ID's
  1709. */
  1710. #include "w3d_obsolete.h"
  1711. #endif // W3D_FILE_H