DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Model_local.h (16983B)


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