OGRE  1.9.0
OgreProgressiveMeshGenerator.h
Go to the documentation of this file.
1/*
2 * -----------------------------------------------------------------------------
3 * This source file is part of OGRE
4 * (Object-oriented Graphics Rendering Engine)
5 * For the latest info, see http://www.ogre3d.org/
6 *
7 * Copyright (c) 2000-2014 Torus Knot Software Ltd
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * -----------------------------------------------------------------------------
27 */
28
29#ifndef __ProgressiveMeshGenerator_H_
30#define __ProgressiveMeshGenerator_H_
31
32#include "OgrePrerequisites.h"
33#include "OgreVector3.h"
34#include "OgreSmallVector.h"
35#include "OgreMesh.h"
36#include "OgreLodConfig.h"
37#include "OgreLogManager.h"
38
39namespace Ogre
40{
41
43{
44public:
50 virtual void generateLodLevels(LodConfig& lodConfig) = 0;
51
58
65 virtual void getAutoconfig(MeshPtr& inMesh, LodConfig& outLodConfig);
66
68};
69
75{
76public:
77
80
82 void generateLodLevels(LodConfig& lodConfig);
83
84protected:
85
86 // VectorSet is basically a helper to use a vector as a small set container.
87 // Also these functions keep the code clean and fast.
88 // You can insert in O(1) time, if you know that it doesn't exists.
89 // You can remove in O(1) time, if you know the position of the item.
90 template<typename T, unsigned S>
92 public SmallVector<T, S> {
94
95 void addNotExists(const T& item); // Complexity: O(1)!!
96 void remove(iterator it); // Complexity: O(1)!!
97 iterator add(const T& item); // Complexity: O(N)
98 void removeExists(const T& item); // Complexity: O(N)
99 bool remove(const T& item); // Complexity: O(N)
100 void replaceExists(const T& oldItem, const T& newItem); // Complexity: O(N)
101 bool has(const T& item); // Complexity: O(N)
102 iterator find(const T& item); // Complexity: O(N)
103 iterator findExists(const T& item); // Complexity: O(N)
104 };
105
106 struct PMEdge;
107 struct PMVertex;
108 struct PMTriangle;
109 struct PMVertexHash;
110 struct PMVertexEqual;
111 struct PMCollapseCostLess;
112 struct PMCollapsedEdge;
113 struct PMIndexBufferInfo;
114
120
123
126
127 // Hash function for UniqueVertexSet.
130
131 PMVertexHash() { assert(0); }
133 size_t operator() (const PMVertex* v) const;
134 };
135
136 // Equality function for UniqueVertexSet.
138 bool operator() (const PMVertex* lhs, const PMVertex* rhs) const;
139 };
140
141 // Directed edge
146
147 explicit PMEdge(PMVertex* destination);
148 bool operator== (const PMEdge& other) const;
149 PMEdge& operator= (const PMEdge& b);
150 PMEdge(const PMEdge& b);
151 bool operator< (const PMEdge& other) const;
152 };
153
163
168 unsigned short submeshID;
169 unsigned int vertexID[3];
170
172 bool hasVertex(const PMVertex* v) const;
173 unsigned int getVertexID(const PMVertex* v) const;
175 };
176
181
183 unsigned short* pshort;
184 unsigned int* pint;
185 };
186
188 unsigned int srcID;
189 unsigned int dstID;
190 unsigned short submeshID;
191 };
192
199 CollapsedEdges tmpCollapsedEdges; // Tmp container used in collapse().
201
203
204#ifndef NDEBUG
211#endif
214
215 size_t calcLodVertexCount(const LodLevel& lodConfig);
217 void addVertexData(VertexData* vertexData, bool useSharedVertexLookup);
218 void addIndexData(IndexData* indexData, bool useSharedVertexLookup, unsigned short submeshID);
219 template<typename IndexType>
220 void addIndexDataImpl(IndexType* iPos, const IndexType* iEnd,
221 VertexLookupList& lookup,
222 unsigned short submeshID)
223 {
224
225 // Loop through all triangles and connect them to the vertices.
226 for (; iPos < iEnd; iPos += 3) {
227 // It should never reallocate or every pointer will be invalid.
228 OgreAssert(mTriangleList.capacity() > mTriangleList.size(), "");
229 mTriangleList.push_back(PMTriangle());
230 PMTriangle* tri = &mTriangleList.back();
231 tri->isRemoved = false;
232 tri->submeshID = submeshID;
233 for (int i = 0; i < 3; i++) {
234 // Invalid index: Index is bigger then vertex buffer size.
235 OgreAssert(iPos[i] < lookup.size(), "");
236 tri->vertexID[i] = iPos[i];
237 tri->vertex[i] = lookup[iPos[i]];
238 }
239 if (tri->isMalformed()) {
240#if OGRE_DEBUG_MODE
241 stringstream str;
242 str << "In " << mMeshName << " malformed triangle found with ID: " << getTriangleID(tri) << ". " <<
243 std::endl;
244 printTriangle(tri, str);
245 str << "It will be excluded from LOD level calculations.";
246 LogManager::getSingleton().stream() << str.str();
247#endif
248 tri->isRemoved = true;
249 mIndexBufferInfoList[tri->submeshID].indexCount -= 3;
250 continue;
251 }
252 tri->computeNormal();
254 }
255 }
256
258 bool isBorderVertex(const PMVertex* vertex) const;
262 virtual void bakeLods();
263 void collapse(PMVertex* vertex);
265 void computeLods(LodConfig& lodConfigs);
267
268 bool hasSrcID(unsigned int srcID, unsigned short submeshID);
269 size_t findDstID(unsigned int srcID, unsigned short submeshID);
270 void replaceVertexID(PMTriangle* triangle, unsigned int oldID, unsigned int newID, PMVertex* dst);
271
272#ifndef NDEBUG
276#endif // ifndef NDEBUG
277
279 void removeTriangleFromEdges(PMTriangle* triangle, PMVertex* skip = NULL);
280 void addEdge(PMVertex* v, const PMEdge& edge);
281 void removeEdge(PMVertex* v, const PMEdge& edge);
282 void printTriangle(PMTriangle* triangle, stringstream& str);
284 bool isDuplicateTriangle(PMTriangle* triangle, PMTriangle* triangle2);
286 int getTriangleID(PMTriangle* triangle);
288};
289
290}
291#endif
#define OgreAssert(a, b)
#define _OgreExport
#define _OgrePrivate
#define HashSet
Summary class collecting together index data source information.
static LogManager & getSingleton(void)
Override standard Singleton retrieval.
virtual void getAutoconfig(MeshPtr &inMesh, LodConfig &outLodConfig)
Fills LOD Config with a config, which works on any mesh.
virtual void generateAutoconfiguredLodLevels(MeshPtr &mesh)
Generates the LOD levels for a mesh without configuring it.
virtual void generateLodLevels(LodConfig &lodConfig)=0
Generates the LOD levels for a mesh.
size_t findDstID(unsigned int srcID, unsigned short submeshID)
void updateVertexCollapseCost(PMVertex *src)
void replaceVertexID(PMTriangle *triangle, unsigned int oldID, unsigned int newID, PMVertex *dst)
int getTriangleID(PMTriangle *triangle)
void assertValidVertex(PMVertex *v)
vector< PMIndexBufferInfo >::type IndexBufferInfoList
void removeTriangleFromEdges(PMTriangle *triangle, PMVertex *skip=NULL)
void assertOutdatedCollapseCost(PMVertex *vertex)
PMTriangle * isDuplicateTriangle(PMTriangle *triangle)
bool isDuplicateTriangle(PMTriangle *triangle, PMTriangle *triangle2)
void removeEdge(PMVertex *v, const PMEdge &edge)
bool isBorderVertex(const PMVertex *vertex) const
void addVertexData(VertexData *vertexData, bool useSharedVertexLookup)
void addTriangleToEdges(PMTriangle *triangle)
bool hasSrcID(unsigned int srcID, unsigned short submeshID)
HashSet< PMVertex *, PMVertexHash, PMVertexEqual > UniqueVertexSet
void addIndexDataImpl(IndexType *iPos, const IndexType *iEnd, VertexLookupList &lookup, unsigned short submeshID)
String mMeshName
The name of the mesh being processed.
void addIndexData(IndexData *indexData, bool useSharedVertexLookup, unsigned short submeshID)
void addEdge(PMVertex *v, const PMEdge &edge)
vector< PMCollapsedEdge >::type CollapsedEdges
Real computeEdgeCollapseCost(PMVertex *src, PMEdge *dstEdge)
size_t calcLodVertexCount(const LodLevel &lodConfig)
multimap< Real, PMVertex * >::type CollapseCostHeap
void collapse(PMVertex *vertex)
PMTriangle * findSideTriangle(const PMVertex *v1, const PMVertex *v2)
void printTriangle(PMTriangle *triangle, stringstream &str)
void computeVertexCollapseCost(PMVertex *vertex)
void generateLodLevels(LodConfig &lodConfig)
Generates the LOD levels for a mesh.
void computeLods(LodConfig &lodConfigs)
PMEdge * getPointer(VEdges::iterator it)
Standard 3-dimensional vector.
Definition OgreVector3.h:52
Summary class collecting together vertex source information.
SharedPtr< Mesh > MeshPtr
StringStream stringstream
float Real
Software floating point type.
_StringBase String
Structure for automatic LOD configuration.
void computeNormal()
Vertex ID in the buffer associated with the submeshID.
unsigned int getVertexID(const PMVertex *v) const
bool hasVertex(const PMVertex *v) const
unsigned int vertexID[3]
ID of the submesh. Usable with mMesh.getSubMesh() function.
PMVertex * collapseTo
Triangle ID set, which are using this vertex.
void replaceExists(const T &oldItem, const T &newItem)
std::multimap< K, V, P, A > type
std::vector< T, A > type