From 82cae6daf46220bdf0d756b7f3cb6b1ff9c0f244 Mon Sep 17 00:00:00 2001 From: Wei Lisi Date: Tue, 26 Mar 2019 21:01:24 +0800 Subject: [PATCH] fix fbx hierarchy issue --- src/osgPlugins/fbx/WriterNodeVisitor.cpp | 36 +++++++++++++++--------- src/osgPlugins/fbx/WriterNodeVisitor.h | 6 +++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.cpp b/src/osgPlugins/fbx/WriterNodeVisitor.cpp index 7871d4207..4844e8a78 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.cpp +++ b/src/osgPlugins/fbx/WriterNodeVisitor.cpp @@ -652,10 +652,10 @@ void WriterNodeVisitor::apply(osg::Geometry& geometry) // retrieved from the geometry. // create fbx node to contain the single geometry - FbxNode* parent = _curFbxNode; - FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, geometry.getName().empty() ? "Geometry" : geometry.getName().c_str()); - _curFbxNode->AddChild(nodeFBX); - _curFbxNode = nodeFBX; + //FbxNode* parent = _curFbxNode; + //FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, geometry.getName().empty() ? "Geometry" : geometry.getName().c_str()); + //_curFbxNode->AddChild(nodeFBX); + //_curFbxNode = nodeFBX; _geometryList.push_back(&geometry); @@ -669,23 +669,33 @@ void WriterNodeVisitor::apply(osg::Geometry& geometry) buildFaces(geometry.getName(), _geometryList, _listTriangles, _texcoords); // return to parent fbx node - _curFbxNode = parent; + //_curFbxNode = parent; } void WriterNodeVisitor::apply(osg::Group& node) { - FbxNode* parent = _curFbxNode; + if (_firstNodeProcessed) + { + FbxNode* parent = _curFbxNode; - FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str()); - _curFbxNode->AddChild(nodeFBX); - _curFbxNode = nodeFBX; + FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str()); + _curFbxNode->AddChild(nodeFBX); + _curFbxNode = nodeFBX; - traverse(node); + traverse(node); - if (_listTriangles.size() > 0) - buildFaces(node.getName(), _geometryList, _listTriangles, _texcoords); + if (_listTriangles.size() > 0) + buildFaces(node.getName(), _geometryList, _listTriangles, _texcoords); - _curFbxNode = parent; + _curFbxNode = parent; + } + else + { + _firstNodeProcessed = true; + traverse(node); + + + } } void WriterNodeVisitor::apply(osg::MatrixTransform& node) diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.h b/src/osgPlugins/fbx/WriterNodeVisitor.h index b0b72ada1..b7b779da4 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.h +++ b/src/osgPlugins/fbx/WriterNodeVisitor.h @@ -86,7 +86,8 @@ class WriterNodeVisitor: public osg::NodeVisitor _options(options), _externalWriter(srcDirectory, osgDB::getFilePath(fileName), true, 0), _texcoords(false), - _drawableNum(0) + _drawableNum(0), + _firstNodeProcessed(false) {} virtual void apply(osg::Geometry& node); @@ -234,6 +235,9 @@ class WriterNodeVisitor: public osg::NodeVisitor ///Tell us if the last apply succeed, useful to stop going through the graph. bool _succeedLastApply; + ///Marks if the first node is processed. + bool _firstNodeProcessed; + ///The current directory. std::string _directory;