Counter Strike : Global Offensive Source Code
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.

264 lines
6.3 KiB

  1. //========= Copyright � 1996-2008, 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. #define MAX_NUM_BONES_PER_STRIP 512
  14. #define OPTIMIZED_MODEL_FILE_VERSION 7
  15. extern bool g_bDumpGLViewFiles;
  16. struct s_bodypart_t;
  17. namespace OptimizedModel
  18. {
  19. #pragma pack(1)
  20. struct BoneStateChangeHeader_t
  21. {
  22. DECLARE_BYTESWAP_DATADESC();
  23. int hardwareID;
  24. int newBoneID;
  25. };
  26. struct Vertex_t
  27. {
  28. DECLARE_BYTESWAP_DATADESC();
  29. // these index into the mesh's vert[origMeshVertID]'s bones
  30. unsigned char boneWeightIndex[MAX_NUM_BONES_PER_VERT];
  31. unsigned char numBones;
  32. unsigned short origMeshVertID;
  33. // for sw skinned verts, these are indices into the global list of bones
  34. // for hw skinned verts, these are hardware bone indices
  35. byte boneID[MAX_NUM_BONES_PER_VERT];
  36. };
  37. // We don't do actual strips anymore, only triangle lists and subd quad lists
  38. enum StripHeaderFlags_t
  39. {
  40. STRIP_IS_TRILIST = 0x01,
  41. STRIP_IS_QUADLIST_REG = 0x02, // Regular sub-d quads
  42. STRIP_IS_QUADLIST_EXTRA = 0x04 // Extraordinary sub-d quads
  43. };
  44. // A strip is a piece of a stripgroup that is divided by bones
  45. struct StripHeader_t
  46. {
  47. DECLARE_BYTESWAP_DATADESC();
  48. int numIndices; // indexOffset offsets into the mesh's index array
  49. int indexOffset;
  50. int numVerts; // vertexOffset offsets into the mesh's vert array
  51. int vertOffset;
  52. // Use this to enable/disable skinning.
  53. // May decide (in optimize.cpp) to put all with 1 bone in a different strip
  54. // than those that need skinning.
  55. short numBones;
  56. unsigned char flags;
  57. int numBoneStateChanges;
  58. int boneStateChangeOffset;
  59. inline BoneStateChangeHeader_t *pBoneStateChange( int i ) const
  60. {
  61. return (BoneStateChangeHeader_t *)(((byte *)this) + boneStateChangeOffset) + i;
  62. };
  63. // These go last on purpose!
  64. int numTopologyIndices;
  65. int topologyOffset;
  66. };
  67. enum StripGroupFlags_t
  68. {
  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. int numTopologyIndices;
  100. int topologyOffset;
  101. inline unsigned short *pTopologyIndex( int i ) const
  102. {
  103. return (unsigned short *)(((byte *)this) + topologyOffset) + i;
  104. };
  105. };
  106. enum MeshFlags_t {
  107. // these are both material properties, and a mesh has a single material.
  108. MESH_IS_TEETH = 0x01,
  109. MESH_IS_EYES = 0x02
  110. };
  111. // a collection of locking groups:
  112. // up to 4:
  113. // non-flexed, hardware skinned
  114. // flexed, hardware skinned
  115. // non-flexed, software skinned
  116. // flexed, software skinned
  117. //
  118. // A mesh has a material associated with it.
  119. struct MeshHeader_t
  120. {
  121. DECLARE_BYTESWAP_DATADESC();
  122. int numStripGroups;
  123. int stripGroupHeaderOffset;
  124. inline StripGroupHeader_t *pStripGroup( int i ) const
  125. {
  126. StripGroupHeader_t *pDebug = (StripGroupHeader_t *)(((byte *)this) + stripGroupHeaderOffset) + i;
  127. return pDebug;
  128. };
  129. unsigned char flags;
  130. };
  131. struct ModelLODHeader_t
  132. {
  133. DECLARE_BYTESWAP_DATADESC();
  134. int numMeshes;
  135. int meshOffset;
  136. float switchPoint;
  137. inline MeshHeader_t *pMesh( int i ) const
  138. {
  139. MeshHeader_t *pDebug = (MeshHeader_t *)(((byte *)this) + meshOffset) + i;
  140. return pDebug;
  141. };
  142. };
  143. // This maps one to one with models in the mdl file.
  144. // There are a bunch of model LODs stored inside potentially due to the qc $lod command
  145. struct ModelHeader_t
  146. {
  147. DECLARE_BYTESWAP_DATADESC();
  148. int numLODs; // garymcthack - this is also specified in FileHeader_t
  149. int lodOffset;
  150. inline ModelLODHeader_t *pLOD( int i ) const
  151. {
  152. ModelLODHeader_t *pDebug = ( ModelLODHeader_t *)(((byte *)this) + lodOffset) + i;
  153. return pDebug;
  154. };
  155. };
  156. struct BodyPartHeader_t
  157. {
  158. DECLARE_BYTESWAP_DATADESC();
  159. int numModels;
  160. int modelOffset;
  161. inline ModelHeader_t *pModel( int i ) const
  162. {
  163. ModelHeader_t *pDebug = (ModelHeader_t *)(((byte *)this) + modelOffset) + i;
  164. return pDebug;
  165. };
  166. };
  167. struct MaterialReplacementHeader_t
  168. {
  169. DECLARE_BYTESWAP_DATADESC();
  170. short materialID;
  171. int replacementMaterialNameOffset;
  172. inline const char *pMaterialReplacementName( void )
  173. {
  174. const char *pDebug = (const char *)(((byte *)this) + replacementMaterialNameOffset);
  175. return pDebug;
  176. }
  177. };
  178. struct MaterialReplacementListHeader_t
  179. {
  180. DECLARE_BYTESWAP_DATADESC();
  181. int numReplacements;
  182. int replacementOffset;
  183. inline MaterialReplacementHeader_t *pMaterialReplacement( int i ) const
  184. {
  185. MaterialReplacementHeader_t *pDebug = ( MaterialReplacementHeader_t *)(((byte *)this) + replacementOffset) + i;
  186. return pDebug;
  187. }
  188. };
  189. struct FileHeader_t
  190. {
  191. DECLARE_BYTESWAP_DATADESC();
  192. // file version as defined by OPTIMIZED_MODEL_FILE_VERSION
  193. int version;
  194. // hardware params that affect how the model is to be optimized.
  195. int vertCacheSize;
  196. unsigned short maxBonesPerStrip;
  197. unsigned short maxBonesPerFace;
  198. int maxBonesPerVert;
  199. // must match checkSum in the .mdl
  200. int checkSum;
  201. int numLODs; // garymcthack - this is also specified in ModelHeader_t and should match
  202. // one of these for each LOD
  203. int materialReplacementListOffset;
  204. MaterialReplacementListHeader_t *pMaterialReplacementList( int lodID ) const
  205. {
  206. MaterialReplacementListHeader_t *pDebug =
  207. (MaterialReplacementListHeader_t *)(((byte *)this) + materialReplacementListOffset) + lodID;
  208. return pDebug;
  209. }
  210. int numBodyParts;
  211. int bodyPartOffset;
  212. inline BodyPartHeader_t *pBodyPart( int i ) const
  213. {
  214. BodyPartHeader_t *pDebug = (BodyPartHeader_t *)(((byte *)this) + bodyPartOffset) + i;
  215. return pDebug;
  216. };
  217. };
  218. #pragma pack()
  219. void WriteOptimizedFiles( studiohdr_t *phdr, s_bodypart_t *pSrcBodyParts );
  220. }; // namespace OptimizedModel
  221. #endif // OPTIMIZE_H