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 typedef struct overridetagname_s
70 // a replacement set of tag names, per skin
71 typedef struct overridetagnameset_s
73 int num_overridetagnames;
74 overridetagname_t *data_overridetagnames;
78 #define SHADOWMESHVERTEXHASH 1024
79 typedef struct shadowmeshvertexhash_s
81 struct shadowmeshvertexhash_s *next;
83 shadowmeshvertexhash_t;
85 typedef struct shadowmesh_s
87 struct shadowmesh_s *next;
88 int numverts, maxverts;
89 int numtriangles, maxtriangles;
93 // these are NULL after Mod_ShadowMesh_Finish is performed, only used
94 // while building meshes
95 shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
100 #include "matrixlib.h"
102 #include "model_brush.h"
103 #include "model_sprite.h"
104 #include "model_alias.h"
106 typedef struct model_alias_s
108 // LordHavoc: Q2/ZYM model support
111 // mdl/md2/md3 models are the same after loading
113 aliasmesh_t *aliasdata_meshes;
116 int aliasnum_tagframes;
117 aliastag_t *aliasdata_tags;
119 // for Zymotic models
125 float *zymdata_texcoords;
126 rtexture_t **zymdata_textures;
127 qbyte *zymdata_trizone;
128 zymbone_t *zymdata_bones;
129 unsigned int *zymdata_vertbonecounts;
130 zymvertex_t *zymdata_verts;
131 unsigned int *zymdata_renderlist;
132 float *zymdata_poses;
136 typedef struct model_sprite_s
139 mspriteframe_t *sprdata_frames;
145 typedef struct model_brush_s
148 void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
149 void (*TraceBox)(struct model_s *model, struct trace_s *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs);
153 typedef struct model_brushq1_s
155 // true if this model is a HalfLife .bsp file
158 int firstmodelsurface, nummodelsurfaces;
160 // lightmap format, set to r_lightmaprgba when model is loaded
169 // number of visible leafs, not counting 0 (solid)
186 msurface_t *surfaces;
187 int *surfacevisframes;
188 int *surfacepvsframes;
189 msurface_t *surfacepvsnext;
190 surfmesh_t *entiremesh;
191 surfmesh_t *surfmeshes;
197 dclipnode_t *clipnodes;
202 hull_t hulls[MAX_MAP_HULLS];
214 mvertex_t *portalpoints;
219 // pvs visibility marking
220 mleaf_t *pvsviewleaf;
221 int pvsviewleafnovis;
223 mleaf_t *pvsleafchain;
225 int pvssurflistlength;
226 // these get rebuilt as the player moves around if this is the world,
227 // otherwise they are left alone (no pvs for bmodels)
228 msurface_t ***pvstexturechains;
229 msurface_t **pvstexturechainsbuffer;
230 int *pvstexturechainslength;
232 // lightmap update chains for light styles
235 int *light_stylevalue;
236 msurface_t ***light_styleupdatechains;
237 msurface_t **light_styleupdatechainsbuffer;
241 mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p);
242 qbyte *(*LeafPVS)(struct model_s *model, mleaf_t *leaf);
243 void (*BuildPVSTextureChains)(struct model_s *model);
247 /* MSVC can't compile empty structs, so this is commented out for now
248 typedef struct model_brushq2_s
254 typedef struct q3mtexture_s
256 char name[Q3PATHLENGTH];
265 typedef struct q3mnode_s
268 struct q3mnode_s *parent;
269 struct mplane_s *plane;
270 struct q3mnode_s *children[2];
274 typedef struct q3mleaf_s
277 struct q3mnode_s *parent;
281 struct q3mface_s **firstleafface;
283 struct q3mbrush_s **firstleafbrush;
289 typedef struct q3mmodel_s
294 struct q3mface_s *firstface;
296 struct q3mbrush_s *firstbrush;
300 typedef struct q3mbrush_s
303 struct q3mbrushside_s *firstbrushside;
304 struct q3mtexture_s *texture;
308 typedef struct q3mbrushside_s
310 struct mplane_s *plane;
311 struct q3mtexture_s *texture;
315 typedef struct q3meffect_s
317 char shadername[Q3PATHLENGTH];
318 struct q3mbrush_s *brush;
319 int unknown; // 5 or -1
323 typedef struct q3mface_s
325 struct q3mtexture_s *texture;
326 struct q3meffect_s *effect;
327 rtexture_t *lightmaptexture;
335 float *data_vertex3f;
336 float *data_texturetexcoord2f;
337 float *data_lightmaptexcoord2f;
338 float *data_svector3f;
339 float *data_tvector3f;
340 float *data_normal3f;
344 int *data_neighbor3i;
348 typedef struct model_brushq3_s
351 q3mtexture_t *data_textures;
354 mplane_t *data_planes;
357 q3mnode_t *data_nodes;
360 q3mleaf_t *data_leafs;
363 q3mbrush_t **data_leafbrushes;
366 q3mface_t **data_leaffaces;
369 q3mmodel_t *data_models;
370 // each submodel gets its own model struct so this is different for each.
371 q3mmodel_t data_thismodel;
374 q3mbrush_t *data_brushes;
377 q3mbrushside_t *data_brushsides;
380 float *data_vertex3f;
381 float *data_texturetexcoord2f;
382 float *data_lightmaptexcoord2f;
383 float *data_svector3f;
384 float *data_tvector3f;
385 float *data_normal3f;
390 int *data_neighbor3i;
393 q3meffect_t *data_effects;
396 q3mface_t *data_faces;
400 rtexture_t **data_lightmaps;
402 // voxel light data with directional shading
404 q3dlightgrid_t *data_lightgrid;
405 // size of each cell (may vary by map, typically 64 64 128)
406 float num_lightgrid_cellsize[3];
407 // 1.0 / num_lightgrid_cellsize
408 float num_lightgrid_scale[3];
409 // dimensions of the world model in lightgrid cells
410 int num_lightgrid_imins[3];
411 int num_lightgrid_imaxs[3];
412 int num_lightgrid_isize[3];
414 int num_lightgrid_dimensions[3];
415 // transform modelspace coordinates to lightgrid index
416 matrix4x4_t num_lightgrid_indexfromworld;
420 int num_pvschainlength;
421 unsigned char *data_pvschains;
423 //pvschain = model->brushq3.data_pvschains + mycluster * model->brushq3.num_pvschainlength;
424 //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
428 typedef struct model_s
430 // name and path of model, for example "progs/player.mdl"
431 char name[MAX_QPATH];
432 // model needs to be loaded if this is true
434 // set if the model is used in current map, models which are not, are purged
436 // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
437 qboolean isworldmodel;
438 // CRC of the file this model was loaded from, to reload if changed
440 // mod_brush, mod_alias, mod_sprite
442 // memory pool for allocations
444 // all models use textures...
445 rtexturepool_t *texturepool;
446 // flags from the model file
448 // engine calculated flags, ones that can not be set in the file
450 // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
452 // number of QC accessible frame(group)s in the model
454 // number of QC accessible skin(group)s in the model
456 // whether to randomize animated framegroups
458 // bounding box at angles '0 0 0'
459 vec3_t normalmins, normalmaxs;
460 // bounding box if yaw angle is not 0, but pitch and roll are
461 vec3_t yawmins, yawmaxs;
462 // bounding box if pitch or roll are used
463 vec3_t rotatedmins, rotatedmaxs;
464 // sphere radius, usable at any angles
466 // squared sphere radius for easier comparisons
468 // skin animation info
469 animscene_t *skinscenes; // [numskins]
470 // skin animation info
471 animscene_t *animscenes; // [numframes]
472 // draw the model's sky polygons (only used by brush models)
473 void(*DrawSky)(struct entity_render_s *ent);
474 // draw the model using lightmap/dlight shading
475 void(*Draw)(struct entity_render_s *ent);
476 // draw a fake shadow for the model
477 void(*DrawFakeShadow)(struct entity_render_s *ent);
478 // draw a shadow volume for the model based on light source
479 void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
480 // draw the lighting on a model (through stencil)
481 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);
482 // fields belonging to each type of model
484 model_sprite_t sprite;
486 model_brushq1_t brushq1;
487 /* MSVC can't handle an empty struct, so this is commented out for now
488 model_brushq2_t brushq2;
490 model_brushq3_t brushq3;
491 // skin files can have different tags for each skin
492 overridetagnameset_t *data_overridetagnamesforskin;
496 //============================================================================
498 // this can be used for anything without a valid texture
499 extern rtexture_t *r_notexture;
500 #define NUM_DETAILTEXTURES 1
501 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
502 // every texture must be in a pool...
503 extern rtexturepool_t *mod_shared_texturepool;
506 extern model_t *loadmodel;
507 extern qbyte *mod_base;
508 // sky/water subdivision
509 //extern cvar_t gl_subdivide_size;
510 // texture fullbrights
511 extern cvar_t r_fullbrights;
513 void Mod_Init (void);
514 void Mod_CheckLoaded (model_t *mod);
515 void Mod_ClearAll (void);
516 model_t *Mod_FindName (const char *name);
517 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
518 void Mod_TouchModel (const char *name);
519 void Mod_UnloadModel (model_t *mod);
521 void Mod_ClearUsed(void);
522 void Mod_PurgeUnused(void);
523 void Mod_LoadModels(void);
525 extern model_t *loadmodel;
526 extern char loadname[32]; // for hunk tags
528 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
529 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
530 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
531 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
533 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
534 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
535 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
536 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
537 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
538 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, float *verts, int numtris, int *elements);
539 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
540 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
541 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
542 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
544 int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
545 int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);
547 extern cvar_t r_mipskins;
549 typedef struct skinfileitem_s
551 struct skinfileitem_s *next;
552 char name[MAX_QPATH];
553 char replacement[MAX_QPATH];
557 typedef struct skinfile_s
559 struct skinfile_s *next;
560 skinfileitem_t *items;
564 skinfile_t *Mod_LoadSkinFiles(void);
565 void Mod_FreeSkinFiles(skinfile_t *skinfile);
566 int Mod_CountSkinFiles(skinfile_t *skinfile);