summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2019-09-03 12:13:31 +0300
committerTomi Korpipaa <tomi.korpipaa@qt.io>2019-09-03 12:25:56 +0300
commita28046576c9f02144984c66e421fce2361f06a44 (patch)
treee66ed4c4e39dff528a512a96c0e89826674ca5ae
parenta8e3d0e5a23d3e957b9b0d29518af5f3ac7aeec3 (diff)
Fix light and camera import from Blender FBX
We may still get slightly different values sometimes, so it's best to leave the warning message in place. It should be noted that importing the same FBX back to Blender also results in slightly different values in some cases. Task-number: QT3DS-3368 Change-Id: I8cb772c6fa83ae0f15ca00dc5249ca90880ab483 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp2
-rw-r--r--src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp17
2 files changed, 16 insertions, 3 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
index 2e773291..6b87bfeb 100644
--- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
+++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
@@ -5424,7 +5424,7 @@ void IDocumentEditor::DisplayImportErrors(const QString &inImportSource,
for (size_t idx = 0; idx < inTranslationLog.m_Warnings.size(); ++idx) {
const std::pair<ESceneGraphWarningCode, Q3DStudio::CString> &warning(
inTranslationLog.m_Warnings[idx]);
- const wchar_t *formatStr = L"Unrecognized warning";
+ const wchar_t *formatStr = L"Unrecognized warning: \"%ls\"";
switch (warning.first) {
case ESceneGraphWarningCode_OnlySupportTriangles:
formatStr = L"Model \"%ls\" contains geometric elements other than triangles";
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp
index 56bd7407..644fc0b4 100644
--- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp
+++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp
@@ -258,7 +258,9 @@ bool FbxDomWalker::LoadDocument(const std::string &inFilePath)
major * 1000 + minor * 100 + revision);
m_AuthoringToolType = EAuthoringToolType_FBX_Maya;
} else if (strstr(appName, "Blender")) {
- qWarning("Importing from Blender. Light and Camera rotations may be incorrect");
+ m_Translator->LogWarning(ESceneGraphWarningCode_Generic,
+ "Imported from Blender. Light and Camera rotations may"
+ " be incorrect");
m_Translator->SetAuthoringTool(EAuthoringToolType_FBX_Blender,
major * 1000 + minor * 100 + revision);
m_AuthoringToolType = EAuthoringToolType_FBX_Blender;
@@ -487,6 +489,8 @@ void FbxDomWalker::ProcessLight(FbxNode *inFbxNode)
int lightType = light->LightType.Get();
if (lightType == FbxLight::eArea)
lightType = 4; // Area light type is 3 in FBX and 4 in DAE and internally
+ else if (lightType == FbxLight::eSpot)
+ m_Translator->LogWarning(ESceneGraphWarningCode_UnsupportedLight, lightName.c_str());
FbxLight::EDecayType decayType = light->DecayType.Get();
double linearDecay = (decayType == FbxLight::eLinear) ? light->DecayStart.Get() : 0.;
double quadDecay = (decayType == FbxLight::eQuadratic) ? light->DecayStart.Get() : 0.;
@@ -657,7 +661,16 @@ void FbxDomWalker::ProcessTransform(FbxNode *inFbxNode, bool ignoreScale)
// Lights and cameras should ignore scale
if (ignoreScale)
theTransformMatrix.SetS(FbxVector4(1.0, 1.0, 1.0, 1.0));
- // TODO: Do some rotation magic if m_AuthoringToolType == Blender?
+
+ // 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();
+ 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));
+ }
theTransforms.push_back(new NodeTransform(ETransformType_Matrix4x4));