[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 | {
|
---|
| 36 | unsigned long strip;
|
---|
| 37 | char position;
|
---|
| 38 | char vertexRepetition;
|
---|
| 39 | char edgeRepetition;
|
---|
| 40 | } LODRegisterType;
|
---|
| 41 |
|
---|
| 42 | typedef struct
|
---|
| 43 | {
|
---|
[1070] | 44 | float Vertex[3];
|
---|
| 45 | SmallInt Next;
|
---|
[774] | 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.
|
---|
[1014] | 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.
|
---|
[774] | 60 | \n\n
|
---|
| 61 |
|
---|
| 62 | Inputs:\n
|
---|
| 63 | - The module receives a file describing a multiresolution object.
|
---|
| 64 | .
|
---|
| 65 |
|
---|
| 66 | Outputs:\n
|
---|
[1014] | 67 | - The module returns a strip set that represents the level of
|
---|
| 68 | detail requested.
|
---|
[774] | 69 | .
|
---|
| 70 |
|
---|
| 71 | */
|
---|
[1078] | 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 | };
|
---|
[1056] | 80 | class LodStripsLibrary : public Geometry::LodObject
|
---|
[774] | 81 | {
|
---|
| 82 | private:
|
---|
[1014] | 83 |
|
---|
| 84 | // The name of the object.
|
---|
| 85 | String mName;
|
---|
[774] | 86 |
|
---|
[1014] | 87 | // Structures with the data read from the file
|
---|
| 88 | // We won't work with these structures
|
---|
[1058] | 89 | SmallIntVector mFileVertices;
|
---|
| 90 | std::vector <LODRegisterType> mFileChangesLOD;
|
---|
| 91 | std::vector <SmallIntVector> mFileStrips;
|
---|
| 92 | LongVector mData;
|
---|
[774] | 93 |
|
---|
[1014] | 94 | // Structures with the data to work with
|
---|
[774] | 95 |
|
---|
[1014] | 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 |
|
---|
[774] | 113 | // For the efficient version.
|
---|
[1058] | 114 | SmallInt mTotalFaces;
|
---|
| 115 | SmallInt *mCurrentData;
|
---|
| 116 | SmallInt *mStripsChanges;
|
---|
[774] | 117 | LODRegisterType *mCurrentRegLOD;
|
---|
[1058] | 118 | SmallInt *mVertex;
|
---|
| 119 |
|
---|
| 120 | SmallInt minFaces, maxFaces;
|
---|
[774] | 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 |
|
---|
[1009] | 131 | // Copa STL vectors to C arrays.
|
---|
[774] | 132 | void CopyVectors2Arrays();
|
---|
| 133 |
|
---|
[1009] | 134 | // Loads Mesh.
|
---|
[1083] | 135 | void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh);
|
---|
[774] | 136 |
|
---|
[1069] | 137 | Geometry::CREATEINDEXDATAFUNC create_index_data_func;
|
---|
[774] | 138 |
|
---|
| 139 | // Strips vector.
|
---|
| 140 | SmallIntVector *mStrips;
|
---|
[1083] | 141 | int *indices_x_submesh;
|
---|
| 142 | int *offsets_x_submesh;
|
---|
[1018] | 143 |
|
---|
[1078] | 144 | void UpdateDataRetrievalInterface(void);
|
---|
[1018] | 145 |
|
---|
[1090] | 146 | //Number of strips in each submesh
|
---|
| 147 | int* mStripsSubmesh;
|
---|
| 148 |
|
---|
[1018] | 149 | public:
|
---|
| 150 |
|
---|
[1069] | 151 | IndexData *dataRetrievalInterface;
|
---|
[774] | 152 |
|
---|
[1014] | 153 | /** Constructor, receives as a parameter the name of the file
|
---|
| 154 | * including the multiresolution object.
|
---|
| 155 | */
|
---|
[1083] | 156 | LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL);
|
---|
[774] | 157 |
|
---|
| 158 | /// Destructor.
|
---|
| 159 | ~LodStripsLibrary(void);
|
---|
| 160 |
|
---|
| 161 | /// Returns de current LOD and changes to the specified LOD.
|
---|
[1058] | 162 | virtual void GoToLod(Real);
|
---|
[774] | 163 |
|
---|
| 164 | /// Establishes the new LOD range.
|
---|
| 165 | /// Only the LODs in that range are stored and used.
|
---|
[1018] | 166 | void TrimByLod(uint32, uint32);
|
---|
[774] | 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();
|
---|
[1078] | 179 |
|
---|
[1083] | 180 | uint32 GetValidIndexCount(int submeshid) const { return indices_x_submesh[submeshid]; }
|
---|
| 181 | uint32 GetValidOffset(int submeshid) const { return offsets_x_submesh[submeshid]; }
|
---|
[1090] | 182 | uint32 GetTotalStripCount(void) const { return mTotalStrips; }
|
---|
| 183 | uint32 GetSubMeshtripCount(int submeshid) const { return mStripsSubmesh[submeshid]; }
|
---|
[774] | 184 | };
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[980] | 187 | #endif
|
---|
[1009] | 188 |
|
---|