zoukankan      html  css  js  c++  java
  • osg 加载 fbx文件

    #ifdef _WIN32
    #include <Windows.h>
    #endif // _WIN32
    
    #include <osg/Group>
    #include <osg/Camera>
    #include <osg/Node>
    #include <osg/Geometry>
    
    #include <osg/Image>
    #include <osg/ShapeDrawable>
    #include <osg/Texture2D>
    #include <osg/MatrixTransform>
    
    #include <osg/AnimationPath>
    #include <osg/ArgumentParser>
    #include <osg/NodeVisitor>
    
    #include <osgDB/FileNameUtils>
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    #include <osgViewer/ViewerEventHandlers>
    
    #include <osgGA/DriveManipulator>
    #include <osgGA/GUIEventHandler>
    #include <osgGA/GUIEventAdapter>
    #include <osgGA/GUIActionAdapter>
    
    #include <osgGA/AnimationPathManipulator>
    #include <osgGA/KeySwitchMatrixManipulator>
    
    #include <osgUtil/LineSegmentIntersector>
    #include <osgAnimation/BasicAnimationManager>
    
    #include <iostream>
    using namespace std;
    
    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** argv)
    {
        //osg::ArgumentParser arguments(&argc, argv);
        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("I:\BIM\fbx\Worker201907.fbx");
        //osg::ref_ptr<osgAnimation::BasicAnimationManager> basicAnimationManager1 = dynamic_cast<osgAnimation::BasicAnimationManager*>(node1->getUpdateCallback());
        /*
        osgAnimation::BasicAnimationManager* basicAnimationManager1 = dynamic_cast<osgAnimation::BasicAnimationManager*>(node1->getUpdateCallback());
        osgAnimation::AnimationList animationList1 = basicAnimationManager1->getAnimationList();
        osgAnimation::AnimationList::iterator animationList_iter;
        for (animationList_iter = animationList1.begin();animationList_iter != animationList1.end();++animationList_iter)
        {
            std::string name = (*animationList_iter)->getName();
            std::cout << name << std::endl;
            basicAnimationManager1->playAnimation(*animationList_iter);
        }
    */
    /*
        for (unsigned int i = 0; i<animationList1.size(); ++i)
        {
            const std::string& name = animationList1[i]->getName();
            basicAnimationManager1->playAnimation(animationList1[i].get());
            if (true)
            {
                std::cout << name << std::endl;
            }
        }
    */
        AnimationManagerFinder animationManagerFinder1;
        group1->accept(animationManagerFinder1);
    
        if (animationManagerFinder1._am.valid())
        {
            std::string playModeOpt;
            osgAnimation::Animation::PlayMode playMode = osgAnimation::Animation::LOOP;
            
            if (osgDB::equalCaseInsensitive(playModeOpt, "ONCE"))
            {
                playMode = osgAnimation::Animation::ONCE;
            }
            else if (osgDB::equalCaseInsensitive(playModeOpt, "STAY"))
            {
                playMode = osgAnimation::Animation::STAY;
            }
            else if (osgDB::equalCaseInsensitive(playModeOpt, "LOOP"))
            {
                playMode = osgAnimation::Animation::LOOP;
            }
            else if (osgDB::equalCaseInsensitive(playModeOpt, "PPONG"))
            {
                playMode = osgAnimation::Animation::PPONG;
            }
    
            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);
        return viewer1->run();
    }

     

    export root node
    Node : RootNode
    Node : RootNode
    Node : construction_worker
    Node : Bip001
    Node : Bip001 Pelvis
    Node : Bip001 Spine
    Node : Bip001 Spine1
    Node : Bip001 Neck
    Node : Bip001 L Clavicle
    Node : Bip001 L UpperArm
    Node : Bip001 L Forearm
    Node : Bip001 L Hand
    Node : Bip001 L Finger0
    Node : Bip001 L Finger01
    Node : Bip001 L Finger02
    Node : Bip001 L Finger1
    Node : Bip001 L Finger11
    Node : Bip001 L Finger12
    Node : Bip001 L Finger2
    Node : Bip001 L Finger21
    Node : Bip001 L Finger22
    Node : Bip001 L Finger3
    Node : Bip001 L Finger31
    Node : Bip001 L Finger32
    Node : Bip001 L Finger4
    Node : Bip001 L Finger41
    Node : Bip001 L Finger42
    Node : Bip001 R Clavicle
    Node : Bip001 R UpperArm
    Node : Bip001 R Forearm
    Node : Bip001 R Hand
    Node : Bip001 R Finger0
    Node : Bip001 R Finger01
    Node : Bip001 R Finger02
    Node : Bip001 R Finger1
    Node : Bip001 R Finger11
    Node : Bip001 R Finger12
    Node : Bip001 R Finger2
    Node : Bip001 R Finger21
    Node : Bip001 R Finger22
    Node : Bip001 R Finger3
    Node : Bip001 R Finger31
    Node : Bip001 R Finger32
    Node : Bip001 R Finger4
    Node : Bip001 R Finger41
    Node : Bip001 R Finger42
    Node : Bip001 Head
    Node : helmet_bone
    Node : Bip001 L Thigh
    Node : Bip001 L Calf
    Node : Bip001 L Foot
    Node : Bip001 L Toe0
    Node : hip_adjustment_bone_left
    Node : Bip001 R Thigh
    Node : Bip001 R Calf
    Node : Bip001 R Foot
    Node : Bip001 R Toe0
    Node : hip_adjustment_bone_right
    export root node done
    done

  • 相关阅读:
    Vue学习Day05-Vue中组件间的通讯(父到子,子到父,兄弟间)
    mysql数据库阻塞事务分析(thread_running突然升高)
    新建npm的nexus本地仓库,npm install报错npm ERR! code E401
    sqlserver数据库可以ping通但是1433端口无法telnet
    ansible使用synchronize模块报Broken pipe
    centos7上vagrant的安装及使用
    centos无法安装后无法识别r6818网卡问题
    手动上传snapshot和第三方jar包到nexus3
    搭建docker私有仓库nexus
    python3的pip安装报错pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  • 原文地址:https://www.cnblogs.com/herd/p/11137065.html
Copyright © 2011-2022 走看看