00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2011 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 // The underlying algorithms in this class are based heavily on: 00029 /* 00030 * Progressive Mesh type Polygon Reduction Algorithm 00031 * by Stan Melax (c) 1998 00032 */ 00033 00034 #ifndef __ProgressiveMesh_H_ 00035 #define __ProgressiveMesh_H_ 00036 00037 #include "OgrePrerequisites.h" 00038 #include "OgreVector3.h" 00039 #include "OgreHardwareVertexBuffer.h" 00040 #include "OgreHardwareIndexBuffer.h" 00041 #include "OgreRenderOperation.h" 00042 00043 namespace Ogre { 00044 00064 class _OgreExport ProgressiveMesh : public ProgMeshAlloc 00065 { 00066 public: 00067 00069 enum VertexReductionQuota 00070 { 00072 VRQ_CONSTANT, 00074 VRQ_PROPORTIONAL 00075 }; 00076 00077 typedef vector<IndexData*>::type LODFaceList; 00078 00086 ProgressiveMesh(const VertexData* vertexData, const IndexData* indexData); 00087 virtual ~ProgressiveMesh(); 00088 00104 virtual void addExtraVertexPositionBuffer(const VertexData* vertexData); 00105 00114 virtual void build(ushort numLevels, LODFaceList* outList, 00115 VertexReductionQuota quota = VRQ_PROPORTIONAL, Real reductionValue = 0.5f ); 00116 00117 protected: 00118 const VertexData *mpVertexData; 00119 const IndexData *mpIndexData; 00120 00121 size_t mCurrNumIndexes; 00122 size_t mNumCommonVertices; 00123 00124 // Internal classes 00125 class PMTriangle; 00126 class PMVertex; 00127 00128 public: // VC6 hack 00129 00132 class _OgrePrivate PMFaceVertex { 00133 public: 00134 size_t realIndex; 00135 PMVertex* commonVertex; 00136 }; 00137 00138 protected: 00139 00141 class _OgrePrivate PMTriangle { 00142 public: 00143 PMTriangle(); 00144 void setDetails(size_t index, PMFaceVertex *v0, PMFaceVertex *v1, PMFaceVertex *v2); 00145 void computeNormal(void); 00146 void replaceVertex(PMFaceVertex *vold, PMFaceVertex *vnew); 00147 bool hasCommonVertex(PMVertex *v) const; 00148 bool hasFaceVertex(PMFaceVertex *v) const; 00149 PMFaceVertex* getFaceVertexFromCommon(PMVertex* commonVert); 00150 void notifyRemoved(void); 00151 00152 PMFaceVertex* vertex[3]; // the 3 points that make this tri 00153 Vector3 normal; // unit vector orthogonal to this face 00154 bool removed; // true if this tri is now removed 00155 size_t index; 00156 }; 00157 00164 class _OgrePrivate PMVertex { 00165 public: 00166 PMVertex(); 00167 void setDetails(const Vector3& v, size_t index); 00168 void removeIfNonNeighbor(PMVertex *n); 00169 bool isBorder(void); 00170 bool isManifoldEdgeWith(PMVertex* v); // is edge this->src a manifold edge? 00171 void notifyRemoved(void); 00172 00173 Vector3 position; // location of point in euclidean space 00174 size_t index; // place of vertex in original list 00175 typedef set<PMVertex *>::type NeighborList; 00176 typedef set<PMVertex *>::type DuplicateList; 00177 NeighborList neighbor; // adjacent vertices 00178 typedef set<PMTriangle *>::type FaceList; 00179 FaceList face; // adjacent triangles 00180 00181 Real collapseCost; // cached cost of collapsing edge 00182 PMVertex * collapseTo; // candidate vertex for collapse 00183 bool removed; // true if this vert is now removed 00184 bool toBeRemoved; // denug 00185 00186 bool seam; 00187 00188 }; 00189 00190 typedef vector<PMTriangle>::type TriangleList; 00191 typedef vector<PMFaceVertex>::type FaceVertexList; 00192 typedef vector<PMVertex>::type CommonVertexList; 00193 typedef vector<Real>::type WorstCostList; 00194 00196 struct PMWorkingData 00197 { 00198 TriangleList mTriList; 00199 FaceVertexList mFaceVertList; // The vertex details referenced by the triangles 00200 CommonVertexList mVertList; // The master list of common vertices 00201 }; 00202 00203 typedef vector<PMWorkingData>::type WorkingDataList; 00205 WorkingDataList mWorkingData; 00206 00208 WorstCostList mWorstCosts; 00209 00211 void addWorkingData(const VertexData* vertexData, const IndexData* indexData); 00212 00214 void initialiseEdgeCollapseCosts(void); 00216 Real computeEdgeCollapseCost(PMVertex *src, PMVertex *dest); 00218 Real computeEdgeCostAtVertexForBuffer(WorkingDataList::iterator idata, size_t vertIndex); 00220 void computeEdgeCostAtVertex(size_t vertIndex); 00222 void computeAllCosts(void); 00224 size_t getNextCollapser(void); 00226 void bakeNewLOD(IndexData* pData); 00227 00234 void collapse(PMVertex *collapser); 00235 00237 void dumpContents(const String& log); 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 }; 00248 00249 00253 } 00254 00255 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:43