2008-07-21 18:57:06 +08:00
|
|
|
/* OpenSceneGraph example, osgtexture3D.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Notify>
|
2008-07-22 22:47:59 +08:00
|
|
|
#include <osg/Texture1D>
|
2008-07-21 18:57:06 +08:00
|
|
|
#include <osg/Texture2D>
|
2008-07-22 22:47:59 +08:00
|
|
|
#include <osg/Texture3D>
|
|
|
|
#include <osg/TextureRectangle>
|
2008-07-21 18:57:06 +08:00
|
|
|
#include <osg/ImageSequence>
|
|
|
|
#include <osg/Geode>
|
|
|
|
|
|
|
|
#include <osgDB/Registry>
|
|
|
|
#include <osgDB/ReadFile>
|
2008-07-22 22:47:59 +08:00
|
|
|
#include <osgDB/WriteFile>
|
2012-09-13 00:35:12 +08:00
|
|
|
#include <osgDB/FileNameUtils>
|
|
|
|
#include <osgDB/FileUtils>
|
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
|
|
|
|
#include <osgViewer/Viewer>
|
2008-09-22 23:56:22 +08:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2008-07-21 18:57:06 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
static osgDB::DirectoryContents getSuitableFiles(osg::ArgumentParser& arguments)
|
|
|
|
{
|
|
|
|
osgDB::DirectoryContents files;
|
|
|
|
for(int i=1; i<arguments.argc(); ++i)
|
|
|
|
{
|
|
|
|
if (osgDB::fileType(arguments[i]) == osgDB::DIRECTORY)
|
|
|
|
{
|
|
|
|
const std::string& directory = arguments[i];
|
|
|
|
osgDB::DirectoryContents dc = osgDB::getSortedDirectoryContents(directory);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
for(osgDB::DirectoryContents::iterator itr = dc.begin(); itr != dc.end(); ++itr)
|
|
|
|
{
|
|
|
|
std::string full_file_name = directory + "/" + (*itr);
|
|
|
|
std::string ext = osgDB::getLowerCaseFileExtension(full_file_name);
|
|
|
|
if ((ext == "jpg") || (ext == "png") || (ext == "gif") || (ext == "rgb") || (ext == "dds") )
|
|
|
|
{
|
|
|
|
files.push_back(full_file_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
files.push_back(arguments[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
2008-08-15 00:28:45 +08:00
|
|
|
|
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
//
|
2008-07-22 05:00:57 +08:00
|
|
|
// A simple demo demonstrating how to set on an animated texture using an osg::ImageSequence
|
2008-07-21 18:57:06 +08:00
|
|
|
//
|
|
|
|
|
2008-09-11 17:05:16 +08:00
|
|
|
osg::StateSet* createState(osg::ArgumentParser& arguments)
|
2008-07-21 18:57:06 +08:00
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
|
2008-09-23 00:18:02 +08:00
|
|
|
|
|
|
|
bool preLoad = true;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-23 00:18:02 +08:00
|
|
|
while (arguments.read("--page-and-discard"))
|
|
|
|
{
|
|
|
|
imageSequence->setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES);
|
|
|
|
preLoad = false;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-23 00:18:02 +08:00
|
|
|
while (arguments.read("--page-and-retain"))
|
|
|
|
{
|
|
|
|
imageSequence->setMode(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES);
|
|
|
|
preLoad = false;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-23 00:18:02 +08:00
|
|
|
while (arguments.read("--preload"))
|
|
|
|
{
|
|
|
|
imageSequence->setMode(osg::ImageSequence::PRE_LOAD_ALL_IMAGES);
|
|
|
|
preLoad = true;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-23 00:18:02 +08:00
|
|
|
double length = -1.0;
|
|
|
|
while (arguments.read("--length",length)) {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-06-07 18:08:42 +08:00
|
|
|
double fps = 30.0;
|
|
|
|
while (arguments.read("--fps",fps)) {}
|
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
osgDB::DirectoryContents files = getSuitableFiles(arguments);
|
|
|
|
if (!files.empty())
|
2008-09-11 17:05:16 +08:00
|
|
|
{
|
2012-09-13 00:35:12 +08:00
|
|
|
for(osgDB::DirectoryContents::iterator itr = files.begin();
|
|
|
|
itr != files.end();
|
|
|
|
++itr)
|
2008-09-11 17:05:16 +08:00
|
|
|
{
|
2012-09-13 00:35:12 +08:00
|
|
|
const std::string& filename = *itr;
|
2008-09-23 00:18:02 +08:00
|
|
|
if (preLoad)
|
2008-09-11 17:05:16 +08:00
|
|
|
{
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
2008-09-23 00:18:02 +08:00
|
|
|
if (image.valid())
|
|
|
|
{
|
|
|
|
imageSequence->addImage(image.get());
|
|
|
|
}
|
2008-09-11 17:05:16 +08:00
|
|
|
}
|
2008-09-23 00:18:02 +08:00
|
|
|
else
|
|
|
|
{
|
2012-09-13 00:35:12 +08:00
|
|
|
imageSequence->addImageFile(filename);
|
2008-09-23 00:18:02 +08:00
|
|
|
}
|
2012-06-07 18:08:42 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-23 00:18:02 +08:00
|
|
|
if (length>0.0)
|
|
|
|
{
|
|
|
|
imageSequence->setLength(length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
unsigned int maxNum = imageSequence->getNumImageData();
|
2012-06-07 18:08:42 +08:00
|
|
|
imageSequence->setLength(double(maxNum)*(1.0/fps));
|
2008-09-11 17:05:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-23 00:18:02 +08:00
|
|
|
if (length>0.0)
|
|
|
|
{
|
|
|
|
imageSequence->setLength(length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageSequence->setLength(4.0);
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posx.png"));
|
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negx.png"));
|
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posy.png"));
|
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negy.png"));
|
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posz.png"));
|
|
|
|
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negz.png"));
|
2008-09-11 17:05:16 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-09-10 19:27:00 +08:00
|
|
|
// start the image sequence playing
|
|
|
|
imageSequence->play();
|
2008-07-22 22:47:59 +08:00
|
|
|
|
|
|
|
#if 1
|
2008-07-21 18:57:06 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
2008-07-22 22:47:59 +08:00
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
|
2008-07-21 18:57:06 +08:00
|
|
|
texture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
texture->setImage(imageSequence.get());
|
2008-07-22 01:28:22 +08:00
|
|
|
//texture->setTextureSize(512,512);
|
2015-10-22 21:42:19 +08:00
|
|
|
#else
|
2008-07-22 22:47:59 +08:00
|
|
|
osg::TextureRectangle* texture = new osg::TextureRectangle;
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
|
|
|
|
texture->setImage(imageSequence.get());
|
|
|
|
//texture->setTextureSize(512,512);
|
|
|
|
#endif
|
2008-07-21 18:57:06 +08:00
|
|
|
|
|
|
|
// create the StateSet to store the texture data
|
|
|
|
osg::StateSet* stateset = new osg::StateSet;
|
2008-07-22 01:28:22 +08:00
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
return stateset;
|
|
|
|
}
|
|
|
|
|
2008-09-11 17:05:16 +08:00
|
|
|
osg::Node* createModel(osg::ArgumentParser& arguments)
|
2008-07-21 18:57:06 +08:00
|
|
|
{
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
// create the geometry of the model, just a simple 2d quad right now.
|
2008-07-21 18:57:06 +08:00
|
|
|
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)));
|
|
|
|
|
2008-09-11 17:05:16 +08:00
|
|
|
geode->setStateSet(createState(arguments));
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
return geode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
osg::ImageStream* s_imageStream = 0;
|
|
|
|
class MovieEventHandler : public osgGA::GUIEventHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-12-18 21:56:30 +08:00
|
|
|
MovieEventHandler():_playToggle(true),_trackMouse(false) {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
void setMouseTracking(bool track) { _trackMouse = track; }
|
|
|
|
bool getMouseTracking() const { return _trackMouse; }
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
void set(osg::Node* node);
|
|
|
|
|
2012-10-05 18:35:06 +08:00
|
|
|
void setTrackMouse(bool tm)
|
|
|
|
{
|
|
|
|
if (tm==_trackMouse) return;
|
|
|
|
|
|
|
|
_trackMouse = tm;
|
|
|
|
|
|
|
|
std::cout << "tracking mouse: " << (_trackMouse ? "ON" : "OFF") << std::endl;
|
|
|
|
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if ((*itr)->getStatus()==osg::ImageStream::PLAYING)
|
|
|
|
{
|
|
|
|
(*itr)->pause();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*itr)->play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getTrackMouse() const { return _trackMouse; }
|
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
|
|
|
|
typedef std::vector< osg::observer_ptr<osg::ImageStream> > ImageStreamList;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
struct ImageStreamPlaybackSpeedData {
|
|
|
|
double fps;
|
|
|
|
unsigned char* lastData;
|
|
|
|
double timeStamp, lastOutput;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
ImageStreamPlaybackSpeedData() : fps(0), lastData(NULL), timeStamp(0), lastOutput(0) {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
};
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
typedef std::vector< ImageStreamPlaybackSpeedData > ImageStreamPlayBackSpeedList;
|
2008-08-15 00:28:45 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~MovieEventHandler() {}
|
|
|
|
|
|
|
|
class FindImageStreamsVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FindImageStreamsVisitor(ImageStreamList& imageStreamList):
|
|
|
|
_imageStreamList(imageStreamList) {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
virtual void apply(osg::Geode& geode)
|
|
|
|
{
|
|
|
|
apply(geode.getStateSet());
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
|
|
|
{
|
|
|
|
apply(geode.getDrawable(i)->getStateSet());
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
traverse(geode);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(osg::Node& node)
|
|
|
|
{
|
|
|
|
apply(node.getStateSet());
|
|
|
|
traverse(node);
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
inline void apply(osg::StateSet* stateset)
|
|
|
|
{
|
|
|
|
if (!stateset) return;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
osg::StateAttribute* attr = stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE);
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr);
|
|
|
|
if (texture2D) apply(dynamic_cast<osg::ImageStream*>(texture2D->getImage()));
|
|
|
|
|
|
|
|
osg::TextureRectangle* textureRec = dynamic_cast<osg::TextureRectangle*>(attr);
|
|
|
|
if (textureRec) apply(dynamic_cast<osg::ImageStream*>(textureRec->getImage()));
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
inline void apply(osg::ImageStream* imagestream)
|
|
|
|
{
|
|
|
|
if (imagestream)
|
|
|
|
{
|
2015-10-22 21:42:19 +08:00
|
|
|
_imageStreamList.push_back(imagestream);
|
2008-08-15 00:28:45 +08:00
|
|
|
s_imageStream = imagestream;
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
ImageStreamList& _imageStreamList;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2009-02-03 23:28:53 +08:00
|
|
|
protected:
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2009-02-03 23:28:53 +08:00
|
|
|
FindImageStreamsVisitor& operator = (const FindImageStreamsVisitor&) { return *this; }
|
2008-08-15 00:28:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool _playToggle;
|
|
|
|
bool _trackMouse;
|
|
|
|
ImageStreamList _imageStreamList;
|
2012-09-13 00:35:12 +08:00
|
|
|
ImageStreamPlayBackSpeedList _imageStreamPlayBackSpeedList;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MovieEventHandler::set(osg::Node* node)
|
|
|
|
{
|
|
|
|
_imageStreamList.clear();
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
FindImageStreamsVisitor fisv(_imageStreamList);
|
|
|
|
node->accept(fisv);
|
|
|
|
}
|
2012-09-13 00:35:12 +08:00
|
|
|
_imageStreamPlayBackSpeedList.resize(_imageStreamList.size());
|
2008-08-15 00:28:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
switch(ea.getEventType())
|
|
|
|
{
|
2012-09-13 00:35:12 +08:00
|
|
|
case(osgGA::GUIEventAdapter::FRAME):
|
|
|
|
{
|
|
|
|
double t = ea.getTime();
|
|
|
|
bool printed(false);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
ImageStreamPlayBackSpeedList::iterator fps_itr = _imageStreamPlayBackSpeedList.begin();
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr, ++fps_itr)
|
|
|
|
{
|
|
|
|
if (((*itr)->getStatus()==osg::ImageStream::PLAYING) && ((*itr)->data() != (*fps_itr).lastData))
|
|
|
|
{
|
|
|
|
ImageStreamPlaybackSpeedData& data(*fps_itr);
|
|
|
|
double dt = (data.timeStamp > 0) ? t - data.timeStamp : 1/60.0;
|
|
|
|
data.lastData = (*itr)->data();
|
|
|
|
data.fps = (*fps_itr).fps * 0.8 + 0.2 * (1/dt);
|
|
|
|
data.timeStamp = t;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
if (t-data.lastOutput > 1)
|
|
|
|
{
|
|
|
|
std::cout << data.fps << " ";
|
|
|
|
data.lastOutput = t;
|
|
|
|
printed = true;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-09-13 00:35:12 +08:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
if (printed)
|
2012-09-13 00:35:12 +08:00
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case(osgGA::GUIEventAdapter::MOVE):
|
|
|
|
{
|
|
|
|
if (_trackMouse)
|
|
|
|
{
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
double dt = (*itr)->getLength() * ((1.0+ea.getXnormalized()) / 2.0);
|
|
|
|
(*itr)->seek(dt);
|
|
|
|
std::cout << "seeking to " << dt << " length: " <<(*itr)->getLength() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
case(osgGA::GUIEventAdapter::KEYDOWN):
|
|
|
|
{
|
|
|
|
if (ea.getKey()=='p')
|
|
|
|
{
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if ((*itr)->getStatus()==osg::ImageStream::PLAYING)
|
|
|
|
{
|
|
|
|
// playing, so pause
|
|
|
|
std::cout<<"Pause"<<std::endl;
|
|
|
|
(*itr)->pause();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// playing, so pause
|
|
|
|
std::cout<<"Play"<<std::endl;
|
|
|
|
(*itr)->play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ea.getKey()=='r')
|
|
|
|
{
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
std::cout<<"Restart"<<std::endl;
|
|
|
|
(*itr)->rewind();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ea.getKey()=='L')
|
|
|
|
{
|
|
|
|
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
|
|
|
itr!=_imageStreamList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if ( (*itr)->getLoopingMode() == osg::ImageStream::LOOPING)
|
|
|
|
{
|
|
|
|
std::cout<<"Toggle Looping Off"<<std::endl;
|
|
|
|
(*itr)->setLoopingMode( osg::ImageStream::NO_LOOPING );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout<<"Toggle Looping On"<<std::endl;
|
|
|
|
(*itr)->setLoopingMode( osg::ImageStream::LOOPING );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2012-09-13 00:35:12 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
else if (ea.getKey() == 'i')
|
2012-09-13 00:35:12 +08:00
|
|
|
{
|
2012-10-05 18:35:06 +08:00
|
|
|
setTrackMouse(!_trackMouse);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-13 00:35:12 +08:00
|
|
|
|
|
|
|
return false;
|
2008-08-15 00:28:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const
|
|
|
|
{
|
2012-09-13 00:35:12 +08:00
|
|
|
usage.addKeyboardMouseBinding("i","toggle interactive mode, scrub via mouse-move");
|
2008-08-15 00:28:45 +08:00
|
|
|
usage.addKeyboardMouseBinding("p","Play/Pause movie");
|
|
|
|
usage.addKeyboardMouseBinding("r","Restart movie");
|
|
|
|
usage.addKeyboardMouseBinding("l","Toggle looping of movie");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-07-22 22:47:59 +08:00
|
|
|
int main(int argc, char **argv)
|
2008-07-21 18:57:06 +08:00
|
|
|
{
|
2008-07-22 22:47:59 +08:00
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
// construct the viewer.
|
2008-07-22 22:47:59 +08:00
|
|
|
osgViewer::Viewer viewer(arguments);
|
2008-07-21 18:57:06 +08:00
|
|
|
|
2008-09-11 17:05:16 +08:00
|
|
|
std::string filename;
|
|
|
|
arguments.read("-o",filename);
|
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
// create a model from the images and pass it to the viewer.
|
2008-09-11 17:05:16 +08:00
|
|
|
viewer.setSceneData(createModel(arguments));
|
2008-07-21 18:57:06 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
// pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate.
|
|
|
|
MovieEventHandler* meh = new MovieEventHandler();
|
|
|
|
meh->set( viewer.getSceneData() );
|
2012-10-05 18:35:06 +08:00
|
|
|
|
|
|
|
if (arguments.read("--track-mouse")) meh->setTrackMouse(true);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 00:28:45 +08:00
|
|
|
viewer.addEventHandler( meh );
|
|
|
|
|
2008-09-22 23:56:22 +08:00
|
|
|
viewer.addEventHandler( new osgViewer::StatsHandler());
|
2008-08-15 00:28:45 +08:00
|
|
|
|
2008-09-11 17:05:16 +08:00
|
|
|
if (!filename.empty())
|
2008-07-23 00:44:49 +08:00
|
|
|
{
|
|
|
|
osgDB::writeNodeFile(*viewer.getSceneData(),filename);
|
|
|
|
}
|
2008-07-22 22:47:59 +08:00
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
return viewer.run();
|
|
|
|
}
|