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 minus 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
54 rtexture_t *merged; // original texture minus glow
55 rtexture_t *fog; // white texture with alpha of the base texture, NULL if not transparent
56 rtexture_t *nmap; // normalmap (bumpmap for dot3)
57 rtexture_t *gloss; // glossmap (for dot3)
63 #define SHADOWMESHVERTEXHASH 1024
64 typedef struct shadowmeshvertexhash_s
66 struct shadowmeshvertexhash_s *next;
68 shadowmeshvertexhash_t;
70 typedef struct shadowmesh_s
72 struct shadowmesh_s *next;
73 int numverts, maxverts;
74 int numtriangles, maxtriangles;
78 // these are NULL after Mod_ShadowMesh_Finish is performed, only used
79 // while building meshes
80 shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
85 #include "model_brush.h"
86 #include "model_sprite.h"
87 #include "model_alias.h"
89 typedef struct model_s
92 // model needs to be loaded if this is true
94 // set if the model is used in current map, models which are not, are purged
96 // CRC of the file this model was loaded from, to reload if changed
98 // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
99 qboolean isworldmodel;
100 // true if this model is a HalfLife .bsp file
102 // true if this model was not successfully loaded and should be purged
105 // mod_brush, mod_alias, mod_sprite
107 // LordHavoc: Q2/ZYM model support
109 // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
111 // number of QC accessable frame(group)s in the model
113 // whether to randomize animated framegroups
116 // used for sprites and models
123 // flags from the model file
125 // engine calculated flags, ones that can not be set in the file
128 // all models use textures...
129 rtexturepool_t *texturepool;
131 // volume occupied by the model
132 // bounding box at angles '0 0 0'
133 vec3_t normalmins, normalmaxs;
134 // bounding box if yaw angle is not 0, but pitch and roll are
135 vec3_t yawmins, yawmaxs;
136 // bounding box if pitch or roll are used
137 vec3_t rotatedmins, rotatedmaxs;
138 // sphere radius, usable at any angles
140 // squared sphere radius for easier comparisons
143 // brush model specific
144 int firstmodelsurface, nummodelsurfaces;
146 // lightmap format, set to r_lightmaprgba when model is loaded
155 // number of visible leafs, not counting 0 (solid)
172 msurface_t *surfaces;
173 int *surfacevisframes;
174 int *surfacepvsframes;
175 msurface_t *surfacepvsnext;
181 dclipnode_t *clipnodes;
186 hull_t hulls[MAX_MAP_HULLS];
191 msurface_t **texturesurfacechains;
201 mvertex_t *portalpoints;
206 // used only for casting dynamic shadow volumes
207 shadowmesh_t *shadowmesh;
208 vec3_t shadowmesh_mins, shadowmesh_maxs, shadowmesh_center;
209 float shadowmesh_radius;
211 // pvs visibility marking
212 mleaf_t *pvsviewleaf;
213 int pvsviewleafnovis;
215 mleaf_t *pvsleafchain;
217 int pvssurflistlength;
219 // skin animation info
220 animscene_t *skinscenes; // [numskins]
222 skinframe_t *skinframes;
224 animscene_t *animscenes; // [numframes]
226 // Q1 and Q2 models are the same after loading
227 int *mdlmd2data_indices;
228 float *mdlmd2data_texcoords;
229 md2frame_t *mdlmd2data_frames;
230 trivertx_t *mdlmd2data_pose;
231 int *mdlmd2data_triangleneighbors;
233 // for Zymotic models
239 float *zymdata_texcoords;
240 rtexture_t **zymdata_textures;
241 qbyte *zymdata_trizone;
242 zymbone_t *zymdata_bones;
243 unsigned int *zymdata_vertbonecounts;
244 zymvertex_t *zymdata_verts;
245 unsigned int *zymdata_renderlist;
246 float *zymdata_poses;
249 mspriteframe_t *sprdata_frames;
252 // functions used in both rendering modes
253 // draw the model's sky polygons (only used by brush models)
254 void(*DrawSky)(struct entity_render_s *ent);
256 // functions used only in normal rendering mode
258 void(*Draw)(struct entity_render_s *ent);
259 // draw a fake shadow for the model
260 void(*DrawFakeShadow)(struct entity_render_s *ent);
262 // functions used only in shadow volume rendering mode
263 // draw a shadow volume for the model based on light source
264 void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
265 // draw the lighting on a model (through stencil)
266 void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor);
268 // memory pool for allocations
273 //============================================================================
275 // this can be used for anything without a valid texture
276 extern rtexture_t *r_notexture;
277 // every texture must be in a pool...
278 extern rtexturepool_t *r_notexturepool;
281 extern model_t *loadmodel;
282 extern qbyte *mod_base;
283 // sky/water subdivision
284 //extern cvar_t gl_subdivide_size;
285 // texture fullbrights
286 extern cvar_t r_fullbrights;
288 void Mod_Init (void);
289 void Mod_CheckLoaded (model_t *mod);
290 void Mod_ClearAll (void);
291 void Mod_ClearErrorModels (void);
292 model_t *Mod_FindName (const char *name);
293 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
294 void Mod_TouchModel (const char *name);
295 void Mod_UnloadModel (model_t *mod);
297 void Mod_ClearUsed(void);
298 void Mod_PurgeUnused(void);
299 void Mod_LoadModels(void);
301 extern model_t *loadmodel;
302 extern char loadname[32]; // for hunk tags
304 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end);
305 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
306 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
307 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
309 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
310 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
311 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
312 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
313 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
314 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts, int numtris, int *elements);
315 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
316 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
317 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
318 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);