OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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 "OgreManualObject.h"
33 #include "OgreVector3.h"
34 #include "OgreAxisAlignedBox.h"
36 
37 namespace Ogre {
38 namespace Volume {
39 
42  typedef struct _OgreVolumeExport Vertex
43  {
46 
49 
52 
55 
58 
61 
68  Vertex(const Vector3 &v, const Vector3 &n) :
69  x(v.x), y(v.y), z(v.z),
70  nX(n.x), nY(n.y), nZ(n.z)
71  {
72  }
74  {
75  }
76  } Vertex;
77 
84  bool _OgreVolumeExport operator==(Vertex const& a, Vertex const& b);
85 
94  bool _OgreVolumeExport operator<(const Vertex& a, const Vertex& b);
95 
99 
103 
108  {
109  public:
110  virtual ~MeshBuilderCallback() {}
111 
124  virtual void ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess) = 0;
125  };
126 
130  {
131  protected:
132 
134  static const unsigned short MAIN_BINDING;
135 
139 
142 
145 
148 
150  bool mBoxInit;
151 
156  inline void addVertex(const Vertex &v)
157  {
158  size_t i = 0;
159  if (mIndexMap.find(v) == mIndexMap.end())
160  {
161  i = mVertices.size();
162  mIndexMap[v] = i;
163  mVertices.push_back(v);
164 
165  // Update bounding box
166  if (!mBoxInit)
167  {
168  mBox.setExtents(v.x, v.y, v.z, v.x, v.y, v.z);
169  mBoxInit = true;
170  }
171  else
172  {
173  if (v.x < mBox.getMinimum().x)
174  {
175  mBox.setMinimumX(v.x);
176  }
177  if (v.y < mBox.getMinimum().y)
178  {
179  mBox.setMinimumY(v.y);
180  }
181  if (v.z < mBox.getMinimum().z)
182  {
183  mBox.setMinimumZ(v.z);
184  }
185  if (v.x > mBox.getMaximum().x)
186  {
187  mBox.setMaximumX(v.x);
188  }
189  if (v.y > mBox.getMaximum().y)
190  {
191  mBox.setMaximumY(v.y);
192  }
193  if (v.z > mBox.getMaximum().z)
194  {
195  mBox.setMaximumZ(v.z);
196  }
197  }
198  }
199  else
200  {
201  i = mIndexMap[v];
202  }
203  mIndices.push_back(i);
204  }
205 
206  public:
207 
235  static inline void addCubeToManualObject(
236  ManualObject *manual,
237  const Vector3 &c0,
238  const Vector3 &c1,
239  const Vector3 &c2,
240  const Vector3 &c3,
241  const Vector3 &c4,
242  const Vector3 &c5,
243  const Vector3 &c6,
244  const Vector3 &c7,
245  uint32 &baseIndex
246  )
247  {
248  manual->position(c0);
249  manual->position(c1);
250  manual->position(c2);
251  manual->position(c3);
252  manual->position(c4);
253  manual->position(c5);
254  manual->position(c6);
255  manual->position(c7);
256 
257  manual->index(baseIndex + 0); manual->index(baseIndex + 1);
258  manual->index(baseIndex + 1); manual->index(baseIndex + 2);
259  manual->index(baseIndex + 2); manual->index(baseIndex + 3);
260  manual->index(baseIndex + 3); manual->index(baseIndex + 0);
261 
262  manual->index(baseIndex + 4); manual->index(baseIndex + 5);
263  manual->index(baseIndex + 5); manual->index(baseIndex + 6);
264  manual->index(baseIndex + 6); manual->index(baseIndex + 7);
265  manual->index(baseIndex + 7); manual->index(baseIndex + 4);
266 
267  manual->index(baseIndex + 0); manual->index(baseIndex + 4);
268  manual->index(baseIndex + 1); manual->index(baseIndex + 5);
269  manual->index(baseIndex + 2); manual->index(baseIndex + 6);
270  manual->index(baseIndex + 3); manual->index(baseIndex + 7);
271  baseIndex += 8;
272  }
273 
276  MeshBuilder(void);
277 
292  inline void addTriangle(const Vector3 &v0, const Vector3 &n0, const Vector3 &v1, const Vector3 &n1, const Vector3 &v2, const Vector3 &n2)
293  {
294  addVertex(Vertex(v0, n0));
295  addVertex(Vertex(v1, n1));
296  addVertex(Vertex(v2, n2));
297  }
298 
306  size_t generateBuffers(RenderOperation &operation);
307 
318  Entity* generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material);
319 
324  AxisAlignedBox getBoundingBox(void);
325 
336  void executeCallback(MeshBuilderCallback *callback, const SimpleRenderable *simpleRenderable, size_t level, int inProcess) const;
337 
338  };
339 }
340 }
341 
342 #endif
Real nZ
Z component of the normal.
bool _OgreVolumeExport operator<(const Vector3 &a, const Vector3 &b)
A less operator.
vector< Vertex >::type VecVertex
To hold vertices.
float Real
Software floating point type.
Callback class when the user needs information about the triangles of chunks of a LOD level...
void addVertex(const Vertex &v)
Adds a vertex to the data structure, reusing the index if it is already known.
unsigned int uint32
Definition: OgrePlatform.h:420
VecVertex mVertices
Holds the vertices of the mesh.
Class providing a much simplified interface to generating manual objects with custom geometry...
Real nY
Y component of the normal.
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.
Manages the organisation and rendering of a 'scene' i.e.
static const unsigned short MAIN_BINDING
The buffer binding.
Simple implementation of MovableObject and Renderable for single-part custom objects.
A 3D box aligned with the x/y/z axes.
virtual void position(const Vector3 &pos)
Add a vertex position, starting a new vertex at the same time.
AxisAlignedBox mBox
Holds the bounding box.
bool mBoxInit
Holds whether the initial bounding box has been set.
Real nX
X component of the normal.
Vertex(const Vector3 &v, const Vector3 &n)
Convenience constructor.
Real y
Y coordinate of the position.
virtual void index(uint32 idx)
Add a vertex index to construct faces / lines / points via indexing rather than just by a simple list...
bool _OgreVolumeExport operator==(Vertex const &a, Vertex const &b)
== operator for two vertices.
Lightweight struct to represent a mesh vertex.
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.
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:81
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
VecIndices mIndices
Holds the indices of the mesh.
Real x
X coordinate of the position.
Real z
Z coordinate of the position.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
'New' rendering operation using vertex buffers.
struct _OgreVolumeExport Ogre::Volume::Vertex Vertex
Lightweight struct to represent a mesh vertex.
map< Vertex, size_t >::type UMapVertexIndex
Map to get a vertex index.
_StringBase String
Definition: OgreCommon.h:53
vector< size_t >::type VecIndices
To hold indices.
#define _OgreVolumeExport
Class to build up a mesh with vertices and indices.