1 | #include "OgreOctreeHierarchyInterface.h"
|
---|
2 | #include "OgreVisibilityOctreeSceneManager.h"
|
---|
3 | #include <OgreOctree.h>
|
---|
4 | #include <OgreLogManager.h>
|
---|
5 | #include <OgreStringConverter.h>
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace Ogre {
|
---|
9 |
|
---|
10 | //-----------------------------------------------------------------------
|
---|
11 | OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys):
|
---|
12 | SceneNodeHierarchyInterface(sm, rsys)
|
---|
13 | {
|
---|
14 | }
|
---|
15 | //-----------------------------------------------------------------------
|
---|
16 | void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
17 | {
|
---|
18 | ++ mNumTraversedNodes;
|
---|
19 |
|
---|
20 | Octree *octree = static_cast<Octree *>(node);
|
---|
21 |
|
---|
22 | // if we come across some renderable geometry => render it
|
---|
23 | if (!octree->mNodes.empty())
|
---|
24 | {
|
---|
25 | RenderNode(node);
|
---|
26 | }
|
---|
27 |
|
---|
28 | // if not all subtrees are empty
|
---|
29 | if (!IsLeaf(node))
|
---|
30 | {
|
---|
31 | Octree *nextChild;
|
---|
32 |
|
---|
33 | if ((nextChild = octree->mChildren[0][0][0]) != NULL)
|
---|
34 | mDistanceQueue->push(nextChild);
|
---|
35 | if ((nextChild = octree->mChildren[0][0][1]) != NULL)
|
---|
36 | mDistanceQueue->push(nextChild);
|
---|
37 | if ((nextChild = octree->mChildren[0][1][0]) != NULL)
|
---|
38 | mDistanceQueue->push(nextChild);
|
---|
39 | if ((nextChild = octree->mChildren[0][1][1]) != NULL)
|
---|
40 | mDistanceQueue->push(nextChild);
|
---|
41 | if ((nextChild = octree->mChildren[1][0][0]) != NULL)
|
---|
42 | mDistanceQueue->push(nextChild);
|
---|
43 | if ((nextChild = octree->mChildren[1][0][1]) != NULL)
|
---|
44 | mDistanceQueue->push(nextChild);
|
---|
45 | if ((nextChild = octree->mChildren[1][1][0]) != NULL)
|
---|
46 | mDistanceQueue->push(nextChild);
|
---|
47 | if ((nextChild = octree->mChildren[1][1][1]) != NULL)
|
---|
48 | mDistanceQueue->push(nextChild);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | //-----------------------------------------------------------------------
|
---|
52 | bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
53 | {
|
---|
54 | Octree *octree = static_cast<Octree *>(node);
|
---|
55 | // HACK: if there are subtrees, they are empty => we are not interested in them
|
---|
56 | return octree->numNodes() == (int)octree->mNodes.size();
|
---|
57 | }
|
---|
58 | //-----------------------------------------------------------------------
|
---|
59 | bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
60 | {
|
---|
61 | return !(static_cast<Octree *>(node))->mNodes.empty();
|
---|
62 | }
|
---|
63 | //-----------------------------------------------------------------------
|
---|
64 | float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
65 | {
|
---|
66 | const Vector3 bmin = static_cast<Octree *>(node)->mBox.getMinimum();
|
---|
67 | const Vector3 bmax = static_cast<Octree *>(node)->mBox.getMaximum();
|
---|
68 |
|
---|
69 | const Vector3 pos = (bmax - bmin) * 0.5 + bmin;
|
---|
70 |
|
---|
71 | return (mCameraPosition - pos).squaredLength();
|
---|
72 | }
|
---|
73 | //-----------------------------------------------------------------------
|
---|
74 | void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
75 | const bool visible) const
|
---|
76 | {
|
---|
77 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
78 | static_cast<Octree *>(node)->setOctreeVisible(visible);
|
---|
79 | #endif
|
---|
80 | }
|
---|
81 | //-----------------------------------------------------------------------
|
---|
82 | void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
83 | const unsigned int frameId) const
|
---|
84 | {
|
---|
85 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
86 | static_cast<Octree *>(node)->setLastVisited(frameId);
|
---|
87 | #endif
|
---|
88 | }
|
---|
89 | //-----------------------------------------------------------------------
|
---|
90 | void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
|
---|
91 | {
|
---|
92 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
93 | Octree *octant = static_cast<Octree *>(node);
|
---|
94 |
|
---|
95 | while (octant && !octant->isOctreeVisible())
|
---|
96 | {
|
---|
97 | octant->setOctreeVisible(true);
|
---|
98 | octant = octant->getParent();
|
---|
99 | }
|
---|
100 | #endif
|
---|
101 | }
|
---|
102 | //-----------------------------------------------------------------------
|
---|
103 | void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
104 | {
|
---|
105 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
106 | Octree *octant = static_cast<Octree *>(node);
|
---|
107 |
|
---|
108 | if (octant->lastRendered() != mFrameId)
|
---|
109 | {
|
---|
110 | octant->setLastRendered(mFrameId);
|
---|
111 | OctreeSceneManager *ocm =
|
---|
112 | //dynamic_cast<OctreeSceneManager *>(mSceneManager);
|
---|
113 | static_cast<OctreeSceneManager *>(mSceneManager);
|
---|
114 | ocm->_renderOctant(mCamera, octant, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
115 |
|
---|
116 | mVisibleNodes.push_back(node);
|
---|
117 | }
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | }
|
---|
121 | //-----------------------------------------------------------------------
|
---|
122 | bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
123 | {
|
---|
124 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
125 | return static_cast<Octree *>(node)->isOctreeVisible();
|
---|
126 | #else
|
---|
127 | return true;
|
---|
128 | #endif
|
---|
129 | }
|
---|
130 | //-----------------------------------------------------------------------
|
---|
131 | unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
132 | {
|
---|
133 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
134 | return static_cast<Octree *>(node)->lastVisited();
|
---|
135 | #else
|
---|
136 | return 0;
|
---|
137 | #endif
|
---|
138 | }
|
---|
139 | //-----------------------------------------------------------------------
|
---|
140 | AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
141 | {
|
---|
142 | if (node != mSavedNode)
|
---|
143 | {
|
---|
144 | mSavedNode = node;
|
---|
145 | //static_cast<Octree *>(node)->_getCullBounds(&mBox);
|
---|
146 | mBox = static_cast<Octree *>(node)->_getWorldAABB();
|
---|
147 | }
|
---|
148 |
|
---|
149 | return &mBox;
|
---|
150 | }
|
---|
151 | //-----------------------------------------------------------------------
|
---|
152 | void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
153 | GtpVisibility::CullingType type) const
|
---|
154 | {
|
---|
155 | WireBoundingBox *box = static_cast<Octree *>(node)->getWireBoundingBox();
|
---|
156 |
|
---|
157 | if (type == GtpVisibility::FRUSTUM_CULLED)
|
---|
158 | {
|
---|
159 | box->setMaterial("FrustumCulledNodesMaterial");
|
---|
160 | }
|
---|
161 | else // type == GtpVisibility::QUERY_CULLED
|
---|
162 | {
|
---|
163 | box->setMaterial("QueryCulledNodesMaterial");
|
---|
164 | }
|
---|
165 |
|
---|
166 | //dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
|
---|
167 | static_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
|
---|
168 | }
|
---|
169 | //-----------------------------------------------------------------------
|
---|
170 | void OctreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
171 | GtpVisibility::GeometryVector *geometryList,
|
---|
172 | bool includeChildren)
|
---|
173 | {
|
---|
174 | NodeList::const_iterator nodeIt, nodeIt_end;
|
---|
175 | nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
|
---|
176 |
|
---|
177 | for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
|
---|
178 | {
|
---|
179 | SceneNodeHierarchyInterface::GetNodeGeometryList(*nodeIt, geometryList, includeChildren);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | } // namespace Ogre
|
---|