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.size() > 0)
|
---|
24 | {
|
---|
25 | RenderNode(node);
|
---|
26 | }
|
---|
27 |
|
---|
28 | // if not all subtrees are empty
|
---|
29 | //if (octree->numNodes() > (int)octree->mNodes.size())
|
---|
30 | if (!IsLeaf(node))
|
---|
31 | {
|
---|
32 | for(int i=0; i<8; ++i)
|
---|
33 | {
|
---|
34 | Octree *nextChild =
|
---|
35 | octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
|
---|
36 |
|
---|
37 | if (nextChild)
|
---|
38 | {
|
---|
39 | mDistanceQueue->push(nextChild);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 | //-----------------------------------------------------------------------
|
---|
45 | bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
46 | {
|
---|
47 | Octree *octree = static_cast<Octree *>(node);
|
---|
48 | // HACK: if there are subtrees, they are empty => we are not interested in them
|
---|
49 | return octree->numNodes() == (int)octree->mNodes.size();
|
---|
50 | }
|
---|
51 | //-----------------------------------------------------------------------
|
---|
52 | bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
53 | {
|
---|
54 | return static_cast<Octree *>(node)->mNodes.size() > 0;
|
---|
55 | }
|
---|
56 | //-----------------------------------------------------------------------
|
---|
57 | void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
|
---|
58 | {
|
---|
59 | mNumOctreeNodes = num;
|
---|
60 | }
|
---|
61 | //-----------------------------------------------------------------------
|
---|
62 | float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
63 | {
|
---|
64 | AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
|
---|
65 | Vector3 mid = ((box->getMaximum() - box->getMinimum()) * 0.5) + box->getMinimum();
|
---|
66 |
|
---|
67 | return (mCullCamera->getDerivedPosition() - mid).squaredLength();
|
---|
68 | }
|
---|
69 | //-----------------------------------------------------------------------
|
---|
70 | void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
71 | const bool visible)
|
---|
72 | {
|
---|
73 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
74 | static_cast<Octree *>(node)->setOctreeVisible(visible);
|
---|
75 | #endif
|
---|
76 | }
|
---|
77 | //-----------------------------------------------------------------------
|
---|
78 | void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
79 | const unsigned int frameId)
|
---|
80 | {
|
---|
81 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
82 | static_cast<Octree *>(node)->setLastVisited(frameId);
|
---|
83 | #endif
|
---|
84 | }
|
---|
85 | //-----------------------------------------------------------------------
|
---|
86 | void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
|
---|
87 | {
|
---|
88 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
89 | Octree *octant = static_cast<Octree *>(node);
|
---|
90 |
|
---|
91 | while(octant && !octant->isOctreeVisible())
|
---|
92 | {
|
---|
93 | octant->setOctreeVisible(true);
|
---|
94 | octant = octant->getParent();
|
---|
95 | }
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 | //-----------------------------------------------------------------------
|
---|
99 | void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
100 | {
|
---|
101 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
102 | Octree *octant = static_cast<Octree *>(node);
|
---|
103 |
|
---|
104 | if (octant->lastRendered() != mFrameId)
|
---|
105 | {
|
---|
106 | octant->setLastRendered(mFrameId);
|
---|
107 |
|
---|
108 | dynamic_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera,
|
---|
109 | octant, mOnlyShadowCasters, mLeavePassesInQueue);
|
---|
110 |
|
---|
111 | mRenderedNodes.push_back(node);
|
---|
112 | }
|
---|
113 | #endif
|
---|
114 | }
|
---|
115 | //-----------------------------------------------------------------------
|
---|
116 | bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
117 | {
|
---|
118 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
119 | return static_cast<Octree *>(node)->isOctreeVisible();
|
---|
120 | #else
|
---|
121 | return true;
|
---|
122 | #endif
|
---|
123 | }
|
---|
124 | //-----------------------------------------------------------------------
|
---|
125 | unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
126 | {
|
---|
127 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
128 | return static_cast<Octree *>(node)->lastVisited();
|
---|
129 | #else
|
---|
130 | return 0;
|
---|
131 | #endif
|
---|
132 | }
|
---|
133 | //-----------------------------------------------------------------------
|
---|
134 | AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
135 | {
|
---|
136 | if (node != mPreviousNode)
|
---|
137 | {
|
---|
138 | mPreviousNode = node;
|
---|
139 | //static_cast<Octree *>(node)->_getCullBounds(&mBox);
|
---|
140 | mBox = static_cast<Octree *>(node)->_getWorldAABB();
|
---|
141 | //std::stringstream d; d << mBox;LogManager::getSingleton().logMessage(d.str());
|
---|
142 | }
|
---|
143 |
|
---|
144 | return &mBox;
|
---|
145 | }
|
---|
146 | //-----------------------------------------------------------------------
|
---|
147 | void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
148 | GtpVisibility::CullingType type)
|
---|
149 | {
|
---|
150 | WireBoundingBox *box = static_cast<Octree *>(node)->getWireBoundingBox();
|
---|
151 |
|
---|
152 | if (type == GtpVisibility::FRUSTUM_CULLED)
|
---|
153 | {
|
---|
154 | box->setMaterial("FrustumCulledNodesMaterial");
|
---|
155 | }
|
---|
156 | else // type == GtpVisibility::QUERY_CULLED
|
---|
157 | {
|
---|
158 | box->setMaterial("QueryCulledNodesMaterial");
|
---|
159 | }
|
---|
160 |
|
---|
161 | dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
|
---|
162 | }
|
---|
163 | //-----------------------------------------------------------------------
|
---|
164 | void OctreeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,
|
---|
165 | GtpVisibility::GeometryList *geometryList,
|
---|
166 | bool includeChildren)
|
---|
167 | {
|
---|
168 | NodeList::const_iterator nodeIt, nodeIt_end;
|
---|
169 | nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
|
---|
170 |
|
---|
171 | for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
|
---|
172 | {
|
---|
173 | SceneNodeHierarchyInterface::GetGeometry(*nodeIt, geometryList, includeChildren);
|
---|
174 | }
|
---|
175 | }
|
---|
176 | //-----------------------------------------------------------------------
|
---|
177 | /*bool OctreeHierarchyInterface::FindVisibleObjects(GtpVisibility::HierarchyNode *node,
|
---|
178 | InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
|
---|
179 | bool includeChildren)
|
---|
180 | {
|
---|
181 | bool foundVisible = false;
|
---|
182 |
|
---|
183 | PlatformOcclusionQuery query(mRenderSystem);
|
---|
184 |
|
---|
185 | NodeList *nodes = &static_cast<Octree *>(node)->mNodes;
|
---|
186 |
|
---|
187 | NodeList::const_iterator nodeIt = nodes->begin(), nodeIt_end;
|
---|
188 |
|
---|
189 | nodeIt_end = nodes->end();
|
---|
190 |
|
---|
191 | while (nodeIt != nodeIt_end)
|
---|
192 | {
|
---|
193 | OctreeNode *octreeNode = (*nodeIt);
|
---|
194 | if (SceneNodeHierarchyInterface::FindVisibleObjects(octreeNode, visibleGeometry, includeChildren))
|
---|
195 | {
|
---|
196 | foundVisible = true;
|
---|
197 | }
|
---|
198 | ++nodeIt;
|
---|
199 | }
|
---|
200 |
|
---|
201 | return foundVisible;
|
---|
202 | }*/
|
---|
203 |
|
---|
204 | } // namespace Ogre
|
---|