summaryrefslogtreecommitdiffstats
path: root/src/plugins/sceneparsers/assimp/assimpimporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sceneparsers/assimp/assimpimporter.cpp')
-rw-r--r--src/plugins/sceneparsers/assimp/assimpimporter.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/plugins/sceneparsers/assimp/assimpimporter.cpp b/src/plugins/sceneparsers/assimp/assimpimporter.cpp
index 91763d156..4d32d1cc7 100644
--- a/src/plugins/sceneparsers/assimp/assimpimporter.cpp
+++ b/src/plugins/sceneparsers/assimp/assimpimporter.cpp
@@ -20,9 +20,8 @@
#include <Qt3DExtras/qdiffusespecularmapmaterial.h>
#include <Qt3DExtras/qphongmaterial.h>
#include <Qt3DExtras/qmorphphongmaterial.h>
-#include <Qt3DExtras/qdiffusemapmaterial.h>
-#include <Qt3DExtras/qdiffusespecularmapmaterial.h>
-#include <Qt3DExtras/qphongmaterial.h>
+#include <Qt3DExtras/qnormaldiffusemapmaterial.h>
+#include <Qt3DExtras/qnormaldiffusespecularmapmaterial.h>
#include <Qt3DAnimation/qkeyframeanimation.h>
#include <Qt3DAnimation/qmorphinganimation.h>
#include <QtCore/QFileInfo>
@@ -36,11 +35,12 @@
QT_BEGIN_NAMESPACE
-using namespace Qt3DCore;
-using namespace Qt3DExtras;
namespace Qt3DRender {
+using namespace Qt3DCore;
+using namespace Qt3DExtras;
+
/*!
\class Qt3DRender::AssimpImporter
\inmodule Qt3DRender
@@ -69,6 +69,8 @@ const QString ASSIMP_MATERIAL_AMBIENT_TEXTURE = QLatin1String("ambientTex");
const QString ASSIMP_MATERIAL_SPECULAR_TEXTURE = QLatin1String("specularTexture");
const QString ASSIMP_MATERIAL_EMISSIVE_TEXTURE = QLatin1String("emissiveTex");
const QString ASSIMP_MATERIAL_NORMALS_TEXTURE = QLatin1String("normalsTex");
+// Keep the old "normalsTex" parameter name to keep backwards compatibility, add "normalTexture" as a new one
+const QString ASSIMP_MATERIAL_NORMALS_TEXTURE2 = QLatin1String("normalTexture");
const QString ASSIMP_MATERIAL_OPACITY_TEXTURE = QLatin1String("opacityTex");
const QString ASSIMP_MATERIAL_REFLECTION_TEXTURE = QLatin1String("reflectionTex");
const QString ASSIMP_MATERIAL_HEIGHT_TEXTURE = QLatin1String("heightTex");
@@ -115,9 +117,14 @@ inline QString aiStringToQString(const aiString &str)
QMaterial *createBestApproachingMaterial(const aiMaterial *assimpMaterial)
{
aiString path; // unused but necessary
+ const bool hasNormalTexture = (assimpMaterial->GetTexture(aiTextureType_NORMALS, 0, &path) == AI_SUCCESS);
const bool hasDiffuseTexture = (assimpMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &path) == AI_SUCCESS);
const bool hasSpecularTexture = (assimpMaterial->GetTexture(aiTextureType_SPECULAR, 0, &path) == AI_SUCCESS);
+ if (hasNormalTexture && hasDiffuseTexture && hasSpecularTexture)
+ return QAbstractNodeFactory::createNode<QNormalDiffuseSpecularMapMaterial>("QNormalDiffuseSpecularMapMaterial");
+ if (hasNormalTexture && hasDiffuseTexture)
+ return QAbstractNodeFactory::createNode<QNormalDiffuseMapMaterial>("QNormalDiffuseMapMaterial");
if (hasDiffuseTexture && hasSpecularTexture)
return QAbstractNodeFactory::createNode<QDiffuseSpecularMapMaterial>("QDiffuseSpecularMapMaterial");
if (hasDiffuseTexture)
@@ -810,11 +817,7 @@ QGeometryRenderer *AssimpImporter::loadMesh(uint meshIndex)
= new Qt3DAnimation::QMorphingAnimation(geometryRenderer);
QList<QString> names;
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QList<Qt3DAnimation::QMorphTarget *> targets;
-#else
- QVector<Qt3DAnimation::QMorphTarget *> targets;
-#endif
uint voff = 0;
uint noff = 0;
uint tanoff = 0;
@@ -1131,11 +1134,7 @@ void AssimpImporter::loadAnimation(uint animationIndex)
aiMesh *mesh = m_scene->m_aiScene->mMeshes[targetNode->mMeshes[0]];
Qt3DAnimation::QMorphingAnimation *morphingAnimation = new Qt3DAnimation::QMorphingAnimation;
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QList<float> positions;
-#else
- QVector<float> positions;
-#endif
positions.resize(morphAnim->mNumKeys);
// set so that weights array is allocated to correct size in morphingAnimation
morphingAnimation->setTargetPositions(positions);
@@ -1143,11 +1142,7 @@ void AssimpImporter::loadAnimation(uint animationIndex)
aiMeshMorphKey &key = morphAnim->mKeys[j];
positions[j] = key.mTime * tickScale;
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QList<float> weights;
-#else
- QVector<float> weights;
-#endif
weights.resize(key.mNumValuesAndWeights);
for (int k = 0; k < weights.size(); k++) {
const unsigned int value = key.mValues[k];
@@ -1286,8 +1281,12 @@ void AssimpImporter::copyMaterialTextures(QMaterial *material, aiMaterial *assim
tex->setWrapMode(wrapMode);
qCDebug(AssimpImporterLog) << Q_FUNC_INFO << " Loaded Texture " << fullPath;
- setParameterValue(m_scene->m_textureToParameterName[textureType[i]],
- material, QVariant::fromValue(tex));
+ const QString parameterName = m_scene->m_textureToParameterName[textureType[i]];
+ setParameterValue(parameterName, material, QVariant::fromValue(tex));
+
+ if (parameterName == ASSIMP_MATERIAL_NORMALS_TEXTURE) {
+ setParameterValue(ASSIMP_MATERIAL_NORMALS_TEXTURE2, material, QVariant::fromValue(tex));
+ }
}
}
}