]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/renderer/Model_local.h
hello world
[icculus/iodoom3.git] / neo / renderer / Model_local.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #ifndef __MODEL_LOCAL_H__
30 #define __MODEL_LOCAL_H__
31
32 /*
33 ===============================================================================
34
35         Static model
36
37 ===============================================================================
38 */
39
40 class idRenderModelStatic : public idRenderModel {
41 public:
42         // the inherited public interface
43         static idRenderModel *          Alloc();
44
45                                                                 idRenderModelStatic();
46         virtual                                         ~idRenderModelStatic();
47
48         virtual void                            InitFromFile( const char *fileName );
49         virtual void                            PartialInitFromFile( const char *fileName );
50         virtual void                            PurgeModel();
51         virtual void                            Reset() {};
52         virtual void                            LoadModel();
53         virtual bool                            IsLoaded();
54         virtual void                            SetLevelLoadReferenced( bool referenced );
55         virtual bool                            IsLevelLoadReferenced();
56         virtual void                            TouchData();
57         virtual void                            InitEmpty( const char *name );
58         virtual void                            AddSurface( modelSurface_t surface );
59         virtual void                            FinishSurfaces();
60         virtual void                            FreeVertexCache();
61         virtual const char *            Name() const;
62         virtual void                            Print() const;
63         virtual void                            List() const;
64         virtual int                                     Memory() const;
65         virtual ID_TIME_T                               Timestamp() const;
66         virtual int                                     NumSurfaces() const;
67         virtual int                                     NumBaseSurfaces() const;
68         virtual const modelSurface_t *Surface( int surfaceNum ) const;
69         virtual srfTriangles_t *        AllocSurfaceTriangles( int numVerts, int numIndexes ) const;
70         virtual void                            FreeSurfaceTriangles( srfTriangles_t *tris ) const;
71         virtual srfTriangles_t *        ShadowHull() const;
72         virtual bool                            IsStaticWorldModel() const;
73         virtual dynamicModel_t          IsDynamicModel() const;
74         virtual bool                            IsDefaultModel() const;
75         virtual bool                            IsReloadable() const;
76         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
77         virtual int                                     NumJoints( void ) const;
78         virtual const idMD5Joint *      GetJoints( void ) const;
79         virtual jointHandle_t           GetJointHandle( const char *name ) const;
80         virtual const char *            GetJointName( jointHandle_t handle ) const;
81         virtual const idJointQuat *     GetDefaultPose( void ) const;
82         virtual int                                     NearestJoint( int surfaceNum, int a, int b, int c ) const;
83         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
84         virtual void                            ReadFromDemoFile( class idDemoFile *f );
85         virtual void                            WriteToDemoFile( class idDemoFile *f );
86         virtual float                           DepthHack() const;
87
88         void                                            MakeDefaultModel();
89         
90         bool                                            LoadASE( const char *fileName );
91         bool                                            LoadLWO( const char *fileName );
92         bool                                            LoadFLT( const char *fileName );
93         bool                                            LoadMA( const char *filename );
94
95         bool                                            ConvertASEToModelSurfaces( const struct aseModel_s *ase );
96         bool                                            ConvertLWOToModelSurfaces( const struct st_lwObject *lwo );
97         bool                                            ConvertMAToModelSurfaces (const struct maModel_s *ma );
98
99         struct aseModel_s *                     ConvertLWOToASE( const struct st_lwObject *obj, const char *fileName );
100
101         bool                                            DeleteSurfaceWithId( int id );
102         void                                            DeleteSurfacesWithNegativeId( void );
103         bool                                            FindSurfaceWithId( int id, int &surfaceNum );
104
105 public:
106         idList<modelSurface_t>          surfaces;
107         idBounds                                        bounds;
108         int                                                     overlaysAdded;
109
110 protected:
111         int                                                     lastModifiedFrame;
112         int                                                     lastArchivedFrame;
113
114         idStr                                           name;
115         srfTriangles_t *                        shadowHull;
116         bool                                            isStaticWorldModel;
117         bool                                            defaulted;
118         bool                                            purged;                                 // eventually we will have dynamic reloading
119         bool                                            fastLoad;                               // don't generate tangents and shadow data
120         bool                                            reloadable;                             // if not, reloadModels won't check timestamp
121         bool                                            levelLoadReferenced;    // for determining if it needs to be freed
122         ID_TIME_T                                               timeStamp;
123
124         static idCVar                           r_mergeModelSurfaces;   // combine model surfaces with the same material
125         static idCVar                           r_slopVertex;                   // merge xyz coordinates this far apart
126         static idCVar                           r_slopTexCoord;                 // merge texture coordinates this far apart
127         static idCVar                           r_slopNormal;                   // merge normals that dot less than this
128 };
129
130 /*
131 ===============================================================================
132
133         MD5 animated model
134
135 ===============================================================================
136 */
137
138 class idMD5Mesh {
139         friend class                            idRenderModelMD5;
140
141 public:
142                                                                 idMD5Mesh();
143                                                                 ~idMD5Mesh();
144
145         void                                            ParseMesh( idLexer &parser, int numJoints, const idJointMat *joints );
146         void                                            UpdateSurface( const struct renderEntity_s *ent, const idJointMat *joints, modelSurface_t *surf );
147         idBounds                                        CalcBounds( const idJointMat *joints );
148         int                                                     NearestJoint( int a, int b, int c ) const;
149         int                                                     NumVerts( void ) const;
150         int                                                     NumTris( void ) const;
151         int                                                     NumWeights( void ) const;
152
153 private:
154         idList<idVec2>                          texCoords;                      // texture coordinates
155         int                                                     numWeights;                     // number of weights
156         idVec4 *                                        scaledWeights;          // joint weights
157         int *                                           weightIndex;            // pairs of: joint offset + bool true if next weight is for next vertex
158         const idMaterial *                      shader;                         // material applied to mesh
159         int                                                     numTris;                        // number of triangles
160         struct deformInfo_s *           deformInfo;                     // used to create srfTriangles_t from base frames and new vertexes
161         int                                                     surfaceNum;                     // number of the static surface created for this mesh
162
163         void                                            TransformVerts( idDrawVert *verts, const idJointMat *joints );
164         void                                            TransformScaledVerts( idDrawVert *verts, const idJointMat *joints, float scale );
165 };
166
167 class idRenderModelMD5 : public idRenderModelStatic {
168 public:
169         virtual void                            InitFromFile( const char *fileName );
170         virtual dynamicModel_t          IsDynamicModel() const;
171         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
172         virtual void                            Print() const;
173         virtual void                            List() const;
174         virtual void                            TouchData();
175         virtual void                            PurgeModel();
176         virtual void                            LoadModel();
177         virtual int                                     Memory() const;
178         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
179         virtual int                                     NumJoints( void ) const;
180         virtual const idMD5Joint *      GetJoints( void ) const;
181         virtual jointHandle_t           GetJointHandle( const char *name ) const;
182         virtual const char *            GetJointName( jointHandle_t handle ) const;
183         virtual const idJointQuat *     GetDefaultPose( void ) const;
184         virtual int                                     NearestJoint( int surfaceNum, int a, int b, int c ) const;
185
186 private:
187         idList<idMD5Joint>                      joints;
188         idList<idJointQuat>                     defaultPose;
189         idList<idMD5Mesh>                       meshes;
190
191         void                                            CalculateBounds( const idJointMat *joints );
192         void                                            GetFrameBounds( const renderEntity_t *ent, idBounds &bounds ) const;
193         void                                            DrawJoints( const renderEntity_t *ent, const struct viewDef_s *view ) const;
194         void                                            ParseJoint( idLexer &parser, idMD5Joint *joint, idJointQuat *defaultPose );
195 };
196
197 /*
198 ===============================================================================
199
200         MD3 animated model
201
202 ===============================================================================
203 */
204
205 struct md3Header_s;
206 struct md3Surface_s;
207
208 class idRenderModelMD3 : public idRenderModelStatic {
209 public:
210         virtual void                            InitFromFile( const char *fileName );
211         virtual dynamicModel_t          IsDynamicModel() const;
212         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
213         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
214
215 private:
216         int                                                     index;                  // model = tr.models[model->index]
217         int                                                     dataSize;               // just for listing purposes
218         struct md3Header_s *            md3;                    // only if type == MOD_MESH
219         int                                                     numLods;
220
221         void                                            LerpMeshVertexes( srfTriangles_t *tri, const struct md3Surface_s *surf, const float backlerp, const int frame, const int oldframe ) const;
222 };
223
224 /*
225 ===============================================================================
226
227         Liquid model
228
229 ===============================================================================
230 */
231
232 class idRenderModelLiquid : public idRenderModelStatic {
233 public:
234                                                                 idRenderModelLiquid();
235
236         virtual void                            InitFromFile( const char *fileName );
237         virtual dynamicModel_t          IsDynamicModel() const;
238         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
239         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
240
241         virtual void                            Reset();
242         void                                            IntersectBounds( const idBounds &bounds, float displacement );
243
244 private:
245         modelSurface_t                          GenerateSurface( float lerp );
246         void                                            WaterDrop( int x, int y, float *page );
247         void                                            Update( void );
248                                                 
249         int                                                     verts_x;
250         int                                                     verts_y;
251         float                                           scale_x;
252         float                                           scale_y;
253         int                                                     time;
254         int                                                     liquid_type;
255         int                                                     update_tics;
256         int                                                     seed;
257
258         idRandom                                        random;
259                                                 
260         const idMaterial *                      shader;
261         struct deformInfo_s     *               deformInfo;             // used to create srfTriangles_t from base frames
262                                                                                         // and new vertexes
263                                                 
264         float                                           density;
265         float                                           drop_height;
266         int                                                     drop_radius;
267         float                                           drop_delay;
268
269         idList<float>                           pages;
270         float *                                         page1;
271         float *                                         page2;
272
273         idList<idDrawVert>                      verts;
274
275         int                                                     nextDropTime;
276
277 };
278
279 /*
280 ===============================================================================
281
282         PRT model
283
284 ===============================================================================
285 */
286
287 class idRenderModelPrt : public idRenderModelStatic {
288 public:
289                                                                 idRenderModelPrt();
290
291         virtual void                            InitFromFile( const char *fileName );
292         virtual void                            TouchData();
293         virtual dynamicModel_t          IsDynamicModel() const;
294         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
295         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
296         virtual float                           DepthHack() const;
297         virtual int                                     Memory() const;
298
299 private:
300         const idDeclParticle *          particleSystem;
301 };
302
303 /*
304 ===============================================================================
305
306         Beam model
307
308 ===============================================================================
309 */
310
311 class idRenderModelBeam : public idRenderModelStatic {
312 public:
313         virtual dynamicModel_t          IsDynamicModel() const;
314         virtual bool                            IsLoaded() const;
315         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
316         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
317 };
318
319 /*
320 ===============================================================================
321
322         Beam model
323
324 ===============================================================================
325 */
326 #define MAX_TRAIL_PTS   20
327
328 struct Trail_t {
329         int                                                     lastUpdateTime;
330         int                                                     duration;
331
332         idVec3                                          pts[MAX_TRAIL_PTS];
333         int                                                     numPoints;
334 };
335
336 class idRenderModelTrail : public idRenderModelStatic {
337         idList<Trail_t>                         trails;
338         int                                                     numActive;
339         idBounds                                        trailBounds;
340
341 public:
342                                                                 idRenderModelTrail();
343
344         virtual dynamicModel_t          IsDynamicModel() const;
345         virtual bool                            IsLoaded() const;
346         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
347         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
348
349         int                                                     NewTrail( idVec3 pt, int duration );
350         void                                            UpdateTrail( int index, idVec3 pt );
351         void                                            DrawTrail( int index, const struct renderEntity_s *ent, srfTriangles_t *tri, float globalAlpha );
352 };
353
354 /*
355 ===============================================================================
356
357         Lightning model
358
359 ===============================================================================
360 */
361
362 class idRenderModelLightning : public idRenderModelStatic {
363 public:
364         virtual dynamicModel_t          IsDynamicModel() const;
365         virtual bool                            IsLoaded() const;
366         virtual idRenderModel *         InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
367         virtual idBounds                        Bounds( const struct renderEntity_s *ent ) const;
368 };
369
370 /*
371 ================================================================================
372
373         idRenderModelSprite 
374
375 ================================================================================
376 */
377 class idRenderModelSprite : public idRenderModelStatic {
378 public:
379         virtual dynamicModel_t  IsDynamicModel() const;
380         virtual bool                    IsLoaded() const;
381         virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel );
382         virtual idBounds                Bounds( const struct renderEntity_s *ent ) const;
383 };
384
385 #endif /* !__MODEL_LOCAL_H__ */