]> icculus.org git repositories - divverent/darkplaces.git/blob - model_shared.h
CalcSurfaceExtents now uses surf->poly_verts instead of edges
[divverent/darkplaces.git] / model_shared.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #ifndef __MODEL__
22 #define __MODEL__
23
24 #ifndef SYNCTYPE_T
25 #define SYNCTYPE_T
26 typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
27 #endif
28
29 /*
30
31 d*_t structures are on-disk representations
32 m*_t structures are in-memory
33
34 */
35
36 typedef enum {mod_invalid, mod_brush, mod_sprite, mod_alias} modtype_t;
37
38 typedef struct animscene_s
39 {
40         char name[32]; // for viewthing support
41         int firstframe;
42         int framecount;
43         int loop; // true or false
44         float framerate;
45 }
46 animscene_t;
47
48 typedef struct skinframe_s
49 {
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)
58 }
59 skinframe_t;
60
61 #define MAX_SKINS 256
62
63 #define SHADOWMESHVERTEXHASH 1024
64 typedef struct shadowmeshvertexhash_s
65 {
66         struct shadowmeshvertexhash_s *next;
67 }
68 shadowmeshvertexhash_t;
69
70 typedef struct shadowmesh_s
71 {
72         struct shadowmesh_s *next;
73         int numverts, maxverts;
74         int numtriangles, maxtriangles;
75         float *verts;
76         int *elements;
77         int *neighbors;
78         // these are NULL after Mod_ShadowMesh_Finish is performed, only used
79         // while building meshes
80         shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
81 }
82 shadowmesh_t;
83
84
85 #include "model_brush.h"
86 #include "model_sprite.h"
87 #include "model_alias.h"
88
89 typedef struct model_s
90 {
91         char                    name[MAX_QPATH];
92         // model needs to be loaded if this is true
93         qboolean                needload;
94         // set if the model is used in current map, models which are not, are purged
95         qboolean                used;
96         // CRC of the file this model was loaded from, to reload if changed
97         qboolean                crc;
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
101         qboolean                ishlbsp;
102         // true if this model was not successfully loaded and should be purged
103         qboolean                error;
104
105         // mod_brush, mod_alias, mod_sprite
106         modtype_t               type;
107         // LordHavoc: Q2/ZYM model support
108         int                             aliastype;
109         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
110         int                             fullbright;
111         // number of QC accessable frame(group)s in the model
112         int                             numframes;
113         // whether to randomize animated framegroups
114         synctype_t              synctype;
115
116         // used for sprites and models
117         int                             numtris;
118         // used for models
119         int                             numskins;
120         // used by models
121         int                             numverts;
122
123         // flags from the model file
124         int                             flags;
125         // engine calculated flags, ones that can not be set in the file
126         int                             flags2;
127
128         // all models use textures...
129         rtexturepool_t  *texturepool;
130
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
139         float                   radius;
140         // squared sphere radius for easier comparisons
141         float                   radius2;
142
143         // brush model specific
144         int                             firstmodelsurface, nummodelsurfaces;
145
146         // lightmap format, set to r_lightmaprgba when model is loaded
147         int                             lightmaprgba;
148
149         int                             numsubmodels;
150         dmodel_t                *submodels;
151
152         int                             numplanes;
153         mplane_t                *planes;
154
155         // number of visible leafs, not counting 0 (solid)
156         int                             numleafs;
157         mleaf_t                 *leafs;
158
159         int                             numvertexes;
160         mvertex_t               *vertexes;
161
162         int                             numedges;
163         medge_t                 *edges;
164
165         int                             numnodes;
166         mnode_t                 *nodes;
167
168         int                             numtexinfo;
169         mtexinfo_t              *texinfo;
170
171         int                             numsurfaces;
172         msurface_t              *surfaces;
173         int                             *surfacevisframes;
174         int                             *surfacepvsframes;
175         msurface_t              *surfacepvsnext;
176
177         int                             numsurfedges;
178         int                             *surfedges;
179
180         int                             numclipnodes;
181         dclipnode_t             *clipnodes;
182
183         int                             nummarksurfaces;
184         int                             *marksurfaces;
185
186         hull_t                  hulls[MAX_MAP_HULLS];
187
188         int                             numtextures;
189         texture_t               *textures;
190
191         qbyte                   *visdata;
192         qbyte                   *lightdata;
193         char                    *entities;
194
195         int                             numportals;
196         mportal_t               *portals;
197
198         int                             numportalpoints;
199         mvertex_t               *portalpoints;
200
201         int                             numlights;
202         mlight_t                *lights;
203
204         // pvs visibility marking
205         mleaf_t                 *pvsviewleaf;
206         int                             pvsviewleafnovis;
207         int                             pvsframecount;
208         mleaf_t                 *pvsleafchain;
209         int                             *pvssurflist;
210         int                             pvssurflistlength;
211         // these get rebuilt as the player moves around if this is the world,
212         // otherwise they are left alone (no pvs for bmodels)
213         msurface_t              ***pvstexturechains;
214         msurface_t              **pvstexturechainsbuffer;
215         int                             *pvstexturechainslength;
216
217         // lightmap update chains for light styles
218         int                             light_styles;
219         qbyte                   *light_style;
220         int                             *light_stylevalue;
221         msurface_t              ***light_styleupdatechains;
222         msurface_t              **light_styleupdatechainsbuffer;
223         int                             light_scalebit;
224         float                   light_ambient;
225
226         // skin animation info
227         animscene_t             *skinscenes; // [numskins]
228         // skin frame info
229         skinframe_t             *skinframes;
230
231         animscene_t             *animscenes; // [numframes]
232
233         // Q1 and Q2 models are the same after loading
234         int                             *mdlmd2data_indices;
235         float                   *mdlmd2data_texcoords;
236         md2frame_t              *mdlmd2data_frames;
237         trivertx_t              *mdlmd2data_pose;
238         int                             *mdlmd2data_triangleneighbors;
239
240         // for Zymotic models
241         int                             zymnum_verts;
242         int                             zymnum_tris;
243         int                             zymnum_shaders;
244         int                             zymnum_bones;
245         int                             zymnum_scenes;
246         float                   *zymdata_texcoords;
247         rtexture_t              **zymdata_textures;
248         qbyte                   *zymdata_trizone;
249         zymbone_t               *zymdata_bones;
250         unsigned int    *zymdata_vertbonecounts;
251         zymvertex_t             *zymdata_verts;
252         unsigned int    *zymdata_renderlist;
253         float                   *zymdata_poses;
254
255         int                             sprnum_type;
256         mspriteframe_t  *sprdata_frames;
257
258
259         // functions used in both rendering modes
260         // draw the model's sky polygons (only used by brush models)
261         void(*DrawSky)(struct entity_render_s *ent);
262
263         // functions used only in normal rendering mode
264         // draw the model
265         void(*Draw)(struct entity_render_s *ent);
266         // draw a fake shadow for the model
267         void(*DrawFakeShadow)(struct entity_render_s *ent);
268
269         // functions used only in shadow volume rendering mode
270         // draw a shadow volume for the model based on light source
271         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
272         // draw the lighting on a model (through stencil)
273         void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor);
274
275         // memory pool for allocations
276         mempool_t               *mempool;
277 }
278 model_t;
279
280 //============================================================================
281
282 // this can be used for anything without a valid texture
283 extern rtexture_t *r_notexture;
284 // every texture must be in a pool...
285 extern rtexturepool_t *r_notexturepool;
286
287 // model loading
288 extern model_t *loadmodel;
289 extern qbyte *mod_base;
290 // sky/water subdivision
291 //extern cvar_t gl_subdivide_size;
292 // texture fullbrights
293 extern cvar_t r_fullbrights;
294
295 void Mod_Init (void);
296 void Mod_CheckLoaded (model_t *mod);
297 void Mod_ClearAll (void);
298 void Mod_ClearErrorModels (void);
299 model_t *Mod_FindName (const char *name);
300 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
301 void Mod_TouchModel (const char *name);
302 void Mod_UnloadModel (model_t *mod);
303
304 void Mod_ClearUsed(void);
305 void Mod_PurgeUnused(void);
306 void Mod_LoadModels(void);
307
308 extern model_t *loadmodel;
309 extern char loadname[32];       // for hunk tags
310
311 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end);
312 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
313 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
314 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
315
316 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
317 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
318 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
319 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
320 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
321 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts, int numtris, int *elements);
322 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
323 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
324 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
325 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
326
327 #endif  // __MODEL__
328