diff --git a/src/osg/ObserverNodePath.cpp b/src/osg/ObserverNodePath.cpp index 0adf40ca5..794197264 100644 --- a/src/osg/ObserverNodePath.cpp +++ b/src/osg/ObserverNodePath.cpp @@ -12,6 +12,7 @@ */ #include +#include using namespace osg; @@ -53,6 +54,32 @@ ObserverNodePath& ObserverNodePath::operator = (const ObserverNodePath& rhs) return *this; } +void ObserverNodePath::setNodePathTo(osg::Node* node) +{ + if (node) + { + NodePathList nodePathList = node->getParentalNodePaths(); + if (nodePathList.empty()) + { + NodePath nodePath; + nodePath.push_back(node); + setNodePath(nodePath); + } + else + { + if (nodePathList[0].empty()) + { + nodePathList[0].push_back(node); + } + setNodePath(nodePathList[0]); + } + } + else + { + clearNodePath(); + } +} + void ObserverNodePath::setNodePath(const osg::NodePath& nodePath) { OpenThreads::ScopedLock lock(_mutex); @@ -89,7 +116,7 @@ bool ObserverNodePath::getRefNodePath(RefNodePath& refNodePath) const refNodePath.push_back(*itr); } - return !refNodePath.empty(); + return true; } bool ObserverNodePath::getNodePath(NodePath& nodePath) const @@ -99,7 +126,7 @@ bool ObserverNodePath::getNodePath(NodePath& nodePath) const OpenThreads::ScopedLock lock(_mutex); if (!_valid) return false; nodePath = _nodePath; - return !nodePath.empty(); + return true; } void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) @@ -108,12 +135,15 @@ void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) _clearNodePath(); + //OSG_NOTICE<<"ObserverNodePath["<addObserver(this); } @@ -122,10 +152,12 @@ void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) void ObserverNodePath::_clearNodePath() { + //OSG_NOTICE<<"ObserverNodePath["<removeObserver(this); } _nodePath.clear(); @@ -148,10 +180,15 @@ bool ObserverNodePath::objectUnreferenced(void* ptr) { _nodePath.erase(itr); - // return true as we wish calling method to remove self from observert set. + //OSG_NOTICE<<"ObserverNodePath["<(_observers); if (os)