diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2019-09-02 09:34:24 +0300 |
---|---|---|
committer | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2019-09-02 11:02:27 +0300 |
commit | 9ecb622c57f4b7262f5ee72b40fd1d297b86646a (patch) | |
tree | 464825d87618576e0cb97a960d230ca91df71ebb | |
parent | 747f520cc2e16a97d38c3caf28ecb1880ae1aa4c (diff) |
Fix FBX light import
Also change DAE import to match FBX import
on Hemi lights.
Task-number: QT3DS-3391
Change-Id: Ie1f36bd7a41f7ce461b2877a3664db27fd18e4fe
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
3 files changed, 45 insertions, 32 deletions
diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp index c58d4436..cea6ec8e 100644 --- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp +++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportColladaSGTranslation.cpp @@ -128,6 +128,7 @@ protected: void TrackObjectIndex(const daeElement *inElement, long inIndex); void GetIndicesFromElement(const daeElement *inElement, TLongsList &outIndicies); bool ApplyAnimation(const daeElement *inContainerElement); + int CheckLightType(const domLight *light); protected: std::function<void(const char *)> PushGroup; @@ -599,39 +600,26 @@ void ColladaDOMWalker::ProcessNode(const domNodeRef inNode) double linearFade = 0; double quadFade = 0; if (technique->getPoint()) { + // Blender exports Area light as Point type, so we need to check if we are + // dealing with Blender, and dig the actual light type from inside extra + // elements + type = CheckLightType(light); + type = (type == -1) ? 0 : type; domLight::domTechnique_common::domPointRef point = technique->getPoint(); color = point->getColor()->getValue(); linearFade = point->getLinear_attenuation()->getValue() * 1000; quadFade = point->getQuadratic_attenuation()->getValue() * 1000; - // Blender exports Area light as Point type, so we need to check if we are - // dealing with Blender, and dig the actual light type from inside extra - // elements - const domExtra_Array &lightExtraArray = light->getExtra_array(); - size_t extrasCount = lightExtraArray.getCount(); - for (size_t i = 0; i < extrasCount; ++i) { - domExtraRef lightExtra = lightExtraArray[i]; - const domTechnique_Array &lightExtraTechniqueArray - = lightExtra->getTechnique_array(); - size_t techniqueCount = lightExtraTechniqueArray.getCount(); - for (size_t j = 0; j < techniqueCount; ++j) { - domTechniqueRef lightExtraTechnique = lightExtraTechniqueArray[i]; - const char *profile = lightExtraTechnique->getProfile(); - if (::strcmp(profile, "blender") == 0) { - if (daeElement *theElement - = lightExtraTechnique->getChild("type")) { - type = GetIntFromElementChar(theElement); - } - break; - } - } - } } else if (technique->getDirectional()) { type = 1; domLight::domTechnique_common::domDirectionalRef directional = technique->getDirectional(); color = directional->getColor()->getValue(); } else if (technique->getAmbient()) { - type = 4; + // Blender exports Hemi light as Ambient type, so we need to check if we are + // dealing with Blender, and dig the actual light type from inside extra + // elements + type = CheckLightType(light); + type = (type == -1) ? 4 : type; domLight::domTechnique_common::domAmbientRef ambient = technique->getAmbient(); color = ambient->getColor()->getValue(); } else { @@ -675,6 +663,29 @@ void ColladaDOMWalker::ProcessNode(const domNodeRef inNode) } } +int ColladaDOMWalker::CheckLightType(const domLight *light) +{ + // In case of Blender, dig the actual light type from inside extra techniques + const domExtra_Array &lightExtraArray = light->getExtra_array(); + size_t extrasCount = lightExtraArray.getCount(); + for (size_t i = 0; i < extrasCount; ++i) { + domExtraRef lightExtra = lightExtraArray[i]; + const domTechnique_Array &lightExtraTechniqueArray + = lightExtra->getTechnique_array(); + size_t techniqueCount = lightExtraTechniqueArray.getCount(); + for (size_t j = 0; j < techniqueCount; ++j) { + domTechniqueRef lightExtraTechnique = lightExtraTechniqueArray[i]; + const char *profile = lightExtraTechnique->getProfile(); + if (::strcmp(profile, "blender") == 0) { + if (daeElement *theElement = lightExtraTechnique->getChild("type")) + return GetIntFromElementChar(theElement); + break; + } + } + } + return -1; // Not found +} + //============================================================================== /** * Processes transform elements on a <node>. diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp index d68df5d7..200584d2 100644 --- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp +++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportFbxSGTranslation.cpp @@ -484,9 +484,15 @@ void FbxDomWalker::ProcessLight(FbxNode *inFbxNode) ProcessTransform(inFbxNode, true); FbxLight *light = inFbxNode->GetLight(); FbxDouble3 color = light->Color.Get(); - m_Translator->SetLightProperties(light->LightType.Get(), - SFloat4(color[0], color[1], color[2], 1.0f), - light->Intensity.Get(), 0, 0, light->CastShadows.Get()); + int lightType = light->LightType.Get(); + if (lightType == FbxLight::eArea) + lightType = 4; // Area light type is 3 in FBX and 4 in DAE and internally + FbxLight::EDecayType decayType = light->DecayType.Get(); + double linearDecay = (decayType == FbxLight::eLinear) ? light->DecayStart.Get() : 0.; + double quadDecay = (decayType == FbxLight::eQuadratic) ? light->DecayStart.Get() : 0.; + m_Translator->SetLightProperties(lightType, SFloat4(float(color[0]), float(color[1]), + float(color[2]), 1.0f), light->Intensity.Get(), linearDecay, quadDecay, + light->CastShadows.Get()); ProcessNodeChildren(inFbxNode); m_Translator->PopLight(); } diff --git a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp index 66f5bb2b..45eed2c3 100644 --- a/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp +++ b/src/Authoring/QT3DSIMP/Qt3DSImportSGTranslation/Qt3DSImportSceneGraphTranslation.cpp @@ -490,8 +490,6 @@ public: void SetLightProperties(int type, const SFloat4 &color, double intensity, double linearfade, double quadfade, bool shadows) override { - Q_UNUSED(linearfade) - Q_UNUSED(quadfade) TIMPHandle light = m_InstanceStack.back(); switch (type) { case 0: @@ -510,10 +508,8 @@ public: } m_Import.SetInstancePropertyValue(light, m_Light.m_LightColor, color); m_Import.SetInstancePropertyValue(light, m_Light.m_Brightness, intensity); - // TODO: These do not seem to be incuded in FbxLight. Kept here in case Collada has support - // for them (QT3DS-2857) - //m_Import.SetInstancePropertyValue(light, m_Light.m_LinearFade, linearfade); - //m_Import.SetInstancePropertyValue(light, m_Light.m_ExpFade, quadfade); + m_Import.SetInstancePropertyValue(light, m_Light.m_LinearFade, linearfade); + m_Import.SetInstancePropertyValue(light, m_Light.m_ExpFade, quadfade); m_Import.SetInstancePropertyValue(light, m_Light.m_CastShadow, shadows); } void PopLight() override { PopObject(); } |