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 )"
This commit is contained in:
Robert Osfield 2014-04-09 17:40:27 +00:00
parent db6df6fefd
commit c168887e5e
2 changed files with 91 additions and 22 deletions

View File

@ -18,8 +18,10 @@ ELSEIF(MSVC90)
SET(FBX_LIBDIR "vs2008") SET(FBX_LIBDIR "vs2008")
ELSEIF(MSVC10) ELSEIF(MSVC10)
SET(FBX_LIBDIR "vs2010") SET(FBX_LIBDIR "vs2010")
ELSEIF(MSVC11 OR MSVC_VERSION>1700) ELSEIF(MSVC11)
SET(FBX_LIBDIR "vs2012") SET(FBX_LIBDIR "vs2012")
ELSEIF(MSVC12 OR MSVC_VERSION>1800)
SET(FBX_LIBDIR "vs2013")
ENDIF() ENDIF()
IF(APPLE) IF(APPLE)
@ -44,8 +46,8 @@ SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
SET( FBX_SEARCH_PATHS SET( FBX_SEARCH_PATHS
$ENV{FBX_DIR} $ENV{FBX_DIR}
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.1" "$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.2"
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.1" "$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.2"
/Applications/Autodesk/FBXSDK20141 /Applications/Autodesk/FBXSDK20141
) )
@ -74,21 +76,21 @@ ELSE()
ENDIF() ENDIF()
IF(NOT FBX_FOUND) IF(NOT FBX_FOUND)
#try to use 2013.3 version #try to use 2014.1 version
IF(APPLE) IF(APPLE)
SET(FBX_LIBNAME "fbxsdk-2013.3-static") SET(FBX_LIBNAME "fbxsdk-2014.1")
ELSEIF(CMAKE_COMPILER_IS_GNUCXX) ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
SET(FBX_LIBNAME "fbxsdk-2013.3-static") SET(FBX_LIBNAME "fbxsdk-2014.1")
ELSE() ELSE()
SET(FBX_LIBNAME "fbxsdk-2013.3-md") SET(FBX_LIBNAME "fbxsdk-2014.1")
ENDIF() ENDIF()
SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d) SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
SET( FBX_SEARCH_PATHS SET( FBX_SEARCH_PATHS
$ENV{FBX_DIR} $ENV{FBX_DIR}
$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2013.3 $ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.1
$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2013.3 $ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.1
/Applications/Autodesk/FBXSDK20141 /Applications/Autodesk/FBXSDK20141
) )
@ -110,3 +112,41 @@ IF(NOT FBX_FOUND)
ENDIF() ENDIF()
ENDIF() ENDIF()
IF(NOT FBX_FOUND)
#try to use 2013.3 version
IF(APPLE)
SET(FBX_LIBNAME "fbxsdk-2013.3-static")
ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
SET(FBX_LIBNAME "fbxsdk-2013.3-static")
ELSE()
SET(FBX_LIBNAME "fbxsdk-2013.3-md")
ENDIF()
SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
SET( FBX_SEARCH_PATHS
$ENV{FBX_DIR}
$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2013.3
$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2013.3
/Applications/Autodesk/FBXSDK20133
)
# 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()

View File

@ -265,6 +265,7 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
bool useFbxRoot = false; bool useFbxRoot = false;
bool lightmapTextures = false; bool lightmapTextures = false;
bool tessellatePolygons = false; bool tessellatePolygons = false;
bool zUp = false;
if (options) if (options)
{ {
std::istringstream iss(options->getOptionString()); std::istringstream iss(options->getOptionString());
@ -283,6 +284,10 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
{ {
tessellatePolygons = true; tessellatePolygons = true;
} }
if (opt == "ZUp")
{
zUp = true;
}
} }
} }
@ -370,29 +375,53 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
} }
FbxAxisSystem fbxAxis = pScene->GetGlobalSettings().GetAxisSystem(); FbxAxisSystem fbxAxis = pScene->GetGlobalSettings().GetAxisSystem();
// some reminder: http://www.realtimerendering.com/blog/left-handed-vs-right-handed-world-coordinates/
if (fbxAxis != FbxAxisSystem::OpenGL)
{
int upSign; int upSign;
FbxAxisSystem::EUpVector eUp = fbxAxis.GetUpVector(upSign); FbxAxisSystem::EUpVector eUp = fbxAxis.GetUpVector(upSign);
bool bLeftHanded = fbxAxis.GetCoorSystem() == FbxAxisSystem::eLeftHanded; bool bLeftHanded = fbxAxis.GetCoorSystem() == FbxAxisSystem::eLeftHanded;
float fSign = upSign < 0 ? -1.0f : 1.0f; float fSign = upSign < 0 ? 1.0f : -1.0f;
float zScale = bLeftHanded ? -1.0f : 1.0f; float HorizSign = bLeftHanded ? -1.0f : 1.0f;
bool refCoordSysChange = false;
osg::Matrix mat; osg::Matrix mat;
if (zUp)
{
if (eUp != FbxAxisSystem::eZAxis || fSign != 1.0 || upSign != 1.0)
{
switch (eUp) switch (eUp)
{ {
case FbxAxisSystem::eXAxis: 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; break;
case FbxAxisSystem::eYAxis: 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,0,-fSign*HorizSign,0,0,fSign,0,0,0,0,0,1);
break; break;
case FbxAxisSystem::eZAxis: 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,fSign,0,0,0,0,fSign*HorizSign,0,0,0,0,1);
break; break;
} }
refCoordSysChange = true;
}
}
else if (fbxAxis != FbxAxisSystem::OpenGL)
{
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,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*HorizSign,0,0,fSign,0,0,0,0,0,1);
break;
}
refCoordSysChange = true;
}
if (refCoordSysChange)
{
osg::Transform* pTransformTemp = osgNode->asTransform(); osg::Transform* pTransformTemp = osgNode->asTransform();
osg::MatrixTransform* pMatrixTransform = pTransformTemp ? osg::MatrixTransform* pMatrixTransform = pTransformTemp ?
pTransformTemp->asMatrixTransform() : NULL; pTransformTemp->asMatrixTransform() : NULL;