diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2019-09-26 12:16:11 +0300 |
---|---|---|
committer | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2019-09-30 11:19:02 +0300 |
commit | 2d5a605cc21b66be30c250c26ab24150eb3a2ea7 (patch) | |
tree | 2526754c6f11f8f22cfb8599f225d8b7f17731ce | |
parent | 9460bfccae565337bc4b617db6431a0ffb7ba359 (diff) |
Fix light and camera import from 3ds Max FBX
Task-number: QT3DS-3952
Change-Id: Ie1f1126199f0b01bba69288e248924c9a970399f
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp index 86f22e56..8e0a0dc4 100644 --- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp +++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp @@ -159,6 +159,7 @@ protected: TNodeSet m_importNodes; EAuthoringToolType m_AuthoringToolType; bool m_reportedUnknownMaterials = false; + FbxAxisSystem::EUpVector m_originalUpVector; }; FbxDomWalker::FbxDomWalker(ISceneGraphTranslation *inTranslation) @@ -363,7 +364,8 @@ void FbxDomWalker::ProcessScene(bool animations) if (m_FbxScene != nullptr) { FbxAxisSystem SceneAxisSystem = m_FbxScene->GetGlobalSettings().GetAxisSystem(); int sign; - if (SceneAxisSystem.GetUpVector(sign) == FbxAxisSystem::eZAxis + m_originalUpVector = SceneAxisSystem.GetUpVector(sign); + if (m_originalUpVector == FbxAxisSystem::eZAxis && m_AuthoringToolType != EAuthoringToolType_FBX_Maya) { // Do automatic axis system conversion from Z-up to Y-up FbxAxisSystem::OpenGL.ConvertScene(m_FbxScene); @@ -675,13 +677,24 @@ void FbxDomWalker::ProcessTransform(FbxNode *inFbxNode, bool ignoreScale) theTransformMatrix.SetS(FbxVector4(1.0, 1.0, 1.0, 1.0)); // Do rotation corrections for cameras and lights if importing from Blender - // Note: Blender must have "Y Forward" and "Z Up" export settings defined for these to work - if (m_AuthoringToolType == EAuthoringToolType_FBX_Blender) { - FbxDouble3 rot = inFbxNode->LclRotation.Get(); + // Note: Blender and 3ds max must have "Y Forward" and "Z Up" export settings defined for + // these to work. For 3ds Max it is the default setting, but for Blender it is not. + if (m_originalUpVector == FbxAxisSystem::eZAxis) { + if (m_AuthoringToolType == EAuthoringToolType_FBX_Blender) { + FbxDouble3 rot = inFbxNode->LclRotation.Get(); + if (inFbxNode->GetLight()) + theTransformMatrix.SetR(FbxVector4(rot[0] - 90., rot[1], rot[2], 1.0)); + else if (inFbxNode->GetCamera()) + theTransformMatrix.SetR(FbxVector4(rot[0], rot[1] - 90., rot[2], 1.0)); + } + } else if (m_originalUpVector == FbxAxisSystem::eYAxis + && m_AuthoringToolType == EAuthoringToolType_FBX_Max) { + // 3ds Max messes up the positions if FBX is exported with y-up axis system. + // Fix that by switching the positions between z and y axes. + FbxDouble3 pos = inFbxNode->LclTranslation.Get(); + // Override the converted rotations with correct ones if (inFbxNode->GetLight()) - theTransformMatrix.SetR(FbxVector4(rot[0] - 90., rot[1], rot[2], 1.0)); - else if (inFbxNode->GetCamera()) - theTransformMatrix.SetR(FbxVector4(rot[0], rot[1] - 90., rot[2], 1.0)); + theTransformMatrix.SetT(FbxVector4(pos[0], pos[1], pos[2], 1.0)); } theTransforms.push_back(new NodeTransform(ETransformType_Matrix4x4)); |