包含的头
#include <iostream>
#include <Windows.h>
#include <osgDB/ReadFile>
#include <osgViewer/ViewerEventHandlers>
#include <osgAnimation/BasicAnimationManager>
#include <osgEarthUtil/ExampleResources>
#include <osgEarth/Registry>
#include <osgEarthUtil/Controls>
#include <osgEarthSymbology/Color>
using namespace std;
所需要的类(结构体)
struct AnimationManagerFinder : public osg::NodeVisitor
{
osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;
AnimationManagerFinder()
{
osg::NodeVisitor sss=osg::NodeVisitor::TRAVERSE_ALL_CHILDREN;
}
void apply(osg::Node& node) {
if (_am.valid())
return;
if (node.getUpdateCallback()) {
osgAnimation::AnimationManagerBase* b = dynamic_cast<osgAnimation::AnimationManagerBase*>(node.getUpdateCallback());
if (b) {
_am = new osgAnimation::BasicAnimationManager(*b);
return;
}
}
traverse(node);
}
};
加载吧显示模型
void xx()
{
osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> group1 = new osg::Group;
osg::ref_ptr<osg::MatrixTransform> matrixTransform1 = new osg::MatrixTransform;
osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("E:\\......\\0000.fbx");
AnimationManagerFinder animationManagerFinder1;
group1->accept(animationManagerFinder1);
if (animationManagerFinder1._am.valid())
{
std::string playModeOpt;
osgAnimation::Animation::PlayMode playMode = osgAnimation::Animation::LOOP;
//此处加if的内容
for (osgAnimation::AnimationList::const_iterator animIter = animationManagerFinder1._am->getAnimationList().begin();
animIter != animationManagerFinder1._am->getAnimationList().end();
++animIter)
{
(*animIter)->setPlayMode(playMode);
}
}
matrixTransform1->setMatrix(osg::Matrix::translate(0.0, 0.0, 0.0));
matrixTransform1->addChild(node1);
group1->addChild(matrixTransform1);
viewer1->setSceneData(group1);
viewer1->setUpViewInWindow(200, 200, 800, 600, 0);
viewer1->run();
}
文件夹中数据
灰度效果的模型展示
参考技术
https://www.jianshu.com/p/c29f7c2fa865
https://blog.csdn.net/weixin_30622181/article/details/95825855