osg动态加载模型不显示_OSG仿真案例(8)——读取FBX格式文件并显示(无动画)...
包含的頭
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
所需要的類(結(jié)構(gòu)體)
struct AnimationManagerFinder : public osg::NodeVisitor
{
osg::ref_ptr<: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<:animationmanagerbase>(node.getUpdateCallback());
if (b) {
_am = new osgAnimation::BasicAnimationManager(*b);
return;
}
}
traverse(node);
}
};
加載吧顯示模型
void xx()
{
osg::ref_ptr<:viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<:group> group1 = new osg::Group;
osg::ref_ptr<:matrixtransform> matrixTransform1 = new osg::MatrixTransform;
osg::ref_ptr<: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的內(nèi)容
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();
}
文件夾中數(shù)據(jù)
模型數(shù)據(jù)文件中的內(nèi)容
灰度效果的模型展示
模型顯示
參考技術(shù)
https://www.jianshu.com/p/c29f7c2fa865
https://blog.csdn.net/weixin_30622181/article/details/95825855
總結(jié)
以上是生活随笔為你收集整理的osg动态加载模型不显示_OSG仿真案例(8)——读取FBX格式文件并显示(无动画)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql 以 db 结尾_MySQL的
- 下一篇: 控制反转 java_控制反转( Ioc)