00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Ogre_Volume_Chunk_H__ 00029 #define __Ogre_Volume_Chunk_H__ 00030 00031 #include "OgreSimpleRenderable.h" 00032 #include "OgreSceneNode.h" 00033 #include "OgreResourceGroupManager.h" 00034 #include "OgreFrameListener.h" 00035 00036 #include "OgreVolumePrerequisites.h" 00037 #include "OgreVolumeChunkHandler.h" 00038 #include "OgreVolumeSource.h" 00039 #include "OgreVolumeOctreeNode.h" 00040 #include "OgreVolumeDualGridGenerator.h" 00041 #include "OgreVolumeMeshBuilder.h" 00042 00043 00044 namespace Ogre { 00045 namespace Volume { 00046 00047 class ChunkHandler; 00048 00051 typedef struct ChunkParameters 00052 { 00054 SceneManager *sceneManager; 00055 00057 Source *src; 00058 00060 Real baseError; 00061 00063 Real errorMultiplicator; 00064 00066 bool createOctreeVisualization; 00067 00069 bool createDualGridVisualization; 00070 00072 Real skirtFactor; 00073 00075 MeshBuilderCallback *lodCallback; 00076 00078 Real scale; 00079 00081 Real maxScreenSpaceError; 00082 00084 size_t createGeometryFromLevel; 00085 00087 Vector3 updateFrom; 00088 00090 Vector3 updateTo; 00091 00093 bool async; 00094 00097 ChunkParameters(void) : 00098 sceneManager(0), src(0), baseError((Real)0.0), errorMultiplicator((Real)1.0), createOctreeVisualization(false), 00099 createDualGridVisualization(false), skirtFactor(0), lodCallback(0), scale((Real)1.0), maxScreenSpaceError(0), createGeometryFromLevel(0), 00100 updateFrom(Vector3::ZERO), updateTo(Vector3::ZERO), async(false) 00101 { 00102 } 00103 } ChunkParameters; 00104 00107 typedef struct ChunkTreeSharedData 00108 { 00110 bool octreeVisible; 00111 00113 bool dualGridVisible; 00114 00116 bool volumeVisible; 00117 00119 int chunksBeingProcessed; 00120 00122 ChunkParameters *parameters; 00123 00126 ChunkTreeSharedData(const ChunkParameters *params) : octreeVisible(false), dualGridVisible(false), volumeVisible(true), chunksBeingProcessed(0) 00127 { 00128 this->parameters = new ChunkParameters(*params); 00129 } 00130 00133 ~ChunkTreeSharedData(void) 00134 { 00135 delete parameters; 00136 } 00137 00138 } ChunkTreeSharedData; 00139 00142 class _OgreVolumeExport Chunk : public SimpleRenderable, public FrameListener 00143 { 00144 00146 friend class ChunkHandler; 00147 00148 protected: 00149 00151 static ChunkHandler mChunkHandler; 00152 00154 SceneNode *mNode; 00155 00157 Real mError; 00158 00160 Entity *mDualGrid; 00161 00163 Entity *mOctree; 00164 00166 Chunk **mChildren; 00167 00169 bool mInvisible; 00170 00172 bool isRoot; 00173 00175 ChunkTreeSharedData *mShared; 00176 00193 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); 00194 00204 virtual bool contributesToVolumeMesh(const Vector3 &from, const Vector3 &to) const; 00205 00222 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); 00223 00240 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); 00241 00256 virtual void prepareGeometry(size_t level, OctreeNode *root, DualGridGenerator *dualGridGenerator, MeshBuilder *meshBuilder, const Vector3 &totalFrom, const Vector3 &totalTo); 00257 00270 virtual void loadGeometry(MeshBuilder *meshBuilder, DualGridGenerator *dualGridGenerator, OctreeNode *root, size_t level, bool isUpdate); 00271 00278 inline void setChunkVisible(const bool visible, const bool applyToChildren) 00279 { 00280 if (mInvisible) 00281 { 00282 return; 00283 } 00284 if (mShared->volumeVisible) 00285 { 00286 mVisible = visible; 00287 } 00288 if (mOctree) 00289 { 00290 mOctree->setVisible(mShared->octreeVisible && visible); 00291 } 00292 if (mDualGrid) 00293 { 00294 mDualGrid->setVisible(mShared->dualGridVisible && visible); 00295 } 00296 if (applyToChildren && mChildren) 00297 { 00298 mChildren[0]->setChunkVisible(visible, applyToChildren); 00299 if (mChildren[1]) 00300 { 00301 mChildren[1]->setChunkVisible(visible, applyToChildren); 00302 mChildren[2]->setChunkVisible(visible, applyToChildren); 00303 mChildren[3]->setChunkVisible(visible, applyToChildren); 00304 mChildren[4]->setChunkVisible(visible, applyToChildren); 00305 mChildren[5]->setChunkVisible(visible, applyToChildren); 00306 mChildren[6]->setChunkVisible(visible, applyToChildren); 00307 mChildren[7]->setChunkVisible(visible, applyToChildren); 00308 } 00309 } 00310 } 00311 00312 public: 00313 00315 static const String MOVABLE_TYPE_NAME; 00316 00319 Chunk(void); 00320 00323 virtual ~Chunk(void); 00324 00327 virtual const String& getMovableType(void) const; 00328 00331 virtual Real getSquaredViewDepth(const Camera* camera) const; 00332 00335 virtual Real getBoundingRadius() const; 00336 00349 virtual void load(SceneNode *parent, const Vector3 &from, const Vector3 &to, size_t level, const ChunkParameters *parameters); 00350 00367 virtual void load(SceneNode *parent, SceneManager *sceneManager, const String& filename, bool validSourceResult = false, MeshBuilderCallback *lodCallback = 0, const String& resourceGroup = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 00368 00373 virtual void setDualGridVisible(const bool visible); 00374 00380 virtual bool getDualGridVisible(void) const; 00381 00386 virtual void setOctreeVisible(const bool visible); 00387 00393 virtual bool getOctreeVisible(void) const; 00394 00399 virtual void setVolumeVisible(const bool visible); 00400 00405 virtual bool getVolumeVisible(void) const; 00406 00409 virtual bool frameStarted(const FrameEvent& evt); 00410 00415 virtual Chunk* createInstance(void); 00416 00420 virtual void setMaterial(const String& matName); 00421 00430 virtual void setMaterialOfLevel(size_t level, const String& matName); 00431 00434 typedef vector<const Chunk*>::type VecChunk; 00435 00443 virtual void getChunksOfLevel(const size_t level, VecChunk &result) const; 00444 00449 ChunkParameters* getChunkParameters(void); 00450 00451 }; 00452 } 00453 } 00454 00455 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48