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-2005 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 // The underlying algorithms in this class are based heavily on: 00026 /* 00027 * Progressive Mesh type Polygon Reduction Algorithm 00028 * by Stan Melax (c) 1998 00029 */ 00030 00031 #ifndef __ProgressiveMesh_H_ 00032 #define __ProgressiveMesh_H_ 00033 00034 #include "OgrePrerequisites.h" 00035 #include "OgreVector3.h" 00036 #include "OgreHardwareVertexBuffer.h" 00037 #include "OgreHardwareIndexBuffer.h" 00038 #include "OgreRenderOperation.h" 00039 00040 namespace Ogre { 00041 00055 class _OgreExport ProgressiveMesh 00056 { 00057 public: 00058 00060 enum VertexReductionQuota 00061 { 00063 VRQ_CONSTANT, 00065 VRQ_PROPORTIONAL 00066 }; 00067 00068 typedef std::vector<IndexData*> LODFaceList; 00069 00077 ProgressiveMesh(const VertexData* vertexData, const IndexData* indexData); 00078 virtual ~ProgressiveMesh(); 00079 00095 virtual void addExtraVertexPositionBuffer(const VertexData* vertexData); 00096 00105 virtual void build(ushort numLevels, LODFaceList* outList, 00106 VertexReductionQuota quota = VRQ_PROPORTIONAL, Real reductionValue = 0.5f ); 00107 00108 protected: 00109 const VertexData *mpVertexData; 00110 const IndexData *mpIndexData; 00111 00112 size_t mCurrNumIndexes; 00113 size_t mNumCommonVertices; 00114 00115 // Internal classes 00116 class PMTriangle; 00117 class PMVertex; 00118 00119 public: // VC6 hack 00120 00123 class _OgrePrivate PMFaceVertex { 00124 public: 00125 size_t realIndex; 00126 PMVertex* commonVertex; 00127 }; 00128 00129 protected: 00130 00132 class _OgrePrivate PMTriangle { 00133 public: 00134 PMTriangle(); 00135 void setDetails(size_t index, PMFaceVertex *v0, PMFaceVertex *v1, PMFaceVertex *v2); 00136 void computeNormal(void); 00137 void replaceVertex(PMFaceVertex *vold, PMFaceVertex *vnew); 00138 bool hasCommonVertex(PMVertex *v) const; 00139 bool hasFaceVertex(PMFaceVertex *v) const; 00140 PMFaceVertex* getFaceVertexFromCommon(PMVertex* commonVert); 00141 void notifyRemoved(void); 00142 00143 PMFaceVertex* vertex[3]; // the 3 points that make this tri 00144 Vector3 normal; // unit vector othogonal to this face 00145 bool removed; // true if this tri is now removed 00146 size_t index; 00147 }; 00148 00155 class _OgrePrivate PMVertex { 00156 public: 00157 PMVertex(); 00158 void setDetails(const Vector3& v, size_t index); 00159 void removeIfNonNeighbor(PMVertex *n); 00160 bool isBorder(void); 00161 bool isManifoldEdgeWith(PMVertex* v); // is edge this->src a manifold edge? 00162 void notifyRemoved(void); 00163 00164 Vector3 position; // location of point in euclidean space 00165 size_t index; // place of vertex in original list 00166 typedef std::set<PMVertex *> NeighborList; 00167 typedef std::set<PMVertex *> DuplicateList; 00168 NeighborList neighbor; // adjacent vertices 00169 typedef std::set<PMTriangle *> FaceList; 00170 FaceList face; // adjacent triangles 00171 00172 Real collapseCost; // cached cost of collapsing edge 00173 PMVertex * collapseTo; // candidate vertex for collapse 00174 bool removed; // true if this vert is now removed 00175 bool toBeRemoved; // denug 00176 00177 bool seam; 00178 00179 }; 00180 00181 typedef std::vector<PMTriangle> TriangleList; 00182 typedef std::vector<PMFaceVertex> FaceVertexList; 00183 typedef std::vector<PMVertex> CommonVertexList; 00184 typedef std::vector<Real> WorstCostList; 00185 00187 struct PMWorkingData 00188 { 00189 TriangleList mTriList; 00190 FaceVertexList mFaceVertList; // The vertex details referenced by the triangles 00191 CommonVertexList mVertList; // The master list of common vertices 00192 }; 00193 00194 typedef std::vector<PMWorkingData> WorkingDataList; 00196 WorkingDataList mWorkingData; 00197 00199 WorstCostList mWorstCosts; 00200 00202 void addWorkingData(const VertexData* vertexData, const IndexData* indexData); 00203 00205 void initialiseEdgeCollapseCosts(void); 00207 Real computeEdgeCollapseCost(PMVertex *src, PMVertex *dest); 00209 Real computeEdgeCostAtVertexForBuffer(WorkingDataList::iterator idata, size_t vertIndex); 00211 void computeEdgeCostAtVertex(size_t vertIndex); 00213 void computeAllCosts(void); 00215 size_t getNextCollapser(void); 00217 void bakeNewLOD(IndexData* pData); 00218 00225 void collapse(PMVertex *collapser); 00226 00228 void dumpContents(const String& log); 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 }; 00239 00240 00241 00242 } 00243 00244 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:50 2006