osg::ImageSequence实现纹理动画播放

#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();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值