w3d_file.h 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081
  1. /*
  2. ** Command & Conquer Generals(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 16 8/29/01 9:49p 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:: 8/29/01 7:29p $*
  30. * *
  31. * $Revision:: 16 $*
  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_AGGREGATE =0x00000600, // description of an aggregate object
  352. W3D_CHUNK_AGGREGATE_HEADER, // general information such as name and version
  353. W3D_CHUNK_AGGREGATE_INFO, // references to 'contained' models
  354. W3D_CHUNK_TEXTURE_REPLACER_INFO, // information about which meshes need textures replaced
  355. W3D_CHUNK_AGGREGATE_CLASS_INFO, // information about the original class that created this aggregate
  356. W3D_CHUNK_HLOD =0x00000700, // description of an HLod object (see HLodClass)
  357. W3D_CHUNK_HLOD_HEADER, // general information such as name and version
  358. W3D_CHUNK_HLOD_LOD_ARRAY, // wrapper around the array of objects for each level of detail
  359. W3D_CHUNK_HLOD_SUB_OBJECT_ARRAY_HEADER, // info on the objects in this level of detail array
  360. W3D_CHUNK_HLOD_SUB_OBJECT, // an object in this level of detail array
  361. W3D_CHUNK_HLOD_AGGREGATE_ARRAY, // array of aggregates, contains W3D_CHUNK_SUB_OBJECT_ARRAY_HEADER and W3D_CHUNK_SUB_OBJECT_ARRAY
  362. W3D_CHUNK_HLOD_PROXY_ARRAY, // array of proxies, used for application-defined purposes, provides a name and a bone.
  363. W3D_CHUNK_BOX =0x00000740, // defines an collision box render object (W3dBoxStruct)
  364. W3D_CHUNK_SPHERE,
  365. W3D_CHUNK_RING,
  366. W3D_CHUNK_NULL_OBJECT =0x00000750, // defines a NULL object (W3dNullObjectStruct)
  367. W3D_CHUNK_LIGHTSCAPE =0x00000800, // wrapper for lights created with Lightscape.
  368. W3D_CHUNK_LIGHTSCAPE_LIGHT, // definition of a light created with Lightscape.
  369. W3D_CHUNK_LIGHT_TRANSFORM, // position and orientation (defined as right-handed 4x3 matrix transform W3dLightTransformStruct).
  370. W3D_CHUNK_DAZZLE =0x00000900, // wrapper for a glare object. Creates halos and flare lines seen around a bright light source
  371. W3D_CHUNK_DAZZLE_NAME, // null-terminated string, name of the dazzle (typical w3d object naming: "container.object")
  372. W3D_CHUNK_DAZZLE_TYPENAME, // null-terminated string, type of dazzle (from dazzle.ini)
  373. W3D_CHUNK_SOUNDROBJ =0x00000A00, // description of a sound render object
  374. W3D_CHUNK_SOUNDROBJ_HEADER, // general information such as name and version
  375. W3D_CHUNK_SOUNDROBJ_DEFINITION, // chunk containing the definition of the sound that is to play
  376. };
  377. struct W3dChunkHeader
  378. {
  379. uint32 ChunkType; // Type of chunk (see above enumeration)
  380. uint32 ChunkSize; // Size of the chunk, (not including the chunk header)
  381. };
  382. /////////////////////////////////////////////////////////////////////////////////////////////
  383. // vector
  384. /////////////////////////////////////////////////////////////////////////////////////////////
  385. typedef IOVector3Struct W3dVectorStruct;
  386. /////////////////////////////////////////////////////////////////////////////////////////////
  387. // quaternion
  388. /////////////////////////////////////////////////////////////////////////////////////////////
  389. typedef IOQuaternionStruct W3dQuaternionStruct;
  390. /////////////////////////////////////////////////////////////////////////////////////////////
  391. // texture coordinate
  392. /////////////////////////////////////////////////////////////////////////////////////////////
  393. struct W3dTexCoordStruct
  394. {
  395. bool operator == (W3dTexCoordStruct t)
  396. {
  397. return ((U == t.U) && (V == t.V));
  398. }
  399. float32 U; // U,V coordinates
  400. float32 V;
  401. };
  402. /////////////////////////////////////////////////////////////////////////////////////////////
  403. // rgb color, one byte per channel, padded to an even 4 bytes
  404. /////////////////////////////////////////////////////////////////////////////////////////////
  405. struct W3dRGBStruct
  406. {
  407. W3dRGBStruct () {}
  408. W3dRGBStruct (uint8 r, uint8 g, uint8 b)
  409. {
  410. R = r;
  411. G = g;
  412. B = b;
  413. }
  414. void Set (uint8 r, uint8 g, uint8 b)
  415. {
  416. R = r;
  417. G = g;
  418. B = b;
  419. }
  420. void Set (float r, float g, float b)
  421. {
  422. R = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, r) * ((float) (UCHAR_MAX + 1)));
  423. G = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, g) * ((float) (UCHAR_MAX + 1)));
  424. B = (unsigned char) MIN ((float) UCHAR_MAX, MAX (0.0f, b) * ((float) (UCHAR_MAX + 1)));
  425. }
  426. bool operator == (W3dRGBStruct c)
  427. {
  428. return ((R == c.R) && (G == c.G) && (B == c.B));
  429. }
  430. bool operator != (W3dRGBStruct c)
  431. {
  432. return (!(*this == c));
  433. }
  434. W3dRGBStruct operator += (W3dRGBStruct c)
  435. {
  436. R = MIN (((unsigned) R) + ((unsigned) c.R), (unsigned) UCHAR_MAX);
  437. G = MIN (((unsigned) G) + ((unsigned) c.G), (unsigned) UCHAR_MAX);
  438. B = MIN (((unsigned) B) + ((unsigned) c.B), (unsigned) UCHAR_MAX);
  439. return (*this);
  440. }
  441. W3dRGBStruct operator *= (W3dRGBStruct c)
  442. {
  443. R = (((unsigned) R) * ((unsigned) c.R)) / ((unsigned) UCHAR_MAX);
  444. G = (((unsigned) G) * ((unsigned) c.G)) / ((unsigned) UCHAR_MAX);
  445. B = (((unsigned) B) * ((unsigned) c.B)) / ((unsigned) UCHAR_MAX);
  446. return (*this);
  447. }
  448. unsigned Get_Color()
  449. {
  450. return (R<<24)|(G<<16)|(B<<8);
  451. }
  452. uint8 R;
  453. uint8 G;
  454. uint8 B;
  455. uint8 pad;
  456. };
  457. struct W3dRGBAStruct
  458. {
  459. uint8 R;
  460. uint8 G;
  461. uint8 B;
  462. uint8 A;
  463. };
  464. /////////////////////////////////////////////////////////////////////////////////////////////
  465. // MATERIALS
  466. //
  467. // Surrender 1.40 significantly changed the way that materials are described. To
  468. // accomodate this, the w3d file format has changed since there are new features and
  469. // optimizations that we want to take advangage of.
  470. //
  471. // The VertexMaterial defines parameters which control the calculation of the primary
  472. // and secondary gradients. The shader defines how those gradients are combined with
  473. // the texel and the frame buffer contents.
  474. //
  475. /////////////////////////////////////////////////////////////////////////////////////////////
  476. struct W3dMaterialInfoStruct
  477. {
  478. uint32 PassCount; // how many material passes this render object uses
  479. uint32 VertexMaterialCount; // how many vertex materials are used
  480. uint32 ShaderCount; // how many shaders are used
  481. uint32 TextureCount; // how many textures are used
  482. };
  483. #define W3DVERTMAT_USE_DEPTH_CUE 0x00000001
  484. #define W3DVERTMAT_ARGB_EMISSIVE_ONLY 0x00000002
  485. #define W3DVERTMAT_COPY_SPECULAR_TO_DIFFUSE 0x00000004
  486. #define W3DVERTMAT_DEPTH_CUE_TO_ALPHA 0x00000008
  487. #define W3DVERTMAT_STAGE0_MAPPING_MASK 0x00FF0000
  488. #define W3DVERTMAT_STAGE0_MAPPING_UV 0x00000000
  489. #define W3DVERTMAT_STAGE0_MAPPING_ENVIRONMENT 0x00010000
  490. #define W3DVERTMAT_STAGE0_MAPPING_CHEAP_ENVIRONMENT 0x00020000
  491. #define W3DVERTMAT_STAGE0_MAPPING_SCREEN 0x00030000
  492. #define W3DVERTMAT_STAGE0_MAPPING_LINEAR_OFFSET 0x00040000
  493. #define W3DVERTMAT_STAGE0_MAPPING_SILHOUETTE 0x00050000
  494. #define W3DVERTMAT_STAGE0_MAPPING_SCALE 0x00060000
  495. #define W3DVERTMAT_STAGE0_MAPPING_GRID 0x00070000
  496. #define W3DVERTMAT_STAGE0_MAPPING_ROTATE 0x00080000
  497. #define W3DVERTMAT_STAGE0_MAPPING_SINE_LINEAR_OFFSET 0x00090000
  498. #define W3DVERTMAT_STAGE0_MAPPING_STEP_LINEAR_OFFSET 0x000A0000
  499. #define W3DVERTMAT_STAGE0_MAPPING_ZIGZAG_LINEAR_OFFSET 0x000B0000
  500. #define W3DVERTMAT_STAGE0_MAPPING_WS_CLASSIC_ENV 0x000C0000
  501. #define W3DVERTMAT_STAGE0_MAPPING_WS_ENVIRONMENT 0x000D0000
  502. #define W3DVERTMAT_STAGE0_MAPPING_GRID_CLASSIC_ENV 0x000E0000
  503. #define W3DVERTMAT_STAGE0_MAPPING_GRID_ENVIRONMENT 0x000F0000
  504. #define W3DVERTMAT_STAGE0_MAPPING_RANDOM 0x00100000
  505. #define W3DVERTMAT_STAGE0_MAPPING_EDGE 0x00110000
  506. #define W3DVERTMAT_STAGE0_MAPPING_BUMPENV 0x00120000
  507. #define W3DVERTMAT_STAGE1_MAPPING_MASK 0x0000FF00
  508. #define W3DVERTMAT_STAGE1_MAPPING_UV 0x00000000
  509. #define W3DVERTMAT_STAGE1_MAPPING_ENVIRONMENT 0x00000100
  510. #define W3DVERTMAT_STAGE1_MAPPING_CHEAP_ENVIRONMENT 0x00000200
  511. #define W3DVERTMAT_STAGE1_MAPPING_SCREEN 0x00000300
  512. #define W3DVERTMAT_STAGE1_MAPPING_LINEAR_OFFSET 0x00000400
  513. #define W3DVERTMAT_STAGE1_MAPPING_SILHOUETTE 0x00000500
  514. #define W3DVERTMAT_STAGE1_MAPPING_SCALE 0x00000600
  515. #define W3DVERTMAT_STAGE1_MAPPING_GRID 0x00000700
  516. #define W3DVERTMAT_STAGE1_MAPPING_ROTATE 0x00000800
  517. #define W3DVERTMAT_STAGE1_MAPPING_SINE_LINEAR_OFFSET 0x00000900
  518. #define W3DVERTMAT_STAGE1_MAPPING_STEP_LINEAR_OFFSET 0x00000A00
  519. #define W3DVERTMAT_STAGE1_MAPPING_ZIGZAG_LINEAR_OFFSET 0x00000B00
  520. #define W3DVERTMAT_STAGE1_MAPPING_WS_CLASSIC_ENV 0x00000C00
  521. #define W3DVERTMAT_STAGE1_MAPPING_WS_ENVIRONMENT 0x00000D00
  522. #define W3DVERTMAT_STAGE1_MAPPING_GRID_CLASSIC_ENV 0x00000E00
  523. #define W3DVERTMAT_STAGE1_MAPPING_GRID_ENVIRONMENT 0x00000F00
  524. #define W3DVERTMAT_STAGE1_MAPPING_RANDOM 0x00001000
  525. #define W3DVERTMAT_STAGE1_MAPPING_EDGE 0x00001100
  526. #define W3DVERTMAT_STAGE1_MAPPING_BUMPENV 0x00001200
  527. #define W3DVERTMAT_PSX_MASK 0xFF000000
  528. #define W3DVERTMAT_PSX_TRANS_MASK 0x07000000
  529. #define W3DVERTMAT_PSX_TRANS_NONE 0x00000000
  530. #define W3DVERTMAT_PSX_TRANS_100 0x01000000
  531. #define W3DVERTMAT_PSX_TRANS_50 0x02000000
  532. #define W3DVERTMAT_PSX_TRANS_25 0x03000000
  533. #define W3DVERTMAT_PSX_TRANS_MINUS_100 0x04000000
  534. #define W3DVERTMAT_PSX_NO_RT_LIGHTING 0x08000000
  535. struct W3dVertexMaterialStruct
  536. {
  537. W3dVertexMaterialStruct(void) {}
  538. bool operator == (W3dVertexMaterialStruct vm)
  539. {
  540. return ( Attributes == vm.Attributes
  541. && Ambient == vm.Ambient
  542. && Diffuse == vm.Diffuse
  543. && Specular == vm.Specular
  544. && Emissive == vm.Emissive
  545. && Shininess == vm.Shininess
  546. && Opacity == vm.Opacity
  547. && Translucency == vm.Translucency);
  548. }
  549. bool operator != (W3dVertexMaterialStruct vm)
  550. {
  551. return (!(*this == vm));
  552. }
  553. uint32 Attributes; // bitfield for the flags defined above
  554. W3dRGBStruct Ambient;
  555. W3dRGBStruct Diffuse;
  556. W3dRGBStruct Specular;
  557. W3dRGBStruct Emissive;
  558. float32 Shininess; // how tight the specular highlight will be, 1 - 1000 (default = 1)
  559. float32 Opacity; // how opaque the material is, 0.0 = invisible, 1.0 = fully opaque (default = 1)
  560. float32 Translucency; // how much light passes through the material. (default = 0)
  561. };
  562. inline void W3d_Vertex_Material_Reset(W3dVertexMaterialStruct * vmat)
  563. {
  564. vmat->Attributes = 0;
  565. vmat->Ambient.R = vmat->Ambient.G = vmat->Ambient.B = 255;
  566. vmat->Diffuse.R = vmat->Diffuse.G = vmat->Diffuse.B = 255;
  567. vmat->Specular.R = vmat->Specular.G = vmat->Specular.B = 0;
  568. vmat->Emissive.R = vmat->Emissive.G = vmat->Emissive.B = 0;
  569. vmat->Shininess = 1.0f;
  570. vmat->Opacity = 1.0f;
  571. vmat->Translucency = 0.0f;
  572. }
  573. // W3dShaderStruct bits. These control every setting in the shader. Use the helper functions
  574. // to set them and test them more easily.
  575. enum
  576. {
  577. W3DSHADER_DEPTHCOMPARE_PASS_NEVER = 0, // pass never (i.e. always fail depth comparison test)
  578. W3DSHADER_DEPTHCOMPARE_PASS_LESS, // pass if incoming less than stored
  579. W3DSHADER_DEPTHCOMPARE_PASS_EQUAL, // pass if incoming equal to stored
  580. W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL, // pass if incoming less than or equal to stored (default)
  581. W3DSHADER_DEPTHCOMPARE_PASS_GREATER, // pass if incoming greater than stored
  582. W3DSHADER_DEPTHCOMPARE_PASS_NOTEQUAL, // pass if incoming not equal to stored
  583. W3DSHADER_DEPTHCOMPARE_PASS_GEQUAL, // pass if incoming greater than or equal to stored
  584. W3DSHADER_DEPTHCOMPARE_PASS_ALWAYS, // pass always
  585. W3DSHADER_DEPTHCOMPARE_PASS_MAX, // end of enumeration
  586. W3DSHADER_DEPTHMASK_WRITE_DISABLE = 0, // disable depth buffer writes
  587. W3DSHADER_DEPTHMASK_WRITE_ENABLE, // enable depth buffer writes (default)
  588. W3DSHADER_DEPTHMASK_WRITE_MAX, // end of enumeration
  589. W3DSHADER_ALPHATEST_DISABLE = 0, // disable alpha testing (default)
  590. W3DSHADER_ALPHATEST_ENABLE, // enable alpha testing
  591. W3DSHADER_ALPHATEST_MAX, // end of enumeration
  592. W3DSHADER_DESTBLENDFUNC_ZERO = 0, // destination pixel doesn't affect blending (default)
  593. W3DSHADER_DESTBLENDFUNC_ONE, // destination pixel added unmodified
  594. W3DSHADER_DESTBLENDFUNC_SRC_COLOR, // destination pixel multiplied by fragment RGB components
  595. W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_COLOR, // destination pixel multiplied by one minus (i.e. inverse) fragment RGB components
  596. W3DSHADER_DESTBLENDFUNC_SRC_ALPHA, // destination pixel multiplied by fragment alpha component
  597. W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_ALPHA, // destination pixel multiplied by fragment inverse alpha
  598. W3DSHADER_DESTBLENDFUNC_SRC_COLOR_PREFOG, // destination pixel multiplied by fragment RGB components prior to fogging
  599. W3DSHADER_DESTBLENDFUNC_MAX, // end of enumeration
  600. W3DSHADER_PRIGRADIENT_DISABLE = 0, // disable primary gradient (same as OpenGL 'decal' texture blend)
  601. W3DSHADER_PRIGRADIENT_MODULATE, // modulate fragment ARGB by gradient ARGB (default)
  602. W3DSHADER_PRIGRADIENT_ADD, // add gradient RGB to fragment RGB, copy gradient A to fragment A
  603. W3DSHADER_PRIGRADIENT_BUMPENVMAP, // environment-mapped bump mapping
  604. W3DSHADER_PRIGRADIENT_MAX, // end of enumeration
  605. W3DSHADER_SECGRADIENT_DISABLE = 0, // don't draw secondary gradient (default)
  606. W3DSHADER_SECGRADIENT_ENABLE, // add secondary gradient RGB to fragment RGB
  607. W3DSHADER_SECGRADIENT_MAX, // end of enumeration
  608. W3DSHADER_SRCBLENDFUNC_ZERO = 0, // fragment not added to color buffer
  609. W3DSHADER_SRCBLENDFUNC_ONE, // fragment added unmodified to color buffer (default)
  610. W3DSHADER_SRCBLENDFUNC_SRC_ALPHA, // fragment RGB components multiplied by fragment A
  611. W3DSHADER_SRCBLENDFUNC_ONE_MINUS_SRC_ALPHA, // fragment RGB components multiplied by fragment inverse (one minus) A
  612. W3DSHADER_SRCBLENDFUNC_MAX, // end of enumeration
  613. W3DSHADER_TEXTURING_DISABLE = 0, // no texturing (treat fragment initial color as 1,1,1,1) (default)
  614. W3DSHADER_TEXTURING_ENABLE, // enable texturing
  615. W3DSHADER_TEXTURING_MAX, // end of enumeration
  616. W3DSHADER_DETAILCOLORFUNC_DISABLE = 0, // local (default)
  617. W3DSHADER_DETAILCOLORFUNC_DETAIL, // other
  618. W3DSHADER_DETAILCOLORFUNC_SCALE, // local * other
  619. W3DSHADER_DETAILCOLORFUNC_INVSCALE, // ~(~local * ~other) = local + (1-local)*other
  620. W3DSHADER_DETAILCOLORFUNC_ADD, // local + other
  621. W3DSHADER_DETAILCOLORFUNC_SUB, // local - other
  622. W3DSHADER_DETAILCOLORFUNC_SUBR, // other - local
  623. W3DSHADER_DETAILCOLORFUNC_BLEND, // (localAlpha)*local + (~localAlpha)*other
  624. W3DSHADER_DETAILCOLORFUNC_DETAILBLEND, // (otherAlpha)*local + (~otherAlpha)*other
  625. W3DSHADER_DETAILCOLORFUNC_MAX, // end of enumeration
  626. W3DSHADER_DETAILALPHAFUNC_DISABLE = 0, // local (default)
  627. W3DSHADER_DETAILALPHAFUNC_DETAIL, // other
  628. W3DSHADER_DETAILALPHAFUNC_SCALE, // local * other
  629. W3DSHADER_DETAILALPHAFUNC_INVSCALE, // ~(~local * ~other) = local + (1-local)*other
  630. W3DSHADER_DETAILALPHAFUNC_MAX, // end of enumeration
  631. W3DSHADER_DEPTHCOMPARE_DEFAULT = W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL,
  632. W3DSHADER_DEPTHMASK_DEFAULT = W3DSHADER_DEPTHMASK_WRITE_ENABLE,
  633. W3DSHADER_ALPHATEST_DEFAULT = W3DSHADER_ALPHATEST_DISABLE,
  634. W3DSHADER_DESTBLENDFUNC_DEFAULT = W3DSHADER_DESTBLENDFUNC_ZERO,
  635. W3DSHADER_PRIGRADIENT_DEFAULT = W3DSHADER_PRIGRADIENT_MODULATE,
  636. W3DSHADER_SECGRADIENT_DEFAULT = W3DSHADER_SECGRADIENT_DISABLE,
  637. W3DSHADER_SRCBLENDFUNC_DEFAULT = W3DSHADER_SRCBLENDFUNC_ONE,
  638. W3DSHADER_TEXTURING_DEFAULT = W3DSHADER_TEXTURING_DISABLE,
  639. W3DSHADER_DETAILCOLORFUNC_DEFAULT = W3DSHADER_DETAILCOLORFUNC_DISABLE,
  640. W3DSHADER_DETAILALPHAFUNC_DEFAULT = W3DSHADER_DETAILALPHAFUNC_DISABLE,
  641. };
  642. enum PS2_SHADER_SETTINGS {
  643. PSS_SRC = 0,
  644. PSS_DEST,
  645. PSS_ZERO,
  646. PSS_SRC_ALPHA = 0,
  647. PSS_DEST_ALPHA,
  648. PSS_ONE,
  649. // From combo box. To match the PC default gradient.
  650. PSS_PRIGRADIENT_DECAL = 0,
  651. PSS_PRIGRADIENT_MODULATE,
  652. PSS_PRIGRADIENT_HIGHLIGHT,
  653. PSS_PRIGRADIENT_HIGHLIGHT2,
  654. // Actual PS2 numbers.
  655. PSS_PS2_PRIGRADIENT_MODULATE = 0,
  656. PSS_PS2_PRIGRADIENT_DECAL,
  657. PSS_PS2_PRIGRADIENT_HIGHLIGHT,
  658. PSS_PS2_PRIGRADIENT_HIGHLIGHT2,
  659. PSS_DEPTHCOMPARE_PASS_NEVER = 0,
  660. PSS_DEPTHCOMPARE_PASS_LESS,
  661. PSS_DEPTHCOMPARE_PASS_ALWAYS,
  662. PSS_DEPTHCOMPARE_PASS_LEQUAL,
  663. };
  664. struct W3dShaderStruct
  665. {
  666. W3dShaderStruct(void) {}
  667. uint8 DepthCompare;
  668. uint8 DepthMask;
  669. uint8 ColorMask; // now obsolete and ignored
  670. uint8 DestBlend;
  671. uint8 FogFunc; // now obsolete and ignored
  672. uint8 PriGradient;
  673. uint8 SecGradient;
  674. uint8 SrcBlend;
  675. uint8 Texturing;
  676. uint8 DetailColorFunc;
  677. uint8 DetailAlphaFunc;
  678. uint8 ShaderPreset; // now obsolete and ignored
  679. uint8 AlphaTest;
  680. uint8 PostDetailColorFunc;
  681. uint8 PostDetailAlphaFunc;
  682. uint8 pad[1];
  683. };
  684. struct W3dPS2ShaderStruct
  685. {
  686. uint8 DepthCompare;
  687. uint8 DepthMask;
  688. uint8 PriGradient;
  689. uint8 Texturing;
  690. uint8 AlphaTest;
  691. uint8 AParam;
  692. uint8 BParam;
  693. uint8 CParam;
  694. uint8 DParam;
  695. uint8 pad[3];
  696. };
  697. inline void W3d_Shader_Reset(W3dShaderStruct * s) {
  698. s->DepthCompare = W3DSHADER_DEPTHCOMPARE_PASS_LEQUAL;
  699. s->DepthMask = W3DSHADER_DEPTHMASK_WRITE_ENABLE;
  700. s->ColorMask = 0; // obsolete
  701. s->DestBlend = W3DSHADER_DESTBLENDFUNC_ZERO;
  702. s->FogFunc = 0; // obsolete
  703. s->PriGradient = W3DSHADER_PRIGRADIENT_MODULATE;
  704. s->SecGradient = W3DSHADER_SECGRADIENT_DISABLE;
  705. s->SrcBlend = W3DSHADER_SRCBLENDFUNC_ONE;
  706. s->Texturing = W3DSHADER_TEXTURING_DISABLE;
  707. s->DetailColorFunc = W3DSHADER_DETAILCOLORFUNC_DISABLE;
  708. s->DetailAlphaFunc = W3DSHADER_DETAILALPHAFUNC_DISABLE;
  709. s->ShaderPreset = 0; // obsolete
  710. s->AlphaTest = W3DSHADER_ALPHATEST_DISABLE;
  711. s->PostDetailColorFunc = W3DSHADER_DETAILCOLORFUNC_DISABLE;
  712. s->PostDetailAlphaFunc = W3DSHADER_DETAILALPHAFUNC_DISABLE;
  713. s->pad[0] = 0;
  714. }
  715. inline void W3d_Shader_Set_Depth_Compare(W3dShaderStruct * s,int val) { s->DepthCompare = val; }
  716. inline void W3d_Shader_Set_Depth_Mask(W3dShaderStruct * s,int val) { s->DepthMask = val; }
  717. inline void W3d_Shader_Set_Dest_Blend_Func(W3dShaderStruct * s,int val) { s->DestBlend = val; }
  718. inline void W3d_Shader_Set_Pri_Gradient(W3dShaderStruct * s,int val) { s->PriGradient = val; }
  719. inline void W3d_Shader_Set_Sec_Gradient(W3dShaderStruct * s,int val) { s->SecGradient = val; }
  720. inline void W3d_Shader_Set_Src_Blend_Func(W3dShaderStruct * s,int val) { s->SrcBlend = val; }
  721. inline void W3d_Shader_Set_Texturing(W3dShaderStruct * s,int val) { s->Texturing = val; }
  722. inline void W3d_Shader_Set_Detail_Color_Func(W3dShaderStruct * s,int val) { s->DetailColorFunc = val; }
  723. inline void W3d_Shader_Set_Detail_Alpha_Func(W3dShaderStruct * s,int val) { s->DetailAlphaFunc = val; }
  724. inline void W3d_Shader_Set_Alpha_Test(W3dShaderStruct * s,int val) { s->AlphaTest = val; }
  725. inline void W3d_Shader_Set_Post_Detail_Color_Func(W3dShaderStruct * s,int val) { s->PostDetailColorFunc = val; }
  726. inline void W3d_Shader_Set_Post_Detail_Alpha_Func(W3dShaderStruct * s,int val) { s->PostDetailAlphaFunc = val; }
  727. // These functions use the existing W3dShaderStruct unused members to store PS2 specific parameters.
  728. // At mesh save time, if a PS2 material was used, a separate PS2 material chunk is saved out.
  729. // If W3dShaderStruct is changed this should still work because it is only used for the PS2 stuff.
  730. inline void W3d_Shader_Set_PS2_Param_A(W3dShaderStruct *s, int val) {s->ColorMask = val;}
  731. inline void W3d_Shader_Set_PS2_Param_B(W3dShaderStruct *s, int val) {s->FogFunc = val;}
  732. inline void W3d_Shader_Set_PS2_Param_C(W3dShaderStruct *s, int val) {s->ShaderPreset = val;}
  733. inline void W3d_Shader_Set_PS2_Param_D(W3dShaderStruct *s, int val) {s->pad[0] = val;}
  734. inline int W3d_Shader_Get_PS2_Param_A(const W3dShaderStruct *s) {return (s->ColorMask);}
  735. inline int W3d_Shader_Get_PS2_Param_B(const W3dShaderStruct *s) {return (s->FogFunc);}
  736. inline int W3d_Shader_Get_PS2_Param_C(const W3dShaderStruct *s) {return (s->ShaderPreset);}
  737. inline int W3d_Shader_Get_PS2_Param_D(const W3dShaderStruct *s) {return (s->pad[0]);}
  738. inline int W3d_Shader_Get_PS2_Param_A(const W3dPS2ShaderStruct *s) {return (s->AParam);}
  739. inline int W3d_Shader_Get_PS2_Param_B(const W3dPS2ShaderStruct *s) {return (s->BParam);}
  740. inline int W3d_Shader_Get_PS2_Param_C(const W3dPS2ShaderStruct *s) {return (s->CParam);}
  741. inline int W3d_Shader_Get_PS2_Param_D(const W3dPS2ShaderStruct *s) {return (s->DParam);}
  742. inline int W3d_Shader_Get_Depth_Compare(const W3dPS2ShaderStruct * s) { return s->DepthCompare; }
  743. inline int W3d_Shader_Get_Depth_Mask(const W3dPS2ShaderStruct * s) { return s->DepthMask; }
  744. inline int W3d_Shader_Get_Pri_Gradient(const W3dPS2ShaderStruct * s) { return s->PriGradient; }
  745. inline int W3d_Shader_Get_Texturing(const W3dPS2ShaderStruct * s) { return s->Texturing; }
  746. inline int W3d_Shader_Get_Alpha_Test(const W3dPS2ShaderStruct * s) { return s->AlphaTest; }
  747. inline int W3d_Shader_Get_Depth_Compare(const W3dShaderStruct * s) { return s->DepthCompare; }
  748. inline int W3d_Shader_Get_Depth_Mask(const W3dShaderStruct * s) { return s->DepthMask; }
  749. inline int W3d_Shader_Get_Dest_Blend_Func(const W3dShaderStruct * s) { return s->DestBlend; }
  750. inline int W3d_Shader_Get_Pri_Gradient(const W3dShaderStruct * s) { return s->PriGradient; }
  751. inline int W3d_Shader_Get_Sec_Gradient(const W3dShaderStruct * s) { return s->SecGradient; }
  752. inline int W3d_Shader_Get_Src_Blend_Func(const W3dShaderStruct * s) { return s->SrcBlend; }
  753. inline int W3d_Shader_Get_Texturing(const W3dShaderStruct * s) { return s->Texturing; }
  754. inline int W3d_Shader_Get_Detail_Color_Func(const W3dShaderStruct * s) { return s->DetailColorFunc; }
  755. inline int W3d_Shader_Get_Detail_Alpha_Func(const W3dShaderStruct * s) { return s->DetailAlphaFunc; }
  756. inline int W3d_Shader_Get_Alpha_Test(const W3dShaderStruct * s) { return s->AlphaTest; }
  757. inline int W3d_Shader_Get_Post_Detail_Color_Func(const W3dShaderStruct * s) { return s->PostDetailColorFunc; }
  758. inline int W3d_Shader_Get_Post_Detail_Alpha_Func(const W3dShaderStruct * s) { return s->PostDetailAlphaFunc; }
  759. /////////////////////////////////////////////////////////////////////////////////////////////
  760. // Texture Animation parameters
  761. // May occur inside a texture chunk if its needed
  762. /////////////////////////////////////////////////////////////////////////////////////////////
  763. #define W3DTEXTURE_PUBLISH 0x0001 // this texture should be "published" (indirected so its changeable in code)
  764. #define W3DTEXTURE_RESIZE_OBSOLETE 0x0002 // this texture should be resizeable (OBSOLETE!!!)
  765. #define W3DTEXTURE_NO_LOD 0x0004 // this texture should not have any LOD (mipmapping or resizing)
  766. #define W3DTEXTURE_CLAMP_U 0x0008 // this texture should be clamped on U
  767. #define W3DTEXTURE_CLAMP_V 0x0010 // this texture should be clamped on V
  768. #define W3DTEXTURE_ALPHA_BITMAP 0x0020 // this texture's alpha channel should be collapsed to one bit
  769. // Specify desired no. of mip-levels to be generated.
  770. #define W3DTEXTURE_MIP_LEVELS_MASK 0x00c0
  771. #define W3DTEXTURE_MIP_LEVELS_ALL 0x0000 // generate all mip-levels
  772. #define W3DTEXTURE_MIP_LEVELS_2 0x0040 // generate up to 2 mip-levels (NOTE: use W3DTEXTURE_NO_LOD to generate just 1 mip-level)
  773. #define W3DTEXTURE_MIP_LEVELS_3 0x0080 // generate up to 3 mip-levels
  774. #define W3DTEXTURE_MIP_LEVELS_4 0x00c0 // generate up to 4 mip-levels
  775. // Hints to describe the intended use of the various passes / stages
  776. // This will go into the high byte of Attributes.
  777. #define W3DTEXTURE_HINT_SHIFT 8 // number of bits to shift up
  778. #define W3DTEXTURE_HINT_MASK 0x0000ff00 // mask for shifted hint value
  779. #define W3DTEXTURE_HINT_BASE 0x0000 // base texture
  780. #define W3DTEXTURE_HINT_EMISSIVE 0x0100 // emissive map
  781. #define W3DTEXTURE_HINT_ENVIRONMENT 0x0200 // environment/reflection map
  782. #define W3DTEXTURE_HINT_SHINY_MASK 0x0300 // shinyness mask map
  783. #define W3DTEXTURE_TYPE_MASK 0x1000
  784. #define W3DTEXTURE_TYPE_COLORMAP 0x0000 // Color map.
  785. #define W3DTEXTURE_TYPE_BUMPMAP 0x1000 // Grayscale heightmap (to be converted to bumpmap).
  786. // Animation types
  787. #define W3DTEXTURE_ANIM_LOOP 0x0000
  788. #define W3DTEXTURE_ANIM_PINGPONG 0x0001
  789. #define W3DTEXTURE_ANIM_ONCE 0x0002
  790. #define W3DTEXTURE_ANIM_MANUAL 0x0003
  791. struct W3dTextureInfoStruct
  792. {
  793. W3dTextureInfoStruct(void) {}
  794. uint16 Attributes; // flags for this texture
  795. uint16 AnimType; // animation logic
  796. uint32 FrameCount; // Number of frames (1 if not animated)
  797. float32 FrameRate; // Frame rate, frames per second in floating point
  798. };
  799. /////////////////////////////////////////////////////////////////////////////////////////////
  800. // A triangle, occurs inside the W3D_CHUNK_TRIANGLES chunk
  801. // This was introduced with version 3.0 of the file format
  802. /////////////////////////////////////////////////////////////////////////////////////////////
  803. struct W3dTriStruct
  804. {
  805. uint32 Vindex[3]; // vertex,vnormal,texcoord,color indices
  806. uint32 Attributes; // attributes bits
  807. W3dVectorStruct Normal; // plane normal
  808. float32 Dist; // plane distance
  809. };
  810. /////////////////////////////////////////////////////////////////////////////////////////////
  811. // Flags for the Triangle Attributes member
  812. /////////////////////////////////////////////////////////////////////////////////////////////
  813. typedef enum
  814. {
  815. SURFACE_TYPE_LIGHT_METAL = 0,
  816. SURFACE_TYPE_HEAVY_METAL,
  817. SURFACE_TYPE_WATER,
  818. SURFACE_TYPE_SAND,
  819. SURFACE_TYPE_DIRT,
  820. SURFACE_TYPE_MUD,
  821. SURFACE_TYPE_GRASS,
  822. SURFACE_TYPE_WOOD,
  823. SURFACE_TYPE_CONCRETE,
  824. SURFACE_TYPE_FLESH,
  825. SURFACE_TYPE_ROCK,
  826. SURFACE_TYPE_SNOW,
  827. SURFACE_TYPE_ICE,
  828. SURFACE_TYPE_DEFAULT,
  829. SURFACE_TYPE_GLASS,
  830. SURFACE_TYPE_CLOTH,
  831. SURFACE_TYPE_TIBERIUM_FIELD,
  832. SURFACE_TYPE_FOLIAGE_PERMEABLE,
  833. SURFACE_TYPE_GLASS_PERMEABLE,
  834. SURFACE_TYPE_ICE_PERMEABLE,
  835. SURFACE_TYPE_CLOTH_PERMEABLE,
  836. SURFACE_TYPE_ELECTRICAL,
  837. SURFACE_TYPE_FLAMMABLE,
  838. SURFACE_TYPE_STEAM,
  839. SURFACE_TYPE_ELECTRICAL_PERMEABLE,
  840. SURFACE_TYPE_FLAMMABLE_PERMEABLE,
  841. SURFACE_TYPE_STEAM_PERMEABLE,
  842. SURFACE_TYPE_MAX // NOTE: if you add a surface type, add it to the SurfaceEffects.INI file!
  843. } W3D_SURFACE_TYPES;
  844. const char * const SURFACE_TYPE_STRINGS[SURFACE_TYPE_MAX] =
  845. {
  846. "Light Metal",
  847. "Heavy Metal",
  848. "Water",
  849. "Sand",
  850. "Dirt",
  851. "Mud",
  852. "Grass",
  853. "Wood",
  854. "Concrete",
  855. "Flesh",
  856. "Rock",
  857. "Snow",
  858. "Ice",
  859. "Default",
  860. "Glass",
  861. "Cloth",
  862. "Tiberium Field",
  863. "Foliage Permeable",
  864. "Glass Permeable",
  865. "Ice Permeable",
  866. "Cloth Permeable",
  867. "Electrical",
  868. "Electrical Permeable",
  869. "Flammable",
  870. "Flammable Permeable",
  871. "Steam",
  872. "Steam Permeable",
  873. };
  874. /////////////////////////////////////////////////////////////////////////////////////////////
  875. // Flags for the Mesh Attributes member
  876. /////////////////////////////////////////////////////////////////////////////////////////////
  877. #define W3D_MESH_FLAG_NONE 0x00000000 // plain ole normal mesh
  878. #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)
  879. #define W3D_MESH_FLAG_SKIN 0x00000002 // (obsolete as of 4.1) skin mesh
  880. #define W3D_MESH_FLAG_SHADOW 0x00000004 // (obsolete as of 4.1) intended to be projected as a shadow
  881. #define W3D_MESH_FLAG_ALIGNED 0x00000008 // (obsolete as of 4.1) always aligns with camera
  882. #define W3D_MESH_FLAG_COLLISION_TYPE_MASK 0x00000FF0 // mask for the collision type bits
  883. #define W3D_MESH_FLAG_COLLISION_TYPE_SHIFT 4 // shifting to get to the collision type bits
  884. #define W3D_MESH_FLAG_COLLISION_TYPE_PHYSICAL 0x00000010 // physical collisions
  885. #define W3D_MESH_FLAG_COLLISION_TYPE_PROJECTILE 0x00000020 // projectiles (rays) collide with this
  886. #define W3D_MESH_FLAG_COLLISION_TYPE_VIS 0x00000040 // vis rays collide with this mesh
  887. #define W3D_MESH_FLAG_COLLISION_TYPE_CAMERA 0x00000080 // camera rays/boxes collide with this mesh
  888. #define W3D_MESH_FLAG_COLLISION_TYPE_VEHICLE 0x00000100 // vehicles collide with this mesh (and with physical collision meshes)
  889. #define W3D_MESH_FLAG_HIDDEN 0x00001000 // this mesh is hidden by default
  890. #define W3D_MESH_FLAG_TWO_SIDED 0x00002000 // render both sides of this mesh
  891. #define OBSOLETE_W3D_MESH_FLAG_LIGHTMAPPED 0x00004000 // obsolete lightmapped mesh
  892. // NOTE: retained for backwards compatibility - use W3D_MESH_FLAG_PRELIT_* instead.
  893. #define W3D_MESH_FLAG_CAST_SHADOW 0x00008000 // this mesh casts shadows
  894. #define W3D_MESH_FLAG_GEOMETRY_TYPE_MASK 0x00FF0000 // (introduced with 4.1)
  895. #define W3D_MESH_FLAG_GEOMETRY_TYPE_NORMAL 0x00000000 // (4.1+) normal mesh geometry
  896. #define W3D_MESH_FLAG_GEOMETRY_TYPE_CAMERA_ALIGNED 0x00010000 // (4.1+) camera aligned mesh
  897. #define W3D_MESH_FLAG_GEOMETRY_TYPE_SKIN 0x00020000 // (4.1+) skin mesh
  898. #define OBSOLETE_W3D_MESH_FLAG_GEOMETRY_TYPE_SHADOW 0x00030000 // (4.1+) shadow mesh OBSOLETE!
  899. #define W3D_MESH_FLAG_GEOMETRY_TYPE_AABOX 0x00040000 // (4.1+) aabox OBSOLETE!
  900. #define W3D_MESH_FLAG_GEOMETRY_TYPE_OBBOX 0x00050000 // (4.1+) obbox OBSOLETE!
  901. #define W3D_MESH_FLAG_GEOMETRY_TYPE_CAMERA_ORIENTED 0x00060000 // (4.1+) camera oriented mesh (points _towards_ camera)
  902. #define W3D_MESH_FLAG_PRELIT_MASK 0x0F000000 // (4.2+)
  903. #define W3D_MESH_FLAG_PRELIT_UNLIT 0x01000000 // mesh contains an unlit material chunk wrapper
  904. #define W3D_MESH_FLAG_PRELIT_VERTEX 0x02000000 // mesh contains a precalculated vertex-lit material chunk wrapper
  905. #define W3D_MESH_FLAG_PRELIT_LIGHTMAP_MULTI_PASS 0x04000000 // mesh contains a precalculated multi-pass lightmapped material chunk wrapper
  906. #define W3D_MESH_FLAG_PRELIT_LIGHTMAP_MULTI_TEXTURE 0x08000000 // mesh contains a precalculated multi-texture lightmapped material chunk wrapper
  907. #define W3D_MESH_FLAG_SHATTERABLE 0x10000000 // this mesh is shatterable.
  908. #define W3D_MESH_FLAG_NPATCHABLE 0x20000000 // it is ok to NPatch this mesh
  909. /********************************************************************************
  910. Meshes
  911. Version 3 Mesh Header, trimmed out some of the junk that was in the
  912. previous versions.
  913. ********************************************************************************/
  914. #define W3D_CURRENT_MESH_VERSION W3D_MAKE_VERSION(4,2)
  915. #define W3D_VERTEX_CHANNEL_LOCATION 0x00000001 // object-space location of the vertex
  916. #define W3D_VERTEX_CHANNEL_NORMAL 0x00000002 // object-space normal for the vertex
  917. #define W3D_VERTEX_CHANNEL_TEXCOORD 0x00000004 // texture coordinate
  918. #define W3D_VERTEX_CHANNEL_COLOR 0x00000008 // vertex color
  919. #define W3D_VERTEX_CHANNEL_BONEID 0x00000010 // per-vertex bone id for skins
  920. #define W3D_FACE_CHANNEL_FACE 0x00000001 // basic face info, W3dTriStruct...
  921. // boundary values for W3dMeshHeaderStruct::SortLevel
  922. #define SORT_LEVEL_NONE 0
  923. #define MAX_SORT_LEVEL 32
  924. #define SORT_LEVEL_BIN1 10
  925. #define SORT_LEVEL_BIN2 15
  926. #define SORT_LEVEL_BIN3 20
  927. struct W3dMeshHeader3Struct
  928. {
  929. uint32 Version;
  930. uint32 Attributes;
  931. char MeshName[W3D_NAME_LEN];
  932. char ContainerName[W3D_NAME_LEN];
  933. //
  934. // Counts, these can be regarded as an inventory of what is to come in the file.
  935. //
  936. uint32 NumTris; // number of triangles
  937. uint32 NumVertices; // number of unique vertices
  938. uint32 NumMaterials; // number of unique materials
  939. uint32 NumDamageStages; // number of damage offset chunks
  940. sint32 SortLevel; // static sorting level of this mesh
  941. uint32 PrelitVersion; // mesh generated by this version of Lightmap Tool
  942. uint32 FutureCounts[1]; // future counts
  943. uint32 VertexChannels; // bits for presence of types of per-vertex info
  944. uint32 FaceChannels; // bits for presence of types of per-face info
  945. //
  946. // Bounding volumes
  947. //
  948. W3dVectorStruct Min; // Min corner of the bounding box
  949. W3dVectorStruct Max; // Max corner of the bounding box
  950. W3dVectorStruct SphCenter; // Center of bounding sphere
  951. float32 SphRadius; // Bounding sphere radius
  952. };
  953. //
  954. // Vertex Influences. For "skins" each vertex can be associated with a
  955. // different bone.
  956. //
  957. struct W3dVertInfStruct
  958. {
  959. uint16 BoneIdx;
  960. uint8 Pad[6];
  961. };
  962. //
  963. // Deform information. Each mesh can have sets of keyframes of
  964. // deform info associated with it.
  965. //
  966. struct W3dMeshDeform
  967. {
  968. uint32 SetCount;
  969. uint32 AlphaPasses;
  970. uint32 reserved[3];
  971. };
  972. //
  973. // Deform set information. Each set is made up of a series
  974. // of keyframes.
  975. //
  976. struct W3dDeformSetInfo
  977. {
  978. uint32 KeyframeCount;
  979. uint32 flags;
  980. uint32 reserved[1];
  981. };
  982. #define W3D_DEFORM_SET_MANUAL_DEFORM 0x00000001 // set is isn't applied during sphere or point tests.
  983. //
  984. // Deform keyframe information. Each keyframe is made up of
  985. // a set of per-vert deform data.
  986. //
  987. struct W3dDeformKeyframeInfo
  988. {
  989. float32 DeformPercent;
  990. uint32 DataCount;
  991. uint32 reserved[2];
  992. };
  993. //
  994. // Deform data. Contains deform information about a vertex
  995. // in the mesh.
  996. //
  997. struct W3dDeformData
  998. {
  999. uint32 VertexIndex;
  1000. W3dVectorStruct Position;
  1001. W3dRGBAStruct Color;
  1002. uint32 reserved[2];
  1003. };
  1004. //
  1005. // AABTree header. Each mesh can have an associated Axis-Aligned-Bounding-Box tree
  1006. // which is used for collision detection and certain rendering algorithms (like
  1007. // texture projection.
  1008. //
  1009. struct W3dMeshAABTreeHeader
  1010. {
  1011. uint32 NodeCount;
  1012. uint32 PolyCount;
  1013. uint32 Padding[6];
  1014. };
  1015. //
  1016. // AABTree Node. This is a node in the AABTree.
  1017. // If the MSB of FrontOrPoly0 is 1, then the node is a leaf and contains Poly0 and PolyCount
  1018. // else, the node is not a leaf and contains indices to its front and back children. This matches
  1019. // the format used by AABTreeClass in WW3D.
  1020. //
  1021. struct W3dMeshAABTreeNode
  1022. {
  1023. W3dVectorStruct Min; // min corner of the box
  1024. W3dVectorStruct Max; // max corner of the box
  1025. uint32 FrontOrPoly0; // index of the front child or poly0 (if MSB is set, then leaf and poly0 is valid)
  1026. uint32 BackOrPolyCount; // index of the back child or polycount
  1027. };
  1028. /********************************************************************************
  1029. WHT ( Westwood Hierarchy Tree )
  1030. A hierarchy tree defines a set of coordinate systems which are connected
  1031. hierarchically. The header defines the name, number of pivots, etc.
  1032. The pivots chunk will contain a W3dPivotStructs for each node in the
  1033. tree.
  1034. The W3dPivotFixupStruct contains a transform for each MAX coordinate
  1035. system and our version of that same coordinate system (bone). It is
  1036. needed when the user exports the base pose using "Translation Only".
  1037. These are the matrices which go from the MAX rotated coordinate systems
  1038. to a system which is unrotated in the base pose. These transformations
  1039. are needed when exporting a hierarchy animation with the given hierarchy
  1040. tree file.
  1041. Another explanation of these kludgy "fixup" matrices:
  1042. What are the "fixup" matrices? These are the transforms which
  1043. were applied to the base pose when the user wanted to force the
  1044. base pose to use only matrices with certain properties. For
  1045. example, if we wanted the base pose to use translations only,
  1046. the fixup transform for each node is a transform which when
  1047. multiplied by the real node's world transform, yeilds a pure
  1048. translation matrix. Fixup matrices are used in the mesh
  1049. exporter since all vertices must be transformed by their inverses
  1050. in order to make things work. They also show up in the animation
  1051. exporter because they are needed to make the animation work with
  1052. the new base pose.
  1053. ********************************************************************************/
  1054. #define W3D_CURRENT_HTREE_VERSION W3D_MAKE_VERSION(4,1)
  1055. struct W3dHierarchyStruct
  1056. {
  1057. uint32 Version;
  1058. char Name[W3D_NAME_LEN]; // Name of the hierarchy
  1059. uint32 NumPivots;
  1060. W3dVectorStruct Center;
  1061. };
  1062. struct W3dPivotStruct
  1063. {
  1064. char Name[W3D_NAME_LEN]; // Name of the node (UR_ARM, LR_LEG, TORSO, etc)
  1065. uint32 ParentIdx; // 0xffffffff = root pivot; no parent
  1066. W3dVectorStruct Translation; // translation to pivot point
  1067. W3dVectorStruct EulerAngles; // orientation of the pivot point
  1068. W3dQuaternionStruct Rotation; // orientation of the pivot point
  1069. };
  1070. struct W3dPivotFixupStruct
  1071. {
  1072. float32 TM[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1073. };
  1074. /********************************************************************************
  1075. WHA (Westwood Hierarchy Animation)
  1076. A Hierarchy Animation is a set of data defining deltas from the base
  1077. position of a hierarchy tree. Translation and Rotation channels can be
  1078. attached to any node of the hierarchy tree which the animation is
  1079. associated with.
  1080. ********************************************************************************/
  1081. #define W3D_CURRENT_HANIM_VERSION W3D_MAKE_VERSION(4,1)
  1082. #define W3D_CURRENT_COMPRESSED_HANIM_VERSION W3D_MAKE_VERSION(0,1)
  1083. #define W3D_CURRENT_MORPH_HANIM_VERSION W3D_MAKE_VERSION(0,1)
  1084. struct W3dAnimHeaderStruct
  1085. {
  1086. uint32 Version;
  1087. char Name[W3D_NAME_LEN];
  1088. char HierarchyName[W3D_NAME_LEN];
  1089. uint32 NumFrames;
  1090. uint32 FrameRate;
  1091. };
  1092. struct W3dCompressedAnimHeaderStruct
  1093. {
  1094. uint32 Version;
  1095. char Name[W3D_NAME_LEN];
  1096. char HierarchyName[W3D_NAME_LEN];
  1097. uint32 NumFrames;
  1098. uint16 FrameRate;
  1099. uint16 Flavor;
  1100. };
  1101. enum
  1102. {
  1103. ANIM_CHANNEL_X = 0,
  1104. ANIM_CHANNEL_Y,
  1105. ANIM_CHANNEL_Z,
  1106. ANIM_CHANNEL_XR,
  1107. ANIM_CHANNEL_YR,
  1108. ANIM_CHANNEL_ZR,
  1109. ANIM_CHANNEL_Q,
  1110. ANIM_CHANNEL_TIMECODED_X,
  1111. ANIM_CHANNEL_TIMECODED_Y,
  1112. ANIM_CHANNEL_TIMECODED_Z,
  1113. ANIM_CHANNEL_TIMECODED_Q,
  1114. ANIM_CHANNEL_ADAPTIVEDELTA_X,
  1115. ANIM_CHANNEL_ADAPTIVEDELTA_Y,
  1116. ANIM_CHANNEL_ADAPTIVEDELTA_Z,
  1117. ANIM_CHANNEL_ADAPTIVEDELTA_Q,
  1118. };
  1119. //
  1120. // Flavor Enumerations
  1121. //
  1122. enum
  1123. {
  1124. ANIM_FLAVOR_TIMECODED = 0,
  1125. ANIM_FLAVOR_ADAPTIVE_DELTA,
  1126. ANIM_FLAVOR_VALID
  1127. };
  1128. // Begin Classic Structures
  1129. struct W3dAnimChannelStruct
  1130. {
  1131. uint16 FirstFrame;
  1132. uint16 LastFrame;
  1133. uint16 VectorLen; // length of each vector in this channel
  1134. uint16 Flags; // channel type.
  1135. uint16 Pivot; // pivot affected by this channel
  1136. uint16 pad;
  1137. float32 Data[1]; // will be (LastFrame - FirstFrame + 1) * VectorLen long
  1138. };
  1139. enum
  1140. {
  1141. BIT_CHANNEL_VIS = 0, // turn meshes on and off depending on anim frame.
  1142. BIT_CHANNEL_TIMECODED_VIS,
  1143. };
  1144. struct W3dBitChannelStruct
  1145. {
  1146. uint16 FirstFrame; // all frames outside "First" and "Last" are assumed = DefaultVal
  1147. uint16 LastFrame;
  1148. uint16 Flags; // channel type.
  1149. uint16 Pivot; // pivot affected by this channel
  1150. uint8 DefaultVal; // default state when outside valid range.
  1151. uint8 Data[1]; // will be (LastFrame - FirstFrame + 1) / 8 long
  1152. };
  1153. // End Classic Structures
  1154. // Begin Time Coded Structures
  1155. // A time code is a uint32 that prefixes each vector
  1156. // the MSB is used to indicate a binary (non interpolated) movement
  1157. #define W3D_TIMECODED_BINARY_MOVEMENT_FLAG 0x80000000
  1158. struct W3dTimeCodedAnimChannelStruct
  1159. {
  1160. uint32 NumTimeCodes; // number of time coded entries
  1161. uint16 Pivot; // pivot affected by this channel
  1162. uint8 VectorLen; // length of each vector in this channel
  1163. uint8 Flags; // channel type.
  1164. uint32 Data[1]; // will be (NumTimeCodes * ((VectorLen * sizeof(uint32)) + sizeof(uint32)))
  1165. };
  1166. // The bit channel is encoded right into the MSB of each time code
  1167. #define W3D_TIMECODED_BIT_MASK 0x80000000
  1168. struct W3dTimeCodedBitChannelStruct
  1169. {
  1170. uint32 NumTimeCodes; // number of time coded entries
  1171. uint16 Pivot; // pivot affected by this channel
  1172. uint8 Flags; // channel type.
  1173. uint8 DefaultVal; // default state when outside valid range.
  1174. uint32 Data[1]; // will be (NumTimeCodes * sizeof(uint32))
  1175. };
  1176. // End Time Coded Structures
  1177. // Begin AdaptiveDelta Structures
  1178. struct W3dAdaptiveDeltaAnimChannelStruct
  1179. {
  1180. uint32 NumFrames; // number of frames of animation
  1181. uint16 Pivot; // pivot effected by this channel
  1182. uint8 VectorLen; // num Channels
  1183. uint8 Flags; // channel type
  1184. float Scale; // Filter Table Scale
  1185. uint32 Data[1]; // OpCode Data Stream
  1186. };
  1187. // End AdaptiveDelta Structures
  1188. /********************************************************************************
  1189. HMorphAnimClass
  1190. This is an animation format which describes morphs between poses in another
  1191. animation. It is used for Renegade's facial animation system. There is
  1192. a normal anim which defines the pose for each phoneme and then a "Morph Anim"
  1193. which defines the transitions between phonemes over time. In addition there
  1194. is the concept of multiple morph channels in a morph anim. Each "channel"
  1195. controls a set of pivots in the skeleton and has its own set of morph keys
  1196. and poses. This lets us have one set of poses for expressions and another
  1197. for phonemes (a bone is only moved in one or the other anims though)
  1198. The chunks used to describe a "morph" anim are as follows:
  1199. W3D_CHUNK_MORPH_ANIMATION =0x000002C0, // wrapper for the entire anim
  1200. W3D_CHUNK_MORPHANIM_HEADER, // W3dMorphAnimHeaderStruct describes playback rate, number of frames, and type of compression
  1201. W3D_CHUNK_MORPHANIM_CHANNEL, // wrapper for a channel
  1202. W3D_CHUNK_MORPHANIM_POSENAME, // name of the other anim which contains the poses for this morph channel
  1203. W3D_CHUNK_MORPHANIM_KEYDATA, // array of W3dMorphAnimKeyStruct's (use chunk length to determine how many)
  1204. W3D_CHUNK_MORPHANIM_PIVOTCHANNELDATA, // uin32 per pivot in the htree, indicating which channel controls the pivot
  1205. ********************************************************************************/
  1206. struct W3dMorphAnimHeaderStruct
  1207. {
  1208. uint32 Version;
  1209. char Name[W3D_NAME_LEN];
  1210. char HierarchyName[W3D_NAME_LEN];
  1211. uint32 FrameCount;
  1212. float32 FrameRate;
  1213. uint32 ChannelCount;
  1214. };
  1215. struct W3dMorphAnimKeyStruct
  1216. {
  1217. uint32 MorphFrame;
  1218. uint32 PoseFrame;
  1219. };
  1220. /********************************************************************************
  1221. HModel - Hiearchical Model
  1222. A Hierarchy Model is a set of render objects which should be attached to
  1223. bones in a hierarchy tree. There can be multiple objects per node
  1224. in the tree. Or there may be no objects attached to a particular bone.
  1225. (gth) 09/22/2000 - Simplified the HModel file format. The W3DHModelAuxDataStruct
  1226. was un-needed and moved to w3d_obsolete.h. The safe way to parse previous
  1227. and current HModel formats is this:
  1228. - Read in the header from W3D_CHUNK_HMODEL_HEADER
  1229. - Allocate space for 'NumConnections' nodes that will follow
  1230. - Read in the rest of the chunks
  1231. - Create a sub-object for W3D_CHUNK_NODE, W3D_CHUNK_COLLISION_NODE, or
  1232. W3D_CHUNK_SKIN_NODE.
  1233. - Skip the OBSOLETE_W3D_CHUNK_HMODEL_AUX_DATA and OBSOLETE_W3D_CHUNK_SHADOW_NODE
  1234. ********************************************************************************/
  1235. #define W3D_CURRENT_HMODEL_VERSION W3D_MAKE_VERSION(4,2)
  1236. struct W3dHModelHeaderStruct
  1237. {
  1238. uint32 Version;
  1239. char Name[W3D_NAME_LEN]; // Name of this model
  1240. char HierarchyName[W3D_NAME_LEN]; // Name of the hierarchy tree this model uses
  1241. uint16 NumConnections;
  1242. };
  1243. struct W3dHModelNodeStruct
  1244. {
  1245. // Note: the full name of the Render object is expected to be: <HModelName>.<RenderObjName>
  1246. char RenderObjName[W3D_NAME_LEN];
  1247. uint16 PivotIdx;
  1248. };
  1249. /********************************************************************************
  1250. (LODModel - Level-Of-Detail Model)
  1251. An LOD Model is a set of render objects which are interchangeable and
  1252. designed to be different resolution versions of the same object.
  1253. ********************************************************************************/
  1254. struct W3dLODModelHeaderStruct
  1255. {
  1256. uint32 Version;
  1257. char Name[W3D_NAME_LEN]; // Name of this LOD Model
  1258. uint16 NumLODs;
  1259. };
  1260. struct W3dLODStruct
  1261. {
  1262. char RenderObjName[2*W3D_NAME_LEN];
  1263. float32 LODMin; // "artist" inspired switching distances
  1264. float32 LODMax;
  1265. };
  1266. /********************************************************************************
  1267. Collection
  1268. A collection chunk is generated when the user exports a bunch of meshes.
  1269. The collection will be named with the root name of the w3d file and will
  1270. contain a string chunk for the name of each render object in the collection.
  1271. A collection may also contain a "Snap Points" chunk.
  1272. W3D_CHUNK_COLLECTION
  1273. W3D_CHUNK_COLLECTION_HEADER
  1274. W3D_CHUNK_SNAP_POINTS
  1275. W3D_CHUNK_COLLECTION_OBJ_NAME
  1276. W3D_CHUNK_COLLECTION_OBJ_NAME
  1277. W3D_CHUNK_COLLECTION_OBJ_NAME
  1278. ...
  1279. ********************************************************************************/
  1280. #define W3D_CURRENT_COLLECTION_VERSION W3D_MAKE_VERSION(4,2)
  1281. struct W3dCollectionHeaderStruct
  1282. {
  1283. uint32 Version;
  1284. char Name[W3D_NAME_LEN];
  1285. uint32 RenderObjectCount;
  1286. uint32 pad[2];
  1287. };
  1288. /*
  1289. ** Placeholder chunks. Also known as "PROXIES". These are used by the Renegade
  1290. ** level editor to instruct the editor to instance a particular named object
  1291. */
  1292. #define W3D_CURRENT_PLACEHOLDER_VERSION W3D_MAKE_VERSION(1,0)
  1293. //
  1294. // Note: This structure is follwed directly by an array of char's 'name_len' in length
  1295. // which specify the name of the placeholder object in our Commando-level editor.
  1296. //
  1297. struct W3dPlaceholderStruct
  1298. {
  1299. uint32 version;
  1300. float32 transform[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1301. uint32 name_len;
  1302. };
  1303. /*
  1304. ** Transform chunks. These chunks refer to other W3D files which should be transformed by
  1305. ** this file. This feature is used to allow user to (for example) lightmap the interior
  1306. ** of a building once and then just transform that into all of our levels that use it.
  1307. */
  1308. #define W3D_CURRENT_TRANSFORM_VERSION W3D_MAKE_VERSION(1,0)
  1309. //
  1310. // Note: This structure is followed directly by an array of char's 'name_len' in length
  1311. // which specifies the name of the file to apply the transform to.
  1312. //
  1313. struct W3dTransformNodeStruct
  1314. {
  1315. uint32 version;
  1316. float32 transform[4][3]; // this is a direct dump of a MAX 3x4 matrix
  1317. uint32 name_len;
  1318. };
  1319. /********************************************************************************
  1320. Lights
  1321. The following structs are used to define lights in the w3d file. Currently
  1322. we have point lights, directional lights, and spot lights.
  1323. ********************************************************************************/
  1324. #define W3D_CURRENT_LIGHT_VERSION W3D_MAKE_VERSION(1,0)
  1325. #define W3D_LIGHT_ATTRIBUTE_TYPE_MASK 0x000000FF
  1326. #define W3D_LIGHT_ATTRIBUTE_POINT 0x00000001
  1327. #define W3D_LIGHT_ATTRIBUTE_DIRECTIONAL 0x00000002
  1328. #define W3D_LIGHT_ATTRIBUTE_SPOT 0x00000003
  1329. #define W3D_LIGHT_ATTRIBUTE_CAST_SHADOWS 0x00000100
  1330. struct W3dLightStruct
  1331. {
  1332. uint32 Attributes;
  1333. uint32 Unused; // Old exclusion bit deprecated
  1334. W3dRGBStruct Ambient;
  1335. W3dRGBStruct Diffuse;
  1336. W3dRGBStruct Specular;
  1337. float32 Intensity;
  1338. };
  1339. struct W3dSpotLightStruct
  1340. {
  1341. W3dVectorStruct SpotDirection;
  1342. float32 SpotAngle;
  1343. float32 SpotExponent;
  1344. };
  1345. struct W3dLightAttenuationStruct
  1346. {
  1347. float32 Start;
  1348. float32 End;
  1349. };
  1350. struct W3dLightTransformStruct
  1351. {
  1352. float32 Transform [3][4];
  1353. };
  1354. /********************************************************************************
  1355. Particle emitters
  1356. The following structs are used to define emitters in the w3d file.
  1357. ********************************************************************************/
  1358. #define W3D_CURRENT_EMITTER_VERSION 0x00020000
  1359. //
  1360. // This enum contains valid defines for the Type field
  1361. // of the W3dEmitterUserInfoStruct. The programmer
  1362. // can add entries here that their specific loader
  1363. // can switch on to determine what type the emitter is.
  1364. //
  1365. // NOTE: Please add a string the the EMITTER_TYPE_NAMES
  1366. // array when you add an entry to the enum.
  1367. //
  1368. enum
  1369. {
  1370. EMITTER_TYPEID_DEFAULT = 0,
  1371. EMITTER_TYPEID_COUNT
  1372. };
  1373. //
  1374. // The definition of this string array can be found in
  1375. // Part_Ldr.cpp. Please update this array accordingly.
  1376. //
  1377. extern const char *EMITTER_TYPE_NAMES[EMITTER_TYPEID_COUNT];
  1378. struct W3dEmitterHeaderStruct
  1379. {
  1380. uint32 Version;
  1381. char Name[W3D_NAME_LEN];
  1382. };
  1383. struct W3dEmitterUserInfoStruct
  1384. {
  1385. uint32 Type; // One of the EMITTER_TYPEID_ enum's defined above
  1386. uint32 SizeofStringParam; // Size (in bytes) of the following string data
  1387. char StringParam[1]; // Array of bytes. Where "count = SizeofStringParam"
  1388. };
  1389. struct W3dEmitterInfoStruct
  1390. {
  1391. char TextureFilename[260];
  1392. float32 StartSize;
  1393. float32 EndSize;
  1394. float32 Lifetime;
  1395. float32 EmissionRate;
  1396. float32 MaxEmissions;
  1397. float32 VelocityRandom;
  1398. float32 PositionRandom;
  1399. float32 FadeTime;
  1400. float32 Gravity;
  1401. float32 Elasticity;
  1402. W3dVectorStruct Velocity;
  1403. W3dVectorStruct Acceleration;
  1404. W3dRGBAStruct StartColor;
  1405. W3dRGBAStruct EndColor;
  1406. };
  1407. struct W3dVolumeRandomizerStruct
  1408. {
  1409. uint32 ClassID;
  1410. float32 Value1;
  1411. float32 Value2;
  1412. float32 Value3;
  1413. uint32 reserved[4];
  1414. };
  1415. #define W3D_EMITTER_RENDER_MODE_TRI_PARTICLES 0
  1416. #define W3D_EMITTER_RENDER_MODE_QUAD_PARTICLES 1
  1417. #define W3D_EMITTER_RENDER_MODE_LINE 2
  1418. #define W3D_EMITTER_FRAME_MODE_1x1 0
  1419. #define W3D_EMITTER_FRAME_MODE_2x2 1
  1420. #define W3D_EMITTER_FRAME_MODE_4x4 2
  1421. #define W3D_EMITTER_FRAME_MODE_8x8 3
  1422. #define W3D_EMITTER_FRAME_MODE_16x16 4
  1423. struct W3dEmitterInfoStructV2
  1424. {
  1425. uint32 BurstSize;
  1426. W3dVolumeRandomizerStruct CreationVolume;
  1427. W3dVolumeRandomizerStruct VelRandom;
  1428. float32 OutwardVel;
  1429. float32 VelInherit;
  1430. W3dShaderStruct Shader;
  1431. uint32 RenderMode; // render as particles or lines?
  1432. uint32 FrameMode; // chop the texture into a grid of smaller squares?
  1433. uint32 reserved[6];
  1434. };
  1435. // W3D_CHUNK_EMITTER_PROPS
  1436. // Contains a W3dEmitterPropertyStruct followed by a number of color keyframes,
  1437. // opacity keyframes, and size keyframes
  1438. struct W3dEmitterPropertyStruct
  1439. {
  1440. uint32 ColorKeyframes;
  1441. uint32 OpacityKeyframes;
  1442. uint32 SizeKeyframes;
  1443. W3dRGBAStruct ColorRandom;
  1444. float32 OpacityRandom;
  1445. float32 SizeRandom;
  1446. uint32 reserved[4];
  1447. };
  1448. struct W3dEmitterColorKeyframeStruct
  1449. {
  1450. float32 Time;
  1451. W3dRGBAStruct Color;
  1452. };
  1453. struct W3dEmitterOpacityKeyframeStruct
  1454. {
  1455. float32 Time;
  1456. float32 Opacity;
  1457. };
  1458. struct W3dEmitterSizeKeyframeStruct
  1459. {
  1460. float32 Time;
  1461. float32 Size;
  1462. };
  1463. // W3D_CHUNK_EMITTER_ROTATION_KEYFRAMES
  1464. // Contains a W3dEmitterRotationHeaderStruct followed by a number of
  1465. // rotational velocity keyframes.
  1466. struct W3dEmitterRotationHeaderStruct
  1467. {
  1468. uint32 KeyframeCount;
  1469. float32 Random; // random initial rotational velocity (rotations/sec)
  1470. float32 OrientationRandom; // random initial orientation (rotations, 1.0=360deg)
  1471. uint32 Reserved[1];
  1472. };
  1473. struct W3dEmitterRotationKeyframeStruct
  1474. {
  1475. float32 Time;
  1476. float32 Rotation; // rotational velocity in rotations/sec
  1477. };
  1478. // W3D_CHUNK_EMITTER_FRAME_KEYFRAMES
  1479. // Contains a W3dEmitterFrameHeaderStruct followed by a number of
  1480. // frame keyframes (sub-texture indexing)
  1481. struct W3dEmitterFrameHeaderStruct
  1482. {
  1483. uint32 KeyframeCount;
  1484. float32 Random;
  1485. uint32 Reserved[2];
  1486. };
  1487. struct W3dEmitterFrameKeyframeStruct
  1488. {
  1489. float32 Time;
  1490. float32 Frame;
  1491. };
  1492. // W3D_CHUNK_EMITTER_LINE_PROPERTIES
  1493. // Contains a W3dEmitterLinePropertiesStruct.
  1494. // Emiter Line Flags (used in the Flags field of W3dEmitterLinePropertiesStruct):
  1495. #define W3D_ELINE_MERGE_INTERSECTIONS 0x00000001 // Merge intersections
  1496. #define W3D_ELINE_FREEZE_RANDOM 0x00000002 // Freeze random (note: offsets are in camera space)
  1497. #define W3D_ELINE_DISABLE_SORTING 0x00000004 // Disable sorting (even if shader has alpha-blending)
  1498. #define W3D_ELINE_END_CAPS 0x00000008 // Draw end caps on the line
  1499. #define W3D_ELINE_TEXTURE_MAP_MODE_MASK 0xFF000000 // Must cover all possible TextureMapMode values
  1500. #define W3D_ELINE_TEXTURE_MAP_MODE_OFFSET 24 // By how many bits do I need to shift the texture mapping mode?
  1501. #define W3D_ELINE_UNIFORM_WIDTH_TEXTURE_MAP 0x00000000 // Entire line uses one row of texture (constant V)
  1502. #define W3D_ELINE_UNIFORM_LENGTH_TEXTURE_MAP 0x00000001 // Entire line uses one row of texture stretched length-wise
  1503. #define W3D_ELINE_TILED_TEXTURE_MAP 0x00000002 // Tiled continuously over line
  1504. #define W3D_ELINE_DEFAULT_BITS (W3D_ELINE_MERGE_INTERSECTIONS | (W3D_ELINE_UNIFORM_WIDTH_TEXTURE_MAP << W3D_ELINE_TEXTURE_MAP_MODE_OFFSET))
  1505. struct W3dEmitterLinePropertiesStruct
  1506. {
  1507. uint32 Flags;
  1508. uint32 SubdivisionLevel;
  1509. float32 NoiseAmplitude;
  1510. float32 MergeAbortFactor;
  1511. float32 TextureTileFactor;
  1512. float32 UPerSec;
  1513. float32 VPerSec;
  1514. uint32 Reserved[9];
  1515. };
  1516. /********************************************************************************
  1517. Aggregate objects
  1518. The following structs are used to define aggregates in the w3d file. An
  1519. 'aggregate' is simply a 'shell' that contains references to a hierarchy
  1520. model and subobjects to attach to its bones.
  1521. ********************************************************************************/
  1522. #define W3D_CURRENT_AGGREGATE_VERSION 0x00010003
  1523. const int MESH_PATH_ENTRIES = 15;
  1524. const int MESH_PATH_ENTRY_LEN = (W3D_NAME_LEN * 2);
  1525. struct W3dAggregateHeaderStruct
  1526. {
  1527. uint32 Version;
  1528. char Name[W3D_NAME_LEN];
  1529. };
  1530. struct W3dAggregateInfoStruct
  1531. {
  1532. char BaseModelName[W3D_NAME_LEN*2];
  1533. uint32 SubobjectCount;
  1534. };
  1535. struct W3dAggregateSubobjectStruct
  1536. {
  1537. char SubobjectName[W3D_NAME_LEN*2];
  1538. char BoneName[W3D_NAME_LEN*2];
  1539. };
  1540. //
  1541. // Structures for version 1.1 and newer
  1542. //
  1543. struct W3dTextureReplacerHeaderStruct
  1544. {
  1545. uint32 ReplacedTexturesCount;
  1546. };
  1547. struct W3dTextureReplacerStruct
  1548. {
  1549. char MeshPath[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN];
  1550. char BonePath[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN];
  1551. char OldTextureName[260];
  1552. char NewTextureName[260];
  1553. W3dTextureInfoStruct TextureParams;
  1554. };
  1555. //
  1556. // Flags used in the W3dAggregateMiscInfo structure
  1557. //
  1558. const int W3D_AGGREGATE_FORCE_SUB_OBJ_LOD = 0x00000001;
  1559. //
  1560. // Structures for version 1.2 and newer
  1561. //
  1562. struct W3dAggregateMiscInfo
  1563. {
  1564. uint32 OriginalClassID;
  1565. uint32 Flags;
  1566. uint32 reserved[3];
  1567. };
  1568. /********************************************************************************
  1569. HLod (Hierarchical LOD Model)
  1570. This is a hierarchical model which has multiple arrays of models which can
  1571. be switched for LOD purposes.
  1572. Relevant Chunks:
  1573. ----------------
  1574. W3D_CHUNK_HLOD =0x00000700, // description of an HLod object (see HLodClass)
  1575. W3D_CHUNK_HLOD_HEADER, // general information such as name and version
  1576. W3D_CHUNK_HLOD_LOD_ARRAY, // wrapper around the array of objects for each level of detail
  1577. W3D_CHUNK_HLOD_SUB_OBJECT_ARRAY_HEADER, // info on the objects in this level of detail array
  1578. W3D_CHUNK_HLOD_SUB_OBJECT, // an object in this level of detail array
  1579. W3D_CHUNK_HLOD_AGGREGATE_ARRAY, // array of aggregates, contains W3D_CHUNK_SUB_OBJECT_ARRAY_HEADER and W3D_CHUNK_SUB_OBJECT_ARRAY
  1580. W3D_CHUNK_HLOD_PROXY_ARRAY, // array of proxies, used for application-defined purposes
  1581. An HLOD is the basic hierarchical model format used by W3D. It references
  1582. an HTree for its hierarchical structure and animation data and several arrays
  1583. of sub-objects; one for each LOD in the model. In addition, it can contain
  1584. an array of "aggregates" which are references to external W3D objects to
  1585. be automatically attached into it. And it can have a list of "proxy" objects
  1586. which can be used for application purposes such as instantiating game objects
  1587. at the specified transform.
  1588. ********************************************************************************/
  1589. #define W3D_CURRENT_HLOD_VERSION W3D_MAKE_VERSION(1,0)
  1590. #define NO_MAX_SCREEN_SIZE WWMATH_FLOAT_MAX
  1591. struct W3dHLodHeaderStruct
  1592. {
  1593. uint32 Version;
  1594. uint32 LodCount;
  1595. char Name[W3D_NAME_LEN];
  1596. char HierarchyName[W3D_NAME_LEN]; // name of the hierarchy tree to use (\0 if none)
  1597. };
  1598. struct W3dHLodArrayHeaderStruct
  1599. {
  1600. uint32 ModelCount;
  1601. float32 MaxScreenSize; // if model is bigger than this, switch to higher lod.
  1602. };
  1603. struct W3dHLodSubObjectStruct
  1604. {
  1605. uint32 BoneIndex;
  1606. char Name[W3D_NAME_LEN*2];
  1607. };
  1608. /********************************************************************************
  1609. Collision Boxes
  1610. Collision boxes are meant to be used for, you guessed it, collision detection.
  1611. For this reason, they only contain a minimal amount of rendering information
  1612. (a color).
  1613. Axis Aligned - This is a bounding box which is *always* aligned with the world
  1614. coordinate system. So, the center point is to be transformed by whatever
  1615. transformation matrix is being used but the extents always point down the
  1616. world space x,y, and z axes. (in effect, you are translating the center).
  1617. Oriented - This is an oriented 3D box. It is aligned with the coordinate system
  1618. it is in. So its extents always point along the local coordinate system axes.
  1619. ********************************************************************************/
  1620. #define W3D_BOX_CURRENT_VERSION W3D_MAKE_VERSION(1,0)
  1621. #define W3D_BOX_ATTRIBUTE_ORIENTED 0x00000001
  1622. #define W3D_BOX_ATTRIBUTE_ALIGNED 0x00000002
  1623. #define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_MASK 0x00000FF0 // mask for the collision type bits
  1624. #define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_SHIFT 4 // shifting to get to the collision type bits
  1625. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PHYSICAL 0x00000010 // physical collisions
  1626. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PROJECTILE 0x00000020 // projectiles (rays) collide with this
  1627. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VIS 0x00000040 // vis rays collide with this mesh
  1628. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_CAMERA 0x00000080 // cameras collide with this mesh
  1629. #define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VEHICLE 0x00000100 // vehicles collide with this mesh
  1630. struct W3dBoxStruct
  1631. {
  1632. uint32 Version; // file format version
  1633. uint32 Attributes; // box attributes (above #define's)
  1634. char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<boxname>
  1635. W3dRGBStruct Color; // color to use when drawing the box
  1636. W3dVectorStruct Center; // center of the box
  1637. W3dVectorStruct Extent; // extent of the box
  1638. };
  1639. /********************************************************************************
  1640. NULL Objects
  1641. Null objects are used by the LOD system to make meshes dissappear at lower
  1642. levels of detail.
  1643. ********************************************************************************/
  1644. #define W3D_NULL_OBJECT_CURRENT_VERSION W3D_MAKE_VERSION(1,0)
  1645. struct W3dNullObjectStruct
  1646. {
  1647. uint32 Version; // file format version
  1648. uint32 Attributes; // object attributes (currently un-used)
  1649. uint32 pad[2]; // pad space
  1650. char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<boxname>
  1651. };
  1652. /********************************************************************************
  1653. Dazzle Objects
  1654. The only data needed to instantiate a dazzle object is the type-name of
  1655. the dazzle to use. The dazzle is always assumed to be at the pivot point
  1656. of the bone it is attached to (you should enable Export_Transform) for
  1657. dazzles. If the dazzle-type (from dazzle.ini) is directional, then the
  1658. coordinate-system of the bone will define the direction.
  1659. ********************************************************************************/
  1660. /********************************************************************************
  1661. Sound render objects
  1662. The following structs are used to define sound render object in the w3d file.
  1663. These objects are used to trigger a sound effect in the world. When the object
  1664. is shown, its associated sound is added to the world and played, when the object
  1665. is hidden, the associated sound is stopped and removed from the world.
  1666. ********************************************************************************/
  1667. #define W3D_CURRENT_SOUNDROBJ_VERSION 0x00010000
  1668. //
  1669. // Note: This structure is follwed directly by a chunk (W3D_CHUNK_SOUNDROBJ_DEFINITION)
  1670. // that contains an embedded AudibleSoundDefinitionClass's storage. See audibledound.h
  1671. // for details.
  1672. //
  1673. struct W3dSoundRObjHeaderStruct
  1674. {
  1675. uint32 Version;
  1676. char Name[W3D_NAME_LEN];
  1677. uint32 Flags;
  1678. uint32 Padding[8];
  1679. };
  1680. /*
  1681. ** Include the obsolete structures and chunk ID's
  1682. */
  1683. #include "w3d_obsolete.h"
  1684. #endif // W3D_FILE_H