00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright © 2000-2002 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 00037 namespace Ogre { 00038 00052 class _OgreExport ProgressiveMesh 00053 { 00054 public: 00055 00057 enum VertexReductionQuota 00058 { 00060 VRQ_CONSTANT, 00062 VRQ_PROPORTIONAL 00063 }; 00065 struct LODFaceData 00066 { 00067 ushort numIndexes; 00068 ushort* pIndexes; 00069 }; 00070 00071 typedef std::vector<LODFaceData> LODFaceList; 00072 00074 ProgressiveMesh(GeometryData* data, ushort* indexBuffer, ushort numIndexes); 00075 virtual ~ProgressiveMesh(); 00076 00087 virtual void addExtraVertexPositionBuffer(Real* buffer); 00088 00097 virtual void build(ushort numLevels, LODFaceList* outList, 00098 VertexReductionQuota quota = VRQ_PROPORTIONAL, Real reductionValue = 0.5f ); 00099 00100 protected: 00101 GeometryData* mpGeomData; 00102 ushort* mpIndexBuffer; 00103 ushort mNumIndexes; 00104 ushort mCurrNumIndexes; 00105 ushort mNumCommonVertices; 00106 00107 // Internal classes 00108 class PMTriangle; 00109 class PMVertex; 00110 00111 public: // VC6 hack 00112 00115 class PMFaceVertex { 00116 public: 00117 ushort realIndex; 00118 PMVertex* commonVertex; 00119 }; 00120 00121 protected: 00122 00124 class PMTriangle { 00125 public: 00126 PMTriangle(); 00127 void setDetails(ushort index, PMFaceVertex *v0, PMFaceVertex *v1, PMFaceVertex *v2); 00128 void computeNormal(void); 00129 void replaceVertex(PMFaceVertex *vold, PMFaceVertex *vnew); 00130 bool hasCommonVertex(PMVertex *v); 00131 bool hasFaceVertex(PMFaceVertex *v); 00132 PMFaceVertex* getFaceVertexFromCommon(PMVertex* commonVert); 00133 void notifyRemoved(void); 00134 00135 PMFaceVertex* vertex[3]; // the 3 points that make this tri 00136 Vector3 normal; // unit vector othogonal to this face 00137 bool removed; // true if this tri is now removed 00138 ushort index; 00139 }; 00140 00147 class PMVertex { 00148 public: 00149 PMVertex(); 00150 void setDetails(const Vector3& v, int index); 00151 void removeIfNonNeighbor(PMVertex *n); 00152 bool isBorder(void); 00153 bool isManifoldEdgeWith(PMVertex* v); // is edge this->src a manifold edge? 00154 void notifyRemoved(void); 00155 00156 Vector3 position; // location of point in euclidean space 00157 ushort index; // place of vertex in original list 00158 typedef std::set<PMVertex *> NeighborList; 00159 typedef std::set<PMVertex *> DuplicateList; 00160 NeighborList neighbor; // adjacent vertices 00161 typedef std::set<PMTriangle *> FaceList; 00162 FaceList face; // adjacent triangles 00163 00164 Real collapseCost; // cached cost of collapsing edge 00165 PMVertex * collapseTo; // candidate vertex for collapse 00166 bool removed; // true if this vert is now removed 00167 bool toBeRemoved; // denug 00168 00169 bool seam; 00170 00171 }; 00172 00173 typedef std::vector<PMTriangle> TriangleList; 00174 typedef std::vector<PMFaceVertex> FaceVertexList; 00175 typedef std::vector<PMVertex> CommonVertexList; 00176 typedef std::vector<Real> WorstCostList; 00177 00179 struct PMWorkingData 00180 { 00181 TriangleList mTriList; 00182 FaceVertexList mFaceVertList; // The vertex details referenced by the triangles 00183 CommonVertexList mVertList; // The master list of common vertices 00184 }; 00185 00186 typedef std::vector<PMWorkingData> WorkingDataList; 00188 WorkingDataList mWorkingData; 00189 00191 WorstCostList mWorstCosts; 00192 00194 void addWorkingData(Real* pPositions, GeometryData* data, ushort* indexBuffer, ushort numIndexes); 00195 00197 void initialiseEdgeCollapseCosts(void); 00199 Real computeEdgeCollapseCost(PMVertex *src, PMVertex *dest); 00201 Real computeEdgeCostAtVertexForBuffer(WorkingDataList::iterator idata, ushort vertIndex); 00203 void computeEdgeCostAtVertex(ushort vertIndex); 00205 void computeAllCosts(void); 00207 ushort getNextCollapser(void); 00209 void bakeNewLOD(LODFaceData* pData); 00210 00217 void collapse(PMVertex *collapser); 00218 00220 void dumpContents(const String& log); 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 }; 00231 00232 00233 00234 } 00235 00236 #endif
Copyright © 2002 by The OGRE Team