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-2006 Torus Knot Software Ltd 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 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef __EdgeListBuilder_H__ 00030 #define __EdgeListBuilder_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreVector4.h" 00034 #include "OgreHardwareVertexBuffer.h" 00035 #include "OgreRenderOperation.h" 00036 00037 namespace Ogre { 00038 00039 00046 class _OgreExport EdgeData : public EdgeDataAlloc 00047 { 00048 public: 00050 struct Triangle { 00053 size_t indexSet; 00055 size_t vertexSet; 00056 size_t vertIndex[3]; 00057 size_t sharedVertIndex[3]; 00058 // duplicates eliminated (this buffer is not exposed) 00059 }; 00061 struct Edge { 00065 size_t triIndex[2]; 00068 size_t vertIndex[2]; 00070 size_t sharedVertIndex[2]; 00072 bool degenerate; 00073 }; 00074 00075 // Array of 4D vector of triangle face normal, which is unit vector orthogonal 00076 // to the triangles, plus distance from origin. 00077 // Use aligned policy here because we are intended to use in SIMD optimised routines . 00078 typedef std::vector<Vector4, STLAllocator<Vector4, CategorisedAlignAllocPolicy<MEMCATEGORY_GEOMETRY> > > TriangleFaceNormalList; 00079 00080 // Working vector used when calculating the silhouette. 00081 // Use std::vector<char> instead of std::vector<bool> which might implemented 00082 // similar bit-fields causing loss performance. 00083 typedef std::vector<char> TriangleLightFacingList; 00084 00085 typedef std::vector<Triangle> TriangleList; 00086 typedef std::vector<Edge> EdgeList; 00087 00089 struct EdgeGroup 00090 { 00092 size_t vertexSet; 00094 const VertexData* vertexData; 00099 size_t triStart; 00101 size_t triCount; 00103 EdgeList edges; 00104 00105 }; 00106 00107 typedef std::vector<EdgeGroup> EdgeGroupList; 00108 00112 TriangleList triangles; 00114 TriangleFaceNormalList triangleFaceNormals; 00116 TriangleLightFacingList triangleLightFacings; 00118 EdgeGroupList edgeGroups; 00120 bool isClosed; 00121 00122 00132 void updateTriangleLightFacing(const Vector4& lightPos); 00138 void updateFaceNormals(size_t vertexSet, const HardwareVertexBufferSharedPtr& positionBuffer); 00139 00140 00141 00142 // Debugging method 00143 void log(Log* log); 00144 00145 }; 00146 00156 class _OgreExport EdgeListBuilder 00157 { 00158 public: 00159 00160 EdgeListBuilder(); 00161 virtual ~EdgeListBuilder(); 00167 void addVertexData(const VertexData* vertexData); 00178 void addIndexData(const IndexData* indexData, size_t vertexSet = 0, 00179 RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST); 00180 00185 EdgeData* build(void); 00186 00188 void log(Log* l); 00189 protected: 00190 00196 struct CommonVertex { 00197 Vector3 position; // location of point in euclidean space 00198 size_t index; // place of vertex in common vertex list 00199 size_t vertexSet; // The vertex set this came from 00200 size_t indexSet; // The index set this was referenced (first) from 00201 size_t originalIndex; // place of vertex in original vertex set 00202 }; 00204 struct Geometry { 00205 size_t vertexSet; // The vertex data set this geometry data refers to 00206 size_t indexSet; // The index data set this geometry data refers to 00207 const IndexData* indexData; // The index information which describes the triangles. 00208 RenderOperation::OperationType opType; // The operation type used to render this geometry 00209 }; 00211 struct geometryLess { 00212 bool operator()(const Geometry& a, const Geometry& b) const 00213 { 00214 if (a.vertexSet < b.vertexSet) return true; 00215 if (a.vertexSet > b.vertexSet) return false; 00216 return a.indexSet < b.indexSet; 00217 } 00218 }; 00220 struct vectorLess { 00221 bool operator()(const Vector3& a, const Vector3& b) const 00222 { 00223 if (a.x < b.x) return true; 00224 if (a.x > b.x) return false; 00225 if (a.y < b.y) return true; 00226 if (a.y > b.y) return false; 00227 return a.z < b.z; 00228 } 00229 }; 00230 00231 typedef std::vector<const VertexData*> VertexDataList; 00232 typedef std::vector<Geometry> GeometryList; 00233 typedef std::vector<CommonVertex> CommonVertexList; 00234 00235 GeometryList mGeometryList; 00236 VertexDataList mVertexDataList; 00237 CommonVertexList mVertices; 00238 EdgeData* mEdgeData; 00240 typedef std::map<Vector3, size_t, vectorLess> CommonVertexMap; 00241 CommonVertexMap mCommonVertexMap; 00245 typedef std::multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> > EdgeMap; 00246 EdgeMap mEdgeMap; 00247 00248 void buildTrianglesEdges(const Geometry &geometry); 00249 00251 size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet, 00252 size_t indexSet, size_t originalIndex); 00254 void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1, 00255 size_t sharedVertIndex0, size_t sharedVertIndex1); 00256 }; 00257 00258 } 00259 #endif 00260
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:23 2009