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
147 // true if this model is a HalfLife .bsp file
149 // string of entity definitions (.map format)
151 // number of submodels in this map (just used by server to know how many
152 // submodels to load)
155 int (*SuperContentsFromNativeContents)(struct model_s *model, int nativecontents);
156 int (*NativeContentsFromSuperContents)(struct model_s *model, int supercontents);
157 qbyte *(*GetPVS)(struct model_s *model, const vec3_t p);
158 int (*FatPVS)(struct model_s *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength);
159 int (*BoxTouchingPVS)(struct model_s *model, const qbyte *pvs, const vec3_t mins, const vec3_t maxs);
160 void (*LightPoint)(struct model_s *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal);
161 void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
162 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, int hitsupercontentsmask);
163 // these are actually only found on brushq1, but NULL is handled gracefully
164 void (*AmbientSoundLevelsForPoint)(struct model_s *model, const vec3_t p, qbyte *out, int outsize);
165 void (*RoundUpToHullSize)(struct model_s *cmodel, const vec3_t inmins, const vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs);
169 typedef struct model_brushq1_s
171 int firstmodelsurface, nummodelsurfaces;
173 // lightmap format, set to r_lightmaprgba when model is loaded
181 // number of actual leafs (including 0 which is solid)
183 // visible leafs, not counting 0 (solid)
200 msurface_t *surfaces;
201 int *surfacevisframes;
202 int *surfacepvsframes;
203 msurface_t *surfacepvsnext;
204 surfmesh_t *entiremesh;
210 dclipnode_t *clipnodes;
215 hull_t hulls[MAX_MAP_HULLS];
220 int num_compressedpvs;
221 qbyte *data_compressedpvs;
222 qbyte *data_decompressedpvs;
231 mvertex_t *portalpoints;
236 // pvs visibility marking
237 mleaf_t *pvsviewleaf;
238 int pvsviewleafnovis;
240 mleaf_t *pvsleafchain;
242 int pvssurflistlength;
243 // these get rebuilt as the player moves around if this is the world,
244 // otherwise they are left alone (no pvs for bmodels)
245 msurface_t ***pvstexturechains;
246 msurface_t **pvstexturechainsbuffer;
247 int *pvstexturechainslength;
249 // lightmap update chains for light styles
252 int *light_stylevalue;
253 msurface_t ***light_styleupdatechains;
254 msurface_t **light_styleupdatechainsbuffer;
258 mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p);
259 void (*BuildPVSTextureChains)(struct model_s *model);
263 /* MSVC can't compile empty structs, so this is commented out for now
264 typedef struct model_brushq2_s
270 #define Q3MTEXTURERENDERFLAGS_NODRAW 1
271 #define Q3MTEXTURERENDERFLAGS_SKY 2
273 typedef struct q3mtexture_s
275 char name[Q3PATHLENGTH];
286 typedef struct q3mnode_s
288 //this part shared between node and leaf
290 struct q3mnode_s *parent;
293 // this part unique to nodes
294 struct mplane_s *plane;
295 struct q3mnode_s *children[2];
299 typedef struct q3mleaf_s
301 //this part shared between node and leaf
303 struct q3mnode_s *parent;
306 // this part unique to leafs
310 struct q3mface_s **firstleafface;
312 struct q3mbrush_s **firstleafbrush;
316 typedef struct q3mmodel_s
321 struct q3mface_s *firstface;
323 struct q3mbrush_s *firstbrush;
327 typedef struct q3mbrush_s
329 struct colbrushf_s *colbrushf;
331 struct q3mbrushside_s *firstbrushside;
332 struct q3mtexture_s *texture;
336 typedef struct q3mbrushside_s
338 struct mplane_s *plane;
339 struct q3mtexture_s *texture;
343 typedef struct q3meffect_s
345 char shadername[Q3PATHLENGTH];
346 struct q3mbrush_s *brush;
347 int unknown; // 5 or -1
351 typedef struct q3mface_s
353 struct q3mtexture_s *texture;
354 struct q3meffect_s *effect;
355 rtexture_t *lightmaptexture;
356 int collisions; // performs per triangle collisions on this surface
357 int collisionmarkframe; // don't collide twice in one trace
362 // used for processing
364 // (world only) visframe == r_framecount means it is visible this frame
366 // bounding box for culling
372 float *data_vertex3f;
373 float *data_texcoordtexture2f;
374 float *data_texcoordlightmap2f;
375 float *data_svector3f;
376 float *data_tvector3f;
377 float *data_normal3f;
380 int *data_neighbor3i;
384 typedef struct model_brushq3_s
386 // if non-zero this is a submodel
387 // (this is the number of the submodel, an index into data_models)
391 q3mtexture_t *data_textures;
394 mplane_t *data_planes;
397 q3mnode_t *data_nodes;
400 q3mleaf_t *data_leafs;
403 q3mbrush_t **data_leafbrushes;
406 q3mface_t **data_leaffaces;
409 q3mmodel_t *data_models;
410 // each submodel gets its own model struct so this is different for each.
411 q3mmodel_t *data_thismodel;
414 q3mbrush_t *data_brushes;
417 q3mbrushside_t *data_brushsides;
420 float *data_vertex3f;
421 float *data_texcoordtexture2f;
422 float *data_texcoordlightmap2f;
423 float *data_svector3f;
424 float *data_tvector3f;
425 float *data_normal3f;
430 int *data_neighbor3i;
433 q3meffect_t *data_effects;
436 q3mface_t *data_faces;
440 rtexture_t **data_lightmaps;
442 // voxel light data with directional shading
444 q3dlightgrid_t *data_lightgrid;
445 // size of each cell (may vary by map, typically 64 64 128)
446 float num_lightgrid_cellsize[3];
447 // 1.0 / num_lightgrid_cellsize
448 float num_lightgrid_scale[3];
449 // dimensions of the world model in lightgrid cells
450 int num_lightgrid_imins[3];
451 int num_lightgrid_imaxs[3];
452 int num_lightgrid_isize[3];
454 int num_lightgrid_dimensions[3];
455 // transform modelspace coordinates to lightgrid index
456 matrix4x4_t num_lightgrid_indexfromworld;
460 int num_pvschainlength;
461 unsigned char *data_pvschains;
463 //pvschain = model->brushq3.data_pvschains + mycluster * model->brushq3.num_pvschainlength;
464 //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
468 typedef struct model_s
470 // name and path of model, for example "progs/player.mdl"
471 char name[MAX_QPATH];
472 // model needs to be loaded if this is true
474 // set if the model is used in current map, models which are not, are purged
476 // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
477 qboolean isworldmodel;
478 // CRC of the file this model was loaded from, to reload if changed
480 // mod_brush, mod_alias, mod_sprite
482 // memory pool for allocations
484 // all models use textures...
485 rtexturepool_t *texturepool;
486 // flags from the model file
488 // engine calculated flags, ones that can not be set in the file
490 // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
492 // number of QC accessible frame(group)s in the model
494 // number of QC accessible skin(group)s in the model
496 // whether to randomize animated framegroups
498 // bounding box at angles '0 0 0'
499 vec3_t normalmins, normalmaxs;
500 // bounding box if yaw angle is not 0, but pitch and roll are
501 vec3_t yawmins, yawmaxs;
502 // bounding box if pitch or roll are used
503 vec3_t rotatedmins, rotatedmaxs;
504 // sphere radius, usable at any angles
506 // squared sphere radius for easier comparisons
508 // skin animation info
509 animscene_t *skinscenes; // [numskins]
510 // skin animation info
511 animscene_t *animscenes; // [numframes]
512 // draw the model's sky polygons (only used by brush models)
513 void(*DrawSky)(struct entity_render_s *ent);
514 // draw the model using lightmap/dlight shading
515 void(*Draw)(struct entity_render_s *ent);
516 // draw a shadow volume for the model based on light source
517 void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
518 // draw the lighting on a model (through stencil)
519 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);
520 // fields belonging to each type of model
522 model_sprite_t sprite;
524 model_brushq1_t brushq1;
525 /* MSVC can't handle an empty struct, so this is commented out for now
526 model_brushq2_t brushq2;
528 model_brushq3_t brushq3;
529 // skin files can have different tags for each skin
530 overridetagnameset_t *data_overridetagnamesforskin;
534 //============================================================================
536 // this can be used for anything without a valid texture
537 extern rtexture_t *r_notexture;
538 #define NUM_DETAILTEXTURES 1
539 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
540 // every texture must be in a pool...
541 extern rtexturepool_t *mod_shared_texturepool;
543 extern rtexture_t *mod_shared_distorttexture[64];
546 extern model_t *loadmodel;
547 extern qbyte *mod_base;
548 // sky/water subdivision
549 //extern cvar_t gl_subdivide_size;
550 // texture fullbrights
551 extern cvar_t r_fullbrights;
553 void Mod_Init (void);
554 void Mod_CheckLoaded (model_t *mod);
555 void Mod_ClearAll (void);
556 model_t *Mod_FindName (const char *name);
557 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
558 void Mod_TouchModel (const char *name);
559 void Mod_UnloadModel (model_t *mod);
561 void Mod_ClearUsed(void);
562 void Mod_PurgeUnused(void);
563 void Mod_LoadModels(void);
565 extern model_t *loadmodel;
566 extern char loadname[32]; // for hunk tags
568 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
569 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
570 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
571 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
573 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
574 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
575 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
576 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
577 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
578 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, float *verts, int numtris, int *elements);
579 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
580 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
581 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
582 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
584 int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
585 int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);
587 // used for talking to the QuakeC mainly
588 int Mod_Q1BSP_NativeContentsFromSuperContents(struct model_s *model, int supercontents);
589 int Mod_Q1BSP_SuperContentsFromNativeContents(struct model_s *model, int nativecontents);
591 extern cvar_t r_mipskins;
593 typedef struct skinfileitem_s
595 struct skinfileitem_s *next;
596 char name[MAX_QPATH];
597 char replacement[MAX_QPATH];
601 typedef struct skinfile_s
603 struct skinfile_s *next;
604 skinfileitem_t *items;
608 skinfile_t *Mod_LoadSkinFiles(void);
609 void Mod_FreeSkinFiles(skinfile_t *skinfile);
610 int Mod_CountSkinFiles(skinfile_t *skinfile);
612 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);