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;
|
---|
37 | char position;
|
---|
38 | char vertexRepetition;
|
---|
39 | char edgeRepetition;
|
---|
40 | } LODRegisterType;
|
---|
41 |
|
---|
42 | typedef struct
|
---|
43 | {
|
---|
44 | float Vertex[3];
|
---|
45 | SmallInt Next;
|
---|
46 | } VertexType;
|
---|
47 |
|
---|
48 | typedef std::vector <SmallInt> SmallIntVector;
|
---|
49 | typedef std::vector <LODRegisterType> LODRegisterVector;
|
---|
50 | typedef std::vector <Long> LongVector;
|
---|
51 |
|
---|
52 | /// LodStripsLibrary interface class.
|
---|
53 | /** This module contains functions that handle the levels of detail
|
---|
54 | * of the input multiresolution objects made of polygonal meshes.
|
---|
55 | * For any given resolution and object, this module returns a set
|
---|
56 | * of triangle strips representing the object at that resolution,
|
---|
57 | * that is, at the level of detail requested. These models use
|
---|
58 | * triangle strips to reduce storage usage and to speed up realistic
|
---|
59 | * rendering.
|
---|
60 | \n\n
|
---|
61 |
|
---|
62 | Inputs:\n
|
---|
63 | - The module receives a file describing a multiresolution object.
|
---|
64 | .
|
---|
65 |
|
---|
66 | Outputs:\n
|
---|
67 | - The module returns a strip set that represents the level of
|
---|
68 | detail requested.
|
---|
69 | .
|
---|
70 |
|
---|
71 | */
|
---|
72 | class LodStripsLibraryData
|
---|
73 | {
|
---|
74 | public:
|
---|
75 | SmallIntVector mFileVertices;
|
---|
76 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
77 | LongVector mData;
|
---|
78 | std::vector<unsigned int> p_changes;
|
---|
79 | };
|
---|
80 | class LodStripsLibrary : public Geometry::LodObject
|
---|
81 | {
|
---|
82 | private:
|
---|
83 |
|
---|
84 | // The name of the object.
|
---|
85 | String mName;
|
---|
86 |
|
---|
87 | // Structures with the data read from the file
|
---|
88 | // We won't work with these structures
|
---|
89 | SmallIntVector mFileVertices;
|
---|
90 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
91 | std::vector <SmallIntVector> mFileStrips;
|
---|
92 | LongVector mData;
|
---|
93 |
|
---|
94 | // Structures with the data to work with
|
---|
95 |
|
---|
96 | // Total strips of the multiresolution object.
|
---|
97 | SmallInt mTotalStrips;
|
---|
98 |
|
---|
99 | // Total vertices of the multiresolution object.
|
---|
100 | SmallInt mTotalVertices;
|
---|
101 |
|
---|
102 | // Number of vertices of the max LOD.
|
---|
103 | SmallInt mMaxVerticesLOD;
|
---|
104 |
|
---|
105 | // Total changes of the multiresolution object.
|
---|
106 | SmallInt mTotalChanges;
|
---|
107 |
|
---|
108 | SmallInt mLods; // Available Lods.
|
---|
109 | SmallInt mMaxLod; // Max level of detail.
|
---|
110 | SmallInt mMinLod; // Min level of detail.
|
---|
111 | SmallInt mCurrentLod; // Current Lod.
|
---|
112 |
|
---|
113 | // For the efficient version.
|
---|
114 | SmallInt mTotalFaces;
|
---|
115 | SmallInt *mCurrentData;
|
---|
116 | SmallInt *mStripsChanges;
|
---|
117 | LODRegisterType *mCurrentRegLOD;
|
---|
118 | SmallInt *mVertex;
|
---|
119 |
|
---|
120 | SmallInt minFaces, maxFaces;
|
---|
121 |
|
---|
122 | // Changes of Strips in LOD file (p).
|
---|
123 | SmallInt *mPChanges;
|
---|
124 |
|
---|
125 | ///Total of vertices shown at the moment.
|
---|
126 | long int mTotal;
|
---|
127 |
|
---|
128 | // Global mesh object.
|
---|
129 | Mesh *mGeoMesh;
|
---|
130 |
|
---|
131 | // Copa STL vectors to C arrays.
|
---|
132 | void CopyVectors2Arrays();
|
---|
133 |
|
---|
134 | // Loads Mesh.
|
---|
135 | void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh);
|
---|
136 |
|
---|
137 | Geometry::CREATEINDEXDATAFUNC create_index_data_func;
|
---|
138 |
|
---|
139 | // Strips vector.
|
---|
140 | SmallIntVector *mStrips;
|
---|
141 | int *indices_x_submesh;
|
---|
142 | int *offsets_x_submesh;
|
---|
143 |
|
---|
144 | void UpdateDataRetrievalInterface(void);
|
---|
145 |
|
---|
146 | //Number of strips in each submesh
|
---|
147 | int* mStripsSubmesh;
|
---|
148 |
|
---|
149 | public:
|
---|
150 |
|
---|
151 | IndexData *dataRetrievalInterface;
|
---|
152 |
|
---|
153 | /** Constructor, receives as a parameter the name of the file
|
---|
154 | * including the multiresolution object.
|
---|
155 | */
|
---|
156 | LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL);
|
---|
157 |
|
---|
158 | /// Destructor.
|
---|
159 | ~LodStripsLibrary(void);
|
---|
160 |
|
---|
161 | /// Returns de current LOD and changes to the specified LOD.
|
---|
162 | virtual void GoToLod(Real);
|
---|
163 |
|
---|
164 | /// Establishes the new LOD range.
|
---|
165 | /// Only the LODs in that range are stored and used.
|
---|
166 | void TrimByLod(uint32, uint32);
|
---|
167 |
|
---|
168 | /// Returns the number of triangles of the highest LOD.
|
---|
169 | uint32 MaxFaces();
|
---|
170 |
|
---|
171 | /// Returns the number of triangles of the lowest LOD.
|
---|
172 | uint32 MinFaces();
|
---|
173 |
|
---|
174 | /// Returns the number of vertices of the highest LOD.
|
---|
175 | uint32 MaxVertices();
|
---|
176 |
|
---|
177 | /// Returns the number of vertices of the lowest LOD.
|
---|
178 | uint32 MinVertices();
|
---|
179 |
|
---|
180 | uint32 GetValidIndexCount(int submeshid) const { return indices_x_submesh[submeshid]; }
|
---|
181 | uint32 GetValidOffset(int submeshid) const { return offsets_x_submesh[submeshid]; }
|
---|
182 | uint32 GetTotalStripCount(void) const { return mTotalStrips; }
|
---|
183 | uint32 GetSubMeshtripCount(int submeshid) const { return mStripsSubmesh[submeshid]; }
|
---|
184 | };
|
---|
185 | }
|
---|
186 |
|
---|
187 | #endif
|
---|
188 |
|
---|