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, mod_brushq2, mod_brushq3} 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_alias_s
94 // LordHavoc: Q2/ZYM model support
97 // mdl/md2/md3 models are the same after loading
99 aliasmesh_t *aliasdata_meshes;
101 // for Zymotic models
107 float *zymdata_texcoords;
108 rtexture_t **zymdata_textures;
109 qbyte *zymdata_trizone;
110 zymbone_t *zymdata_bones;
111 unsigned int *zymdata_vertbonecounts;
112 zymvertex_t *zymdata_verts;
113 unsigned int *zymdata_renderlist;
114 float *zymdata_poses;
118 typedef struct model_sprite_s
121 mspriteframe_t *sprdata_frames;
125 typedef struct model_brush_s
131 typedef struct model_brushq1_s
133 // true if this model is a HalfLife .bsp file
136 int firstmodelsurface, nummodelsurfaces;
138 // lightmap format, set to r_lightmaprgba when model is loaded
147 // number of visible leafs, not counting 0 (solid)
164 msurface_t *surfaces;
165 int *surfacevisframes;
166 int *surfacepvsframes;
167 msurface_t *surfacepvsnext;
168 surfmesh_t *entiremesh;
169 surfmesh_t *surfmeshes;
175 dclipnode_t *clipnodes;
180 hull_t hulls[MAX_MAP_HULLS];
192 mvertex_t *portalpoints;
197 // pvs visibility marking
198 mleaf_t *pvsviewleaf;
199 int pvsviewleafnovis;
201 mleaf_t *pvsleafchain;
203 int pvssurflistlength;
204 // these get rebuilt as the player moves around if this is the world,
205 // otherwise they are left alone (no pvs for bmodels)
206 msurface_t ***pvstexturechains;
207 msurface_t **pvstexturechainsbuffer;
208 int *pvstexturechainslength;
210 // lightmap update chains for light styles
213 int *light_stylevalue;
214 msurface_t ***light_styleupdatechains;
215 msurface_t **light_styleupdatechainsbuffer;
219 void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
220 mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p);
221 int (*PointContents)(struct model_s *model, const float *p);
222 qbyte *(*LeafPVS)(struct model_s *model, mleaf_t *leaf);
223 void (*BuildPVSTextureChains)(struct model_s *model);
227 typedef struct model_brushq2_s
232 typedef struct q3mtexture_s
234 char name[Q3PATHLENGTH];
243 typedef struct q3mnode_s
246 struct mplane_s *plane;
247 struct q3mnode_s *parent;
248 struct q3mnode_s *children[2];
252 typedef struct q3mleaf_s
260 struct q3mface_s **leaffaces;
262 struct q3mbrush_s **leafbrushes;
266 typedef struct q3mmodel_s
271 struct q3mface_s *faces;
273 struct q3mbrush_s *brushes;
277 typedef struct q3mbrush_s
280 struct q3mbrushside_s *sides;
281 struct q3mtexture_s *texture;
285 typedef struct q3mbrushside_s
287 struct mplane_s *plane;
288 struct q3mtexture_s *texture;
292 typedef struct q3meffect_s
294 char shadername[Q3PATHLENGTH];
295 struct q3mbrush_s *brush;
296 int unknown; // 5 or -1
300 typedef struct q3mface_s
302 struct q3mtexture_s *texture;
303 struct q3meffect_s *effect;
311 float *data_vertex3f;
312 float *data_texturetexcoord2f;
313 float *data_lightmaptexcoord2f;
314 float *data_svector3f;
315 float *data_tvector3f;
316 float *data_normal3f;
321 typedef struct model_brushq3_s
324 q3mtexture_t *data_textures;
327 mplane_t *data_planes;
330 q3mnode_t *data_nodes;
333 q3mleaf_t *data_leafs;
336 q3mmodel_t *data_models;
337 // each submodel gets its own model struct so this is different for each.
338 q3mmodel_t data_thismodel;
341 q3mbrush_t *data_brushes;
344 q3mbrushside_t *data_brushsides;
347 float *data_vertex3f;
348 float *data_texturetexcoord2f;
349 float *data_lightmaptexcoord2f;
350 float *data_normal3f;
355 int *data_neighbor3i;
358 q3meffect_t data_effects;
361 q3mface_t *data_faces;
365 rtexture_t *data_lightmaps;
367 // transform world coordinates to lightgrid index
368 matrix4x4_t num_lightgrid_indexfromworld;
369 q3dlightgrid_t *data_lightgrid_cells;
373 int num_pvschainlength;
374 unsigned char *data_pvschains;
376 //pvschain = model->brushq3.data_pvschains + mycluster * model->brushq3.num_pvschainlength;
377 //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
381 typedef struct model_s
383 // name and path of model, for example "progs/player.mdl"
384 char name[MAX_QPATH];
385 // model needs to be loaded if this is true
387 // set if the model is used in current map, models which are not, are purged
389 // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
390 qboolean isworldmodel;
391 // CRC of the file this model was loaded from, to reload if changed
393 // mod_brush, mod_alias, mod_sprite
395 // memory pool for allocations
397 // all models use textures...
398 rtexturepool_t *texturepool;
399 // flags from the model file
401 // engine calculated flags, ones that can not be set in the file
403 // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
405 // number of QC accessible frame(group)s in the model
407 // number of QC accessible skin(group)s in the model
409 // whether to randomize animated framegroups
411 // bounding box at angles '0 0 0'
412 vec3_t normalmins, normalmaxs;
413 // bounding box if yaw angle is not 0, but pitch and roll are
414 vec3_t yawmins, yawmaxs;
415 // bounding box if pitch or roll are used
416 vec3_t rotatedmins, rotatedmaxs;
417 // sphere radius, usable at any angles
419 // squared sphere radius for easier comparisons
421 // skin animation info
422 animscene_t *skinscenes; // [numskins]
424 skinframe_t *skinframes;
425 // skin animation info
426 animscene_t *animscenes; // [numframes]
427 // draw the model's sky polygons (only used by brush models)
428 void(*DrawSky)(struct entity_render_s *ent);
429 // draw the model using lightmap/dlight shading
430 void(*Draw)(struct entity_render_s *ent);
431 // draw a fake shadow for the model
432 void(*DrawFakeShadow)(struct entity_render_s *ent);
433 // draw a shadow volume for the model based on light source
434 void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
435 // draw the lighting on a model (through stencil)
436 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);
437 // fields belonging to each type of model
439 model_sprite_t sprite;
441 model_brushq1_t brushq1;
442 model_brushq2_t brushq2;
443 model_brushq3_t brushq3;
447 //============================================================================
449 // this can be used for anything without a valid texture
450 extern rtexture_t *r_notexture;
451 #define NUM_DETAILTEXTURES 1
452 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
453 // every texture must be in a pool...
454 extern rtexturepool_t *mod_shared_texturepool;
457 extern model_t *loadmodel;
458 extern qbyte *mod_base;
459 // sky/water subdivision
460 //extern cvar_t gl_subdivide_size;
461 // texture fullbrights
462 extern cvar_t r_fullbrights;
464 void Mod_Init (void);
465 void Mod_CheckLoaded (model_t *mod);
466 void Mod_ClearAll (void);
467 model_t *Mod_FindName (const char *name);
468 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
469 void Mod_TouchModel (const char *name);
470 void Mod_UnloadModel (model_t *mod);
472 void Mod_ClearUsed(void);
473 void Mod_PurgeUnused(void);
474 void Mod_LoadModels(void);
476 extern model_t *loadmodel;
477 extern char loadname[32]; // for hunk tags
479 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
480 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
481 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
482 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
484 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
485 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
486 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
487 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
488 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
489 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, float *verts, int numtris, int *elements);
490 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
491 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
492 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
493 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
495 int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
496 int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);