osg添加骨骼模型

来源:互联网 发布:知乎提问怎么删除 编辑:程序博客网 时间:2024/04/30 05:13

1.首先是环境,这个不是本文的重点,前提是你环境已经配置好
2.在cmake生成的工程中,有一个FBX的插件,编译此插件会得到一 个DLL(osgdb_fbxd.dll)
3.将上面编译的DLL放置在当前工程的输出路径下就可以了

接下来是使用FBX加载模型,也可以参考OSG工程中的例子(osganimationviewer),不过例子中写的不是很明了,是win32工程,而且需要在工程中设置argv参数,传入fbx模型

我的环境是Qt中嵌入osg,加载FBX模型代码如下:

// 此模型有四套动作,分别是:(Boxing_Attack_02、Boxing_Attack_03 、Boxing_Defense_01、Boxing_Defense_02)    osg::Group* node1 = dynamic_cast<osg::Group*>(osgDB::readNodeFile("D:/OSG/osg_FBX/Sasuke.fbx"));     if(!node1)    {        return ;    }    AnimationManagerFinder finder;    node1->accept(finder);    if (finder._am.valid())     {            node1->setUpdateCallback(finder._am.get());            m_SkeletonControl1 = new AnimtkViewerModelController(finder._am.get());    }     else     {            osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl;    }    //矩阵调整位置    osg::ref_ptr<osg::MatrixTransform> nodeMatrix1 = new osg::MatrixTransform;    nodeMatrix1->addChild(node1);    //nodeMatrix1->addChild(node2);    nodeMatrix1->setMatrix( osg::Matrix::scale(0.5, 0.5, 0.5) *                         osg::Matrixd::rotate(osg::DegreesToRadians(90.0f), 1, 0, 0) *                         osg::Matrixd::translate(0, 0, -300));    //播放动画    m_SkeletonControl1->play();//默认播放第一个动作    //m_SkeletonControl1->playByName("Boxing_Defense_02");//选择某一个动作播放    //设置是否可见(0不可见)    nodeMatrix1->setNodeMask(0x0001);    //关闭光照    nodeMatrix1->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF);    //添加数据到根节点    m_pRoot->addChild(nodeMatrix1.get());

AnimationManagerFinder 和AnimtkViewerModelController可以在例子osganimationviewer中找到,本人对AnimtkViewerModelController类稍做了修改

模型下载地址:http://download.csdn.net/detail/wuchalilun/9724456

环境配置下载地址:http://download.csdn.net/detail/wuchalilun/9682033

FBX插件DLL下载:http://download.csdn.net/detail/wuchalilun/9724470

0 0