Model_local.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __MODEL_LOCAL_H__
  21. #define __MODEL_LOCAL_H__
  22. /*
  23. ===============================================================================
  24. Static model
  25. ===============================================================================
  26. */
  27. class idRenderModelStatic : public idRenderModel {
  28. public:
  29. // the inherited public interface
  30. static idRenderModel * Alloc();
  31. idRenderModelStatic();
  32. virtual ~idRenderModelStatic();
  33. virtual void InitFromFile( const char *fileName );
  34. virtual void PartialInitFromFile( const char *fileName );
  35. virtual void PurgeModel();
  36. virtual void Reset() {};
  37. virtual void LoadModel();
  38. virtual bool IsLoaded();
  39. virtual void SetLevelLoadReferenced( bool referenced );
  40. virtual bool IsLevelLoadReferenced();
  41. virtual void TouchData();
  42. virtual void InitEmpty( const char *name );
  43. virtual void AddSurface( modelSurface_t surface );
  44. virtual void FinishSurfaces();
  45. virtual void FreeVertexCache();
  46. virtual const char * Name() const;
  47. virtual void Print() const;
  48. virtual void List() const;
  49. virtual int Memory() const;
  50. virtual ID_TIME_T Timestamp() const;
  51. virtual int NumSurfaces() const;
  52. virtual int NumBaseSurfaces() const;
  53. virtual const modelSurface_t *Surface( int surfaceNum ) const;
  54. virtual srfTriangles_t * AllocSurfaceTriangles( int numVerts, int numIndexes ) const;
  55. virtual void FreeSurfaceTriangles( srfTriangles_t *tris ) const;
  56. virtual srfTriangles_t * ShadowHull() const;
  57. virtual bool IsStaticWorldModel() const;
  58. virtual dynamicModel_t IsDynamicModel() const;
  59. virtual bool IsDefaultModel() const;
  60. virtual bool IsReloadable() const;
  61. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  62. virtual int NumJoints( void ) const;
  63. virtual const idMD5Joint * GetJoints( void ) const;
  64. virtual jointHandle_t GetJointHandle( const char *name ) const;
  65. virtual const char * GetJointName( jointHandle_t handle ) const;
  66. virtual const idJointQuat * GetDefaultPose( void ) const;
  67. virtual int NearestJoint( int surfaceNum, int a, int b, int c ) const;
  68. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  69. virtual void ReadFromDemoFile( class idDemoFile *f );
  70. virtual void WriteToDemoFile( class idDemoFile *f );
  71. virtual float DepthHack() const;
  72. void MakeDefaultModel();
  73. bool LoadASE( const char *fileName );
  74. bool LoadLWO( const char *fileName );
  75. bool LoadFLT( const char *fileName );
  76. bool LoadMA( const char *filename );
  77. bool ConvertASEToModelSurfaces( const struct aseModel_s *ase );
  78. bool ConvertLWOToModelSurfaces( const struct st_lwObject *lwo );
  79. bool ConvertMAToModelSurfaces (const struct maModel_s *ma );
  80. struct aseModel_s * ConvertLWOToASE( const struct st_lwObject *obj, const char *fileName );
  81. bool DeleteSurfaceWithId( int id );
  82. void DeleteSurfacesWithNegativeId( void );
  83. bool FindSurfaceWithId( int id, int &surfaceNum );
  84. public:
  85. idList<modelSurface_t> surfaces;
  86. idBounds bounds;
  87. int overlaysAdded;
  88. protected:
  89. int lastModifiedFrame;
  90. int lastArchivedFrame;
  91. idStr name;
  92. srfTriangles_t * shadowHull;
  93. bool isStaticWorldModel;
  94. bool defaulted;
  95. bool purged; // eventually we will have dynamic reloading
  96. bool fastLoad; // don't generate tangents and shadow data
  97. bool reloadable; // if not, reloadModels won't check timestamp
  98. bool levelLoadReferenced; // for determining if it needs to be freed
  99. ID_TIME_T timeStamp;
  100. static idCVar r_mergeModelSurfaces; // combine model surfaces with the same material
  101. static idCVar r_slopVertex; // merge xyz coordinates this far apart
  102. static idCVar r_slopTexCoord; // merge texture coordinates this far apart
  103. static idCVar r_slopNormal; // merge normals that dot less than this
  104. };
  105. /*
  106. ===============================================================================
  107. MD5 animated model
  108. ===============================================================================
  109. */
  110. class idMD5Mesh {
  111. friend class idRenderModelMD5;
  112. public:
  113. idMD5Mesh();
  114. ~idMD5Mesh();
  115. void ParseMesh( idLexer &parser, int numJoints, const idJointMat *joints );
  116. void UpdateSurface( const struct renderEntity_s *ent, const idJointMat *joints, modelSurface_t *surf );
  117. idBounds CalcBounds( const idJointMat *joints );
  118. int NearestJoint( int a, int b, int c ) const;
  119. int NumVerts( void ) const;
  120. int NumTris( void ) const;
  121. int NumWeights( void ) const;
  122. private:
  123. idList<idVec2> texCoords; // texture coordinates
  124. int numWeights; // number of weights
  125. idVec4 * scaledWeights; // joint weights
  126. int * weightIndex; // pairs of: joint offset + bool true if next weight is for next vertex
  127. const idMaterial * shader; // material applied to mesh
  128. int numTris; // number of triangles
  129. struct deformInfo_s * deformInfo; // used to create srfTriangles_t from base frames and new vertexes
  130. int surfaceNum; // number of the static surface created for this mesh
  131. void TransformVerts( idDrawVert *verts, const idJointMat *joints );
  132. void TransformScaledVerts( idDrawVert *verts, const idJointMat *joints, float scale );
  133. };
  134. class idRenderModelMD5 : public idRenderModelStatic {
  135. public:
  136. virtual void InitFromFile( const char *fileName );
  137. virtual dynamicModel_t IsDynamicModel() const;
  138. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  139. virtual void Print() const;
  140. virtual void List() const;
  141. virtual void TouchData();
  142. virtual void PurgeModel();
  143. virtual void LoadModel();
  144. virtual int Memory() const;
  145. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  146. virtual int NumJoints( void ) const;
  147. virtual const idMD5Joint * GetJoints( void ) const;
  148. virtual jointHandle_t GetJointHandle( const char *name ) const;
  149. virtual const char * GetJointName( jointHandle_t handle ) const;
  150. virtual const idJointQuat * GetDefaultPose( void ) const;
  151. virtual int NearestJoint( int surfaceNum, int a, int b, int c ) const;
  152. private:
  153. idList<idMD5Joint> joints;
  154. idList<idJointQuat> defaultPose;
  155. idList<idMD5Mesh> meshes;
  156. void CalculateBounds( const idJointMat *joints );
  157. void GetFrameBounds( const renderEntity_t *ent, idBounds &bounds ) const;
  158. void DrawJoints( const renderEntity_t *ent, const struct viewDef_s *view ) const;
  159. void ParseJoint( idLexer &parser, idMD5Joint *joint, idJointQuat *defaultPose );
  160. };
  161. /*
  162. ===============================================================================
  163. MD3 animated model
  164. ===============================================================================
  165. */
  166. struct md3Header_s;
  167. struct md3Surface_s;
  168. class idRenderModelMD3 : public idRenderModelStatic {
  169. public:
  170. virtual void InitFromFile( const char *fileName );
  171. virtual dynamicModel_t IsDynamicModel() const;
  172. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  173. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  174. private:
  175. int index; // model = tr.models[model->index]
  176. int dataSize; // just for listing purposes
  177. struct md3Header_s * md3; // only if type == MOD_MESH
  178. int numLods;
  179. void LerpMeshVertexes( srfTriangles_t *tri, const struct md3Surface_s *surf, const float backlerp, const int frame, const int oldframe ) const;
  180. };
  181. /*
  182. ===============================================================================
  183. Liquid model
  184. ===============================================================================
  185. */
  186. class idRenderModelLiquid : public idRenderModelStatic {
  187. public:
  188. idRenderModelLiquid();
  189. virtual void InitFromFile( const char *fileName );
  190. virtual dynamicModel_t IsDynamicModel() const;
  191. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  192. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  193. virtual void Reset();
  194. void IntersectBounds( const idBounds &bounds, float displacement );
  195. private:
  196. modelSurface_t GenerateSurface( float lerp );
  197. void WaterDrop( int x, int y, float *page );
  198. void Update( void );
  199. int verts_x;
  200. int verts_y;
  201. float scale_x;
  202. float scale_y;
  203. int time;
  204. int liquid_type;
  205. int update_tics;
  206. int seed;
  207. idRandom random;
  208. const idMaterial * shader;
  209. struct deformInfo_s * deformInfo; // used to create srfTriangles_t from base frames
  210. // and new vertexes
  211. float density;
  212. float drop_height;
  213. int drop_radius;
  214. float drop_delay;
  215. idList<float> pages;
  216. float * page1;
  217. float * page2;
  218. idList<idDrawVert> verts;
  219. int nextDropTime;
  220. };
  221. /*
  222. ===============================================================================
  223. PRT model
  224. ===============================================================================
  225. */
  226. class idRenderModelPrt : public idRenderModelStatic {
  227. public:
  228. idRenderModelPrt();
  229. virtual void InitFromFile( const char *fileName );
  230. virtual void TouchData();
  231. virtual dynamicModel_t IsDynamicModel() const;
  232. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  233. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  234. virtual float DepthHack() const;
  235. virtual int Memory() const;
  236. private:
  237. const idDeclParticle * particleSystem;
  238. };
  239. /*
  240. ===============================================================================
  241. Beam model
  242. ===============================================================================
  243. */
  244. class idRenderModelBeam : public idRenderModelStatic {
  245. public:
  246. virtual dynamicModel_t IsDynamicModel() const;
  247. virtual bool IsLoaded() const;
  248. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  249. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  250. };
  251. /*
  252. ===============================================================================
  253. Beam model
  254. ===============================================================================
  255. */
  256. #define MAX_TRAIL_PTS 20
  257. struct Trail_t {
  258. int lastUpdateTime;
  259. int duration;
  260. idVec3 pts[MAX_TRAIL_PTS];
  261. int numPoints;
  262. };
  263. class idRenderModelTrail : public idRenderModelStatic {
  264. idList<Trail_t> trails;
  265. int numActive;
  266. idBounds trailBounds;
  267. public:
  268. idRenderModelTrail();
  269. virtual dynamicModel_t IsDynamicModel() const;
  270. virtual bool IsLoaded() const;
  271. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  272. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  273. int NewTrail( idVec3 pt, int duration );
  274. void UpdateTrail( int index, idVec3 pt );
  275. void DrawTrail( int index, const struct renderEntity_s *ent, srfTriangles_t *tri, float globalAlpha );
  276. };
  277. /*
  278. ===============================================================================
  279. Lightning model
  280. ===============================================================================
  281. */
  282. class idRenderModelLightning : public idRenderModelStatic {
  283. public:
  284. virtual dynamicModel_t IsDynamicModel() const;
  285. virtual bool IsLoaded() const;
  286. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  287. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  288. };
  289. /*
  290. ================================================================================
  291. idRenderModelSprite
  292. ================================================================================
  293. */
  294. class idRenderModelSprite : public idRenderModelStatic {
  295. public:
  296. virtual dynamicModel_t IsDynamicModel() const;
  297. virtual bool IsLoaded() const;
  298. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
  299. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  300. };
  301. #endif /* !__MODEL_LOCAL_H__ */