2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
31 d*_t structures are on-disk representations
32 m*_t structures are in-memory
36 typedef enum {mod_invalid, mod_brush, mod_sprite, mod_alias} modtype_t;
38 typedef struct animscene_s
40 char name[32]; // for viewthing support
43 int loop; // true or false
48 typedef struct skinframe_s
50 rtexture_t *base; // original texture without pants/shirt/glow
51 rtexture_t *pants; // pants only (in greyscale)
52 rtexture_t *shirt; // shirt only (in greyscale)
53 rtexture_t *glow; // glow only (fullbrights)
54 rtexture_t *merged; // original texture without glow
55 rtexture_t *fog; // alpha of the base texture (if not opaque)
56 rtexture_t *nmap; // normalmap (bumpmap for dot3)
57 rtexture_t *gloss; // glossmap (for dot3)
58 rtexture_t *detail; // detail texture (silly bumps for non-dot3)
64 #define SHADOWMESHVERTEXHASH 1024
65 typedef struct shadowmeshvertexhash_s
67 struct shadowmeshvertexhash_s *next;
69 shadowmeshvertexhash_t;
71 typedef struct shadowmesh_s
73 struct shadowmesh_s *next;
74 int numverts, maxverts;
75 int numtriangles, maxtriangles;
79 // these are NULL after Mod_ShadowMesh_Finish is performed, only used
80 // while building meshes
81 shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
86 #include "model_brush.h"
87 #include "model_sprite.h"
88 #include "model_alias.h"
90 #include "matrixlib.h"
92 typedef struct model_s
95 // model needs to be loaded if this is true
97 // set if the model is used in current map, models which are not, are purged
99 // CRC of the file this model was loaded from, to reload if changed
101 // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
102 qboolean isworldmodel;
103 // true if this model is a HalfLife .bsp file
105 // true if this model was not successfully loaded and should be purged
108 // mod_brush, mod_alias, mod_sprite
110 // LordHavoc: Q2/ZYM model support
112 // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
114 // number of QC accessible frame(group)s in the model
116 // number of QC accessible skin(group)s in the model
118 // whether to randomize animated framegroups
122 // flags from the model file
124 // engine calculated flags, ones that can not be set in the file
127 // all models use textures...
128 rtexturepool_t *texturepool;
130 // volume occupied by the model
131 // bounding box at angles '0 0 0'
132 vec3_t normalmins, normalmaxs;
133 // bounding box if yaw angle is not 0, but pitch and roll are
134 vec3_t yawmins, yawmaxs;
135 // bounding box if pitch or roll are used
136 vec3_t rotatedmins, rotatedmaxs;
137 // sphere radius, usable at any angles
139 // squared sphere radius for easier comparisons
142 // brush model specific
143 int firstmodelsurface, nummodelsurfaces;
145 // lightmap format, set to r_lightmaprgba when model is loaded
154 // number of visible leafs, not counting 0 (solid)
171 msurface_t *surfaces;
172 int *surfacevisframes;
173 int *surfacepvsframes;
174 msurface_t *surfacepvsnext;
180 dclipnode_t *clipnodes;
185 hull_t hulls[MAX_MAP_HULLS];
198 mvertex_t *portalpoints;
203 // pvs visibility marking
204 mleaf_t *pvsviewleaf;
205 int pvsviewleafnovis;
207 mleaf_t *pvsleafchain;
209 int pvssurflistlength;
210 // these get rebuilt as the player moves around if this is the world,
211 // otherwise they are left alone (no pvs for bmodels)
212 msurface_t ***pvstexturechains;
213 msurface_t **pvstexturechainsbuffer;
214 int *pvstexturechainslength;
216 // lightmap update chains for light styles
219 int *light_stylevalue;
220 msurface_t ***light_styleupdatechains;
221 msurface_t **light_styleupdatechainsbuffer;
225 // skin animation info
226 animscene_t *skinscenes; // [numskins]
228 skinframe_t *skinframes;
230 animscene_t *animscenes; // [numframes]
232 // mdl/md2/md3 models are the same after loading
234 aliasmesh_t *aliasdata_meshes;
236 // for Zymotic models
242 float *zymdata_texcoords;
243 rtexture_t **zymdata_textures;
244 qbyte *zymdata_trizone;
245 zymbone_t *zymdata_bones;
246 unsigned int *zymdata_vertbonecounts;
247 zymvertex_t *zymdata_verts;
248 unsigned int *zymdata_renderlist;
249 float *zymdata_poses;
252 mspriteframe_t *sprdata_frames;
255 // functions used in both rendering modes
256 // draw the model's sky polygons (only used by brush models)
257 void(*DrawSky)(struct entity_render_s *ent);
259 // functions used only in normal rendering mode
261 void(*Draw)(struct entity_render_s *ent);
262 // draw a fake shadow for the model
263 void(*DrawFakeShadow)(struct entity_render_s *ent);
265 // functions used only in shadow volume rendering mode
266 // draw a shadow volume for the model based on light source
267 void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
268 // draw the lighting on a model (through stencil)
269 void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz);
271 // memory pool for allocations
276 //============================================================================
278 // this can be used for anything without a valid texture
279 extern rtexture_t *r_notexture;
280 #define NUM_DETAILTEXTURES 1
281 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
282 // every texture must be in a pool...
283 extern rtexturepool_t *mod_shared_texturepool;
286 extern model_t *loadmodel;
287 extern qbyte *mod_base;
288 // sky/water subdivision
289 //extern cvar_t gl_subdivide_size;
290 // texture fullbrights
291 extern cvar_t r_fullbrights;
293 void Mod_Init (void);
294 void Mod_CheckLoaded (model_t *mod);
295 void Mod_ClearAll (void);
296 void Mod_ClearErrorModels (void);
297 model_t *Mod_FindName (const char *name);
298 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
299 void Mod_TouchModel (const char *name);
300 void Mod_UnloadModel (model_t *mod);
302 void Mod_ClearUsed(void);
303 void Mod_PurgeUnused(void);
304 void Mod_LoadModels(void);
306 extern model_t *loadmodel;
307 extern char loadname[32]; // for hunk tags
309 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
310 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
311 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
312 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
314 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
315 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
316 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
317 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
318 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
319 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts, int numtris, int *elements);
320 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
321 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
322 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
323 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
325 int Mod_LoadSkinFrame (skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
326 int Mod_LoadSkinFrame_Internal (skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);