OgreVolumeChunk.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_Chunk_H__
29 #define __Ogre_Volume_Chunk_H__
30 
31 #include "OgreSimpleRenderable.h"
32 #include "OgreSceneNode.h"
34 #include "OgreFrameListener.h"
35 
37 #include "OgreVolumeChunkHandler.h"
38 #include "OgreVolumeSource.h"
39 #include "OgreVolumeOctreeNode.h"
41 #include "OgreVolumeMeshBuilder.h"
42 
43 
44 namespace Ogre {
45 namespace Volume {
46 
47  class ChunkHandler;
48 
51  typedef struct ChunkParameters
52  {
55 
58 
61 
64 
67 
70 
73 
76 
79 
82 
85 
88 
91 
93  bool async;
94 
100  updateFrom(Vector3::ZERO), updateTo(Vector3::ZERO), async(false)
101  {
102  }
104 
107  typedef struct ChunkTreeSharedData
108  {
111 
114 
117 
120 
123 
127  {
128  this->parameters = new ChunkParameters(*params);
129  }
130 
134  {
135  delete parameters;
136  }
137 
139 
143  {
144 
146  friend class ChunkHandler;
147 
148  protected:
149 
152 
155 
158 
161 
164 
167 
170 
172  bool isRoot;
173 
176 
193  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);
194 
204  virtual bool contributesToVolumeMesh(const Vector3 &from, const Vector3 &to) const;
205 
222  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);
223 
240  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);
241 
256  virtual void prepareGeometry(size_t level, OctreeNode *root, DualGridGenerator *dualGridGenerator, MeshBuilder *meshBuilder, const Vector3 &totalFrom, const Vector3 &totalTo);
257 
270  virtual void loadGeometry(MeshBuilder *meshBuilder, DualGridGenerator *dualGridGenerator, OctreeNode *root, size_t level, bool isUpdate);
271 
278  inline void setChunkVisible(const bool visible, const bool applyToChildren)
279  {
280  if (mInvisible)
281  {
282  return;
283  }
284  if (mShared->volumeVisible)
285  {
286  mVisible = visible;
287  }
288  if (mOctree)
289  {
290  mOctree->setVisible(mShared->octreeVisible && visible);
291  }
292  if (mDualGrid)
293  {
294  mDualGrid->setVisible(mShared->dualGridVisible && visible);
295  }
296  if (applyToChildren && mChildren)
297  {
298  mChildren[0]->setChunkVisible(visible, applyToChildren);
299  if (mChildren[1])
300  {
301  mChildren[1]->setChunkVisible(visible, applyToChildren);
302  mChildren[2]->setChunkVisible(visible, applyToChildren);
303  mChildren[3]->setChunkVisible(visible, applyToChildren);
304  mChildren[4]->setChunkVisible(visible, applyToChildren);
305  mChildren[5]->setChunkVisible(visible, applyToChildren);
306  mChildren[6]->setChunkVisible(visible, applyToChildren);
307  mChildren[7]->setChunkVisible(visible, applyToChildren);
308  }
309  }
310  }
311 
312  public:
313 
315  static const String MOVABLE_TYPE_NAME;
316 
319  Chunk(void);
320 
323  virtual ~Chunk(void);
324 
327  virtual const String& getMovableType(void) const;
328 
331  virtual Real getSquaredViewDepth(const Camera* camera) const;
332 
335  virtual Real getBoundingRadius() const;
336 
349  virtual void load(SceneNode *parent, const Vector3 &from, const Vector3 &to, size_t level, const ChunkParameters *parameters);
350 
367  virtual void load(SceneNode *parent, SceneManager *sceneManager, const String& filename, bool validSourceResult = false, MeshBuilderCallback *lodCallback = 0, const String& resourceGroup = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
368 
373  virtual void setDualGridVisible(const bool visible);
374 
380  virtual bool getDualGridVisible(void) const;
381 
386  virtual void setOctreeVisible(const bool visible);
387 
393  virtual bool getOctreeVisible(void) const;
394 
399  virtual void setVolumeVisible(const bool visible);
400 
405  virtual bool getVolumeVisible(void) const;
406 
409  virtual bool frameStarted(const FrameEvent& evt);
410 
415  virtual Chunk* createInstance(void);
416 
420  virtual void setMaterial(const String& matName);
421 
430  virtual void setMaterialOfLevel(size_t level, const String& matName);
431 
435 
443  virtual void getChunksOfLevel(const size_t level, VecChunk &result) const;
444 
450 
451  };
452 }
453 }
454 
455 #endif
#define _OgreVolumeExport
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:83
A interface class defining a listener which can be used to receive notifications of frame events.
virtual void setVisible(bool visible)
Tells this object whether to be visible or not, if it has a renderable component.
static String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
Manages the organisation and rendering of a 'scene' i.e.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:59
Simple implementation of MovableObject and Renderable for single-part custom objects.
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
Handles the WorkQueue management of the chunks.
A single volume chunk mesh.
virtual Chunk * createInstance(void)
Overridable factory method.
virtual ~Chunk(void)
Destructor.
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)
Loads the tree children of the current node.
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)
Actually loads the volume tree with all LODs.
bool mInvisible
Flag whether this node will never be shown.
virtual bool getVolumeVisible(void) const
Gets whether the volume mesh is visible.
virtual void load(SceneNode *parent, SceneManager *sceneManager, const String &filename, bool validSourceResult=false, MeshBuilderCallback *lodCallback=0, const String &resourceGroup=ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
Loads a TextureSource volume scene from a config file.
Chunk(void)
Constructor.
virtual void prepareGeometry(size_t level, OctreeNode *root, DualGridGenerator *dualGridGenerator, MeshBuilder *meshBuilder, const Vector3 &totalFrom, const Vector3 &totalTo)
Prepares the geometry of the chunk request.
bool isRoot
Whether this chunk is the root of the tree.
void setChunkVisible(const bool visible, const bool applyToChildren)
Sets the visibility of this chunk.
virtual void setMaterial(const String &matName)
Overridden from SimpleRenderable.
static ChunkHandler mChunkHandler
To handle the WorkQueue.
virtual void setDualGridVisible(const bool visible)
Shows the debug visualization entity of the dualgrid.
Entity * mOctree
The debug visualization of the octree.
SceneNode * mNode
To attach this node to.
virtual void setVolumeVisible(const bool visible)
Sets whether the volume mesh is visible.
Entity * mDualGrid
Holds the dualgrid debug visualization.
virtual Real getBoundingRadius() const
Overridden from MovableObject.
virtual void setOctreeVisible(const bool visible)
Shows the debug visualization entity of the octree.
virtual void load(SceneNode *parent, const Vector3 &from, const Vector3 &to, size_t level, const ChunkParameters *parameters)
Loads the volume mesh with all LODs.
virtual bool getDualGridVisible(void) const
Gets whether the debug visualization entity of the dualgrid is visible.
virtual void getChunksOfLevel(const size_t level, VecChunk &result) const
Gathers all visible chunks (containing triangles) of a specific LOD level.
ChunkTreeSharedData * mShared
Holds some shared data among all chunks of the tree.
virtual bool contributesToVolumeMesh(const Vector3 &from, const Vector3 &to) const
Whether the center of the given cube (from -> to) will contribute something to the total volume mesh.
virtual void setMaterialOfLevel(size_t level, const String &matName)
Sets the material of all chunks of a specific level in the tree.
vector< const Chunk * >::type VecChunk
A list of Chunks.
virtual bool frameStarted(const FrameEvent &evt)
Overridden from FrameListener.
ChunkParameters * getChunkParameters(void)
Gets the parameters with which the chunktree got loaded.
Real mError
Holds the error associated with this chunk.
virtual Real getSquaredViewDepth(const Camera *camera) const
Overridden from Renderable.
virtual const String & getMovableType(void) const
Overridden from MovableObject.
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)
Loads a single chunk of the tree.
virtual void loadGeometry(MeshBuilder *meshBuilder, DualGridGenerator *dualGridGenerator, OctreeNode *root, size_t level, bool isUpdate)
Loads the actual geometry when the processing is done.
Chunk ** mChildren
The more detailed children chunks.
virtual bool getOctreeVisible(void) const
Gets whether the debug visualization entity of the octree is visible.
static const String MOVABLE_TYPE_NAME
The type name.
Class for the generation of the DualGrid.
Callback class when the user needs information about the triangles of chunks of a LOD level.
Class to build up a mesh with vertices and indices.
A node in the volume octree.
Abstract class defining the density function.
struct Ogre::Volume::ChunkParameters ChunkParameters
Parameters for loading the volume.
struct Ogre::Volume::ChunkTreeSharedData ChunkTreeSharedData
Internal shared values of the chunks which are equal in the whole tree.
float Real
Software floating point type.
_StringBase String
Struct containing information about a frame event.
Parameters for loading the volume.
bool createOctreeVisualization
Whether to create the octree debug visualization entity with false as default.
Source * src
The volume source.
SceneManager * sceneManager
The scenemanager to construct the entity with.
Real baseError
The smallest allowed geometric error of the highest LOD.
bool createDualGridVisualization
Whether to create the dualgrid debug visualization entity with false as default.
MeshBuilderCallback * lodCallback
Callback for a specific LOD level.
size_t createGeometryFromLevel
The first LOD level to create geometry for. For scenarios where the lower levels won't be visible any...
bool async
Whether to load the chunks async. if set to false, the call to load waits for the whole chunk....
Real skirtFactor
Factor for the skirt length generation.
Real errorMultiplicator
The error multiplicator per LOD level with 1.0 as default.
ChunkParameters(void)
Constructor.
Real maxScreenSpaceError
The maximum accepted screen space error when choosing the LOD levels to render.
Vector3 updateFrom
If an existing chunktree is to be partially updated, set this to the back lower left point of the (su...
Real scale
The scale of the volume with 1.0 as default.
Vector3 updateTo
If an existing chunktree is to be partially updated, set this to the front upper right point of the (...
Internal shared values of the chunks which are equal in the whole tree.
int chunksBeingProcessed
The amount of chunks being processed (== loading).
bool volumeVisible
Another visibility flag to be user setable.
bool dualGridVisible
Flag whether the dualgrid is visible or not.
bool octreeVisible
Flag whether the octree is visible or not.
ChunkTreeSharedData(const ChunkParameters *params)
Constructor.
ChunkParameters * parameters
The parameters with which the chunktree got loaded.
std::vector< T, A > type

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