1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of the GameTools Project
|
---|
4 | http://www.gametools.org
|
---|
5 |
|
---|
6 | Author: Martin Szydlowski
|
---|
7 | -----------------------------------------------------------------------------
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef _KdTreeSceneManager_H__
|
---|
11 | #define _KdTreeSceneManager_H__
|
---|
12 |
|
---|
13 | #include <OgreSceneManager.h>
|
---|
14 | #include <VisibilityManager.h>
|
---|
15 | #include <ViewCellsManager.h>
|
---|
16 |
|
---|
17 | #include "OgreKdTree.h"
|
---|
18 | #include "OgreKdTreeCamera.h"
|
---|
19 | #include "OgreKdTreeHierarchyInterface.h"
|
---|
20 |
|
---|
21 | #define KDTREE_MAX_DEPTH 12
|
---|
22 |
|
---|
23 | namespace Ogre
|
---|
24 | {
|
---|
25 |
|
---|
26 | class KdTreeSceneNode;
|
---|
27 |
|
---|
28 | class KdTreeSceneManager : public SceneManager
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
|
---|
32 | ~KdTreeSceneManager(void);
|
---|
33 |
|
---|
34 | virtual const String& getTypeName(void) const;
|
---|
35 |
|
---|
36 | //typedef std::list<KdTreeSceneNode *> NodeList;
|
---|
37 | //typedef std::list<WireBoundingBox *> BoxList;
|
---|
38 |
|
---|
39 | /************************************************************************/
|
---|
40 | /* Functions overridden form SceneManager for KdTree */
|
---|
41 | /************************************************************************/
|
---|
42 |
|
---|
43 | /** Override from Scenemanager to create Camera as instance of KdTreeCamera
|
---|
44 | */
|
---|
45 | virtual Camera* createCamera(const String& name);
|
---|
46 |
|
---|
47 | /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
|
---|
48 | */
|
---|
49 | virtual SceneNode* createSceneNode(void);
|
---|
50 | /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
|
---|
51 | */
|
---|
52 | virtual SceneNode* createSceneNode(const String& name);
|
---|
53 |
|
---|
54 | /** Override from Scenemanager, employ kd-tree based culling or CHC
|
---|
55 | */
|
---|
56 | virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
|
---|
57 |
|
---|
58 | virtual bool setOption(const String& strKey, const void* pValue);
|
---|
59 | virtual bool getOption(const String& strKey, void* pDestValue);
|
---|
60 |
|
---|
61 | bool getOptionValues(const String & key, StringVector &refValueList);
|
---|
62 | bool getOptionKeys(StringVector &refKeys);
|
---|
63 |
|
---|
64 | /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed)
|
---|
65 | */
|
---|
66 | virtual void clearScene();
|
---|
67 |
|
---|
68 | /************************************************************************/
|
---|
69 | /* Functions overridden from SceneManager for CHC */
|
---|
70 | /************************************************************************/
|
---|
71 |
|
---|
72 | /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
|
---|
73 | */
|
---|
74 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
75 |
|
---|
76 | /** Override from scene manager to set up culling manager
|
---|
77 | */
|
---|
78 | virtual void _updateSceneGraph(Camera* cam);
|
---|
79 |
|
---|
80 | /** Override from SceneManager, employ normal rendering or CHC
|
---|
81 | */
|
---|
82 | virtual void _renderVisibleObjects();
|
---|
83 |
|
---|
84 | /** Override pass so we can do the z-fail pass.
|
---|
85 | */
|
---|
86 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
87 |
|
---|
88 | /** Render a queue group.
|
---|
89 | Override so we can handle delayed rendering of transparent objects
|
---|
90 | */
|
---|
91 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
92 | QueuedRenderableCollection::OrganisationMode om);
|
---|
93 |
|
---|
94 | /** Override from scene manager
|
---|
95 | */
|
---|
96 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
97 | QueuedRenderableCollection::OrganisationMode om);
|
---|
98 |
|
---|
99 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
100 | */
|
---|
101 | bool validatePassForRendering(Pass* pass);
|
---|
102 |
|
---|
103 | /** Override from SceneManager because idontknow
|
---|
104 | */
|
---|
105 | void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
106 | QueuedRenderableCollection::OrganisationMode om);
|
---|
107 | void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
108 | QueuedRenderableCollection::OrganisationMode om);
|
---|
109 |
|
---|
110 |
|
---|
111 | /************************************************************************/
|
---|
112 | /* Functions which are specific to the KdTree */
|
---|
113 | /************************************************************************/
|
---|
114 |
|
---|
115 | /** Update the KdTree with the node (more or less disabled now)
|
---|
116 | */
|
---|
117 | virtual void _updateNode(KdTreeSceneNode *node); // TODO:
|
---|
118 |
|
---|
119 | /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options
|
---|
120 | */
|
---|
121 | virtual void setShowBoxes(bool showboxes);
|
---|
122 | /** Tell if show boxes is enabled - obsolete, use options
|
---|
123 | */
|
---|
124 | virtual bool getShowBoxes(void) const;
|
---|
125 |
|
---|
126 | /** Recurses the kdtree, adding any nodes intersecting with the
|
---|
127 | box/sphere/volume/ray into the given list.
|
---|
128 | It ignores the exclude scene node.
|
---|
129 | */
|
---|
130 | void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
131 | {
|
---|
132 | if (mKdTree)
|
---|
133 | mKdTree->findNodesIn(box, list, exclude);
|
---|
134 | }
|
---|
135 | void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
136 | {
|
---|
137 | if (mKdTree)
|
---|
138 | mKdTree->findNodesIn(sphere, list, exclude);
|
---|
139 | }
|
---|
140 | void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
141 | {
|
---|
142 | if (mKdTree)
|
---|
143 | mKdTree->findNodesIn(volume, list, exclude);
|
---|
144 | }
|
---|
145 | void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
146 | {
|
---|
147 | if (mKdTree)
|
---|
148 | mKdTree->findNodesIn(ray, list, exclude);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /************************************************************************/
|
---|
152 | /* Functions for PVS */
|
---|
153 | /************************************************************************/
|
---|
154 | /** Loads view cells for this particular scene.
|
---|
155 | */
|
---|
156 | bool LoadViewCells(const String &filename);
|
---|
157 |
|
---|
158 | /************************************************************************/
|
---|
159 | /* Functions for CHC */
|
---|
160 | /************************************************************************/
|
---|
161 |
|
---|
162 | /** Render a list of scenenodes
|
---|
163 | */
|
---|
164 | //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
|
---|
165 | // bool onlyShadowCasters, int leavePassesInQueue);
|
---|
166 | virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
|
---|
167 | bool onlyShadowCasters, int leavePassesInQueue);
|
---|
168 |
|
---|
169 | /** Sets the visibility manager.
|
---|
170 | @param visManager the visibility manager
|
---|
171 | */
|
---|
172 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
173 | /** See set.
|
---|
174 | */
|
---|
175 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
176 |
|
---|
177 | /** Returns pointer to visibility manager.
|
---|
178 | */
|
---|
179 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
180 |
|
---|
181 | /** Returns hierarchy interface.
|
---|
182 | */
|
---|
183 | KdTreeHierarchyInterface *GetHierarchyInterface();
|
---|
184 |
|
---|
185 | protected:
|
---|
186 | /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
|
---|
187 | */
|
---|
188 | void InitDepthPass();
|
---|
189 | /** Creates material for item buffer.
|
---|
190 | */
|
---|
191 | void InitItemBufferPass();
|
---|
192 | /** Fills render queue so that a visualization can be rendered.
|
---|
193 | */
|
---|
194 | void PrepareVisualization(Camera *cam);
|
---|
195 | /** Initialises necessary parameters for hierarchical visibility culling.
|
---|
196 | */
|
---|
197 | void InitVisibilityCulling(Camera *cam);
|
---|
198 |
|
---|
199 | /** Writes out stats into the Ogre log file.
|
---|
200 | */
|
---|
201 | void WriteLog();
|
---|
202 |
|
---|
203 | /************************************************************************/
|
---|
204 | /* Functions for PVS */
|
---|
205 | /************************************************************************/
|
---|
206 | /** Loads / unloads pvs of the view cell to set the visibility in the scene.
|
---|
207 | */
|
---|
208 | void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
|
---|
209 |
|
---|
210 | /** updates pvs in current frame.
|
---|
211 | */
|
---|
212 | void updatePvs(Camera *cam);
|
---|
213 |
|
---|
214 | /** Sets all objects invisible.
|
---|
215 | */
|
---|
216 | void SetObjectsVisible(const bool visible);
|
---|
217 |
|
---|
218 | /************************************************************************/
|
---|
219 | /* CHC-specific options & members */
|
---|
220 | /************************************************************************/
|
---|
221 | // pointer to the visibility manager
|
---|
222 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
223 |
|
---|
224 | // the hierarchy interface for CHC
|
---|
225 | KdTreeHierarchyInterface *mHierarchyInterface;
|
---|
226 |
|
---|
227 | // if hierarchical culling is currently in use
|
---|
228 | bool mIsHierarchicalCulling;
|
---|
229 |
|
---|
230 | // if a visualization of the hierarchical culling is shown
|
---|
231 | bool mShowVisualization;
|
---|
232 |
|
---|
233 | // if the culled nodes are indicated in the visualization
|
---|
234 | bool mVisualizeCulledNodes;
|
---|
235 |
|
---|
236 | // consecutive number for sub-entities
|
---|
237 | int mCurrentEntityId;
|
---|
238 |
|
---|
239 | // flag for passes which should not be deleted from queue during first traversal
|
---|
240 | int mLeavePassesInQueue;
|
---|
241 |
|
---|
242 | // if symbols for the nodes are shown in the visualization
|
---|
243 | bool mRenderNodesForViz;
|
---|
244 | // if content of the nodes is shown in the visualization
|
---|
245 | bool mRenderNodesContentForViz;
|
---|
246 | /// render transparents after the hierarchical traversal
|
---|
247 | bool mDelayRenderTransparents;
|
---|
248 |
|
---|
249 | // if transparent object are considered for item buffer visibility
|
---|
250 | bool mRenderTransparentsForItemBuffer;
|
---|
251 | // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
252 | bool mExecuteVertexProgramForAllPasses;
|
---|
253 |
|
---|
254 | // the depth pass (no lighting, just filling the depth buffer)
|
---|
255 | Pass *mDepthPass;
|
---|
256 | // use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
257 | bool mUseDepthPass;
|
---|
258 | // flag indicating if we currently render the depth pass
|
---|
259 | bool mIsDepthPassPhase;
|
---|
260 | // if depth write should be enabled
|
---|
261 | bool mEnableDepthWrite;
|
---|
262 | // if transparents are skipped during rendering
|
---|
263 | bool mSkipTransparents;
|
---|
264 | // the item buffer pass (render items color-coded)
|
---|
265 | Pass *mItemBufferPass;
|
---|
266 | // if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
267 | bool mUseItemBuffer;
|
---|
268 | // if we currently render the item buffer
|
---|
269 | bool mIsItemBufferPhase;
|
---|
270 | // delete or clear the renderqueue after each rame?
|
---|
271 | bool mDeleteQueueAfterRendering;
|
---|
272 |
|
---|
273 |
|
---|
274 | // remember visited scene nodes for viz
|
---|
275 | KdTree::NodeList mVisibleNodes;
|
---|
276 |
|
---|
277 | /************************************************************************/
|
---|
278 | /* Kd-Tree specific options & members */
|
---|
279 | /************************************************************************/
|
---|
280 | // maximum depth of the kdtree
|
---|
281 | int mMaxDepth;
|
---|
282 |
|
---|
283 | // the kdtree which holds the scene
|
---|
284 | KdTree *mKdTree;
|
---|
285 |
|
---|
286 | // if bounding boxes of kdtree nodes are shown
|
---|
287 | bool mShowBoxes;
|
---|
288 | // bounding boxes of kd nodes will be highlighted on this level of the kd tree
|
---|
289 | int mHiLiteLevel;
|
---|
290 | // if all bounding boxes shall be displayed, not only the highlighted level
|
---|
291 | bool mShowAllBoxes;
|
---|
292 | // visualize kdtree nodes or bounding boxes of objects in nodes
|
---|
293 | bool mShowNodes;
|
---|
294 |
|
---|
295 | // vis mode
|
---|
296 | bool mEnhancedVisiblity;
|
---|
297 |
|
---|
298 | // the method/algorithm used when rendering the scene
|
---|
299 | KdTree::RenderMethod mRenderMethod;
|
---|
300 |
|
---|
301 | // the method of building the tree
|
---|
302 | KdTree::BuildMethod mBuildMethod;
|
---|
303 |
|
---|
304 | /************************************************************************/
|
---|
305 | /* PVS specific options and members */
|
---|
306 | /************************************************************************/
|
---|
307 |
|
---|
308 | // The view cell manager
|
---|
309 | GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
|
---|
310 |
|
---|
311 | /// Used to assign Ogre meshes to view cell entries.
|
---|
312 | GtpVisibilityPreprocessor::ObjectContainer mObjects;
|
---|
313 |
|
---|
314 | GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
|
---|
315 | GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
|
---|
316 |
|
---|
317 | /// If view cells are loaded.
|
---|
318 | bool mViewCellsLoaded;
|
---|
319 |
|
---|
320 | /// If view cells are used.
|
---|
321 | bool mUseViewCells;
|
---|
322 |
|
---|
323 | /// if the view cells are filtered
|
---|
324 | bool mUseVisibilityFilter;
|
---|
325 | };
|
---|
326 |
|
---|
327 |
|
---|
328 |
|
---|
329 | /// Factory for KdTreeSceneManager
|
---|
330 | class KdTreeSceneManagerFactory : public SceneManagerFactory
|
---|
331 | {
|
---|
332 | protected:
|
---|
333 | void initMetaData(void) const;
|
---|
334 | GtpVisibility::VisibilityManager *visManager;
|
---|
335 | public:
|
---|
336 | KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
|
---|
337 | {
|
---|
338 | visManager = vm;
|
---|
339 | };
|
---|
340 | ~KdTreeSceneManagerFactory(void) {};
|
---|
341 | /// Factory type name
|
---|
342 | static const String FACTORY_TYPE_NAME;
|
---|
343 | SceneManager* createInstance(const String& instanceName);
|
---|
344 | void destroyInstance(SceneManager* instance);
|
---|
345 | };
|
---|
346 |
|
---|
347 | } // namespace Ogre
|
---|
348 |
|
---|
349 | #endif // _KdTreeSceneManager_H__ |
---|