From c168887e5e9da4e891904d11ccac8ddd60b0362d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 9 Apr 2014 17:40:27 +0000 Subject: [PATCH] From Paul Cheyrou-Lagreze, "Attached is fix/feature for FBX osgplugins against latest trunk: - ReaderWriterFBX.cpp: add "z up scene axis" support: FBX provides facility to convert model scene axis during conversion. Currently fbx plugin convert axis to fbx:opengl axis system (which is arbitrarily at Y up, as opengl is in reality axis agnostic) and sometimes what is needed is Z up so added an option for Z up conversion - FindFBX.cmake: add support for latest fbx sdk ( 2014.2 )" --- CMakeModules/FindFBX.cmake | 48 ++++++++++++++++++++-- src/osgPlugins/fbx/ReaderWriterFBX.cpp | 57 +++++++++++++++++++------- 2 files changed, 87 insertions(+), 18 deletions(-) diff --git a/CMakeModules/FindFBX.cmake b/CMakeModules/FindFBX.cmake index 8911badbe..ebeeb1d5e 100644 --- a/CMakeModules/FindFBX.cmake +++ b/CMakeModules/FindFBX.cmake @@ -18,8 +18,10 @@ ELSEIF(MSVC90) SET(FBX_LIBDIR "vs2008") ELSEIF(MSVC10) SET(FBX_LIBDIR "vs2010") -ELSEIF(MSVC11 OR MSVC_VERSION>1700) +ELSEIF(MSVC11) SET(FBX_LIBDIR "vs2012") +ELSEIF(MSVC12 OR MSVC_VERSION>1800) + SET(FBX_LIBDIR "vs2013") ENDIF() IF(APPLE) @@ -44,8 +46,8 @@ SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d) SET( FBX_SEARCH_PATHS $ENV{FBX_DIR} - "$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.1" - "$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.1" + "$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.2" + "$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.2" /Applications/Autodesk/FBXSDK20141 ) @@ -73,6 +75,44 @@ ELSE() SET(FBX_FOUND "NO") ENDIF() +IF(NOT FBX_FOUND) +#try to use 2014.1 version + IF(APPLE) + SET(FBX_LIBNAME "fbxsdk-2014.1") + ELSEIF(CMAKE_COMPILER_IS_GNUCXX) + SET(FBX_LIBNAME "fbxsdk-2014.1") + ELSE() + SET(FBX_LIBNAME "fbxsdk-2014.1") + ENDIF() + + SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d) + + SET( FBX_SEARCH_PATHS + $ENV{FBX_DIR} + $ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.1 + $ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.1 + /Applications/Autodesk/FBXSDK20141 + ) + + # search for headers & debug/release libraries + FIND_PATH(FBX_INCLUDE_DIR "fbxsdk.h" + PATHS ${FBX_SEARCH_PATHS} + PATH_SUFFIXES "include") + FIND_LIBRARY( FBX_LIBRARY ${FBX_LIBNAME} + PATHS ${FBX_SEARCH_PATHS} + PATH_SUFFIXES "lib/${FBX_LIBDIR}") + + FIND_LIBRARY( FBX_LIBRARY_DEBUG ${FBX_LIBNAME_DEBUG} + PATHS ${FBX_SEARCH_PATHS} + PATH_SUFFIXES "lib/${FBX_LIBDIR}") + IF(FBX_LIBRARY AND FBX_LIBRARY_DEBUG AND FBX_INCLUDE_DIR) + SET(FBX_FOUND "YES") + ELSE() + SET(FBX_FOUND "NO") + ENDIF() + +ENDIF() + IF(NOT FBX_FOUND) #try to use 2013.3 version IF(APPLE) @@ -89,7 +129,7 @@ IF(NOT FBX_FOUND) $ENV{FBX_DIR} $ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2013.3 $ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2013.3 - /Applications/Autodesk/FBXSDK20141 + /Applications/Autodesk/FBXSDK20133 ) # search for headers & debug/release libraries diff --git a/src/osgPlugins/fbx/ReaderWriterFBX.cpp b/src/osgPlugins/fbx/ReaderWriterFBX.cpp index dc4892f02..103753fe2 100644 --- a/src/osgPlugins/fbx/ReaderWriterFBX.cpp +++ b/src/osgPlugins/fbx/ReaderWriterFBX.cpp @@ -265,6 +265,7 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, bool useFbxRoot = false; bool lightmapTextures = false; bool tessellatePolygons = false; + bool zUp = false; if (options) { std::istringstream iss(options->getOptionString()); @@ -283,6 +284,10 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, { tessellatePolygons = true; } + if (opt == "ZUp") + { + zUp = true; + } } } @@ -370,29 +375,53 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, } FbxAxisSystem fbxAxis = pScene->GetGlobalSettings().GetAxisSystem(); - - if (fbxAxis != FbxAxisSystem::OpenGL) + // some reminder: http://www.realtimerendering.com/blog/left-handed-vs-right-handed-world-coordinates/ + int upSign; + FbxAxisSystem::EUpVector eUp = fbxAxis.GetUpVector(upSign); + bool bLeftHanded = fbxAxis.GetCoorSystem() == FbxAxisSystem::eLeftHanded; + float fSign = upSign < 0 ? 1.0f : -1.0f; + float HorizSign = bLeftHanded ? -1.0f : 1.0f; + + bool refCoordSysChange = false; + osg::Matrix mat; + + if (zUp) + { + if (eUp != FbxAxisSystem::eZAxis || fSign != 1.0 || upSign != 1.0) + { + switch (eUp) + { + case FbxAxisSystem::eXAxis: + mat.set(0,fSign,0,0,-fSign,0,0,0,0,0,HorizSign,0,0,0,0,1); + break; + case FbxAxisSystem::eYAxis: + mat.set(1,0,0,0,0,0,-fSign*HorizSign,0,0,fSign,0,0,0,0,0,1); + break; + case FbxAxisSystem::eZAxis: + mat.set(1,0,0,0,0,fSign,0,0,0,0,fSign*HorizSign,0,0,0,0,1); + break; + } + refCoordSysChange = true; + } + } + else if (fbxAxis != FbxAxisSystem::OpenGL) { - int upSign; - FbxAxisSystem::EUpVector eUp = fbxAxis.GetUpVector(upSign); - bool bLeftHanded = fbxAxis.GetCoorSystem() == FbxAxisSystem::eLeftHanded; - float fSign = upSign < 0 ? -1.0f : 1.0f; - float zScale = bLeftHanded ? -1.0f : 1.0f; - - osg::Matrix mat; switch (eUp) { case FbxAxisSystem::eXAxis: - mat.set(0,fSign,0,0,-fSign,0,0,0,0,0,zScale,0,0,0,0,1); + mat.set(0,fSign,0,0,-fSign,0,0,0,0,0,HorizSign,0,0,0,0,1); break; case FbxAxisSystem::eYAxis: - mat.set(1,0,0,0,0,fSign,0,0,0,0,fSign*zScale,0,0,0,0,1); + mat.set(1,0,0,0,0,fSign,0,0,0,0,fSign*HorizSign,0,0,0,0,1); break; case FbxAxisSystem::eZAxis: - mat.set(1,0,0,0,0,0,-fSign*zScale,0,0,fSign,0,0,0,0,0,1); + mat.set(1,0,0,0,0,0,-fSign*HorizSign,0,0,fSign,0,0,0,0,0,1); break; - } - + } + refCoordSysChange = true; + } + if (refCoordSysChange) + { osg::Transform* pTransformTemp = osgNode->asTransform(); osg::MatrixTransform* pMatrixTransform = pTransformTemp ? pTransformTemp->asMatrixTransform() : NULL;