OgreVolumeChunk.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_Chunk_H__
#define __Ogre_Volume_Chunk_H__
#include "OgreSimpleRenderable.h"
#include "OgreSceneNode.h"
#include "OgreResourceGroupManager.h"
#include "OgreFrameListener.h"
#include "OgreVolumePrerequisites.h"
#include "OgreVolumeChunkHandler.h"
#include "OgreVolumeSource.h"
#include "OgreVolumeOctreeNode.h"
#include "OgreVolumeDualGridGenerator.h"
#include "OgreVolumeMeshBuilder.h"
namespace Ogre {
namespace Volume {
class ChunkHandler;
typedef struct ChunkParameters
{
SceneManager *sceneManager;
Source *src;
Real baseError;
Real errorMultiplicator;
bool createOctreeVisualization;
bool createDualGridVisualization;
Real skirtFactor;
MeshBuilderCallback *lodCallback;
Real scale;
Real maxScreenSpaceError;
size_t createGeometryFromLevel;
Vector3 updateFrom;
Vector3 updateTo;
bool async;
ChunkParameters(void) :
sceneManager(0), src(0), baseError((Real)0.0), errorMultiplicator((Real)1.0), createOctreeVisualization(false),
createDualGridVisualization(false), skirtFactor(0), lodCallback(0), scale((Real)1.0), maxScreenSpaceError(0), createGeometryFromLevel(0),
updateFrom(Vector3::ZERO), updateTo(Vector3::ZERO), async(false)
{
}
} ChunkParameters;
typedef struct ChunkTreeSharedData
{
bool octreeVisible;
bool dualGridVisible;
bool volumeVisible;
int chunksBeingProcessed;
ChunkParameters *parameters;
ChunkTreeSharedData(const ChunkParameters *params) : octreeVisible(false), dualGridVisible(false), volumeVisible(true), chunksBeingProcessed(0)
{
this->parameters = new ChunkParameters(*params);
}
~ChunkTreeSharedData(void)
{
delete parameters;
}
} ChunkTreeSharedData;
class _OgreVolumeExport Chunk : public SimpleRenderable, public FrameListener
{
friend class ChunkHandler;
protected:
static ChunkHandler mChunkHandler;
SceneNode *mNode;
Real mError;
Entity *mDualGrid;
Entity *mOctree;
Chunk **mChildren;
bool mInvisible;
bool isRoot;
ChunkTreeSharedData *mShared;
virtual void loadChunk(SceneNode *parent, const Vector3 &from, const Vector3 &to, const Vector3 &totalFrom, const Vector3 &totalTo, const size_t level, const size_t maxLevels);
virtual bool contributesToVolumeMesh(const Vector3 &from, const Vector3 &to) const;
virtual void loadChildren(SceneNode *parent, const Vector3 &from, const Vector3 &to, const Vector3 &totalFrom, const Vector3 &totalTo, const size_t level, const size_t maxLevels);
virtual void doLoad(SceneNode *parent, const Vector3 &from, const Vector3 &to, const Vector3 &totalFrom, const Vector3 &totalTo, const size_t level, const size_t maxLevels);
virtual void prepareGeometry(size_t level, OctreeNode *root, DualGridGenerator *dualGridGenerator, MeshBuilder *meshBuilder, const Vector3 &totalFrom, const Vector3 &totalTo);
virtual void loadGeometry(MeshBuilder *meshBuilder, DualGridGenerator *dualGridGenerator, OctreeNode *root, size_t level, bool isUpdate);
inline void setChunkVisible(const bool visible, const bool applyToChildren)
{
if (mInvisible)
{
return;
}
if (mShared->volumeVisible)
{
mVisible = visible;
}
if (mOctree)
{
mOctree->setVisible(mShared->octreeVisible && visible);
}
if (mDualGrid)
{
mDualGrid->setVisible(mShared->dualGridVisible && visible);
}
if (applyToChildren && mChildren)
{
mChildren[0]->setChunkVisible(visible, applyToChildren);
if (mChildren[1])
{
mChildren[1]->setChunkVisible(visible, applyToChildren);
mChildren[2]->setChunkVisible(visible, applyToChildren);
mChildren[3]->setChunkVisible(visible, applyToChildren);
mChildren[4]->setChunkVisible(visible, applyToChildren);
mChildren[5]->setChunkVisible(visible, applyToChildren);
mChildren[6]->setChunkVisible(visible, applyToChildren);
mChildren[7]->setChunkVisible(visible, applyToChildren);
}
}
}
public:
static const String MOVABLE_TYPE_NAME;
Chunk(void);
virtual ~Chunk(void);
virtual const String& getMovableType(void) const;
virtual Real getSquaredViewDepth(const Camera* camera) const;
virtual Real getBoundingRadius() const;
virtual void load(SceneNode *parent, const Vector3 &from, const Vector3 &to, size_t level, const ChunkParameters *parameters);
virtual void load(SceneNode *parent, SceneManager *sceneManager, const String& filename, bool validSourceResult = false, MeshBuilderCallback *lodCallback = 0, const String& resourceGroup = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
virtual void setDualGridVisible(const bool visible);
virtual bool getDualGridVisible(void) const;
virtual void setOctreeVisible(const bool visible);
virtual bool getOctreeVisible(void) const;
virtual void setVolumeVisible(const bool visible);
virtual bool getVolumeVisible(void) const;
virtual bool frameStarted(const FrameEvent& evt);
virtual Chunk* createInstance(void);
virtual void setMaterial(const String& matName);
virtual void setMaterialOfLevel(size_t level, const String& matName);
typedef vector<const Chunk*>::type VecChunk;
virtual void getChunksOfLevel(const size_t level, VecChunk &result) const;
ChunkParameters* getChunkParameters(void);
};
}
}
#endif
Ogre::Volume::Chunk::mChunkHandler
static ChunkHandler mChunkHandler
To handle the WorkQueue.
Definition: OgreVolumeChunk.h:151
Ogre::Volume::ChunkTreeSharedData::~ChunkTreeSharedData
~ChunkTreeSharedData(void)
Destructor.
Definition: OgreVolumeChunk.h:133
Ogre::Volume::MeshBuilderCallback
Callback class when the user needs information about the triangles of chunks of a LOD level...
Definition: OgreVolumeMeshBuilder.h:110
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::Volume::ChunkTreeSharedData::dualGridVisible
bool dualGridVisible
Flag whether the dualgrid is visible or not.
Definition: OgreVolumeChunk.h:113
Ogre::Volume::Chunk::setChunkVisible
void setChunkVisible(const bool visible, const bool applyToChildren)
Sets the visibility of this chunk.
Definition: OgreVolumeChunk.h:278
Ogre::Volume::Chunk::mChildren
Chunk ** mChildren
The more detailed children chunks.
Definition: OgreVolumeChunk.h:166
Ogre::Volume::Chunk::mNode
SceneNode * mNode
To attach this node to.
Definition: OgreVolumeChunk.h:154
Ogre::Volume::ChunkParameters::errorMultiplicator
Real errorMultiplicator
The error multiplicator per LOD level with 1.0 as default.
Definition: OgreVolumeChunk.h:63
Ogre::Volume::ChunkParameters::createOctreeVisualization
bool createOctreeVisualization
Whether to create the octree debug visualization entity with false as default.
Definition: OgreVolumeChunk.h:66
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::Chunk::mShared
ChunkTreeSharedData * mShared
Holds some shared data among all chunks of the tree.
Definition: OgreVolumeChunk.h:175
OgreSimpleRenderable.h
Ogre::Volume::ChunkParameters
Parameters for loading the volume.
Definition: OgreVolumeChunk.h:51
Ogre::SceneNode
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
static String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
Definition: OgreResourceGroupManager.h:266
OgreFrameListener.h
Ogre::Volume::ChunkParameters::sceneManager
SceneManager * sceneManager
The scenemanager to construct the entity with.
Definition: OgreVolumeChunk.h:54
Ogre::Volume::ChunkTreeSharedData
Internal shared values of the chunks which are equal in the whole tree.
Definition: OgreVolumeChunk.h:107
Ogre::Volume::Chunk::mOctree
Entity * mOctree
The debug visualization of the octree.
Definition: OgreVolumeChunk.h:163
Ogre::Volume::ChunkParameters::updateFrom
Vector3 updateFrom
If an existing chunktree is to be partially updated, set this to the back lower left point of the (su...
Definition: OgreVolumeChunk.h:87
OgreVolumeDualGridGenerator.h
Ogre::Volume::ChunkHandler
Handles the WorkQueue management of the chunks.
Definition: OgreVolumeChunkHandler.h:90
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::Chunk::mError
Real mError
Holds the error associated with this chunk.
Definition: OgreVolumeChunk.h:157
Ogre::Volume::Chunk
A single volume chunk mesh.
Definition: OgreVolumeChunk.h:142
Ogre::Volume::Chunk::MOVABLE_TYPE_NAME
static const String MOVABLE_TYPE_NAME
The type name.
Definition: OgreVolumeChunk.h:315
Ogre::Volume::ChunkParameters::updateTo
Vector3 updateTo
If an existing chunktree is to be partially updated, set this to the front upper right point of the (...
Definition: OgreVolumeChunk.h:90
Ogre::Volume::ChunkTreeSharedData::ChunkTreeSharedData
ChunkTreeSharedData(const ChunkParameters *params)
Constructor.
Definition: OgreVolumeChunk.h:126
Ogre::Volume::ChunkParameters::skirtFactor
Real skirtFactor
Factor for the skirt length generation.
Definition: OgreVolumeChunk.h:72
Ogre::MovableObject::setVisible
virtual void setVisible(bool visible)
Tells this object whether to be visible or not, if it has a renderable component. ...
Ogre::Volume::ChunkParameters::maxScreenSpaceError
Real maxScreenSpaceError
The maximum accepted screen space error when choosing the LOD levels to render.
Definition: OgreVolumeChunk.h:81
OgreVolumeOctreeNode.h
Ogre::Volume::ChunkParameters::ChunkParameters
ChunkParameters(void)
Constructor.
Definition: OgreVolumeChunk.h:97
Ogre::FrameEvent
Struct containing information about a frame event.
Definition: OgreFrameListener.h:44
Ogre::Volume::ChunkParameters::lodCallback
MeshBuilderCallback * lodCallback
Callback for a specific LOD level.
Definition: OgreVolumeChunk.h:75
Ogre::Volume::ChunkParameters::createDualGridVisualization
bool createDualGridVisualization
Whether to create the dualgrid debug visualization entity with false as default.
Definition: OgreVolumeChunk.h:69
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
OgreVolumePrerequisites.h
Ogre::Volume::ChunkParameters::src
Source * src
The volume source.
Definition: OgreVolumeChunk.h:57
Ogre::Volume::ChunkTreeSharedData::parameters
ChunkParameters * parameters
The parameters with which the chunktree got loaded.
Definition: OgreVolumeChunk.h:122
OgreVolumeSource.h
Ogre::Volume::Chunk::mDualGrid
Entity * mDualGrid
Holds the dualgrid debug visualization.
Definition: OgreVolumeChunk.h:160
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Ogre::Volume::ChunkParameters::baseError
Real baseError
The smallest allowed geometric error of the highest LOD.
Definition: OgreVolumeChunk.h:60
Ogre::Volume::ChunkParameters::async
bool async
Whether to load the chunks async. if set to false, the call to load waits for the whole chunk...
Definition: OgreVolumeChunk.h:93
Ogre::Volume::OctreeNode
A node in the volume octree.
Definition: OgreVolumeOctreeNode.h:45
Ogre::Volume::DualGridGenerator
Class for the generation of the DualGrid.
Definition: OgreVolumeDualGridGenerator.h:67
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::Chunk::isRoot
bool isRoot
Whether this chunk is the root of the tree.
Definition: OgreVolumeChunk.h:172
Ogre::Volume::Chunk::mInvisible
bool mInvisible
Flag whether this node will never be shown.
Definition: OgreVolumeChunk.h:169
Ogre::Volume::ChunkParameters::createGeometryFromLevel
size_t createGeometryFromLevel
The first LOD level to create geometry for. For scenarios where the lower levels won&#39;t be visible any...
Definition: OgreVolumeChunk.h:84
Ogre::Entity
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
OgreResourceGroupManager.h
Ogre::Volume::ChunkTreeSharedData
struct Ogre::Volume::ChunkTreeSharedData ChunkTreeSharedData
Internal shared values of the chunks which are equal in the whole tree.
Ogre::Volume::Source
Abstract class defining the density function.
Definition: OgreVolumeSource.h:41
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::Volume::ChunkParameters::scale
Real scale
The scale of the volume with 1.0 as default.
Definition: OgreVolumeChunk.h:78
Ogre::Volume::Chunk::VecChunk
vector< const Chunk * >::type VecChunk
A list of Chunks.
Definition: OgreVolumeChunk.h:434
OgreSceneNode.h
Ogre::Volume::ChunkTreeSharedData::octreeVisible
bool octreeVisible
Flag whether the octree is visible or not.
Definition: OgreVolumeChunk.h:110
OgreVolumeChunkHandler.h
Ogre::Volume::ChunkTreeSharedData::volumeVisible
bool volumeVisible
Another visibility flag to be user setable.
Definition: OgreVolumeChunk.h:116
_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::FrameListener
A interface class defining a listener which can be used to receive notifications of frame events...
Definition: OgreFrameListener.h:79
Ogre::Volume::ChunkTreeSharedData::chunksBeingProcessed
int chunksBeingProcessed
The amount of chunks being processed (== loading).
Definition: OgreVolumeChunk.h:119
OgreVolumeMeshBuilder.h
Ogre::Volume::MeshBuilder
Class to build up a mesh with vertices and indices.
Definition: OgreVolumeMeshBuilder.h:132

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