[59] | 1 | #include "OgreOctreeHierarchyInterface.h"
|
---|
| 2 | #include "OgreVisibilityOctreeSceneManager.h"
|
---|
| 3 | #include <OgreOctree.h>
|
---|
[94] | 4 | #include <OgreLogManager.h>
|
---|
[113] | 5 | #include <OgreStringConverter.h>
|
---|
[59] | 6 |
|
---|
[115] | 7 |
|
---|
[59] | 8 | namespace Ogre {
|
---|
[94] | 9 |
|
---|
[59] | 10 | //-----------------------------------------------------------------------
|
---|
[130] | 11 | OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys):
|
---|
| 12 | SceneNodeHierarchyInterface(sm, rsys)
|
---|
[59] | 13 | {
|
---|
| 14 | }
|
---|
| 15 | //-----------------------------------------------------------------------
|
---|
| 16 | void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
| 17 | {
|
---|
| 18 | mNumTraversedNodes ++;
|
---|
| 19 |
|
---|
[87] | 20 | Octree *octree = static_cast<Octree *>(node);
|
---|
| 21 |
|
---|
[59] | 22 | // if we come across some renderable geometry => render it
|
---|
[87] | 23 | if (octree->mNodes.size() > 0)
|
---|
| 24 | {
|
---|
| 25 | RenderNode(node);
|
---|
| 26 | }
|
---|
[59] | 27 |
|
---|
[87] | 28 | // if not all subtrees are empty
|
---|
[94] | 29 | //if (octree->numNodes() > (int)octree->mNodes.size())
|
---|
| 30 | if (!IsLeaf(node))
|
---|
[59] | 31 | {
|
---|
[87] | 32 | for(int i=0; i<8; ++i)
|
---|
[59] | 33 | {
|
---|
[87] | 34 | Octree *nextChild =
|
---|
| 35 | octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
|
---|
| 36 |
|
---|
| 37 | if (nextChild)
|
---|
| 38 | {
|
---|
| 39 | mDistanceQueue->push(nextChild);
|
---|
| 40 | }
|
---|
[59] | 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | //-----------------------------------------------------------------------
|
---|
[74] | 45 | bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 46 | {
|
---|
[94] | 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();
|
---|
[59] | 50 | }
|
---|
| 51 | //-----------------------------------------------------------------------
|
---|
[74] | 52 | bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 53 | {
|
---|
[87] | 54 | return static_cast<Octree *>(node)->mNodes.size() > 0;
|
---|
[59] | 55 | }
|
---|
| 56 | //-----------------------------------------------------------------------
|
---|
| 57 | void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
|
---|
| 58 | {
|
---|
| 59 | mNumOctreeNodes = num;
|
---|
| 60 | }
|
---|
| 61 | //-----------------------------------------------------------------------
|
---|
[87] | 62 | float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 63 | {
|
---|
[87] | 64 | AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
|
---|
[101] | 65 | Vector3 mid = ((box->getMaximum() - box->getMinimum()) * 0.5) + box->getMinimum();
|
---|
[86] | 66 |
|
---|
[94] | 67 | return (mCullCamera->getDerivedPosition() - mid).squaredLength();
|
---|
[59] | 68 | }
|
---|
| 69 | //-----------------------------------------------------------------------
|
---|
[74] | 70 | void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
| 71 | const bool visible)
|
---|
[59] | 72 | {
|
---|
| 73 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 74 | static_cast<Octree *>(node)->setOctreeVisible(visible);
|
---|
| 75 | #endif
|
---|
| 76 | }
|
---|
| 77 | //-----------------------------------------------------------------------
|
---|
[74] | 78 | void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
| 79 | const unsigned int frameId)
|
---|
[59] | 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 |
|
---|
[130] | 108 | dynamic_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera,
|
---|
[115] | 109 | octant, mOnlyShadowCasters, mLeaveTransparentsInQueue);
|
---|
[59] | 110 |
|
---|
[130] | 111 | mRenderedNodes.push_back(node);
|
---|
[59] | 112 | }
|
---|
| 113 | #endif
|
---|
| 114 | }
|
---|
| 115 | //-----------------------------------------------------------------------
|
---|
[74] | 116 | bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 117 | {
|
---|
| 118 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 119 | return static_cast<Octree *>(node)->isOctreeVisible();
|
---|
| 120 | #else
|
---|
| 121 | return true;
|
---|
| 122 | #endif
|
---|
| 123 | }
|
---|
| 124 | //-----------------------------------------------------------------------
|
---|
[74] | 125 | unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 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 | {
|
---|
[85] | 136 | if(node != mPreviousNode)
|
---|
| 137 | {
|
---|
| 138 | mPreviousNode = node;
|
---|
[135] | 139 | // static_cast<Octree *>(node)->_getCullBounds(&mBox);
|
---|
| 140 | mBox = static_cast<Octree *>(node)->_getWorldAABB();
|
---|
[85] | 141 | }
|
---|
[59] | 142 |
|
---|
| 143 | return &mBox;
|
---|
| 144 | }
|
---|
[112] | 145 | //-----------------------------------------------------------------------
|
---|
| 146 | void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,
|
---|
| 147 | GtpVisibility::CullingType type)
|
---|
| 148 | {
|
---|
| 149 | WireBoundingBox *box = static_cast<Octree *>(node)->getWireBoundingBox();
|
---|
[59] | 150 |
|
---|
[112] | 151 | if (type == GtpVisibility::FRUSTUM_CULLED)
|
---|
| 152 | {
|
---|
| 153 | box->setMaterial("FrustumCulledNodesMaterial");
|
---|
| 154 | }
|
---|
| 155 | else // type == GtpVisibility::QUERY_CULLED
|
---|
| 156 | {
|
---|
| 157 | box->setMaterial("QueryCulledNodesMaterial");
|
---|
| 158 | }
|
---|
[113] | 159 |
|
---|
[130] | 160 | dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
|
---|
[112] | 161 | }
|
---|
[130] | 162 | //-----------------------------------------------------------------------
|
---|
| 163 | void OctreeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,
|
---|
| 164 | GtpVisibility::GeometryList *geometryList,
|
---|
| 165 | bool includeChildren)
|
---|
| 166 | {
|
---|
| 167 | NodeList::const_iterator nodeIt, nodeIt_end;
|
---|
| 168 | nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
|
---|
| 169 |
|
---|
| 170 | for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
|
---|
| 171 | {
|
---|
| 172 | SceneNodeHierarchyInterface::GetGeometry(*nodeIt, geometryList, includeChildren);
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | //-----------------------------------------------------------------------
|
---|
| 176 | /*bool OctreeHierarchyInterface::FindVisibleObjects(GtpVisibility::HierarchyNode *node,
|
---|
| 177 | InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
|
---|
| 178 | bool includeChildren)
|
---|
| 179 | {
|
---|
| 180 | bool foundVisible = false;
|
---|
| 181 |
|
---|
| 182 | PlatformOcclusionQuery query(mRenderSystem);
|
---|
| 183 |
|
---|
| 184 | NodeList *nodes = &static_cast<Octree *>(node)->mNodes;
|
---|
| 185 |
|
---|
| 186 | NodeList::const_iterator nodeIt = nodes->begin(), nodeIt_end;
|
---|
| 187 |
|
---|
| 188 | nodeIt_end = nodes->end();
|
---|
| 189 |
|
---|
| 190 | while (nodeIt != nodeIt_end)
|
---|
| 191 | {
|
---|
| 192 | OctreeNode *octreeNode = (*nodeIt);
|
---|
| 193 | if (SceneNodeHierarchyInterface::FindVisibleObjects(octreeNode, visibleGeometry, includeChildren))
|
---|
| 194 | {
|
---|
| 195 | foundVisible = true;
|
---|
| 196 | }
|
---|
| 197 | ++nodeIt;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | return foundVisible;
|
---|
| 201 | }*/
|
---|
| 202 |
|
---|
[59] | 203 | } // namespace Ogre
|
---|