Added support for reading source image file names from the command line.

This commit is contained in:
Robert Osfield 2008-09-11 09:05:16 +00:00
parent b4b5b5ea41
commit 4f6b405edf

View File

@ -41,10 +41,24 @@
// A simple demo demonstrating how to set on an animated texture using an osg::ImageSequence // A simple demo demonstrating how to set on an animated texture using an osg::ImageSequence
// //
osg::StateSet* createState() osg::StateSet* createState(osg::ArgumentParser& arguments)
{ {
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
if (arguments.argc()>1)
{
for(unsigned int i=1; i<arguments.argc(); ++i)
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(arguments[i]);
if (image.valid())
{
imageSequence->addImage(image.get());
}
}
imageSequence->setLength(float(imageSequence->getImages().size())*0.1f);
}
else
{
imageSequence->setLength(4.0); imageSequence->setLength(4.0);
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png"));
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png"));
@ -52,6 +66,7 @@ osg::StateSet* createState()
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png"));
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png"));
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png"));
}
// start the image sequence playing // start the image sequence playing
imageSequence->play(); imageSequence->play();
@ -86,14 +101,14 @@ osg::StateSet* createState()
return stateset; return stateset;
} }
osg::Node* createModel() osg::Node* createModel(osg::ArgumentParser& arguments)
{ {
// create the geometry of the model, just a simple 2d quad right now. // create the geometry of the model, just a simple 2d quad right now.
osg::Geode* geode = new osg::Geode; osg::Geode* geode = new osg::Geode;
geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f))); geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f)));
geode->setStateSet(createState()); geode->setStateSet(createState(arguments));
return geode; return geode;
@ -276,8 +291,11 @@ int main(int argc, char **argv)
// construct the viewer. // construct the viewer.
osgViewer::Viewer viewer(arguments); osgViewer::Viewer viewer(arguments);
std::string filename;
arguments.read("-o",filename);
// create a model from the images and pass it to the viewer. // create a model from the images and pass it to the viewer.
viewer.setSceneData(createModel()); viewer.setSceneData(createModel(arguments));
// pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate. // pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate.
MovieEventHandler* meh = new MovieEventHandler(); MovieEventHandler* meh = new MovieEventHandler();
@ -285,8 +303,7 @@ int main(int argc, char **argv)
viewer.addEventHandler( meh ); viewer.addEventHandler( meh );
std::string filename; if (!filename.empty())
if (arguments.read("-o",filename))
{ {
osgDB::writeNodeFile(*viewer.getSceneData(),filename); osgDB::writeNodeFile(*viewer.getSceneData(),filename);
} }