summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2019-09-03 06:36:59 +0300
committerTomi Korpipaa <tomi.korpipaa@qt.io>2019-09-03 11:25:24 +0300
commita8e3d0e5a23d3e957b9b0d29518af5f3ac7aeec3 (patch)
treeac83ae8ba3ebacd0d932c4226b0ce2911b49bff3
parentc9915401595dd054731d427b973cc8d7fad83f26 (diff)
Fix camera fov import from Maya DAE
Task-number: QT3DS-3915 Change-Id: Iead8b633711cbe2c3e6c0534fcd545383a64d67c Reviewed-by: Janne Kangas <janne.kangas@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp16
-rw-r--r--src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp4
-rw-r--r--src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h1
3 files changed, 20 insertions, 1 deletions
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp
index cea6ec8e..20626c9c 100644
--- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp
+++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp
@@ -40,6 +40,7 @@
#include "Qt3DSImportTranslationCommon.h"
#include "Qt3DSImportSceneGraphTranslation.h"
#include "Qt3DSImportTranslation.h"
+#include "Rotation3.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qfileinfo.h>
@@ -174,6 +175,7 @@ protected:
ISceneGraphTranslation *m_Translator;
const char *m_DAEFilename;
TElementToIndicesMap m_ElementToIndicies;
+ EAuthoringToolType m_authoringTool;
};
void FindTexturesViaNewParam(daeElement *inElementPtr, ColladaDOMWalker::TURIList &outTexturePaths)
@@ -466,6 +468,9 @@ void ColladaDOMWalker::SetFColladaAuthoringTool(const char *inName)
} else if (theAuthoringToolLowerCase.find("opencollada") != std::string::npos
&& theAuthoringToolLowerCase.find("3ds max") != std::string::npos) {
theAuthoringToolType = EAuthoringToolType_FCollada_Max;
+ } else if (theAuthoringToolLowerCase.find("opencollada") != std::string::npos) {
+ // Assume Maya if no 3ds max was found
+ theAuthoringToolType = EAuthoringToolType_OpenCollada_Maya;
}
long theAuthoringToolVersion = 0;
@@ -473,6 +478,7 @@ void ColladaDOMWalker::SetFColladaAuthoringTool(const char *inName)
|| theAuthoringToolType == EAuthoringToolType_FCollada_Maya)
theAuthoringToolVersion = GetFColladaVersion(theAuthoringToolLowerCase);
+ m_authoringTool = theAuthoringToolType;
SetAuthoringTool(theAuthoringToolType, theAuthoringToolVersion);
}
@@ -569,20 +575,30 @@ void ColladaDOMWalker::ProcessNode(const domNodeRef inNode)
double clipstart = 0;
double clipend = 0;
bool ortho = false;
+ double aspectRatio = 0;
if (technique->getPerspective()) {
fov = technique->getPerspective()->getXfov() != nullptr
? technique->getPerspective()->getXfov()->getValue()
: technique->getPerspective()->getYfov()->getValue();
clipstart = technique->getPerspective()->getZnear()->getValue();
clipend = technique->getPerspective()->getZfar()->getValue();
+ aspectRatio = technique->getPerspective()->getAspect_ratio()->getValue();
} else if (technique->getOrthographic()) {
fov = technique->getOrthographic()->getXmag() != nullptr
? technique->getOrthographic()->getXmag()->getValue()
: technique->getOrthographic()->getYmag()->getValue();
clipstart = technique->getOrthographic()->getZnear()->getValue();
clipend = technique->getOrthographic()->getZfar()->getValue();
+ aspectRatio = technique->getOrthographic()->getAspect_ratio()->getValue();
ortho = true;
}
+ if (m_authoringTool == EAuthoringToolType_OpenCollada_Maya) {
+ // Calculate horizontal fov from vertical fov:
+ // hfov = 2 * tan-1(w/h * tan(vfov / 2))
+ fov = Q3DStudio::QT3DS_RADIANS_TO_DEGREES * 2
+ * std::atan(aspectRatio * std::tan(Q3DStudio::QT3DS_DEGREES_TO_RADIANS
+ * fov / 2.));
+ }
SetCameraProperties(clipstart, clipend, ortho, fov);
} else if (lights.getCount()) {
// Light
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp
index 45eed2c3..bbc3c8c7 100644
--- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp
+++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp
@@ -525,8 +525,10 @@ public:
m_Import.SetInstancePropertyValue(camera, m_Camera.m_ClipFar, clipend);
m_Import.SetInstancePropertyValue(camera, m_Camera.m_Orthographic, ortho);
m_Import.SetInstancePropertyValue(camera, m_Camera.m_Fov, fov);
- if (m_AuthoringToolType == EAuthoringToolType_FBX_Maya)
+ if (m_AuthoringToolType == EAuthoringToolType_FBX_Maya
+ || m_AuthoringToolType == EAuthoringToolType_OpenCollada_Maya) {
m_Import.SetInstancePropertyValue(camera, m_Camera.m_FovHorizontal, true);
+ }
}
void PopCamera() override { PopObject(); }
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h
index 8935f28b..4a9c1e48 100644
--- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h
+++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.h
@@ -334,6 +334,7 @@ typedef enum _EAuthoringToolType {
EAuthoringToolType_NextGen_Maya,
EAuthoringToolType_FCollada_Max,
EAuthoringToolType_FCollada_Maya,
+ EAuthoringToolType_OpenCollada_Maya,
EAuthoringToolType_SketchUp,
EAuthoringToolType_Cinema4D,
EAuthoringToolType_StudioCORE,