# 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-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 #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         // manifold? NB This value is not stored in the  binary Mesh format yet so
    00092         // cannot be relied upon unless this has been calculated interactively.
    00093         //bool isClosed; // manifold?
    00094
    00095
    00106         void updateTriangleLightFacing(const Vector4& lightPos);
    00112         void updateFaceNormals(size_t vertexSet, HardwareVertexBufferSharedPtr positionBuffer);
    00113
    00114
    00115
    00116         // Debugging method
    00117         void log(Log* log);
    00118
    00119     };
    00120
    00130     class _OgreExport EdgeListBuilder
    00131     {
    00132     public:
    00133
    00134         EdgeListBuilder();
    00135         virtual ~EdgeListBuilder();
    00141         void addVertexData(const VertexData* vertexData);
    00152         void addIndexData(const IndexData* indexData, size_t vertexSet = 0,
    00153             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST);
    00154
    00159         EdgeData* build(void);
    00160
    00162         void log(Log* l);
    00163     protected:
    00164
    00170         struct CommonVertex {
    00171             Vector3  position;  // location of point in euclidean space
    00172             size_t index;       // place of vertex in common vertex list
    00173             size_t vertexSet;   // The vertex set this came from
    00174             size_t indexSet;    // The index set this was referenced (first) from
    00175             size_t originalIndex; // place of vertex in original vertex set
    00176         };
    00178         struct Geometry {
    00179             size_t vertexSet;           // The vertex data set this geometry data refers to
    00180             size_t indexSet;            // The index data set this geometry data refers to
    00181             const IndexData* indexData; // The index information which describes the triangles.
    00182             RenderOperation::OperationType opType;  // The operation type used to render this geometry
    00183         };
    00185         struct geometryLess {
    00186             bool operator()(const Geometry& a, const Geometry& b) const
    00187             {
    00188                 if (a.vertexSet < b.vertexSet) return true;
    00189                 if (a.vertexSet > b.vertexSet) return false;
    00190                 return a.indexSet < b.indexSet;
    00191             }
    00192         };
    00194         struct vectorLess {
    00195             bool operator()(const Vector3& a, const Vector3& b) const
    00196             {
    00197                 if (a.x < b.x) return true;
    00198                 if (a.x > b.x) return false;
    00199                 if (a.y < b.y) return true;
    00200                 if (a.y > b.y) return false;
    00201                 return a.z < b.z;
    00202             }
    00203         };
    00204
    00205         typedef std::vector<const VertexData*> VertexDataList;
    00206         typedef std::vector<Geometry> GeometryList;
    00207         typedef std::vector<CommonVertex> CommonVertexList;
    00208
    00209         GeometryList mGeometryList;
    00210         VertexDataList mVertexDataList;
    00211         CommonVertexList mVertices;
    00212         EdgeData* mEdgeData;
    00214         typedef std::map<Vector3, size_t, vectorLess> CommonVertexMap;
    00215         CommonVertexMap mCommonVertexMap;
    00219         typedef std::multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> > EdgeMap;
    00220         EdgeMap mEdgeMap;
    00221
    00222         void buildTrianglesEdges(const Geometry &geometry);
    00223
    00225         size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet,
    00226             size_t indexSet, size_t originalIndex);
    00228         void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1,
    00229             size_t sharedVertIndex0, size_t sharedVertIndex1);
    00230     };
    00231
    00232 }
    00233 #endif
    00234

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:35:59 2005