OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-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_Chunk_H__
29 #define __Ogre_Volume_Chunk_H__
30 
31 #include "OgreSimpleRenderable.h"
33 #include "OgreFrameListener.h"
34 #include "OgreEntity.h"
35 
37 
38 namespace Ogre {
39 namespace Volume {
40 
41  class Source;
42  class MeshBuilderCallback;
43  class ChunkHandler;
44  class MeshBuilder;
45  class DualGridGenerator;
46  class OctreeNode;
47 
50  typedef struct ChunkParameters
51  {
54 
57 
60 
63 
66 
69 
72 
75 
78 
81 
84 
87 
90 
92  bool async;
93 
99  updateFrom(Vector3::ZERO), updateTo(Vector3::ZERO), async(false)
100  {
101  }
102  } ChunkParameters;
103 
106  typedef struct ChunkTreeSharedData
107  {
110 
113 
116 
119 
122 
126  {
127  this->parameters = new ChunkParameters(*params);
128  }
129 
133  {
134  delete parameters;
135  }
136 
138 
142  {
143 
145  friend class ChunkHandler;
146 
147  protected:
148 
151 
154 
157 
160 
163 
166 
169 
171  bool isRoot;
172 
175 
192  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);
193 
203  virtual bool contributesToVolumeMesh(const Vector3 &from, const Vector3 &to) const;
204 
221  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);
222 
239  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);
240 
255  virtual void prepareGeometry(size_t level, OctreeNode *root, DualGridGenerator *dualGridGenerator, MeshBuilder *meshBuilder, const Vector3 &totalFrom, const Vector3 &totalTo);
256 
269  virtual void loadGeometry(MeshBuilder *meshBuilder, DualGridGenerator *dualGridGenerator, OctreeNode *root, size_t level, bool isUpdate);
270 
277  inline void setChunkVisible(const bool visible, const bool applyToChildren)
278  {
279  if (mInvisible)
280  {
281  return;
282  }
283  if (mShared->volumeVisible)
284  {
285  setVisible(visible);
286  }
287  if (mOctree)
288  {
289  mOctree->setVisible(mShared->octreeVisible && visible);
290  }
291  if (mDualGrid)
292  {
293  mDualGrid->setVisible(mShared->dualGridVisible && visible);
294  }
295  if (applyToChildren && mChildren)
296  {
297  mChildren[0]->setChunkVisible(visible, applyToChildren);
298  if (mChildren[1])
299  {
300  mChildren[1]->setChunkVisible(visible, applyToChildren);
301  mChildren[2]->setChunkVisible(visible, applyToChildren);
302  mChildren[3]->setChunkVisible(visible, applyToChildren);
303  mChildren[4]->setChunkVisible(visible, applyToChildren);
304  mChildren[5]->setChunkVisible(visible, applyToChildren);
305  mChildren[6]->setChunkVisible(visible, applyToChildren);
306  mChildren[7]->setChunkVisible(visible, applyToChildren);
307  }
308  }
309  }
310 
311  public:
312 
314  static const String MOVABLE_TYPE_NAME;
315 
318  Chunk(void);
319 
322  virtual ~Chunk(void);
323 
326  virtual const String& getMovableType(void) const;
327 
330  virtual Real getSquaredViewDepth(const Camera* camera) const;
331 
334  virtual Real getBoundingRadius() const;
335 
348  virtual void load(SceneNode *parent, const Vector3 &from, const Vector3 &to, size_t level, const ChunkParameters *parameters);
349 
366  virtual void load(SceneNode *parent, SceneManager *sceneManager, const String& filename, bool validSourceResult = false, MeshBuilderCallback *lodCallback = 0, const String& resourceGroup = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
367 
372  virtual void setDualGridVisible(const bool visible);
373 
379  virtual bool getDualGridVisible(void) const;
380 
385  virtual void setOctreeVisible(const bool visible);
386 
392  virtual bool getOctreeVisible(void) const;
393 
398  virtual void setVolumeVisible(const bool visible);
399 
404  virtual bool getVolumeVisible(void) const;
405 
408  virtual bool frameStarted(const FrameEvent& evt);
409 
414  virtual Chunk* createInstance(void);
415 
419  virtual void setMaterial(const String& matName);
420 
429  virtual void setMaterialOfLevel(size_t level, const String& matName);
430 
434 
442  virtual void getChunksOfLevel(const size_t level, VecChunk &result) const;
443 
448  ChunkParameters* getChunkParameters(void);
449 
450  };
451 }
452 }
453 
454 #endif
size_t createGeometryFromLevel
The first LOD level to create geometry for. For scenarios where the lower levels won't be visible any...
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
bool isRoot
Whether this chunk is the root of the tree.
ChunkParameters(void)
Constructor.
float Real
Software floating point type.
Callback class when the user needs information about the triangles of chunks of a LOD level...
bool dualGridVisible
Flag whether the dualgrid is visible or not.
std::vector< T, A > type
bool mInvisible
Flag whether this node will never be shown.
Chunk ** mChildren
The more detailed children chunks.
Real scale
The scale of the volume with 1.0 as default.
struct Ogre::Volume::ChunkParameters ChunkParameters
Parameters for loading the volume.
Manages the organisation and rendering of a 'scene' i.e.
static String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
Simple implementation of MovableObject and Renderable for single-part custom objects.
struct Ogre::Volume::ChunkTreeSharedData ChunkTreeSharedData
Internal shared values of the chunks which are equal in the whole tree.
SceneNode * mNode
To attach this node to.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:53
A single volume chunk mesh.
Abstract class defining the density function.
Vector3 updateTo
If an existing chunktree is to be partially updated, set this to the front upper right point of the (...
Entity * mDualGrid
Holds the dualgrid debug visualization.
MeshBuilderCallback * lodCallback
Callback for a specific LOD level.
Real mError
Holds the error associated with this chunk.
Real skirtFactor
Factor for the skirt length generation.
Entity * mOctree
The debug visualization of the octree.
static ChunkHandler mChunkHandler
To handle the WorkQueue.
Real maxScreenSpaceError
The maximum accepted screen space error when choosing the LOD levels to render.
void setChunkVisible(const bool visible, const bool applyToChildren)
Sets the visibility of this chunk.
bool octreeVisible
Flag whether the octree is visible or not.
bool createOctreeVisualization
Whether to create the octree debug visualization entity with false as default.
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:81
ChunkParameters * parameters
The parameters with which the chunktree got loaded.
static const String MOVABLE_TYPE_NAME
The type name.
A interface class defining a listener which can be used to receive notifications of frame events...
Internal shared values of the chunks which are equal in the whole tree.
bool async
Whether to load the chunks async. if set to false, the call to load waits for the whole chunk...
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
int chunksBeingProcessed
The amount of chunks being processed (== loading).
Real baseError
The smallest allowed geometric error of the highest LOD.
Vector3 updateFrom
If an existing chunktree is to be partially updated, set this to the back lower left point of the (su...
A node in the volume octree.
vector< const Chunk * >::type VecChunk
A list of Chunks.
Struct containing information about a frame event.
ChunkTreeSharedData * mShared
Holds some shared data among all chunks of the tree.
_StringBase String
Definition: OgreCommon.h:53
bool createDualGridVisualization
Whether to create the dualgrid debug visualization entity with false as default.
#define _OgreVolumeExport
Source * src
The volume source.
ChunkTreeSharedData(const ChunkParameters *params)
Constructor.
Parameters for loading the volume.
bool volumeVisible
Another visibility flag to be user setable.
Class to build up a mesh with vertices and indices.
Real errorMultiplicator
The error multiplicator per LOD level with 1.0 as default.
SceneManager * sceneManager
The scenemanager to construct the entity with.
Handles the WorkQueue management of the chunks.
Class for the generation of the DualGrid.