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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2018-07-05 IFC—IfcProduct实体继承框架