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