OgreVolumeMeshBuilder.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_Volume_MeshBuilder_H__
#define __Ogre_Volume_MeshBuilder_H__
#include <vector>
#include "OgreSimpleRenderable.h"
#include "OgreManualObject.h"
#include "OgreRenderOperation.h"
#include "OgreVector3.h"
#include "OgreAxisAlignedBox.h"
#include "OgreSceneManager.h"
#include "OgreVolumePrerequisites.h"
namespace Ogre {
namespace Volume {
typedef struct _OgreVolumeExport Vertex
{
Real x;
Real y;
Real z;
Real nX;
Real nY;
Real nZ;
Vertex(const Vector3 &v, const Vector3 &n) :
x(v.x), y(v.y), z(v.z),
nX(n.x), nY(n.y), nZ(n.z)
{
}
Vertex()
{
}
} Vertex;
bool _OgreVolumeExport operator==(Vertex const& a, Vertex const& b);
bool _OgreVolumeExport operator<(const Vertex& a, const Vertex& b);
typedef vector<Vertex>::type VecVertex;
typedef vector<size_t>::type VecIndices;
class _OgreVolumeExport MeshBuilderCallback
{
public:
virtual ~MeshBuilderCallback() {}
virtual void ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess) = 0;
};
class _OgreVolumeExport MeshBuilder : public UtilityAlloc
{
protected:
static const unsigned short MAIN_BINDING;
typedef map<Vertex, size_t>::type UMapVertexIndex;
UMapVertexIndex mIndexMap;
VecVertex mVertices;
VecIndices mIndices;
AxisAlignedBox mBox;
bool mBoxInit;
inline void addVertex(const Vertex &v)
{
size_t i = 0;
if (mIndexMap.find(v) == mIndexMap.end())
{
i = mVertices.size();
mIndexMap[v] = i;
mVertices.push_back(v);
// Update bounding box
if (!mBoxInit)
{
mBox.setExtents(v.x, v.y, v.z, v.x, v.y, v.z);
mBoxInit = true;
}
else
{
if (v.x < mBox.getMinimum().x)
{
mBox.setMinimumX(v.x);
}
if (v.y < mBox.getMinimum().y)
{
mBox.setMinimumY(v.y);
}
if (v.z < mBox.getMinimum().z)
{
mBox.setMinimumZ(v.z);
}
if (v.x > mBox.getMaximum().x)
{
mBox.setMaximumX(v.x);
}
if (v.y > mBox.getMaximum().y)
{
mBox.setMaximumY(v.y);
}
if (v.z > mBox.getMaximum().z)
{
mBox.setMaximumZ(v.z);
}
}
}
else
{
i = mIndexMap[v];
}
mIndices.push_back(i);
}
public:
static inline 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
)
{
manual->position(c0);
manual->position(c1);
manual->position(c2);
manual->position(c3);
manual->position(c4);
manual->position(c5);
manual->position(c6);
manual->position(c7);
manual->index(baseIndex + 0); manual->index(baseIndex + 1);
manual->index(baseIndex + 1); manual->index(baseIndex + 2);
manual->index(baseIndex + 2); manual->index(baseIndex + 3);
manual->index(baseIndex + 3); manual->index(baseIndex + 0);
manual->index(baseIndex + 4); manual->index(baseIndex + 5);
manual->index(baseIndex + 5); manual->index(baseIndex + 6);
manual->index(baseIndex + 6); manual->index(baseIndex + 7);
manual->index(baseIndex + 7); manual->index(baseIndex + 4);
manual->index(baseIndex + 0); manual->index(baseIndex + 4);
manual->index(baseIndex + 1); manual->index(baseIndex + 5);
manual->index(baseIndex + 2); manual->index(baseIndex + 6);
manual->index(baseIndex + 3); manual->index(baseIndex + 7);
baseIndex += 8;
}
MeshBuilder(void);
inline void addTriangle(const Vector3 &v0, const Vector3 &n0, const Vector3 &v1, const Vector3 &n1, const Vector3 &v2, const Vector3 &n2)
{
addVertex(Vertex(v0, n0));
addVertex(Vertex(v1, n1));
addVertex(Vertex(v2, n2));
}
size_t generateBuffers(RenderOperation &operation);
Entity* generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material);
AxisAlignedBox getBoundingBox(void);
void executeCallback(MeshBuilderCallback *callback, const SimpleRenderable *simpleRenderable, size_t level, int inProcess) const;
};
}
}
#endif
Ogre::Vector3::z
Real z
Definition: OgreVector3.h:54
Ogre::AxisAlignedBox::setMaximumY
void setMaximumY(Real y)
Definition: OgreAxisAlignedBox.h:237
Ogre::Volume::MeshBuilderCallback
Callback class when the user needs information about the triangles of chunks of a LOD level...
Definition: OgreVolumeMeshBuilder.h:110
Ogre::Volume::MeshBuilder::UMapVertexIndex
map< Vertex, size_t >::type UMapVertexIndex
Map to get a vertex index.
Definition: OgreVolumeMeshBuilder.h:140
Ogre::Volume::MeshBuilder::mBox
AxisAlignedBox mBox
Holds the bounding box.
Definition: OgreVolumeMeshBuilder.h:150
OgreAxisAlignedBox.h
OgreVector3.h
Ogre::AxisAlignedBox::getMaximum
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
Definition: OgreAxisAlignedBox.h:165
Ogre::Volume::MeshBuilder::mBoxInit
bool mBoxInit
Holds whether the initial bounding box has been set.
Definition: OgreVolumeMeshBuilder.h:153
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
OgreSimpleRenderable.h
Ogre::Volume::Vertex::Vertex
Vertex()
Definition: OgreVolumeMeshBuilder.h:76
Ogre::Volume::MeshBuilderCallback::~MeshBuilderCallback
virtual ~MeshBuilderCallback()
Definition: OgreVolumeMeshBuilder.h:113
Ogre::Volume::MeshBuilder::MAIN_BINDING
static const unsigned short MAIN_BINDING
The buffer binding.
Definition: OgreVolumeMeshBuilder.h:137
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::ManualObject
Class providing a much simplified interface to generating manual objects with custom geometry...
Definition: OgreManualObject.h:106
Ogre::Volume::MeshBuilder::mIndices
VecIndices mIndices
Holds the indices of the mesh.
Definition: OgreVolumeMeshBuilder.h:147
Ogre::AxisAlignedBox::setMinimumZ
void setMinimumZ(Real z)
Definition: OgreAxisAlignedBox.h:208
Ogre::AxisAlignedBox::setMaximumZ
void setMaximumZ(Real z)
Definition: OgreAxisAlignedBox.h:242
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
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
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::AxisAlignedBox::setMinimumY
void setMinimumY(Real y)
Definition: OgreAxisAlignedBox.h:203
Ogre::Vector3::y
Real y
Definition: OgreVector3.h:54
Ogre::Volume::Vertex::nX
Real nX
X component of the normal.
Definition: OgreVolumeMeshBuilder.h:57
OgreRenderOperation.h
Ogre::Volume::Vertex::nZ
Real nZ
Z component of the normal.
Definition: OgreVolumeMeshBuilder.h:63
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
OgreVolumePrerequisites.h
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::Vertex
Lightweight struct to represent a mesh vertex.
Definition: OgreVolumeMeshBuilder.h:45
Ogre::Volume::MeshBuilder::mIndexMap
UMapVertexIndex mIndexMap
Definition: OgreVolumeMeshBuilder.h:141
Ogre::Volume::VecIndices
vector< size_t >::type VecIndices
To hold indices.
Definition: OgreVolumeMeshBuilder.h:105
OgreSceneManager.h
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::Volume::Vertex
struct _OgreVolumeExport Ogre::Volume::Vertex Vertex
Lightweight struct to represent a mesh vertex.
Ogre::AxisAlignedBox::setExtents
void setExtents(const Vector3 &min, const Vector3 &max)
Sets both minimum and maximum extents at once.
Definition: OgreAxisAlignedBox.h:249
Ogre::Vector3::x
Real x
Definition: OgreVector3.h:54
Ogre
Definition: OgreAndroidLogListener.h:34
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::ManualObject::position
virtual void position(const Vector3 &pos)
Add a vertex position, starting a new vertex at the same time.
Ogre::vector
Definition: OgrePrerequisites.h:491
OgreManualObject.h
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::RenderOperation
&#39;New&#39; rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::Entity
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::Volume::operator==
bool _OgreVolumeExport operator==(Vertex const &a, Vertex const &b)
== operator for two vertices.
Ogre::Volume::VecVertex
vector< Vertex >::type VecVertex
To hold vertices.
Definition: OgreVolumeMeshBuilder.h:101
Ogre::Volume::Vertex::Vertex
Vertex(const Vector3 &v, const Vector3 &n)
Convenience constructor.
Definition: OgreVolumeMeshBuilder.h:71
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
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::AxisAlignedBox::getMinimum
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
Definition: OgreAxisAlignedBox.h:150
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::SimpleRenderable
Simple implementation of MovableObject and Renderable for single-part custom objects.
Definition: OgreSimpleRenderable.h:50
Ogre::Volume::MeshBuilder::mVertices
VecVertex mVertices
Holds the vertices of the mesh.
Definition: OgreVolumeMeshBuilder.h:144
Ogre::Volume::operator<
bool _OgreVolumeExport operator<(const Vector3 &a, const Vector3 &b)
A less operator.
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Volume::MeshBuilder
Class to build up a mesh with vertices and indices.
Definition: OgreVolumeMeshBuilder.h:132
Ogre::Volume::Vertex::nY
Real nY
Y component of the normal.
Definition: OgreVolumeMeshBuilder.h:60

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.