OgreVolumeMeshBuilder.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Ogre_Volume_MeshBuilder_H__
29 #define __Ogre_Volume_MeshBuilder_H__
30 
31 #include <vector>
32 #include "OgreSimpleRenderable.h"
33 #include "OgreManualObject.h"
34 #include "OgreRenderOperation.h"
35 #include "OgreVector3.h"
36 #include "OgreAxisAlignedBox.h"
37 #include "OgreSceneManager.h"
39 
40 namespace Ogre {
41 namespace Volume {
42 
45  typedef struct _OgreVolumeExport Vertex
46  {
49 
52 
55 
58 
61 
64 
71  Vertex(const Vector3 &v, const Vector3 &n) :
72  x(v.x), y(v.y), z(v.z),
73  nX(n.x), nY(n.y), nZ(n.z)
74  {
75  }
77  {
78  }
79  } Vertex;
80 
87  bool _OgreVolumeExport operator==(Vertex const& a, Vertex const& b);
88 
97  bool _OgreVolumeExport operator<(const Vertex& a, const Vertex& b);
98 
102 
106 
111  {
112  public:
113  virtual ~MeshBuilderCallback() {}
114 
127  virtual void ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess) = 0;
128  };
129 
133  {
134  protected:
135 
137  static const unsigned short MAIN_BINDING;
138 
142 
145 
148 
151 
153  bool mBoxInit;
154 
159  inline void addVertex(const Vertex &v)
160  {
161  size_t i = 0;
162  if (mIndexMap.find(v) == mIndexMap.end())
163  {
164  i = mVertices.size();
165  mIndexMap[v] = i;
166  mVertices.push_back(v);
167 
168  // Update bounding box
169  if (!mBoxInit)
170  {
171  mBox.setExtents(v.x, v.y, v.z, v.x, v.y, v.z);
172  mBoxInit = true;
173  }
174  else
175  {
176  if (v.x < mBox.getMinimum().x)
177  {
178  mBox.setMinimumX(v.x);
179  }
180  if (v.y < mBox.getMinimum().y)
181  {
182  mBox.setMinimumY(v.y);
183  }
184  if (v.z < mBox.getMinimum().z)
185  {
186  mBox.setMinimumZ(v.z);
187  }
188  if (v.x > mBox.getMaximum().x)
189  {
190  mBox.setMaximumX(v.x);
191  }
192  if (v.y > mBox.getMaximum().y)
193  {
194  mBox.setMaximumY(v.y);
195  }
196  if (v.z > mBox.getMaximum().z)
197  {
198  mBox.setMaximumZ(v.z);
199  }
200  }
201  }
202  else
203  {
204  i = mIndexMap[v];
205  }
206  mIndices.push_back(i);
207  }
208 
209  public:
210 
238  static inline void addCubeToManualObject(
239  ManualObject *manual,
240  const Vector3 &c0,
241  const Vector3 &c1,
242  const Vector3 &c2,
243  const Vector3 &c3,
244  const Vector3 &c4,
245  const Vector3 &c5,
246  const Vector3 &c6,
247  const Vector3 &c7,
248  uint32 &baseIndex
249  )
250  {
251  manual->position(c0);
252  manual->position(c1);
253  manual->position(c2);
254  manual->position(c3);
255  manual->position(c4);
256  manual->position(c5);
257  manual->position(c6);
258  manual->position(c7);
259 
260  manual->index(baseIndex + 0); manual->index(baseIndex + 1);
261  manual->index(baseIndex + 1); manual->index(baseIndex + 2);
262  manual->index(baseIndex + 2); manual->index(baseIndex + 3);
263  manual->index(baseIndex + 3); manual->index(baseIndex + 0);
264 
265  manual->index(baseIndex + 4); manual->index(baseIndex + 5);
266  manual->index(baseIndex + 5); manual->index(baseIndex + 6);
267  manual->index(baseIndex + 6); manual->index(baseIndex + 7);
268  manual->index(baseIndex + 7); manual->index(baseIndex + 4);
269 
270  manual->index(baseIndex + 0); manual->index(baseIndex + 4);
271  manual->index(baseIndex + 1); manual->index(baseIndex + 5);
272  manual->index(baseIndex + 2); manual->index(baseIndex + 6);
273  manual->index(baseIndex + 3); manual->index(baseIndex + 7);
274  baseIndex += 8;
275  }
276 
279  MeshBuilder(void);
280 
295  inline void addTriangle(const Vector3 &v0, const Vector3 &n0, const Vector3 &v1, const Vector3 &n1, const Vector3 &v2, const Vector3 &n2)
296  {
297  addVertex(Vertex(v0, n0));
298  addVertex(Vertex(v1, n1));
299  addVertex(Vertex(v2, n2));
300  }
301 
309  size_t generateBuffers(RenderOperation &operation);
310 
321  Entity* generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material);
322 
327  AxisAlignedBox getBoundingBox(void);
328 
339  void executeCallback(MeshBuilderCallback *callback, const SimpleRenderable *simpleRenderable, size_t level, int inProcess) const;
340 
341  };
342 }
343 }
344 
345 #endif
Ogre::Volume::Vertex::Vertex
Vertex()
Definition: OgreVolumeMeshBuilder.h:76
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::MeshBuilder
Class to build up a mesh with vertices and indices.
Definition: OgreVolumeMeshBuilder.h:132
Ogre::Volume::MeshBuilder::mIndices
VecIndices mIndices
Holds the indices of the mesh.
Definition: OgreVolumeMeshBuilder.h:147
Ogre::map
Definition: OgrePrerequisites.h:533
OgreSceneManager.h
Ogre::Volume::Vertex
Lightweight struct to represent a mesh vertex.
Definition: OgreVolumeMeshBuilder.h:45
Ogre::Vector3::x
Real x
Definition: OgreVector3.h:54
Ogre::Volume::MeshBuilder::MAIN_BINDING
static const unsigned short MAIN_BINDING
The buffer binding.
Definition: OgreVolumeMeshBuilder.h:137
Ogre::AxisAlignedBox::getMinimum
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
Definition: OgreAxisAlignedBox.h:150
Ogre::AxisAlignedBox::setMaximumZ
void setMaximumZ(Real z)
Definition: OgreAxisAlignedBox.h:242
Ogre::Volume::VecVertex
vector< Vertex >::type VecVertex
To hold vertices.
Definition: OgreVolumeMeshBuilder.h:101
Ogre::Volume::MeshBuilder::UMapVertexIndex
map< Vertex, size_t >::type UMapVertexIndex
Map to get a vertex index.
Definition: OgreVolumeMeshBuilder.h:140
OgreSimpleRenderable.h
Ogre::Volume::MeshBuilder::mBox
AxisAlignedBox mBox
Holds the bounding box.
Definition: OgreVolumeMeshBuilder.h:150
Ogre::ManualObject
Class providing a much simplified interface to generating manual objects with custom geometry.
Definition: OgreManualObject.h:106
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::AxisAlignedBox::getMaximum
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
Definition: OgreAxisAlignedBox.h:165
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Volume::MeshBuilderCallback
Callback class when the user needs information about the triangles of chunks of a LOD level.
Definition: OgreVolumeMeshBuilder.h:110
Ogre::Entity
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Ogre::Vector3::y
Real y
Definition: OgreVector3.h:54
Ogre::Volume::MeshBuilder::mIndexMap
UMapVertexIndex mIndexMap
Definition: OgreVolumeMeshBuilder.h:141
Ogre::AxisAlignedBox::setMinimumZ
void setMinimumZ(Real z)
Definition: OgreAxisAlignedBox.h:208
OgreManualObject.h
Ogre::AxisAlignedBox::setMinimumX
void setMinimumX(Real x)
Changes one of the components of the minimum corner of the box used to resize only one dimension of t...
Definition: OgreAxisAlignedBox.h:198
OgreRenderOperation.h
Ogre::Vector3::z
Real z
Definition: OgreVector3.h:54
Ogre::Volume::MeshBuilder::addCubeToManualObject
static void addCubeToManualObject(ManualObject *manual, const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7, uint32 &baseIndex)
Adds a cube to a manual object rendering lines.
Definition: OgreVolumeMeshBuilder.h:238
Ogre::SceneManager
Manages the organisation and rendering of a 'scene' i.e.
Definition: OgreSceneManager.h:143
Ogre::Volume::Vertex::nZ
Real nZ
Z component of the normal.
Definition: OgreVolumeMeshBuilder.h:63
Ogre::AxisAlignedBox::setMinimumY
void setMinimumY(Real y)
Definition: OgreAxisAlignedBox.h:203
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::Volume::Vertex::y
Real y
Y coordinate of the position.
Definition: OgreVolumeMeshBuilder.h:51
Ogre::Volume::Vertex::x
Real x
X coordinate of the position.
Definition: OgreVolumeMeshBuilder.h:48
Ogre::Volume::operator==
bool _OgreVolumeExport operator==(Vertex const &a, Vertex const &b)
== operator for two vertices.
Ogre::ManualObject::index
virtual void index(uint32 idx)
Add a vertex index to construct faces / lines / points via indexing rather than just by a simple list...
Ogre::Volume::MeshBuilder::addTriangle
void addTriangle(const Vector3 &v0, const Vector3 &n0, const Vector3 &v1, const Vector3 &n1, const Vector3 &v2, const Vector3 &n2)
Adds a triangle to the mesh with reusing already existent vertices via their index.
Definition: OgreVolumeMeshBuilder.h:295
Ogre::Volume::MeshBuilder::addVertex
void addVertex(const Vertex &v)
Adds a vertex to the data structure, reusing the index if it is already known.
Definition: OgreVolumeMeshBuilder.h:159
Ogre::AxisAlignedBox::setExtents
void setExtents(const Vector3 &min, const Vector3 &max)
Sets both minimum and maximum extents at once.
Definition: OgreAxisAlignedBox.h:249
Ogre::Volume::operator<
bool _OgreVolumeExport operator<(const Vector3 &a, const Vector3 &b)
A less operator.
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::Volume::Vertex
struct _OgreVolumeExport Ogre::Volume::Vertex Vertex
Lightweight struct to represent a mesh vertex.
Ogre::Volume::MeshBuilder::mVertices
VecVertex mVertices
Holds the vertices of the mesh.
Definition: OgreVolumeMeshBuilder.h:144
Ogre::Volume::Vertex::Vertex
Vertex(const Vector3 &v, const Vector3 &n)
Convenience constructor.
Definition: OgreVolumeMeshBuilder.h:71
Ogre::Volume::MeshBuilderCallback::~MeshBuilderCallback
virtual ~MeshBuilderCallback()
Definition: OgreVolumeMeshBuilder.h:113
Ogre::Volume::Vertex::nX
Real nX
X component of the normal.
Definition: OgreVolumeMeshBuilder.h:57
Ogre::AxisAlignedBox::setMaximumX
void setMaximumX(Real x)
Changes one of the components of the maximum corner of the box used to resize only one dimension of t...
Definition: OgreAxisAlignedBox.h:232
Ogre::SimpleRenderable
Simple implementation of MovableObject and Renderable for single-part custom objects.
Definition: OgreSimpleRenderable.h:50
Ogre::Volume::VecIndices
vector< size_t >::type VecIndices
To hold indices.
Definition: OgreVolumeMeshBuilder.h:105
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::Vertex::z
Real z
Z coordinate of the position.
Definition: OgreVolumeMeshBuilder.h:54
Ogre::AxisAlignedBox::setMaximumY
void setMaximumY(Real y)
Definition: OgreAxisAlignedBox.h:237
OgreVolumePrerequisites.h
OgreAxisAlignedBox.h
Ogre::Volume::Vertex::nY
Real nY
Y component of the normal.
Definition: OgreVolumeMeshBuilder.h:60
Ogre::vector
Definition: OgrePrerequisites.h:491
OgreVector3.h
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::RenderOperation
'New' rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::Volume::MeshBuilder::mBoxInit
bool mBoxInit
Holds whether the initial bounding box has been set.
Definition: OgreVolumeMeshBuilder.h:153
Ogre::ManualObject::position
virtual void position(const Vector3 &pos)
Add a vertex position, starting a new vertex at the same time.

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 Tue Apr 13 2021 08:53:15