Permalink
Browse files

From Paul Cheyrou-Lagreze, "Attached is fix/feature for FBX osgplugin…

…s 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 )"
  • Loading branch information...
1 parent 96c6788 commit b6295ceb7a1b93de238912d061c18d108a8308bb @osg-training-guest osg-training-guest committed Apr 9, 2014
Showing with 87 additions and 18 deletions.
  1. +44 −4 CMakeModules/FindFBX.cmake
  2. +43 −14 src/osgPlugins/fbx/ReaderWriterFBX.cpp
View
@@ -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
)
@@ -74,6 +76,44 @@ ELSE()
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)
SET(FBX_LIBNAME "fbxsdk-2013.3-static")
@@ -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
@@ -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;

0 comments on commit b6295ce

Please sign in to comment.