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 © 2000-2003 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 #ifndef __EdgeListBuilder_H__ 00026 #define __EdgeListBuilder_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 #include "OgreVector4.h" 00030 #include "OgreHardwareVertexBuffer.h" 00031 #include "OgreRenderOperation.h" 00032 00033 namespace Ogre { 00034 00035 00042 class _OgreExport EdgeData 00043 { 00044 public: 00046 struct Triangle { 00049 size_t indexSet; 00051 size_t vertexSet; 00052 size_t vertIndex[3]; 00053 size_t sharedVertIndex[3]; 00054 // duplicates eliminated (this buffer is not exposed) 00055 Vector4 normal; // unit vector othogonal to this face, plus distance from origin 00056 bool lightFacing; // Working vector used when calculating the silhouette 00057 }; 00059 struct Edge { 00063 size_t triIndex[2]; 00066 size_t vertIndex[2]; 00068 size_t sharedVertIndex[2]; 00070 bool degenerate; 00071 }; 00072 00073 typedef std::vector<Triangle> TriangleList; 00074 typedef std::vector<Edge> EdgeList; 00075 00077 struct EdgeGroup 00078 { 00080 size_t vertexSet; 00082 const VertexData* vertexData; 00084 EdgeList edges; 00085 00086 }; 00087 00088 typedef std::vector<EdgeGroup> EdgeGroupList; 00089 TriangleList triangles; 00090 EdgeGroupList edgeGroups; 00091 00092 00103 void updateTriangleLightFacing(const Vector4& lightPos); 00109 void updateFaceNormals(size_t vertexSet, HardwareVertexBufferSharedPtr positionBuffer); 00110 00111 00112 00113 // Debugging method 00114 void log(Log* log); 00115 00116 }; 00117 00127 class _OgreExport EdgeListBuilder 00128 { 00129 public: 00130 00131 EdgeListBuilder(); 00132 virtual ~EdgeListBuilder(); 00138 void addVertexData(const VertexData* vertexData); 00149 void addIndexData(const IndexData* indexData, size_t vertexSet = 0, 00150 RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST); 00151 00156 EdgeData* build(void); 00157 00159 void log(Log* l); 00160 protected: 00161 00167 struct CommonVertex { 00168 Vector3 position; // location of point in euclidean space 00169 size_t index; // place of vertex in common vertex list 00170 size_t vertexSet; // The vertex set this came from 00171 size_t indexSet; // The index set this was referenced (first) from 00172 size_t originalIndex; // place of vertex in original vertex set 00173 }; 00174 00175 typedef std::vector<const VertexData*> VertexDataList; 00176 typedef std::vector<const IndexData*> IndexDataList; 00177 typedef std::vector<CommonVertex> CommonVertexList; 00178 typedef std::vector<RenderOperation::OperationType> OperationTypeList; 00179 00180 IndexDataList mIndexDataList; 00181 OperationTypeList mOperationTypeList; 00182 std::vector<size_t> mIndexDataVertexDataSetList; 00183 VertexDataList mVertexDataList; 00184 CommonVertexList mVertices; 00185 EdgeData* mEdgeData; 00187 typedef std::set< std::pair<size_t, size_t> > UniqueEdgeSet; 00188 UniqueEdgeSet mUniqueEdges; 00189 // Do we weld common vertices at all? 00190 bool mWeldVertices; 00191 // Should we treat coincident vertices from different vertex sets as one? 00192 bool mWeldVerticesAcrossVertexSets; 00193 // Should we treat coincident vertices referenced from different index sets as one? 00194 bool mWeldVerticesAcrossIndexSets; 00195 00196 void buildTrianglesEdges(size_t indexSet, size_t vertexSet); 00197 void connectEdges(void); 00198 EdgeData::Edge* findEdge(size_t sharedIndex1, size_t sharedIndex2); 00199 00201 size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet, 00202 size_t indexSet, size_t originalIndex); 00204 void createEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1, 00205 size_t sharedVertIndex0, size_t sharedVertIndex1); 00206 00208 void attemptBuild(void); 00209 00210 }; 00211 00212 } 00213 #endif 00214
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:23 2004