Added support for reading and writing images
This commit is contained in:
parent
8b4359b77e
commit
658fd4d19d
@ -771,7 +771,7 @@ int main( int argc, char **argv )
|
|||||||
osgDB::Registry::instance()->getOptions()->setObjectCacheHint(osgDB::Options::CACHE_ALL);
|
osgDB::Registry::instance()->getOptions()->setObjectCacheHint(osgDB::Options::CACHE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fileNameOut("converted.osg");
|
std::string fileNameOut("converted.osgt");
|
||||||
if (fileNames.size()>1)
|
if (fileNames.size()>1)
|
||||||
{
|
{
|
||||||
fileNameOut = fileNames.back();
|
fileNameOut = fileNames.back();
|
||||||
@ -780,15 +780,55 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> root = osgDB::readRefNodeFiles(fileNames);
|
typedef std::vector< osg::ref_ptr<osg::Image> > Images;
|
||||||
|
typedef std::vector< osg::ref_ptr<osg::Node> > Nodes;
|
||||||
|
typedef std::vector< osg::ref_ptr<osg::Object> > 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::ref_ptr<osg::Object> object = osgDB::readObjectFile(*itr);
|
||||||
osg::notify(osg::INFO)<<"Time to load files "<<osg::Timer::instance()->delta_m(startTick, endTick)<<" ms"<<std::endl;
|
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"<<std::endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
osg::Timer_t endTick = osg::Timer::instance()->tick();
|
||||||
|
osg::notify(osg::INFO)<<"Time to load files "<<osg::Timer::instance()->delta_m(startTick, endTick)<<" ms"<<std::endl;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Node> root;
|
||||||
|
|
||||||
|
if (nodes.size()==1) root = nodes.front();
|
||||||
|
else if (nodes.size()>1)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Group> 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)
|
if (pruneStateSet)
|
||||||
{
|
{
|
||||||
PruneStateSetVisitor pssv;
|
PruneStateSetVisitor pssv;
|
||||||
@ -801,9 +841,6 @@ int main( int argc, char **argv )
|
|||||||
root->accept(atv);
|
root->accept(atv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( root.valid() )
|
|
||||||
{
|
|
||||||
|
|
||||||
if (smooth)
|
if (smooth)
|
||||||
{
|
{
|
||||||
osgUtil::SmoothingVisitor sv;
|
osgUtil::SmoothingVisitor sv;
|
||||||
@ -868,6 +905,20 @@ int main( int argc, char **argv )
|
|||||||
osg::notify(osg::NOTICE)<<result.message()<< std::endl;
|
osg::notify(osg::NOTICE)<<result.message()<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!images.empty())
|
||||||
|
{
|
||||||
|
if (images.size()>1)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: osgconv does not support writing multiple to a single file."<<std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
osgDB::writeImageFile(*images.front(), fileNameOut);
|
||||||
|
}
|
||||||
|
else if (!objects.empty())
|
||||||
|
{
|
||||||
|
osgDB::writeObjectFile(*images.front(), fileNameOut);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osg::notify(osg::NOTICE)<<"Error no data loaded."<< std::endl;
|
osg::notify(osg::NOTICE)<<"Error no data loaded."<< std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user