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