本文主要介绍通过osg读取fbx 3d模型,并播放模型所带的动画。
所使用到的类为AnimationManagerBase。
下面是完整代码:
//#include "AnimtkViewer.h"
//#include "AnimtkViewerKeyHandler.h"
#include <Windows.h>
#include <iostream>
#include <osgDB/ReadFile>
#include <osgViewer/ViewerEventHandlers>
#include <osgAnimation/BasicAnimationManager>
#include <iostream>
struct AnimationManagerFinder : public osg::NodeVisitor
{
osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;
AnimationManagerFinder() : osg::NodeVisitor(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);
}
};
int main(int argc, char **