From 658fd4d19d0335c19b14eaca441a27800d783837 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 20 Nov 2018 14:19:37 +0000 Subject: [PATCH] Added support for reading and writing images --- applications/osgconv/osgconv.cpp | 77 ++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/applications/osgconv/osgconv.cpp b/applications/osgconv/osgconv.cpp index e5caea059..8604c1df8 100644 --- a/applications/osgconv/osgconv.cpp +++ b/applications/osgconv/osgconv.cpp @@ -771,7 +771,7 @@ int main( int argc, char **argv ) osgDB::Registry::instance()->getOptions()->setObjectCacheHint(osgDB::Options::CACHE_ALL); } - std::string fileNameOut("converted.osg"); + std::string fileNameOut("converted.osgt"); if (fileNames.size()>1) { fileNameOut = fileNames.back(); @@ -780,29 +780,66 @@ int main( int argc, char **argv ) osg::Timer_t startTick = osg::Timer::instance()->tick(); - osg::ref_ptr root = osgDB::readRefNodeFiles(fileNames); + typedef std::vector< osg::ref_ptr > Images; + typedef std::vector< osg::ref_ptr > Nodes; + typedef std::vector< osg::ref_ptr > Objects; - if (root.valid()) + Images images; + Nodes nodes; + Objects objects; + + for(FileNameList::iterator itr = fileNames.begin(); + itr != fileNames.end(); + ++itr) { - osg::Timer_t endTick = osg::Timer::instance()->tick(); - osg::notify(osg::INFO)<<"Time to load files "<delta_m(startTick, endTick)<<" ms"< object = osgDB::readObjectFile(*itr); + if (object.valid()) + { + if (object->asNode()) nodes.push_back(object->asNode()); + else if (object->asImage()) images.push_back(object->asImage()); + else objects.push_back(object); + } + } + + if (images.empty() && nodes.empty() && objects.empty()) + { + osg::notify(osg::NOTICE)<<"Warning: failed to load any files"<accept(pssv); - } + osg::Timer_t endTick = osg::Timer::instance()->tick(); + osg::notify(osg::INFO)<<"Time to load files "<delta_m(startTick, endTick)<<" ms"< root; + + if (nodes.size()==1) root = nodes.front(); + else if (nodes.size()>1) { - FixTransparencyVisitor atv(fixTransparencyMode); - root->accept(atv); + osg::ref_ptr group = new osg::Group; + for(Nodes::iterator itr = nodes.begin(); + itr != nodes.end(); + ++itr) + { + group->addChild(itr->get()); + } + + root = group; } if ( root.valid() ) { + if (pruneStateSet) + { + PruneStateSetVisitor pssv; + root->accept(pssv); + } + + if (fixTransparencyMode != FixTransparencyVisitor::NO_TRANSPARANCY_FIXING) + { + FixTransparencyVisitor atv(fixTransparencyMode); + root->accept(atv); + } if (smooth) { @@ -868,6 +905,20 @@ int main( int argc, char **argv ) osg::notify(osg::NOTICE)<1) + { + OSG_NOTICE<<"Warning: osgconv does not support writing multiple to a single file."<