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