#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Group>
#include <osg/AutoTransform>
#include <osg/ProxyNode>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgText/Text>
#include <osgUtil/Optimizer>
#include<osg/Camera>
#include<osgViewer/Viewer>
#include <osgManipulator/Dragger>
#include <osgManipulator/Selection>
#include <osgManipulator/Constraint>
#include <osgManipulator/TranslateAxisDragger>
#include <osgManipulator/CommandManager>
#include<osgFX/Scribe>
#include<osg/MatrixTransform>
#include<osgAnimation/Animation>
#include<osgAnimation/Bone>
#include<osgAnimation/Skeleton>
#include<osgAnimation/UpdateMatrixTransform>
#include<osgAnimation/BasicAnimationManager>
#include<osgAnimation/MorphGeometry>
#include<osgUtil/SmoothingVisitor>
#include<osgAnimation/easeMotion>
#include<osg/BlendFunc>
#include<osg/ShapeDrawable>
#include<osg/ImageSequence>
#include<osg/Texture2D>
#include <iostream>
#include <thread>
#include <future>
#include <string>
#include<map>
#include<vector>
#include<list>
using std::vector;
using std::string;
using std::list;
using namespace std;
void createTexture2D(osg::StateSet* ss, osg::Image* pImage)
{
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setImage(pImage);
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER);
ss->setTextureAttributeAndModes(0, texture.get());
}
using namespace std;
int main()
{
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
for (int i = 0; i < 6; ++i)
{
char szBuf[10] = {0};
_itoa_s(i, szBuf, 2, 10);
imageSequence->addImage(osgDB::readImageFile(string(szBuf) + ".jpg"));
}
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0, 0.0, 0.0),
osg::Vec3(1.0, 0.0, 0.0), osg::Vec3(0.0, 0.0, 1.0), 1.0, 1.0));
createTexture2D((geode->getOrCreateStateSet()), imageSequence.get());
imageSequence->setLength(10.0); // 相邻两张图片切换的时间,单位秒
imageSequence->play();
osgViewer::Viewer viewer;
viewer.setSceneData(geode.get());
return viewer.run();
}