From Robert Milharcic, "In attached file I implemented LOAD_IMMEDIATELY mode for new osg ProxyNode wrapper. Current version of proxynode loading uses DatabasePager for both modes(DEFER_LOADING_TO_DATABASE_PAGER and LOAD_IMMEDIATELY).

Immediate loading of external references begins after ProxyNode has been deserialized in ProxyNodeFinishedObjectReadCallback."
This commit is contained in:
Robert Osfield
2012-02-06 13:27:25 +00:00
parent 55c4f9b401
commit 2298cc520c

View File

@@ -2,6 +2,8 @@
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
#include <osgDB/FileNameUtils>
#include <osgDB/ReadFile>
// _filenameList
static bool checkFileNames( const osg::ProxyNode& node )
@@ -97,6 +99,30 @@ static bool writeUserCenter( osgDB::OutputStream& os, const osg::ProxyNode& node
return true;
}
struct ProxyNodeFinishedObjectReadCallback : public osgDB::FinishedObjectReadCallback
{
virtual void objectRead(osgDB::InputStream& is, osg::Object& obj)
{
osg::ProxyNode& proxyNode = static_cast<osg::ProxyNode&>(obj);
if (proxyNode.getLoadingExternalReferenceMode() == osg::ProxyNode::LOAD_IMMEDIATELY)
{
for(unsigned int i=0; i<proxyNode.getNumFileNames(); i++)
{
if(i >= proxyNode.getNumChildren() && !proxyNode.getFileName(i).empty())
{
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)is.getOptions())->getDatabasePathList();
fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i)));
osg::Node* node = osgDB::readNodeFile(proxyNode.getFileName(i), is.getOptions());
fpl.pop_front();
if(node)
proxyNode.insertChild(i, node);
}
}
}
}
};
REGISTER_OBJECT_WRAPPER( ProxyNode,
new osg::ProxyNode,
osg::ProxyNode,
@@ -121,4 +147,6 @@ REGISTER_OBJECT_WRAPPER( ProxyNode,
END_ENUM_SERIALIZER(); // _centerMode
ADD_USER_SERIALIZER( UserCenter ); // _userDefinedCenter, _radius
wrapper->addFinishedObjectReadCallback(new ProxyNodeFinishedObjectReadCallback());
}