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-2013 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
38namespace Ogre
39{
40
42{
43public:
49 virtual void generateLodLevels(LodConfig& lodConfig) = 0;
50
57
64 virtual void getAutoconfig(MeshPtr& inMesh, LodConfig& outLodConfig);
65
67};
68
74{
75public:
76
79
81 void generateLodLevels(LodConfig& lodConfig);
82
83protected:
84
85 // VectorSet is basically a helper to use a vector as a small set container.
86 // Also these functions keep the code clean and fast.
87 // You can insert in O(1) time, if you know that it doesn't exists.
88 // You can remove in O(1) time, if you know the position of the item.
89 template<typename T, unsigned S>
91 public SmallVector<T, S> {
93
94 void addNotExists(const T& item); // Complexity: O(1)!!
95 void remove(iterator it); // Complexity: O(1)!!
96 iterator add(const T& item); // Complexity: O(N)
97 void removeExists(const T& item); // Complexity: O(N)
98 bool remove(const T& item); // Complexity: O(N)
99 void replaceExists(const T& oldItem, const T& newItem); // Complexity: O(N)
100 bool has(const T& item); // Complexity: O(N)
101 iterator find(const T& item); // Complexity: O(N)
102 iterator findExists(const T& item); // Complexity: O(N)
103 };
104
105 struct PMEdge;
106 struct PMVertex;
107 struct PMTriangle;
108 struct PMVertexHash;
109 struct PMVertexEqual;
110 struct PMCollapseCostLess;
111 struct PMCollapsedEdge;
112 struct PMIndexBufferInfo;
113
116 typedef HashSet<PMVertex*, PMVertexHash, PMVertexEqual> UniqueVertexSet;
119
122
125
126 // Hash function for UniqueVertexSet.
129
130 PMVertexHash() { assert(0); }
132 size_t operator() (const PMVertex* v) const;
133 };
134
135 // Equality function for UniqueVertexSet.
137 bool operator() (const PMVertex* lhs, const PMVertex* rhs) const;
138 };
139
140 // Directed edge
145
146 explicit PMEdge(PMVertex* destination);
147 bool operator== (const PMEdge& other) const;
148 PMEdge& operator= (const PMEdge& b);
149 PMEdge(const PMEdge& b);
150 bool operator< (const PMEdge& other) const;
151 };
152
157
159 bool seam;
160 CollapseCostHeap::iterator costHeapPosition;
161 };
162
164 PMVertex* vertex[3];
167 unsigned short submeshID;
168 unsigned int vertexID[3];
169
171 bool hasVertex(const PMVertex* v) const;
172 unsigned int getVertexID(const PMVertex* v) const;
174 };
175
177 size_t indexSize;
179 };
180
182 unsigned short* pshort;
183 unsigned int* pint;
184 };
185
187 unsigned int srcID;
188 unsigned int dstID;
189 unsigned short submeshID;
190 };
191
198 CollapsedEdges tmpCollapsedEdges; // Tmp container used in collapse().
200
202
203#ifndef NDEBUG
210#endif
213
214 size_t calcLodVertexCount(const LodLevel& lodConfig);
216 void addVertexData(VertexData* vertexData, bool useSharedVertexLookup);
217 template<typename IndexType>
218 void addIndexDataImpl(IndexType* iPos, const IndexType* iEnd, VertexLookupList& lookup, unsigned short submeshID);
219 void addIndexData(IndexData* indexData, bool useSharedVertexLookup, unsigned short submeshID);
220
222 bool isBorderVertex(const PMVertex* vertex) const;
226 virtual void bakeLods();
227 void collapse(PMVertex* vertex);
229 void computeLods(LodConfig& lodConfigs);
231
232 bool hasSrcID(unsigned int srcID, unsigned short submeshID);
233 size_t findDstID(unsigned int srcID, unsigned short submeshID);
234 void replaceVertexID(PMTriangle* triangle, unsigned int oldID, unsigned int newID, PMVertex* dst);
235
236#ifndef NDEBUG
240#endif // ifndef NDEBUG
241
243 void removeTriangleFromEdges(PMTriangle* triangle, PMVertex* skip = NULL);
244 void addEdge(PMVertex* v, const PMEdge& edge);
245 void removeEdge(PMVertex* v, const PMEdge& edge);
246 void printTriangle(PMTriangle* triangle, stringstream& str);
248 bool isDuplicateTriangle(PMTriangle* triangle, PMTriangle* triangle2);
250 int getTriangleID(PMTriangle* triangle);
252};
253
254}
255#endif
#define _OgreExport
Definition: OgrePlatform.h:257
#define _OgrePrivate
Definition: OgrePlatform.h:258
Summary class collecting together index data source information.
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.
Improved version of ProgressiveMesh.
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
VectorSet< PMTriangle *, 7 > VTriangles
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.
vector< PMVertex * >::type VertexLookupList
void computeLods(LodConfig &lodConfigs)
PMEdge * getPointer(VEdges::iterator it)
SmallVector - This is a 'vector' (really, a variable-sized array), optimized for the case when the ar...
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
Summary class collecting together vertex source information.
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
StringStream stringstream
float Real
Software floating point type.
_StringBase String
Structure for automatic LOD configuration.
Definition: OgreLodConfig.h:41
void computeNormal()
Vertex ID in the buffer associated with the submeshID.
unsigned int getVertexID(const PMVertex *v) const
bool hasVertex(const PMVertex *v) const
PMVertex * collapseTo
Triangle ID set, which are using this vertex.
void replaceExists(const T &oldItem, const T &newItem)

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.