Model_local.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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 idJointMat;
  28. struct deformInfo_t;
  29. class idRenderModelStatic : public idRenderModel {
  30. public:
  31. // the inherited public interface
  32. static idRenderModel * Alloc();
  33. idRenderModelStatic();
  34. virtual ~idRenderModelStatic();
  35. virtual void InitFromFile( const char *fileName );
  36. virtual bool LoadBinaryModel( idFile * file, const ID_TIME_T sourceTimeStamp );
  37. virtual void WriteBinaryModel( idFile * file, ID_TIME_T *_timeStamp = NULL ) const;
  38. virtual bool SupportsBinaryModel() { return true; }
  39. virtual void PartialInitFromFile( const char *fileName );
  40. virtual void PurgeModel();
  41. virtual void Reset() {};
  42. virtual void LoadModel();
  43. virtual bool IsLoaded();
  44. virtual void SetLevelLoadReferenced( bool referenced );
  45. virtual bool IsLevelLoadReferenced();
  46. virtual void TouchData();
  47. virtual void InitEmpty( const char *name );
  48. virtual void AddSurface( modelSurface_t surface );
  49. virtual void FinishSurfaces();
  50. virtual void FreeVertexCache();
  51. virtual const char * Name() const;
  52. virtual void Print() const;
  53. virtual void List() const;
  54. virtual int Memory() const;
  55. virtual ID_TIME_T Timestamp() const;
  56. virtual int NumSurfaces() const;
  57. virtual int NumBaseSurfaces() const;
  58. virtual const modelSurface_t *Surface( int surfaceNum ) const;
  59. virtual srfTriangles_t * AllocSurfaceTriangles( int numVerts, int numIndexes ) const;
  60. virtual void FreeSurfaceTriangles( srfTriangles_t *tris ) const;
  61. virtual bool IsStaticWorldModel() const;
  62. virtual dynamicModel_t IsDynamicModel() const;
  63. virtual bool IsDefaultModel() const;
  64. virtual bool IsReloadable() const;
  65. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  66. virtual int NumJoints() const;
  67. virtual const idMD5Joint * GetJoints() const;
  68. virtual jointHandle_t GetJointHandle( const char *name ) const;
  69. virtual const char * GetJointName( jointHandle_t handle ) const;
  70. virtual const idJointQuat * GetDefaultPose() const;
  71. virtual int NearestJoint( int surfaceNum, int a, int b, int c ) const;
  72. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  73. virtual void ReadFromDemoFile( class idDemoFile *f );
  74. virtual void WriteToDemoFile( class idDemoFile *f );
  75. virtual float DepthHack() const;
  76. virtual bool ModelHasDrawingSurfaces() const { return hasDrawingSurfaces; };
  77. virtual bool ModelHasInteractingSurfaces() const { return hasInteractingSurfaces; };
  78. virtual bool ModelHasShadowCastingSurfaces() const { return hasShadowCastingSurfaces; };
  79. void MakeDefaultModel();
  80. bool LoadASE( const char *fileName );
  81. bool LoadLWO( const char *fileName );
  82. bool LoadMA( const char *filename );
  83. bool ConvertASEToModelSurfaces( const struct aseModel_s *ase );
  84. bool ConvertLWOToModelSurfaces( const struct st_lwObject *lwo );
  85. bool ConvertMAToModelSurfaces (const struct maModel_s *ma );
  86. struct aseModel_s * ConvertLWOToASE( const struct st_lwObject *obj, const char *fileName );
  87. bool DeleteSurfaceWithId( int id );
  88. void DeleteSurfacesWithNegativeId();
  89. bool FindSurfaceWithId( int id, int &surfaceNum ) const;
  90. public:
  91. idList<modelSurface_t, TAG_MODEL> surfaces;
  92. idBounds bounds;
  93. int overlaysAdded;
  94. // when an md5 is instantiated, the inverted joints array is stored to allow GPU skinning
  95. int numInvertedJoints;
  96. idJointMat * jointsInverted;
  97. vertCacheHandle_t jointsInvertedBuffer;
  98. protected:
  99. int lastModifiedFrame;
  100. int lastArchivedFrame;
  101. idStr name;
  102. bool isStaticWorldModel;
  103. bool defaulted;
  104. bool purged; // eventually we will have dynamic reloading
  105. bool fastLoad; // don't generate tangents and shadow data
  106. bool reloadable; // if not, reloadModels won't check timestamp
  107. bool levelLoadReferenced; // for determining if it needs to be freed
  108. bool hasDrawingSurfaces;
  109. bool hasInteractingSurfaces;
  110. bool hasShadowCastingSurfaces;
  111. ID_TIME_T timeStamp;
  112. static idCVar r_mergeModelSurfaces; // combine model surfaces with the same material
  113. static idCVar r_slopVertex; // merge xyz coordinates this far apart
  114. static idCVar r_slopTexCoord; // merge texture coordinates this far apart
  115. static idCVar r_slopNormal; // merge normals that dot less than this
  116. };
  117. /*
  118. ===============================================================================
  119. MD5 animated model
  120. ===============================================================================
  121. */
  122. class idMD5Mesh {
  123. friend class idRenderModelMD5;
  124. public:
  125. idMD5Mesh();
  126. ~idMD5Mesh();
  127. void ParseMesh( idLexer &parser, int numJoints, const idJointMat *joints );
  128. int NumVerts() const { return numVerts; }
  129. int NumTris() const { return numTris; }
  130. void UpdateSurface( const struct renderEntity_s *ent, const idJointMat *joints,
  131. const idJointMat *entJointsInverted, modelSurface_t *surf );
  132. void CalculateBounds( const idJointMat * entJoints, idBounds & bounds ) const;
  133. int NearestJoint( int a, int b, int c ) const;
  134. private:
  135. const idMaterial * shader; // material applied to mesh
  136. int numVerts; // number of vertices
  137. int numTris; // number of triangles
  138. byte * meshJoints; // the joints used by this mesh
  139. int numMeshJoints; // number of mesh joints
  140. float maxJointVertDist; // maximum distance a vertex is separated from a joint
  141. deformInfo_t * deformInfo; // used to create srfTriangles_t from base frames and new vertexes
  142. int surfaceNum; // number of the static surface created for this mesh
  143. };
  144. class idRenderModelMD5 : public idRenderModelStatic {
  145. public:
  146. virtual void InitFromFile( const char *fileName );
  147. virtual bool LoadBinaryModel( idFile * file, const ID_TIME_T sourceTimeStamp );
  148. virtual void WriteBinaryModel( idFile * file, ID_TIME_T *_timeStamp = NULL ) const;
  149. virtual dynamicModel_t IsDynamicModel() const;
  150. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  151. virtual void Print() const;
  152. virtual void List() const;
  153. virtual void TouchData();
  154. virtual void PurgeModel();
  155. virtual void LoadModel();
  156. virtual int Memory() const;
  157. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  158. virtual int NumJoints() const;
  159. virtual const idMD5Joint * GetJoints() const;
  160. virtual jointHandle_t GetJointHandle( const char *name ) const;
  161. virtual const char * GetJointName( jointHandle_t handle ) const;
  162. virtual const idJointQuat * GetDefaultPose() const;
  163. virtual int NearestJoint( int surfaceNum, int a, int b, int c ) const;
  164. virtual bool SupportsBinaryModel() { return true; }
  165. private:
  166. idList<idMD5Joint, TAG_MODEL> joints;
  167. idList<idJointQuat, TAG_MODEL> defaultPose;
  168. idList<idJointMat, TAG_MODEL> invertedDefaultPose;
  169. idList<idMD5Mesh, TAG_MODEL> meshes;
  170. void DrawJoints( const renderEntity_t *ent, const viewDef_t *view ) const;
  171. void ParseJoint( idLexer &parser, idMD5Joint *joint, idJointQuat *defaultPose );
  172. };
  173. /*
  174. ===============================================================================
  175. MD3 animated model
  176. ===============================================================================
  177. */
  178. struct md3Header_s;
  179. struct md3Surface_s;
  180. class idRenderModelMD3 : public idRenderModelStatic {
  181. public:
  182. virtual void InitFromFile( const char *fileName );
  183. virtual bool SupportsBinaryModel() { return false; }
  184. virtual dynamicModel_t IsDynamicModel() const;
  185. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  186. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  187. private:
  188. int index; // model = tr.models[model->index]
  189. int dataSize; // just for listing purposes
  190. struct md3Header_s * md3; // only if type == MOD_MESH
  191. int numLods;
  192. void LerpMeshVertexes( srfTriangles_t *tri, const struct md3Surface_s *surf, const float backlerp, const int frame, const int oldframe ) const;
  193. };
  194. /*
  195. ===============================================================================
  196. Liquid model
  197. ===============================================================================
  198. */
  199. class idRenderModelLiquid : public idRenderModelStatic {
  200. public:
  201. idRenderModelLiquid();
  202. virtual void InitFromFile( const char *fileName );
  203. virtual bool SupportsBinaryModel() { return false; }
  204. virtual dynamicModel_t IsDynamicModel() const;
  205. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  206. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  207. virtual void Reset();
  208. void IntersectBounds( const idBounds &bounds, float displacement );
  209. private:
  210. modelSurface_t GenerateSurface( float lerp );
  211. void WaterDrop( int x, int y, float *page );
  212. void Update();
  213. int verts_x;
  214. int verts_y;
  215. float scale_x;
  216. float scale_y;
  217. int time;
  218. int liquid_type;
  219. int update_tics;
  220. int seed;
  221. idRandom random;
  222. const idMaterial * shader;
  223. deformInfo_t * deformInfo; // used to create srfTriangles_t from base frames
  224. // and new vertexes
  225. float density;
  226. float drop_height;
  227. int drop_radius;
  228. float drop_delay;
  229. idList<float, TAG_MODEL> pages;
  230. float * page1;
  231. float * page2;
  232. idList<idDrawVert, TAG_MODEL> verts;
  233. int nextDropTime;
  234. };
  235. /*
  236. ===============================================================================
  237. PRT model
  238. ===============================================================================
  239. */
  240. class idRenderModelPrt : public idRenderModelStatic {
  241. public:
  242. idRenderModelPrt();
  243. virtual void InitFromFile( const char *fileName );
  244. virtual bool SupportsBinaryModel() { return false; }
  245. virtual void TouchData();
  246. virtual dynamicModel_t IsDynamicModel() const;
  247. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  248. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  249. virtual float DepthHack() const;
  250. virtual int Memory() const;
  251. // with the addModels2 arrangement we could have light accepting and
  252. // shadowing dynamic models, but the original game never did
  253. virtual bool ModelHasDrawingSurfaces() const { return true; };
  254. virtual bool ModelHasInteractingSurfaces() const { return false; };
  255. virtual bool ModelHasShadowCastingSurfaces() const { return false; };
  256. private:
  257. const idDeclParticle * particleSystem;
  258. };
  259. /*
  260. ===============================================================================
  261. Beam model
  262. ===============================================================================
  263. */
  264. class idRenderModelBeam : public idRenderModelStatic {
  265. public:
  266. virtual dynamicModel_t IsDynamicModel() const;
  267. virtual bool SupportsBinaryModel() { return false; }
  268. virtual bool IsLoaded() const;
  269. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  270. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  271. // with the addModels2 arrangement we could have light accepting and
  272. // shadowing dynamic models, but the original game never did
  273. virtual bool ModelHasDrawingSurfaces() const { return true; };
  274. virtual bool ModelHasInteractingSurfaces() const { return false; };
  275. virtual bool ModelHasShadowCastingSurfaces() const { return false; };
  276. };
  277. /*
  278. ===============================================================================
  279. Beam model
  280. ===============================================================================
  281. */
  282. #define MAX_TRAIL_PTS 20
  283. struct Trail_t {
  284. int lastUpdateTime;
  285. int duration;
  286. idVec3 pts[MAX_TRAIL_PTS];
  287. int numPoints;
  288. };
  289. class idRenderModelTrail : public idRenderModelStatic {
  290. idList<Trail_t, TAG_MODEL> trails;
  291. int numActive;
  292. idBounds trailBounds;
  293. public:
  294. idRenderModelTrail();
  295. virtual dynamicModel_t IsDynamicModel() const;
  296. virtual bool SupportsBinaryModel() { return false; }
  297. virtual bool IsLoaded() const;
  298. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  299. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  300. // with the addModels2 arrangement we could have light accepting and
  301. // shadowing dynamic models, but the original game never did
  302. virtual bool ModelHasDrawingSurfaces() const { return true; };
  303. virtual bool ModelHasInteractingSurfaces() const { return false; };
  304. virtual bool ModelHasShadowCastingSurfaces() const { return false; };
  305. int NewTrail( idVec3 pt, int duration );
  306. void UpdateTrail( int index, idVec3 pt );
  307. void DrawTrail( int index, const struct renderEntity_s *ent, srfTriangles_t *tri, float globalAlpha );
  308. };
  309. /*
  310. ===============================================================================
  311. Lightning model
  312. ===============================================================================
  313. */
  314. class idRenderModelLightning : public idRenderModelStatic {
  315. public:
  316. virtual dynamicModel_t IsDynamicModel() const;
  317. virtual bool SupportsBinaryModel() { return false; }
  318. virtual bool IsLoaded() const;
  319. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  320. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  321. // with the addModels2 arrangement we could have light accepting and
  322. // shadowing dynamic models, but the original game never did
  323. virtual bool ModelHasDrawingSurfaces() const { return true; };
  324. virtual bool ModelHasInteractingSurfaces() const { return false; };
  325. virtual bool ModelHasShadowCastingSurfaces() const { return false; };
  326. };
  327. /*
  328. ================================================================================
  329. idRenderModelSprite
  330. ================================================================================
  331. */
  332. class idRenderModelSprite : public idRenderModelStatic {
  333. public:
  334. virtual dynamicModel_t IsDynamicModel() const;
  335. virtual bool SupportsBinaryModel() { return false; }
  336. virtual bool IsLoaded() const;
  337. virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel );
  338. virtual idBounds Bounds( const struct renderEntity_s *ent ) const;
  339. // with the addModels2 arrangement we could have light accepting and
  340. // shadowing dynamic models, but the original game never did
  341. virtual bool ModelHasDrawingSurfaces() const { return true; };
  342. virtual bool ModelHasInteractingSurfaces() const { return false; };
  343. virtual bool ModelHasShadowCastingSurfaces() const { return false; };
  344. };
  345. #endif /* !__MODEL_LOCAL_H__ */