diff --git a/NEWS b/NEWS index 65e2ac359..7c5cd5cdd 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ OSG News (most significant items from ChangeLog) osgSim a seperate add-on library adds support for navigational light points. + osgGA (Gui Abstrabtion) library introduced to provide classes for adatping + different GUI toolkits to work with a standard set of manipulators for + modifying the scene, such as camera and state manipulators. + Support for NodeKits. diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 623919008..727bbcc73 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -133,6 +133,10 @@ SOURCE=..\..\src\osg\ColorMatrix.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\CollectOccludersVisitor.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\ConvexPlanerOccluder.cpp # End Source File # Begin Source File @@ -429,6 +433,10 @@ SOURCE=..\..\Include\Osg\ColorMatrix # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\CollectOccludersVisitor +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\CopyOp # End Source File # Begin Source File diff --git a/include/osg/CollectOccludersVisitor b/include/osg/CollectOccludersVisitor new file mode 100644 index 000000000..43b6eb185 --- /dev/null +++ b/include/osg/CollectOccludersVisitor @@ -0,0 +1,54 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_COLLECTOCCLUDERSVISITOR +#define OSG_COLLECTOCCLUDERSVISITOR 1 + +#include +#include + +namespace osg { + +class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::CullStack +{ + public: + + + CollectOccludersVisitor(); + virtual ~CollectOccludersVisitor(); + + virtual CollectOccludersVisitor* cloneType() const { return new CollectOccludersVisitor(); } + + virtual void reset(); + + virtual void apply(osg::Node&); + virtual void apply(osg::Transform& node); + virtual void apply(osg::Projection& node); + + virtual void apply(osg::Switch& node); + virtual void apply(osg::LOD& node); + virtual void apply(osg::OccluderNode& node); + + typedef std::vector OccluderList; + + OccluderList& getOccluderList() { return _occluderList; } + const OccluderList& getOccluderList() const { return _occluderList; } + + + protected: + + /** prevent unwanted copy construction.*/ + CollectOccludersVisitor(const CollectOccludersVisitor&):osg::NodeVisitor(),osg::CullStack() {} + + /** prevent unwanted copy operator.*/ + CollectOccludersVisitor& operator = (const CollectOccludersVisitor&) { return *this; } + + OccluderList _occluderList; + +}; + +} + +#endif + diff --git a/include/osg/Node b/include/osg/Node index 099f9cfeb..30859410b 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -141,6 +141,12 @@ class SG_EXPORT Node : public Object * note, return true only if no children have culling disabled, and the local _cullingActive flag is true.*/ inline const bool isCullingActive() const { return _numChildrenWithCullingDisabled==0 && _cullingActive && _bsphere.isValid(); } + /** Get the number of Children of this node which are or have OccluderNode's.*/ + inline const int getNumChildrenWithOccluderNodes() const { return _numChildrenWithOccluderNodes; } + + + /** return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.*/ + inline const bool containsOccluderNodes() const; /** * Set user data, data must be subclased from Referenced to allow @@ -248,6 +254,9 @@ class SG_EXPORT Node : public Object int _numChildrenWithCullingDisabled; void setNumChildrenWithCullingDisabled(const int num); + int _numChildrenWithOccluderNodes; + void setNumChildrenWithOccluderNodes(const int num); + osg::ref_ptr _userData; NodeMask _nodeMask; diff --git a/src/osg/CollectOccludersVisitor.cpp b/src/osg/CollectOccludersVisitor.cpp new file mode 100644 index 000000000..d9fe287eb --- /dev/null +++ b/src/osg/CollectOccludersVisitor.cpp @@ -0,0 +1,42 @@ +#include + +using namespace osg; + +CollectOccludersVisitor::CollectOccludersVisitor() +{ +} + +CollectOccludersVisitor::~CollectOccludersVisitor() +{ +} + +void CollectOccludersVisitor::reset() +{ + CullStack::reset(); +} + +void CollectOccludersVisitor::apply(osg::Node&) +{ +} + +void CollectOccludersVisitor::apply(osg::Transform& node) +{ +} + +void CollectOccludersVisitor::apply(osg::Projection& node) +{ +} + +void CollectOccludersVisitor::apply(osg::Switch& node) +{ +} + +void CollectOccludersVisitor::apply(osg::LOD& node) +{ +} + +void CollectOccludersVisitor::apply(osg::OccluderNode& node) +{ +} + + diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index d2899009c..c0970bc13 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -80,6 +81,14 @@ bool Group::addChild( Node *child ) ); } + if (child->getNumChildrenWithOccluderNodes()>0 || + dynamic_cast(child)) + { + setNumChildrenWithOccluderNodes( + getNumChildrenWithOccluderNodes()+1 + ); + } + return true; } else return false; @@ -114,6 +123,14 @@ bool Group::removeChild( Node *child ) ); } + if (child->getNumChildrenWithOccluderNodes()>0 || + dynamic_cast(child)) + { + setNumChildrenWithOccluderNodes( + getNumChildrenWithOccluderNodes()-1 + ); + } + // note ref_ptr<> automatically handles decrementing child's reference count. _children.erase(itr); dirtyBound(); diff --git a/src/osg/Makefile b/src/osg/Makefile index 52f413aac..15b5d6abc 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -12,6 +12,7 @@ CXXFILES =\ ClipPlane.cpp\ ColorMask.cpp\ ColorMatrix.cpp\ + CollectOccludersVisitor.cpp\ ConvexPlanerPolygon.cpp\ ConvexPlanerOccluder.cpp\ CopyOp.cpp\ diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index b12e11982..760b928b8 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -17,6 +18,7 @@ Node::Node() _cullingActive = true; _numChildrenWithCullingDisabled = 0; + _numChildrenWithOccluderNodes = 0; } Node::Node(const Node& node,const CopyOp& copyop): @@ -30,6 +32,7 @@ Node::Node(const Node& node,const CopyOp& copyop): _cullCallback(node._cullCallback), _cullingActive(node._cullingActive), _numChildrenWithCullingDisabled(0), // assume no children yet. + _numChildrenWithOccluderNodes(0), _userData(copyop(node._userData.get())), _nodeMask(node._nodeMask), _descriptions(node._descriptions), @@ -227,6 +230,48 @@ void Node::setNumChildrenWithCullingDisabled(const int num) } +void Node::setNumChildrenWithOccluderNodes(const int num) +{ + // if no changes just return. + if (_numChildrenWithOccluderNodes==num) return; + + // note, if this node is a OccluderNode then the + // parents won't be affected by any changes to + // _numChildrenWithOccluderNodes so no need to inform them. + if (!dynamic_cast(this) && !_parents.empty()) + { + + // need to pass on changes to parents. + int delta = 0; + if (_numChildrenWithOccluderNodes>0) --delta; + if (num>0) ++delta; + if (delta!=0) + { + // the number of callbacks has changed, need to pass this + // on to parents so they know whether app traversal is + // reqired on this subgraph. + for(ParentList::iterator itr =_parents.begin(); + itr != _parents.end(); + ++itr) + { + (*itr)->setNumChildrenWithOccluderNodes( + (*itr)->getNumChildrenWithOccluderNodes()+delta + ); + } + + } + } + + // finally update this objects value. + _numChildrenWithOccluderNodes=num; + +} + +const bool Node::containsOccluderNodes() const +{ + return _numChildrenWithOccluderNodes>0 || dynamic_cast(this); +} + const bool Node::computeBound() const { _bsphere.init(); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 26c6fdc60..dd6831608 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -306,6 +307,34 @@ void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil if (!_initCalled) init(); + // collect any occluder in the view frustum. + if (_sceneData->containsOccluderNodes()) + { + std::cout << "Scene graph contains occluder nodes, searching for them"<getFrameNumber()); + } + + cov.pushViewport(_viewport.get()); + cov.pushProjectionMatrix(projection); + cov.pushModelViewMatrix(modelview); + + // traverse the scene graph to search for occluder in there new positions. + _sceneData->accept(cov); + + cov.popModelViewMatrix(); + cov.popProjectionMatrix(); + cov.popViewport(); + + std::cout << "finished searching for occluder"<reset();