[980] | 1 | /*==========================================================================
|
---|
[774] | 2 | * (C) 2005 Universidad Jaime I de Castellón
|
---|
[980] | 3 | *==========================================================================
|
---|
[774] | 4 | * PROYECT: GAME TOOLS
|
---|
[980] | 5 | *==========================================================================*/
|
---|
| 6 | /* CONTENT:
|
---|
| 7 | *
|
---|
| 8 | *
|
---|
| 9 | * @file GeoLodStripsLibrary.h
|
---|
| 10 | *==========================================================================*/
|
---|
[774] | 11 |
|
---|
[829] | 12 | #ifndef _GEOLODSTRIPSLIBRARY
|
---|
| 13 | #define _GEOLODSTRIPSLIBRARY
|
---|
| 14 |
|
---|
[774] | 15 | #include "GeoMesh.h"
|
---|
| 16 | #include <vector>
|
---|
[1018] | 17 | #include "VertexData.h"
|
---|
[1056] | 18 | #include "GeoLodObject.h"
|
---|
[774] | 19 |
|
---|
| 20 | namespace Geometry
|
---|
| 21 | {
|
---|
| 22 | //typedef unsigned long int SmallInt;
|
---|
| 23 | typedef unsigned long SmallInt;
|
---|
[1009] | 24 | typedef unsigned long ULong;
|
---|
| 25 | typedef long Long;
|
---|
[774] | 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 | {
|
---|
[1526] | 36 | unsigned long strip; // change this to uint32
|
---|
[1560] | 37 | char position;
|
---|
| 38 | char vertexRepetition;
|
---|
| 39 | char edgeRepetition;
|
---|
| 40 | char obligatory;
|
---|
[774] | 41 | } LODRegisterType;
|
---|
| 42 |
|
---|
| 43 | typedef struct
|
---|
| 44 | {
|
---|
[1526] | 45 | float Vertex[3];
|
---|
[1070] | 46 | SmallInt Next;
|
---|
[774] | 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.
|
---|
[1014] | 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.
|
---|
[774] | 61 | \n\n
|
---|
| 62 |
|
---|
| 63 | Inputs:\n
|
---|
| 64 | - The module receives a file describing a multiresolution object.
|
---|
| 65 | .
|
---|
| 66 |
|
---|
| 67 | Outputs:\n
|
---|
[1014] | 68 | - The module returns a strip set that represents the level of
|
---|
| 69 | detail requested.
|
---|
[774] | 70 | .
|
---|
| 71 |
|
---|
| 72 | */
|
---|
[1078] | 73 | class LodStripsLibraryData
|
---|
| 74 | {
|
---|
[1560] | 75 | public:
|
---|
| 76 |
|
---|
| 77 | SmallIntVector mFileVertices;
|
---|
| 78 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
| 79 | LongVector mData;
|
---|
| 80 | std::vector<unsigned int> p_changes;
|
---|
[1078] | 81 | };
|
---|
[1560] | 82 |
|
---|
[1788] | 83 | class GEOLODLIBRARYDLL_API LodStripsLibrary : public Geometry::LodObject
|
---|
[774] | 84 | {
|
---|
| 85 | private:
|
---|
[1014] | 86 |
|
---|
| 87 | // The name of the object.
|
---|
| 88 | String mName;
|
---|
[774] | 89 |
|
---|
[1014] | 90 | // Structures with the data read from the file
|
---|
| 91 | // We won't work with these structures
|
---|
[1560] | 92 | SmallIntVector mFileVertices;
|
---|
[1058] | 93 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
| 94 | std::vector <SmallIntVector> mFileStrips;
|
---|
[1560] | 95 | LongVector mData;
|
---|
[774] | 96 |
|
---|
[1014] | 97 | // Structures with the data to work with
|
---|
[774] | 98 |
|
---|
[1014] | 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 |
|
---|
[774] | 116 | // For the efficient version.
|
---|
[1560] | 117 | SmallInt mTotalFaces;
|
---|
| 118 | SmallInt *mCurrentData;
|
---|
| 119 | SmallInt *mStripsChanges;
|
---|
[774] | 120 | LODRegisterType *mCurrentRegLOD;
|
---|
[1560] | 121 | SmallInt *mVertex;
|
---|
[1058] | 122 |
|
---|
| 123 | SmallInt minFaces, maxFaces;
|
---|
[774] | 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 |
|
---|
[1009] | 134 | // Copa STL vectors to C arrays.
|
---|
[1526] | 135 | void CopyVectors2Arrays(void);
|
---|
[774] | 136 |
|
---|
[1009] | 137 | // Loads Mesh.
|
---|
[1083] | 138 | void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh);
|
---|
[774] | 139 |
|
---|
[1526] | 140 | // Geometry::CREATEINDEXDATAFUNC create_index_data_func;
|
---|
[774] | 141 |
|
---|
| 142 | // Strips vector.
|
---|
| 143 | SmallIntVector *mStrips;
|
---|
[1560] | 144 |
|
---|
| 145 | int *indices_x_submesh;
|
---|
[1083] | 146 | int *offsets_x_submesh;
|
---|
[1018] | 147 |
|
---|
[1560] | 148 | void UpdateDataRetrievalInterface(void);
|
---|
[1018] | 149 |
|
---|
[1090] | 150 | //Number of strips in each submesh
|
---|
[1560] | 151 | int *mStripsSubmesh;
|
---|
| 152 | bool delete_indexdata;
|
---|
| 153 | int *submesh_x_strip;
|
---|
| 154 | Real lodFactor;
|
---|
[1090] | 155 |
|
---|
[1560] | 156 | IndexData *dataRetrievalInterface;
|
---|
| 157 | uint32 current_triangle_count;
|
---|
| 158 |
|
---|
[1018] | 159 | public:
|
---|
| 160 |
|
---|
[1560] | 161 | IndexData *GetIndexDataInterface(void)
|
---|
| 162 | {
|
---|
| 163 | return dataRetrievalInterface;
|
---|
| 164 | }
|
---|
[774] | 165 |
|
---|
[1014] | 166 | /** Constructor, receives as a parameter the name of the file
|
---|
| 167 | * including the multiresolution object.
|
---|
| 168 | */
|
---|
[1560] | 169 | LodStripsLibrary( const LodStripsLibraryData *,
|
---|
| 170 | Mesh *geomesh,
|
---|
| 171 | IndexData *userindexdata = NULL);
|
---|
[774] | 172 |
|
---|
| 173 | /// Destructor.
|
---|
| 174 | ~LodStripsLibrary(void);
|
---|
| 175 |
|
---|
| 176 | /// Returns de current LOD and changes to the specified LOD.
|
---|
[1058] | 177 | virtual void GoToLod(Real);
|
---|
[774] | 178 |
|
---|
| 179 | /// Establishes the new LOD range.
|
---|
| 180 | /// Only the LODs in that range are stored and used.
|
---|
[1018] | 181 | void TrimByLod(uint32, uint32);
|
---|
[774] | 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();
|
---|
[1078] | 194 |
|
---|
[1560] | 195 | uint32 GetValidIndexCount(int submeshid) const
|
---|
| 196 | {
|
---|
| 197 | return indices_x_submesh[submeshid];
|
---|
| 198 | }
|
---|
[1526] | 199 |
|
---|
[1560] | 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 | }
|
---|
[774] | 219 | };
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[980] | 222 | #endif
|
---|
[1009] | 223 |
|
---|