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 | SmallIntVector mFileVertices;
|
---|
77 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
78 | LongVector mData;
|
---|
79 | std::vector<unsigned int> p_changes;
|
---|
80 | };
|
---|
81 | class LodStripsLibrary : public Geometry::LodObject
|
---|
82 | {
|
---|
83 | private:
|
---|
84 |
|
---|
85 | // The name of the object.
|
---|
86 | String mName;
|
---|
87 |
|
---|
88 | // Structures with the data read from the file
|
---|
89 | // We won't work with these structures
|
---|
90 | SmallIntVector mFileVertices;
|
---|
91 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
92 | std::vector <SmallIntVector> mFileStrips;
|
---|
93 | LongVector mData;
|
---|
94 |
|
---|
95 | // Structures with the data to work with
|
---|
96 |
|
---|
97 | // Total strips of the multiresolution object.
|
---|
98 | SmallInt mTotalStrips;
|
---|
99 |
|
---|
100 | // Total vertices of the multiresolution object.
|
---|
101 | SmallInt mTotalVertices;
|
---|
102 |
|
---|
103 | // Number of vertices of the max LOD.
|
---|
104 | SmallInt mMaxVerticesLOD;
|
---|
105 |
|
---|
106 | // Total changes of the multiresolution object.
|
---|
107 | SmallInt mTotalChanges;
|
---|
108 |
|
---|
109 | SmallInt mLods; // Available Lods.
|
---|
110 | SmallInt mMaxLod; // Max level of detail.
|
---|
111 | SmallInt mMinLod; // Min level of detail.
|
---|
112 | SmallInt mCurrentLod; // Current Lod.
|
---|
113 |
|
---|
114 | // For the efficient version.
|
---|
115 | SmallInt mTotalFaces;
|
---|
116 | SmallInt *mCurrentData;
|
---|
117 | SmallInt *mStripsChanges;
|
---|
118 | LODRegisterType *mCurrentRegLOD;
|
---|
119 | SmallInt *mVertex;
|
---|
120 |
|
---|
121 | SmallInt minFaces, maxFaces;
|
---|
122 |
|
---|
123 | // Changes of Strips in LOD file (p).
|
---|
124 | SmallInt *mPChanges;
|
---|
125 |
|
---|
126 | ///Total of vertices shown at the moment.
|
---|
127 | long int mTotal;
|
---|
128 |
|
---|
129 | // Global mesh object.
|
---|
130 | Mesh *mGeoMesh;
|
---|
131 |
|
---|
132 | // Copa STL vectors to C arrays.
|
---|
133 | void CopyVectors2Arrays(void);
|
---|
134 |
|
---|
135 | // Loads Mesh.
|
---|
136 | void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh);
|
---|
137 |
|
---|
138 | // Geometry::CREATEINDEXDATAFUNC create_index_data_func;
|
---|
139 |
|
---|
140 | // Strips vector.
|
---|
141 | SmallIntVector *mStrips;
|
---|
142 | int *indices_x_submesh;
|
---|
143 | int *offsets_x_submesh;
|
---|
144 |
|
---|
145 | void UpdateDataRetrievalInterface(void);
|
---|
146 |
|
---|
147 | //Number of strips in each submesh
|
---|
148 | int* mStripsSubmesh;
|
---|
149 | bool delete_indexdata;
|
---|
150 | int *submesh_x_strip;
|
---|
151 | Real lodFactor;
|
---|
152 | IndexData *dataRetrievalInterface;
|
---|
153 | uint32 current_triangle_count;
|
---|
154 |
|
---|
155 | public:
|
---|
156 |
|
---|
157 | IndexData *GetIndexDataInterface(void){ return dataRetrievalInterface; }
|
---|
158 |
|
---|
159 | /** Constructor, receives as a parameter the name of the file
|
---|
160 | * including the multiresolution object.
|
---|
161 | */
|
---|
162 | LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, IndexData * userindexdata = NULL);
|
---|
163 |
|
---|
164 | /// Destructor.
|
---|
165 | ~LodStripsLibrary(void);
|
---|
166 |
|
---|
167 | /// Returns de current LOD and changes to the specified LOD.
|
---|
168 | virtual void GoToLod(Real);
|
---|
169 |
|
---|
170 | /// Establishes the new LOD range.
|
---|
171 | /// Only the LODs in that range are stored and used.
|
---|
172 | void TrimByLod(uint32, uint32);
|
---|
173 |
|
---|
174 | /// Returns the number of triangles of the highest LOD.
|
---|
175 | uint32 MaxFaces();
|
---|
176 |
|
---|
177 | /// Returns the number of triangles of the lowest LOD.
|
---|
178 | uint32 MinFaces();
|
---|
179 |
|
---|
180 | /// Returns the number of vertices of the highest LOD.
|
---|
181 | uint32 MaxVertices();
|
---|
182 |
|
---|
183 | /// Returns the number of vertices of the lowest LOD.
|
---|
184 | uint32 MinVertices();
|
---|
185 |
|
---|
186 | uint32 GetValidIndexCount(int submeshid) const { return indices_x_submesh[submeshid]; }
|
---|
187 | uint32 GetValidOffset(int submeshid) const { return offsets_x_submesh[submeshid]; }
|
---|
188 | uint32 GetTotalStripCount(void) const { return mTotalStrips; }
|
---|
189 | uint32 GetSubMeshtripCount(int submeshid) const { return mStripsSubmesh[submeshid]; }
|
---|
190 | uint32 GetCurrentTriangleCount(void) const { return current_triangle_count; }
|
---|
191 |
|
---|
192 | virtual Real GetCurrentLodFactor(void) const { return lodFactor; }
|
---|
193 | };
|
---|
194 | }
|
---|
195 |
|
---|
196 | #endif
|
---|
197 |
|
---|