OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreLodInputProviderMesh.h
Go to the documentation of this file.
1 
2 /*
3  * -----------------------------------------------------------------------------
4  * This source file is part of OGRE
5  * (Object-oriented Graphics Rendering Engine)
6  * For the latest info, see http://www.ogre3d.org/
7  *
8  * Copyright (c) 2000-2014 Torus Knot Software Ltd
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  * THE SOFTWARE.
27  * -----------------------------------------------------------------------------
28  */
29 
30 #ifndef _LodInputProviderMesh_H__
31 #define _LodInputProviderMesh_H__
32 
33 #include "OgreLodPrerequisites.h"
34 #include "OgreLodInputProvider.h"
35 #include "OgreLodData.h"
36 #include "OgreSharedPtr.h"
37 #include "OgreLogManager.h"
38 
39 namespace Ogre
40 {
41 
43  public LodInputProvider
44 {
45 public:
48  virtual void initData(LodData* data);
49 
50 protected:
52  // This helps to find the vertex* in LodData for index buffer indices
56 
57  void tuneContainerSize(LodData* data);
58  void initialize(LodData* data);
59  void addIndexData(LodData* data, IndexData* indexData, bool useSharedVertexLookup, unsigned short submeshID);
60  void addVertexData(LodData* data, VertexData* vertexData, bool useSharedVertexLookup);
61  template<typename IndexType>
62  void addIndexDataImpl(LodData* data, IndexType* iPos, const IndexType* iEnd,
63  VertexLookupList& lookup,
64  unsigned short submeshID)
65  {
66  // Loop through all triangles and connect them to the vertices.
67  for (; iPos < iEnd; iPos += 3) {
68  // It should never reallocate or every pointer will be invalid.
69  OgreAssert(data->mTriangleList.capacity() > data->mTriangleList.size(), "");
70  data->mTriangleList.push_back(LodData::Triangle());
71  LodData::Triangle* tri = &data->mTriangleList.back();
72  tri->isRemoved = false;
73  tri->submeshID = submeshID;
74  for (int i = 0; i < 3; i++) {
75  // Invalid index: Index is bigger then vertex buffer size.
76  OgreAssert(iPos[i] < lookup.size(), "");
77  tri->vertexID[i] = iPos[i];
78  tri->vertex[i] = lookup[iPos[i]];
79  }
80  if (tri->isMalformed()) {
81 #if OGRE_DEBUG_MODE
82  stringstream str;
83  str << "In " << data->mMeshName << " malformed triangle found with ID: " << LodData::getVectorIDFromPointer(data->mTriangleList, tri) << ". " <<
84  std::endl;
85  printTriangle(tri, str);
86  str << "It will be excluded from Lod level calculations.";
87  LogManager::getSingleton().stream() << str.str();
88 #endif
89  tri->isRemoved = true;
90  data->mIndexBufferInfoList[tri->submeshID].indexCount -= 3;
91  continue;
92  }
93  tri->computeNormal();
94  addTriangleToEdges(data, tri);
95  }
96  }
97 };
98 
99 }
100 #endif
101 
102 
vector< LodData::Vertex * >::type VertexLookupList
void addIndexDataImpl(LodData *data, IndexType *iPos, const IndexType *iEnd, VertexLookupList &lookup, unsigned short submeshID)
unsigned int vertexID[3]
ID of the submesh. Usable with mMesh.getSubMesh() function.
Definition: OgreLodData.h:112
unsigned short submeshID
Definition: OgreLodData.h:111
#define OgreAssert(a, b)
Definition: OgreException.h:60
TriangleList mTriangleList
Definition: OgreLodData.h:139
static size_t getVectorIDFromPointer(const std::vector< T, A > &vec, const T *pointer)
Definition: OgreLodData.h:156
Log::Stream stream(LogMessageLevel lml=LML_NORMAL, bool maskDebug=false)
Get a stream on the default log.
IndexBufferInfoList mIndexBufferInfoList
Definition: OgreLodData.h:143
Summary class collecting together index data source information.
StringStream stringstream
void computeNormal()
Vertex ID in the buffer associated with the submeshID.
#define _OgreLodExport
Summary class collecting together vertex source information.
static LogManager & getSingleton(void)
Override standard Singleton retrieval.