1 | /*==========================================================================
|
---|
2 | * (C) 2005 Universidad Jaime I de Castellón
|
---|
3 | *==========================================================================
|
---|
4 | * PROYECT: GAME TOOLS
|
---|
5 | *==========================================================================*/
|
---|
6 | /* CONTENT:
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * @file GeoLodStripsLibrary.h
|
---|
10 | *==========================================================================*/
|
---|
11 |
|
---|
12 | #ifndef _GEOLODSTRIPSLIBRARY
|
---|
13 | #define _GEOLODSTRIPSLIBRARY
|
---|
14 |
|
---|
15 | #include "GeoMesh.h"
|
---|
16 | #include <vector>
|
---|
17 | #include "VertexData.h"
|
---|
18 | #include "GeoLodObject.h"
|
---|
19 |
|
---|
20 | namespace Geometry
|
---|
21 | {
|
---|
22 | //typedef unsigned long int SmallInt;
|
---|
23 | typedef unsigned long SmallInt;
|
---|
24 | typedef unsigned long ULong;
|
---|
25 | typedef long Long;
|
---|
26 |
|
---|
27 | typedef struct
|
---|
28 | {
|
---|
29 | SmallInt strip;
|
---|
30 | SmallInt position;
|
---|
31 | SmallInt rep; //For the vertex repetition
|
---|
32 | } PositionType;
|
---|
33 |
|
---|
34 | typedef struct
|
---|
35 | {
|
---|
36 | unsigned long strip; // change this to uint32
|
---|
37 | char position;
|
---|
38 | char vertexRepetition;
|
---|
39 | char edgeRepetition;
|
---|
40 | char obligatory;
|
---|
41 | } LODRegisterType;
|
---|
42 |
|
---|
43 | typedef struct
|
---|
44 | {
|
---|
45 | float Vertex[3];
|
---|
46 | SmallInt Next;
|
---|
47 | } VertexType;
|
---|
48 |
|
---|
49 | typedef std::vector <SmallInt> SmallIntVector;
|
---|
50 | typedef std::vector <LODRegisterType> LODRegisterVector;
|
---|
51 | typedef std::vector <Long> LongVector;
|
---|
52 |
|
---|
53 | /// LodStripsLibrary interface class.
|
---|
54 | /** This module contains functions that handle the levels of detail
|
---|
55 | * of the input multiresolution objects made of polygonal meshes.
|
---|
56 | * For any given resolution and object, this module returns a set
|
---|
57 | * of triangle strips representing the object at that resolution,
|
---|
58 | * that is, at the level of detail requested. These models use
|
---|
59 | * triangle strips to reduce storage usage and to speed up realistic
|
---|
60 | * rendering.
|
---|
61 | \n\n
|
---|
62 |
|
---|
63 | Inputs:\n
|
---|
64 | - The module receives a file describing a multiresolution object.
|
---|
65 | .
|
---|
66 |
|
---|
67 | Outputs:\n
|
---|
68 | - The module returns a strip set that represents the level of
|
---|
69 | detail requested.
|
---|
70 | .
|
---|
71 |
|
---|
72 | */
|
---|
73 | class LodStripsLibraryData
|
---|
74 | {
|
---|
75 | public:
|
---|
76 |
|
---|
77 | SmallIntVector mFileVertices;
|
---|
78 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
79 | LongVector mData;
|
---|
80 | std::vector<unsigned int> p_changes;
|
---|
81 | };
|
---|
82 |
|
---|
83 | class GEOLODLIBRARYDLL_API LodStripsLibrary : public Geometry::LodObject
|
---|
84 | {
|
---|
85 | private:
|
---|
86 |
|
---|
87 | // The name of the object.
|
---|
88 | String mName;
|
---|
89 |
|
---|
90 | // Structures with the data read from the file
|
---|
91 | // We won't work with these structures
|
---|
92 | SmallIntVector mFileVertices;
|
---|
93 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
94 | std::vector <SmallIntVector> mFileStrips;
|
---|
95 | LongVector mData;
|
---|
96 |
|
---|
97 | // Structures with the data to work with
|
---|
98 |
|
---|
99 | // Total strips of the multiresolution object.
|
---|
100 | SmallInt mTotalStrips;
|
---|
101 |
|
---|
102 | // Total vertices of the multiresolution object.
|
---|
103 | SmallInt mTotalVertices;
|
---|
104 |
|
---|
105 | // Number of vertices of the max LOD.
|
---|
106 | SmallInt mMaxVerticesLOD;
|
---|
107 |
|
---|
108 | // Total changes of the multiresolution object.
|
---|
109 | SmallInt mTotalChanges;
|
---|
110 |
|
---|
111 | SmallInt mLods; // Available Lods.
|
---|
112 | SmallInt mMaxLod; // Max level of detail.
|
---|
113 | SmallInt mMinLod; // Min level of detail.
|
---|
114 | SmallInt mCurrentLod; // Current Lod.
|
---|
115 |
|
---|
116 | // For the efficient version.
|
---|
117 | SmallInt mTotalFaces;
|
---|
118 | SmallInt *mCurrentData;
|
---|
119 | SmallInt *mStripsChanges;
|
---|
120 | LODRegisterType *mCurrentRegLOD;
|
---|
121 | SmallInt *mVertex;
|
---|
122 |
|
---|
123 | SmallInt minFaces, maxFaces;
|
---|
124 |
|
---|
125 | // Changes of Strips in LOD file (p).
|
---|
126 | SmallInt *mPChanges;
|
---|
127 |
|
---|
128 | ///Total of vertices shown at the moment.
|
---|
129 | long int mTotal;
|
---|
130 |
|
---|
131 | // Global mesh object.
|
---|
132 | Mesh *mGeoMesh;
|
---|
133 |
|
---|
134 | // Copa STL vectors to C arrays.
|
---|
135 | void CopyVectors2Arrays(void);
|
---|
136 |
|
---|
137 | // Loads Mesh.
|
---|
138 | void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh);
|
---|
139 |
|
---|
140 | // Geometry::CREATEINDEXDATAFUNC create_index_data_func;
|
---|
141 |
|
---|
142 | // Strips vector.
|
---|
143 | SmallIntVector *mStrips;
|
---|
144 |
|
---|
145 | int *indices_x_submesh;
|
---|
146 | int *offsets_x_submesh;
|
---|
147 |
|
---|
148 | void UpdateDataRetrievalInterface(void);
|
---|
149 |
|
---|
150 | //Number of strips in each submesh
|
---|
151 | int *mStripsSubmesh;
|
---|
152 | bool delete_indexdata;
|
---|
153 | int *submesh_x_strip;
|
---|
154 | Real lodFactor;
|
---|
155 |
|
---|
156 | IndexData *dataRetrievalInterface;
|
---|
157 | uint32 current_triangle_count;
|
---|
158 |
|
---|
159 | public:
|
---|
160 |
|
---|
161 | IndexData *GetIndexDataInterface(void)
|
---|
162 | {
|
---|
163 | return dataRetrievalInterface;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /** Constructor, receives as a parameter the name of the file
|
---|
167 | * including the multiresolution object.
|
---|
168 | */
|
---|
169 | LodStripsLibrary( const LodStripsLibraryData *,
|
---|
170 | Mesh *geomesh,
|
---|
171 | IndexData *userindexdata = NULL);
|
---|
172 |
|
---|
173 | /// Destructor.
|
---|
174 | ~LodStripsLibrary(void);
|
---|
175 |
|
---|
176 | /// Returns de current LOD and changes to the specified LOD.
|
---|
177 | virtual void GoToLod(Real);
|
---|
178 |
|
---|
179 | /// Establishes the new LOD range.
|
---|
180 | /// Only the LODs in that range are stored and used.
|
---|
181 | void TrimByLod(uint32, uint32);
|
---|
182 |
|
---|
183 | /// Returns the number of triangles of the highest LOD.
|
---|
184 | uint32 MaxFaces();
|
---|
185 |
|
---|
186 | /// Returns the number of triangles of the lowest LOD.
|
---|
187 | uint32 MinFaces();
|
---|
188 |
|
---|
189 | /// Returns the number of vertices of the highest LOD.
|
---|
190 | uint32 MaxVertices();
|
---|
191 |
|
---|
192 | /// Returns the number of vertices of the lowest LOD.
|
---|
193 | uint32 MinVertices();
|
---|
194 |
|
---|
195 | uint32 GetValidIndexCount(int submeshid) const
|
---|
196 | {
|
---|
197 | return indices_x_submesh[submeshid];
|
---|
198 | }
|
---|
199 |
|
---|
200 | uint32 GetTotalStripCount(void) const
|
---|
201 | {
|
---|
202 | return mTotalStrips;
|
---|
203 | }
|
---|
204 |
|
---|
205 | uint32 GetSubMeshtripCount(int submeshid) const
|
---|
206 | {
|
---|
207 | return mStripsSubmesh[submeshid];
|
---|
208 | }
|
---|
209 |
|
---|
210 | uint32 GetCurrentTriangleCount(void) const
|
---|
211 | {
|
---|
212 | return current_triangle_count;
|
---|
213 | }
|
---|
214 |
|
---|
215 | virtual Real GetCurrentLodFactor(void) const
|
---|
216 | {
|
---|
217 | return lodFactor;
|
---|
218 | }
|
---|
219 | };
|
---|
220 | }
|
---|
221 |
|
---|
222 | #endif
|
---|
223 |
|
---|