From 5d3cb4f7540bff17b6a21bde56f4246544a2e5b8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Jun 2012 04:18:28 +0000 Subject: [PATCH] Added osg::ImageSequence support into osgPresentation::SlideShowConstructor and the associated tag in .p3d. --- include/osgPresentation/SlideShowConstructor | 6 +- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 14 +- src/osgPresentation/SlideShowConstructor.cpp | 128 ++++++++++++++++++- 3 files changed, 139 insertions(+), 9 deletions(-) diff --git a/include/osgPresentation/SlideShowConstructor b/include/osgPresentation/SlideShowConstructor index 87d513a09..04b830cb6 100644 --- a/include/osgPresentation/SlideShowConstructor +++ b/include/osgPresentation/SlideShowConstructor @@ -238,7 +238,9 @@ public: texcoord_rotate(0.0f), loopingMode(osg::ImageStream::NO_LOOPING), page(-1), - backgroundColor(1.0f,1.0f,1.0f,1.0f) {} + backgroundColor(1.0f,1.0f,1.0f,1.0f), + fps(30.0), + duration(-1.0) {} std::string options; float width; @@ -249,6 +251,8 @@ public: osg::ImageStream::LoopingMode loopingMode; int page; osg::Vec4 backgroundColor; + double fps; + double duration; }; struct VolumeData diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 4915a5b8c..9bb556f7d 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -867,7 +867,19 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid OSG_NOTIFY(_notifyLevel)<<"looping \""< #include #include +#include #include #include #include @@ -775,12 +776,16 @@ osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3& bool flipYAxis = image->getOrigin()==osg::Image::TOP_LEFT; -#ifdef __sgi +#if 1 bool useTextureRectangle = false; #else - bool useTextureRectangle = true; + #ifdef __sgi + bool useTextureRectangle = false; + #else + bool useTextureRectangle = true; + #endif #endif - + // pass back info on wether texture 2D is used. usedTextureRectangle = useTextureRectangle; @@ -814,6 +819,8 @@ osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3& texture = new osg::Texture2D(image); + texture->setResizeNonPowerOfTwoHint(false); + stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); @@ -846,15 +853,122 @@ void SlideShowConstructor::addImage(const std::string& filename, const PositionD options->setOptionString(imageData.options); } - osg::Image* image = osgDB::readImageFile(filename, options.get()); - if (image) recordOptionsFilePath(_options.get()); + std::string foundFile = filename; + osg::ref_ptr image; + osg::ref_ptr volume; + osg::ref_ptr tile; + osg::ref_ptr layer; + + osgDB::DirectoryContents filenames; + bool preLoad = true; + + // check for wild cards + if (filename.find('*')!=std::string::npos) + { + OSG_INFO<<"Expanding wildcard "< imageSequence = new osg::ImageSequence; + + for(osgDB::DirectoryContents::iterator itr = filenames.begin(); + itr != filenames.end(); + ++itr) + { + if (preLoad) + { + OSG_INFO<<"Attempting to read "<<*itr< loadedImage = osgDB::readImageFile(*itr, options.get()); + if (loadedImage.valid()) + { + OSG_INFO<<"Loaded image "<<*itr<addImage(loadedImage.get()); + } + } + else + { + OSG_INFO<<"Adding filename for load image on demand "<<*itr<addImageFile(*itr); + } + } + + if (imageData.duration>0.0) + { + imageSequence->setLength(imageData.duration); + } + else + { + unsigned int maxNum = osg::maximum(imageSequence->getFileNames().size(), + imageSequence->getImages().size()); + + imageSequence->setLength(double(maxNum)*(1.0/imageData.fps)); + } + + image = imageSequence; + } if (!image) return; bool isImageTranslucent = false; - osg::ImageStream* imageStream = dynamic_cast(image); + osg::ImageStream* imageStream = dynamic_cast(image.get()); if (imageStream) { imageStream->setLoopingMode(imageData.loopingMode); @@ -1819,7 +1933,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position } else { - // not found image, so fallback to plguins/callbacks to find the model. + // not found image, so fallback to plugins/callbacks to find the model. image = osgDB::readImageFile( filename, options.get() ); if (image) recordOptionsFilePath(options.get() ); }