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

  • 相关阅读:
    【贪心】【堆】Gym
    【并查集】Gym
    【拓扑排序】【bitset】Gym
    【递归】【线段树】【堆】AtCoder Regular Contest 080 E
    【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel
    【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal
    【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix
    【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game
    【推导】【构造】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem E. Space Tourists
    【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures
  • 原文地址:https://www.cnblogs.com/herd/p/11137065.html
Copyright © 2011-2022 走看看