OgreEdgeListBuilder.h
Go to the documentation of this file.
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-2013 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 #ifndef __EdgeListBuilder_H__
00029 #define __EdgeListBuilder_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 #include "OgreVector4.h"
00033 #include "OgreHardwareVertexBuffer.h"
00034 #include "OgreRenderOperation.h"
00035 #include "OgreHeaderPrefix.h"
00036 
00037 namespace Ogre {
00052     class _OgreExport EdgeData : public EdgeDataAlloc
00053     {
00054     public:
00055         
00056         EdgeData();
00057         
00059         struct Triangle {
00062             size_t indexSet; 
00064             size_t vertexSet;
00066             size_t vertIndex[3];
00069             size_t sharedVertIndex[3];
00070 
00071             Triangle() :indexSet(0), vertexSet(0) {}
00072         };
00074         struct Edge {
00078             size_t triIndex[2];
00081             size_t vertIndex[2];
00083             size_t sharedVertIndex[2];
00085             bool degenerate;
00086         };
00087 
00091         typedef std::vector<Vector4, STLAllocator<Vector4, CategorisedAlignAllocPolicy<MEMCATEGORY_GEOMETRY> > > TriangleFaceNormalList;
00092 
00096         typedef vector<char>::type TriangleLightFacingList;
00097 
00098         typedef vector<Triangle>::type TriangleList;
00099         typedef vector<Edge>::type EdgeList;
00100 
00102         struct EdgeGroup
00103         {
00105             size_t vertexSet;
00107             const VertexData* vertexData;
00112             size_t triStart;
00114             size_t triCount;
00116             EdgeList edges;
00117 
00118         };
00119 
00120         typedef vector<EdgeGroup>::type EdgeGroupList;
00121 
00125         TriangleList triangles;
00127         TriangleFaceNormalList triangleFaceNormals;
00129         TriangleLightFacingList triangleLightFacings;
00131         EdgeGroupList edgeGroups;
00133         bool isClosed;
00134 
00135 
00145         void updateTriangleLightFacing(const Vector4& lightPos);
00151         void updateFaceNormals(size_t vertexSet, const HardwareVertexBufferSharedPtr& positionBuffer);
00152 
00153 
00154 
00156         void log(Log* log);
00157         
00158     };
00159 
00169     class _OgreExport EdgeListBuilder 
00170     {
00171     public:
00172 
00173         EdgeListBuilder();
00174         virtual ~EdgeListBuilder();
00180         void addVertexData(const VertexData* vertexData);
00191         void addIndexData(const IndexData* indexData, size_t vertexSet = 0, 
00192             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST);
00193 
00198         EdgeData* build(void);
00199 
00201         void log(Log* l);
00202     protected:
00203 
00209         struct CommonVertex {
00210             Vector3  position;  
00211             size_t index;       
00212             size_t vertexSet;   
00213             size_t indexSet;    
00214             size_t originalIndex; 
00215         };
00217         struct Geometry {
00218             size_t vertexSet;           
00219             size_t indexSet;            
00220             const IndexData* indexData; 
00221             RenderOperation::OperationType opType;  
00222         };
00224         struct geometryLess {
00225             bool operator()(const Geometry& a, const Geometry& b) const
00226             {
00227                 if (a.vertexSet < b.vertexSet) return true;
00228                 if (a.vertexSet > b.vertexSet) return false;
00229                 return a.indexSet < b.indexSet;
00230             }
00231         };
00233         struct vectorLess {
00234             bool operator()(const Vector3& a, const Vector3& b) const
00235             {
00236                 if (a.x < b.x) return true;
00237                 if (a.x > b.x) return false;
00238                 if (a.y < b.y) return true;
00239                 if (a.y > b.y) return false;
00240                 return a.z < b.z;
00241             }
00242         };
00243 
00244         typedef vector<const VertexData*>::type VertexDataList;
00245         typedef vector<Geometry>::type GeometryList;
00246         typedef vector<CommonVertex>::type CommonVertexList;
00247 
00248         GeometryList mGeometryList;
00249         VertexDataList mVertexDataList;
00250         CommonVertexList mVertices;
00251         EdgeData* mEdgeData;
00253         typedef map<Vector3, size_t, vectorLess>::type CommonVertexMap;
00254         CommonVertexMap mCommonVertexMap;
00258         typedef multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> >::type EdgeMap;
00259         EdgeMap mEdgeMap;
00260 
00261         void buildTrianglesEdges(const Geometry &geometry);
00262 
00264         size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet, 
00265             size_t indexSet, size_t originalIndex);
00267         void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1, 
00268             size_t sharedVertIndex0, size_t sharedVertIndex1);
00269     };
00273 }
00274 
00275 #include "OgreHeaderSuffix.h"
00276 
00277 #endif
00278 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:42