diff --git a/include/osgViewer/Scene b/include/osgViewer/Scene index e4b6d79f0..485baaecb 100644 --- a/include/osgViewer/Scene +++ b/include/osgViewer/Scene @@ -29,9 +29,6 @@ class OSGVIEWER_EXPORT Scene : public osg::Referenced { public: - Scene(); - virtual ~Scene(); - void setSceneData(osg::Node* node); osg::Node* getSceneData(); const osg::Node* getSceneData() const; @@ -44,8 +41,16 @@ class OSGVIEWER_EXPORT Scene : public osg::Referenced * return 0 if no Scene has yet been assigned the specified node.*/ static Scene* getScene(osg::Node* node); - protected: + + Scene(); + virtual ~Scene(); + + /** Get the Scene object that has the specified node assigned to it. + * or return a new Scene if no Scene has yet been assigned the specified node.*/ + static Scene* getOrCreateScene(osg::Node* node); + + friend class View; osg::ref_ptr _sceneData; diff --git a/src/osgViewer/Scene.cpp b/src/osgViewer/Scene.cpp index 40de79636..6ae8a5fa6 100644 --- a/src/osgViewer/Scene.cpp +++ b/src/osgViewer/Scene.cpp @@ -52,7 +52,7 @@ void Scene::setSceneData(osg::Node* node) if (_databasePager.valid()) { // register any PagedLOD that need to be tracked in the scene graph - _databasePager->registerPagedLODs(node); + if (node) _databasePager->registerPagedLODs(node); } } @@ -85,3 +85,16 @@ Scene* Scene::getScene(osg::Node* node) return 0; } +Scene* Scene::getOrCreateScene(osg::Node* node) +{ + if (!node) return 0; + + osgViewer::Scene* scene = getScene(node); + if (!scene) + { + scene = new Scene; + scene->setSceneData(node); + } + + return scene; +}