Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef OPTIMIZE_H
  8. #define OPTIMIZE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "studio.h"
  13. // NOTE: You can change this without affecting the vtx file format.
  14. #define MAX_NUM_BONES_PER_TRI ( MAX_NUM_BONES_PER_VERT * 3 )
  15. #define MAX_NUM_BONES_PER_STRIP 512
  16. #define OPTIMIZED_MODEL_FILE_VERSION 7
  17. extern bool g_bDumpGLViewFiles;
  18. struct s_bodypart_t;
  19. namespace OptimizedModel
  20. {
  21. #pragma pack(1)
  22. struct BoneStateChangeHeader_t
  23. {
  24. DECLARE_BYTESWAP_DATADESC();
  25. int hardwareID;
  26. int newBoneID;
  27. };
  28. struct Vertex_t
  29. {
  30. DECLARE_BYTESWAP_DATADESC();
  31. // these index into the mesh's vert[origMeshVertID]'s bones
  32. unsigned char boneWeightIndex[MAX_NUM_BONES_PER_VERT];
  33. unsigned char numBones;
  34. unsigned short origMeshVertID;
  35. // for sw skinned verts, these are indices into the global list of bones
  36. // for hw skinned verts, these are hardware bone indices
  37. char boneID[MAX_NUM_BONES_PER_VERT];
  38. };
  39. enum StripHeaderFlags_t {
  40. STRIP_IS_TRILIST = 0x01,
  41. STRIP_IS_TRISTRIP = 0x02
  42. };
  43. // a strip is a piece of a stripgroup that is divided by bones
  44. // (and potentially tristrips if we remove some degenerates.)
  45. struct StripHeader_t
  46. {
  47. DECLARE_BYTESWAP_DATADESC();
  48. // indexOffset offsets into the mesh's index array.
  49. int numIndices;
  50. int indexOffset;
  51. // vertexOffset offsets into the mesh's vert array.
  52. int numVerts;
  53. int vertOffset;
  54. // use this to enable/disable skinning.
  55. // May decide (in optimize.cpp) to put all with 1 bone in a different strip
  56. // than those that need skinning.
  57. short numBones;
  58. unsigned char flags;
  59. int numBoneStateChanges;
  60. int boneStateChangeOffset;
  61. inline BoneStateChangeHeader_t *pBoneStateChange( int i ) const
  62. {
  63. return (BoneStateChangeHeader_t *)(((byte *)this) + boneStateChangeOffset) + i;
  64. };
  65. };
  66. enum StripGroupFlags_t
  67. {
  68. STRIPGROUP_IS_FLEXED = 0x01,
  69. STRIPGROUP_IS_HWSKINNED = 0x02,
  70. STRIPGROUP_IS_DELTA_FLEXED = 0x04,
  71. STRIPGROUP_SUPPRESS_HW_MORPH = 0x08, // NOTE: This is a temporary flag used at run time.
  72. };
  73. // a locking group
  74. // a single vertex buffer
  75. // a single index buffer
  76. struct StripGroupHeader_t
  77. {
  78. DECLARE_BYTESWAP_DATADESC();
  79. // These are the arrays of all verts and indices for this mesh. strips index into this.
  80. int numVerts;
  81. int vertOffset;
  82. inline Vertex_t *pVertex( int i ) const
  83. {
  84. return (Vertex_t *)(((byte *)this) + vertOffset) + i;
  85. };
  86. int numIndices;
  87. int indexOffset;
  88. inline unsigned short *pIndex( int i ) const
  89. {
  90. return (unsigned short *)(((byte *)this) + indexOffset) + i;
  91. };
  92. int numStrips;
  93. int stripOffset;
  94. inline StripHeader_t *pStrip( int i ) const
  95. {
  96. return (StripHeader_t *)(((byte *)this) + stripOffset) + i;
  97. };
  98. unsigned char flags;
  99. };
  100. enum MeshFlags_t {
  101. // these are both material properties, and a mesh has a single material.
  102. MESH_IS_TEETH = 0x01,
  103. MESH_IS_EYES = 0x02
  104. };
  105. // a collection of locking groups:
  106. // up to 4:
  107. // non-flexed, hardware skinned
  108. // flexed, hardware skinned
  109. // non-flexed, software skinned
  110. // flexed, software skinned
  111. //
  112. // A mesh has a material associated with it.
  113. struct MeshHeader_t
  114. {
  115. DECLARE_BYTESWAP_DATADESC();
  116. int numStripGroups;
  117. int stripGroupHeaderOffset;
  118. inline StripGroupHeader_t *pStripGroup( int i ) const
  119. {
  120. StripGroupHeader_t *pDebug = (StripGroupHeader_t *)(((byte *)this) + stripGroupHeaderOffset) + i;
  121. return pDebug;
  122. };
  123. unsigned char flags;
  124. };
  125. struct ModelLODHeader_t
  126. {
  127. DECLARE_BYTESWAP_DATADESC();
  128. int numMeshes;
  129. int meshOffset;
  130. float switchPoint;
  131. inline MeshHeader_t *pMesh( int i ) const
  132. {
  133. MeshHeader_t *pDebug = (MeshHeader_t *)(((byte *)this) + meshOffset) + i;
  134. return pDebug;
  135. };
  136. };
  137. // This maps one to one with models in the mdl file.
  138. // There are a bunch of model LODs stored inside potentially due to the qc $lod command
  139. struct ModelHeader_t
  140. {
  141. DECLARE_BYTESWAP_DATADESC();
  142. int numLODs; // garymcthack - this is also specified in FileHeader_t
  143. int lodOffset;
  144. inline ModelLODHeader_t *pLOD( int i ) const
  145. {
  146. ModelLODHeader_t *pDebug = ( ModelLODHeader_t *)(((byte *)this) + lodOffset) + i;
  147. return pDebug;
  148. };
  149. };
  150. struct BodyPartHeader_t
  151. {
  152. DECLARE_BYTESWAP_DATADESC();
  153. int numModels;
  154. int modelOffset;
  155. inline ModelHeader_t *pModel( int i ) const
  156. {
  157. ModelHeader_t *pDebug = (ModelHeader_t *)(((byte *)this) + modelOffset) + i;
  158. return pDebug;
  159. };
  160. };
  161. struct MaterialReplacementHeader_t
  162. {
  163. DECLARE_BYTESWAP_DATADESC();
  164. short materialID;
  165. int replacementMaterialNameOffset;
  166. inline const char *pMaterialReplacementName( void )
  167. {
  168. const char *pDebug = (const char *)(((byte *)this) + replacementMaterialNameOffset);
  169. return pDebug;
  170. }
  171. };
  172. struct MaterialReplacementListHeader_t
  173. {
  174. DECLARE_BYTESWAP_DATADESC();
  175. int numReplacements;
  176. int replacementOffset;
  177. inline MaterialReplacementHeader_t *pMaterialReplacement( int i ) const
  178. {
  179. MaterialReplacementHeader_t *pDebug = ( MaterialReplacementHeader_t *)(((byte *)this) + replacementOffset) + i;
  180. return pDebug;
  181. }
  182. };
  183. struct FileHeader_t
  184. {
  185. DECLARE_BYTESWAP_DATADESC();
  186. // file version as defined by OPTIMIZED_MODEL_FILE_VERSION
  187. int version;
  188. // hardware params that affect how the model is to be optimized.
  189. int vertCacheSize;
  190. unsigned short maxBonesPerStrip;
  191. unsigned short maxBonesPerTri;
  192. int maxBonesPerVert;
  193. // must match checkSum in the .mdl
  194. int checkSum;
  195. int numLODs; // garymcthack - this is also specified in ModelHeader_t and should match
  196. // one of these for each LOD
  197. int materialReplacementListOffset;
  198. MaterialReplacementListHeader_t *pMaterialReplacementList( int lodID ) const
  199. {
  200. MaterialReplacementListHeader_t *pDebug =
  201. (MaterialReplacementListHeader_t *)(((byte *)this) + materialReplacementListOffset) + lodID;
  202. return pDebug;
  203. }
  204. int numBodyParts;
  205. int bodyPartOffset;
  206. inline BodyPartHeader_t *pBodyPart( int i ) const
  207. {
  208. BodyPartHeader_t *pDebug = (BodyPartHeader_t *)(((byte *)this) + bodyPartOffset) + i;
  209. return pDebug;
  210. };
  211. };
  212. #pragma pack()
  213. void WriteOptimizedFiles( studiohdr_t *phdr, s_bodypart_t *pSrcBodyParts );
  214. }; // namespace OptimizedModel
  215. #endif // OPTIMIZE_H