]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_shared.h
massive coding has been done on shadow volumes (some scrapped code which will be...
[xonotic/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 }
57 skinframe_t;
58
59 #define MAX_SKINS 256
60
61 typedef struct shadowmesh_s
62 {
63         struct shadowmesh_s *next;
64         int numverts, maxverts;
65         int numtriangles, maxtriangles;
66         float *verts;
67         int *elements;
68         int *neighbors;
69 }
70 shadowmesh_t;
71
72
73 #include "model_brush.h"
74 #include "model_sprite.h"
75 #include "model_alias.h"
76
77 typedef struct model_s
78 {
79         char                    name[MAX_QPATH];
80         // model needs to be loaded if this is true
81         qboolean                needload;
82         // set if the model is used in current map, models which are not, are purged
83         qboolean                used;
84         // CRC of the file this model was loaded from, to reload if changed
85         qboolean                crc;
86         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
87         qboolean                isworldmodel;
88         // true if this model is a HalfLife .bsp file
89         qboolean                ishlbsp;
90
91         // mod_brush, mod_alias, mod_sprite
92         modtype_t               type;
93         // LordHavoc: Q2/ZYM model support
94         int                             aliastype;
95         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
96         int                             fullbright;
97         // number of QC accessable frame(group)s in the model
98         int                             numframes;
99         // whether to randomize animated framegroups
100         synctype_t              synctype;
101
102         // used for sprites and models
103         int                             numtris;
104         // used for models
105         int                             numskins;
106         // used by models
107         int                             numverts;
108
109         // flags from the model file
110         int                             flags;
111         // engine calculated flags, ones that can not be set in the file
112         int                             flags2;
113
114         // all models use textures...
115         rtexturepool_t  *texturepool;
116
117         // volume occupied by the model
118         // bounding box at angles '0 0 0'
119         vec3_t                  normalmins, normalmaxs;
120         // bounding box if yaw angle is not 0, but pitch and roll are
121         vec3_t                  yawmins, yawmaxs;
122         // bounding box if pitch or roll are used
123         vec3_t                  rotatedmins, rotatedmaxs;
124         // sphere radius, usable at any angles
125         float                   radius;
126         // squared sphere radius for easier comparisons
127         float                   radius2;
128
129         // brush model specific
130         int                             firstmodelsurface, nummodelsurfaces;
131
132         // lightmap format, set to r_lightmaprgba when model is loaded
133         int                             lightmaprgba;
134
135         int                             numsubmodels;
136         dmodel_t                *submodels;
137
138         int                             numplanes;
139         mplane_t                *planes;
140
141         // number of visible leafs, not counting 0 (solid)
142         int                             numleafs;
143         mleaf_t                 *leafs;
144
145         int                             numvertexes;
146         mvertex_t               *vertexes;
147
148         int                             numedges;
149         medge_t                 *edges;
150
151         int                             numnodes;
152         mnode_t                 *nodes;
153
154         int                             numtexinfo;
155         mtexinfo_t              *texinfo;
156
157         int                             numsurfaces;
158         msurface_t              *surfaces;
159         int                             *surfacevisframes;
160         int                             *surfacepvsframes;
161         msurface_t              *surfacepvsnext;
162
163         int                             numsurfedges;
164         int                             *surfedges;
165
166         int                             numclipnodes;
167         dclipnode_t             *clipnodes;
168
169         int                             nummarksurfaces;
170         int                             *marksurfaces;
171
172         hull_t                  hulls[MAX_MAP_HULLS];
173
174         int                             numtextures;
175         texture_t               *textures;
176
177         qbyte                   *visdata;
178         qbyte                   *lightdata;
179         char                    *entities;
180
181         int                             numportals;
182         mportal_t               *portals;
183
184         int                             numportalpoints;
185         mvertex_t               *portalpoints;
186
187         int                             numlights;
188         mlight_t                *lights;
189
190         // used only for casting dynamic shadow volumes
191         shadowmesh_t    *shadowmesh;
192         vec3_t                  shadowmesh_mins, shadowmesh_maxs, shadowmesh_center;
193         float                   shadowmesh_radius;
194
195         // skin animation info
196         animscene_t             *skinscenes; // [numskins]
197         // skin frame info
198         skinframe_t             *skinframes;
199
200         animscene_t             *animscenes; // [numframes]
201
202         // Q1 and Q2 models are the same after loading
203         int                             *mdlmd2data_indices;
204         float                   *mdlmd2data_texcoords;
205         md2frame_t              *mdlmd2data_frames;
206         trivertx_t              *mdlmd2data_pose;
207         int                             *mdlmd2data_triangleneighbors;
208
209         // for Zymotic models
210         void                    *zymdata_header;
211
212         int                             sprnum_type;
213         mspriteframe_t  *sprdata_frames;
214
215         // draw the model
216         void(*Draw)(struct entity_render_s *ent);
217         // draw the model's sky polygons (only used by brush models)
218         void(*DrawSky)(struct entity_render_s *ent);
219         // draw a fake shadow for the model
220         void(*DrawFakeShadow)(struct entity_render_s *ent);
221         // draw a shadow volume for the model based on light source
222         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, int visiblevolume);
223
224         // memory pool for allocations
225         mempool_t               *mempool;
226 }
227 model_t;
228
229 //============================================================================
230
231 // this can be used for anything without a valid texture
232 extern rtexture_t *r_notexture;
233 // every texture must be in a pool...
234 extern rtexturepool_t *r_notexturepool;
235
236 // model loading
237 extern model_t *loadmodel;
238 extern qbyte *mod_base;
239 // sky/water subdivision
240 //extern cvar_t gl_subdivide_size;
241 // texture fullbrights
242 extern cvar_t r_fullbrights;
243
244 void Mod_Init (void);
245 void Mod_CheckLoaded (model_t *mod);
246 void Mod_ClearAll (void);
247 model_t *Mod_FindName (const char *name);
248 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
249 void Mod_TouchModel (const char *name);
250 void Mod_UnloadModel (model_t *mod);
251
252 void Mod_ClearUsed(void);
253 void Mod_PurgeUnused(void);
254 void Mod_LoadModels(void);
255
256 extern model_t *loadmodel;
257 extern char loadname[32];       // for hunk tags
258
259 int Mod_FindTriangleWithEdge(int *elements, int numtriangles, int start, int end);
260 void Mod_BuildTriangleNeighbors(int *neighbors, int *elements, int numtriangles);
261
262 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
263 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
264 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
265 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
266 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool);
267 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
268 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
269 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
270
271 #endif  // __MODEL__
272