summaryrefslogtreecommitdiffstats
path: root/src/plugins/sceneparsers
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-05-21 08:26:29 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-05-21 08:26:29 +0100
commit9f8fc3717508a6b8045f65e6c820692fb67dc450 (patch)
treead426afcaa91f61ecd669fbc416838f108554771 /src/plugins/sceneparsers
parenta830a9365832fd52c1849768543a64c55e4cee0a (diff)
parentcd9059a22604307f483764db134d51b15c540758 (diff)
Merge branch '5.9' into dev
Conflicts: .qmake.conf src/core/qscene.cpp src/plugins/sceneparsers/gltf/gltfimporter.cpp src/plugins/sceneparsers/gltfexport/gltfexporter.cpp src/render/texture/gltexture.cpp Change-Id: I7bde0fc0177eae252fef01cc43725fcf69c13a80
Diffstat (limited to 'src/plugins/sceneparsers')
-rw-r--r--src/plugins/sceneparsers/assimp/assimpimporter.cpp58
-rw-r--r--src/plugins/sceneparsers/assimp/assimpimporter.h1
-rw-r--r--src/plugins/sceneparsers/gltf/gltfimporter.cpp2
-rw-r--r--src/plugins/sceneparsers/gltfexport/gltfexporter.cpp43
-rw-r--r--src/plugins/sceneparsers/sceneparsers.pro10
5 files changed, 74 insertions, 40 deletions
diff --git a/src/plugins/sceneparsers/assimp/assimpimporter.cpp b/src/plugins/sceneparsers/assimp/assimpimporter.cpp
index 7e8681981..d5fc113e3 100644
--- a/src/plugins/sceneparsers/assimp/assimpimporter.cpp
+++ b/src/plugins/sceneparsers/assimp/assimpimporter.cpp
@@ -142,7 +142,7 @@ QMatrix4x4 aiMatrix4x4ToQMatrix4x4(const aiMatrix4x4 &matrix) Q_DECL_NOTHROW
/*!
* Returns a QString from \a str;
*/
-static inline QString aiStringToQString(const aiString &str)
+inline QString aiStringToQString(const aiString &str)
{
return QString::fromUtf8(str.data, int(str.length));
}
@@ -246,6 +246,21 @@ QAttribute *createAttribute(QBuffer *buffer,
return attribute;
}
+QTextureWrapMode::WrapMode wrapModeFromaiTextureMapMode(int mode)
+{
+ switch (mode) {
+ case aiTextureMapMode_Wrap:
+ return QTextureWrapMode::Repeat;
+ case aiTextureMapMode_Mirror:
+ return QTextureWrapMode::MirroredRepeat;
+ case aiTextureMapMode_Decal:
+ return QTextureWrapMode::ClampToBorder;
+ case aiTextureMapMode_Clamp:
+ default:
+ return QTextureWrapMode::ClampToEdge;
+ }
+}
+
} // anonymous
QStringList AssimpImporter::assimpSupportedFormatsList = AssimpImporter::assimpSupportedFormats();
@@ -428,7 +443,7 @@ Qt3DCore::QEntity *AssimpImporter::scene(const QString &id)
if (m_scene->m_animations.size() > 0) {
qWarning() << "No target found for " << m_scene->m_animations.size() << " animations!";
- for (Qt3DAnimation::QKeyframeAnimation *anim : m_scene->m_animations)
+ for (Qt3DAnimation::QKeyframeAnimation *anim : qAsConst(m_scene->m_animations))
delete anim;
m_scene->m_animations.clear();
}
@@ -490,7 +505,7 @@ Qt3DCore::QEntity *AssimpImporter::node(aiNode *node)
animations,
aiStringToQString(node->mName));
const auto morphTargetList = morphingAnimations.at(0)->morphTargetList();
- for (Qt3DAnimation::QMorphingAnimation *anim : animations) {
+ for (Qt3DAnimation::QMorphingAnimation *anim : qAsConst(animations)) {
anim->setParent(entityNode);
anim->setTarget(mesh);
anim->setMorphTargets(morphTargetList);
@@ -543,7 +558,7 @@ Qt3DCore::QEntity *AssimpImporter::node(aiNode *node)
animations,
aiStringToQString(node->mName));
- for (Qt3DAnimation::QKeyframeAnimation *anim : animations) {
+ for (Qt3DAnimation::QKeyframeAnimation *anim : qAsConst(animations)) {
anim->setTarget(transform);
anim->setParent(entityNode);
}
@@ -1237,18 +1252,28 @@ void AssimpImporter::copyMaterialTextures(QMaterial *material, aiMaterial *assim
for (unsigned int i = 0; i < sizeof(textureType)/sizeof(textureType[0]); i++) {
aiString path;
if (assimpMaterial->GetTexture(textureType[i], 0, &path) == AI_SUCCESS) {
- QString fullPath = m_sceneDir.absoluteFilePath(texturePath(path));
+ const QString fullPath = m_sceneDir.absoluteFilePath(texturePath(path));
// Load texture if not already loaded
- if (!m_scene->m_materialTextures.contains(fullPath)) {
- QAbstractTexture *tex = QAbstractNodeFactory::createNode<QTexture2D>("QTexture2D");
- QTextureImage *texImage = QAbstractNodeFactory::createNode<QTextureImage>("QTextureImage");
- texImage->setSource(QUrl::fromLocalFile(fullPath));
- tex->addTextureImage(texImage);
- m_scene->m_materialTextures.insert(fullPath, tex);
- qCDebug(AssimpImporterLog) << Q_FUNC_INFO << " Loaded Texture " << fullPath;
- }
+ QAbstractTexture *tex = QAbstractNodeFactory::createNode<QTexture2D>("QTexture2D");
+ QTextureImage *texImage = QAbstractNodeFactory::createNode<QTextureImage>("QTextureImage");
+ texImage->setSource(QUrl::fromLocalFile(fullPath));
+ tex->addTextureImage(texImage);
+
+ // Set proper wrapping mode
+ QTextureWrapMode wrapMode(QTextureWrapMode::Repeat);
+ int xMode = 0;
+ int yMode = 0;
+
+ if (assimpMaterial->Get(AI_MATKEY_MAPPINGMODE_U(textureType[i], 0), xMode) == aiReturn_SUCCESS)
+ wrapMode.setX(wrapModeFromaiTextureMapMode(xMode));
+ if (assimpMaterial->Get(AI_MATKEY_MAPPINGMODE_V(textureType[i], 0), yMode) == aiReturn_SUCCESS)
+ wrapMode.setY(wrapModeFromaiTextureMapMode(yMode));
+
+ tex->setWrapMode(wrapMode);
+
+ qCDebug(AssimpImporterLog) << Q_FUNC_INFO << " Loaded Texture " << fullPath;
setParameterValue(m_scene->m_textureToParameterName[textureType[i]],
- material, QVariant::fromValue(m_scene->m_materialTextures[fullPath]));
+ material, QVariant::fromValue(tex));
}
}
}
@@ -1297,8 +1322,9 @@ AssimpRawTextureImage::AssimpRawTextureImageFunctor::AssimpRawTextureImageFuncto
QTextureImageDataPtr AssimpRawTextureImage::AssimpRawTextureImageFunctor::operator()()
{
- QTextureImageDataPtr dataPtr;
- dataPtr->setData(m_data, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8);
+ QTextureImageDataPtr dataPtr = QTextureImageDataPtr::create();
+ // Note: we assume 4 components per pixel and not compressed for now
+ dataPtr->setData(m_data, 4, false);
return dataPtr;
}
diff --git a/src/plugins/sceneparsers/assimp/assimpimporter.h b/src/plugins/sceneparsers/assimp/assimpimporter.h
index 7335830f5..e37950981 100644
--- a/src/plugins/sceneparsers/assimp/assimpimporter.h
+++ b/src/plugins/sceneparsers/assimp/assimpimporter.h
@@ -143,7 +143,6 @@ private:
QMap<uint, QMaterial*> m_materials;
QMap<uint, QEffect *> m_effects;
QMap<uint, QAbstractTexture *> m_embeddedTextures;
- QMap<QString, QAbstractTexture *> m_materialTextures;
QMap<aiNode*, Qt3DCore::QEntity*> m_cameras;
QHash<aiTextureType, QString> m_textureToParameterName;
QVector<Qt3DAnimation::QKeyframeAnimation *> m_animations;
diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
index 6a10381df..78e230969 100644
--- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp
+++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
@@ -1546,7 +1546,7 @@ void GLTFImporter::processJSONExtensions(const QString &id, const QJsonObject &j
// level GLTF item.
if (id == KEY_COMMON_MAT) {
const auto lights = jsonObject.value(KEY_LIGHTS).toObject();
- for (auto lightKey : lights.keys()) {
+ for (const auto &lightKey : lights.keys()) {
const auto light = lights.value(lightKey).toObject();
auto lightType = light.value(KEY_TYPE).toString();
const auto lightValues = light.value(lightType).toObject();
diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
index 5fb1241d0..7921fce64 100644
--- a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
+++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
@@ -370,7 +370,7 @@ bool GLTFExporter::exportScene(QEntity *sceneRoot, const QString &outDir,
QFile::Permissions targetPermissions = gltfFile.permissions();
// Copy exported scene to actual export directory
- for (auto sourceFileStr : m_exportedFiles) {
+ for (const auto &sourceFileStr : m_exportedFiles) {
QFileInfo fiSource(m_exportDir + sourceFileStr);
QFileInfo fiDestination(finalExportDir + sourceFileStr);
if (fiDestination.exists()) {
@@ -524,7 +524,7 @@ void GLTFExporter::copyTextures()
void GLTFExporter::createShaders()
{
qCDebug(GLTFExporterLog, "Creating shaders...");
- for (auto si : m_shaderInfo) {
+ for (const auto &si : m_shaderInfo) {
const QString fileName = m_exportDir + si.uri;
QFile f(fileName);
if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
@@ -940,11 +940,11 @@ void GLTFExporter::parseMeshes()
qCDebug(GLTFExporterLog, " Vertex buffer size (bytes): %i", vertexBuf.size());
qCDebug(GLTFExporterLog, " Index buffer size (bytes): %i", indexBuf.size());
QStringList sl;
- for (auto bv : meshInfo.views)
+ for (const auto &bv : meshInfo.views)
sl << bv.name;
qCDebug(GLTFExporterLog) << " buffer views:" << sl;
sl.clear();
- for (auto acc : meshInfo.accessors)
+ for (const auto &acc : meshInfo.accessors)
sl << acc.name;
qCDebug(GLTFExporterLog) << " accessors:" << sl;
qCDebug(GLTFExporterLog, " material: '%ls'",
@@ -1129,7 +1129,7 @@ QString GLTFExporter::addShaderInfo(QShaderProgram::ShaderType type, QByteArray
if (code.isEmpty())
return QString();
- for (auto si : m_shaderInfo) {
+ for (const auto &si : m_shaderInfo) {
if (si.type == QShaderProgram::Vertex && code == si.code)
return si.name;
}
@@ -1153,10 +1153,11 @@ bool GLTFExporter::saveScene()
QVector<MeshInfo::BufferView> bvList;
QVector<MeshInfo::Accessor> accList;
- for (auto mi : m_meshInfo.values()) {
- for (auto v : mi.views)
+ for (auto it = m_meshInfo.begin(); it != m_meshInfo.end(); ++it) {
+ auto &mi = it.value();
+ for (auto &v : mi.views)
bvList << v;
- for (auto acc : mi.accessors)
+ for (auto &acc : mi.accessors)
accList << acc;
}
@@ -1193,7 +1194,7 @@ bool GLTFExporter::saveScene()
m_obj["buffers"] = buffers;
QJsonObject bufferViews;
- for (auto bv : bvList) {
+ for (const auto &bv : bvList) {
QJsonObject bufferView;
bufferView["buffer"] = QStringLiteral("buf");
bufferView["byteLength"] = int(bv.length);
@@ -1206,7 +1207,7 @@ bool GLTFExporter::saveScene()
m_obj["bufferViews"] = bufferViews;
QJsonObject accessors;
- for (auto acc : accList) {
+ for (const auto &acc : accList) {
QJsonObject accessor;
accessor["bufferView"] = acc.bufferView;
accessor["byteOffset"] = int(acc.offset);
@@ -1220,7 +1221,8 @@ bool GLTFExporter::saveScene()
m_obj["accessors"] = accessors;
QJsonObject meshes;
- for (auto meshInfo : m_meshInfo.values()) {
+ for (auto it = m_meshInfo.begin(); it != m_meshInfo.end(); ++it) {
+ auto &meshInfo = it.value();
QJsonObject mesh;
mesh["name"] = meshInfo.originalName;
if (meshInfo.meshType != TypeNone) {
@@ -1234,7 +1236,7 @@ bool GLTFExporter::saveScene()
QJsonObject prim;
prim["mode"] = 4; // triangles
QJsonObject attrs;
- for (auto acc : meshInfo.accessors) {
+ for (const auto &acc : meshInfo.accessors) {
if (acc.usage != QStringLiteral("INDEX"))
attrs[acc.usage] = acc.name;
else
@@ -1283,7 +1285,7 @@ bool GLTFExporter::saveScene()
if (m_rootNodeEmpty) {
// Don't export the root node if it is there just to group the scene, so we don't get
// an extra empty node when we import the scene back.
- for (auto c : m_rootNode->children)
+ for (auto c : qAsConst(m_rootNode->children))
sceneNodes << exportNodes(c, nodes);
} else {
sceneNodes << exportNodes(m_rootNode, nodes);
@@ -1305,7 +1307,8 @@ bool GLTFExporter::saveScene()
// Lights must be declared as extensions to the top-level glTF object
QJsonObject lights;
- for (auto lightInfo : m_lightInfo.values()) {
+ for (auto it = m_lightInfo.begin(); it != m_lightInfo.end(); ++it) {
+ const auto &lightInfo = it.value();
QJsonObject light;
QJsonObject lightDetails;
QString type;
@@ -1406,7 +1409,7 @@ bool GLTFExporter::saveScene()
if (!gFilter->vendor().isEmpty())
graphicsApiFilterObj["vendor"] = gFilter->vendor();
QJsonArray extensions;
- for (auto extName : gFilter->extensions())
+ for (const auto &extName : gFilter->extensions())
extensions << extName;
if (!extensions.isEmpty())
graphicsApiFilterObj["extensions"] = extensions;
@@ -1485,7 +1488,7 @@ bool GLTFExporter::saveScene()
// Save shaders for custom materials
QJsonObject shaders;
- for (auto si : m_shaderInfo) {
+ for (const auto &si : m_shaderInfo) {
QJsonObject shaderObj;
shaderObj["uri"] = si.uri;
shaders[si.name] = shaderObj;
@@ -1572,7 +1575,7 @@ bool GLTFExporter::saveScene()
QByteArray pre = "<RCC><qresource prefix=\"/gltf_res\">\n";
QByteArray post = "</qresource></RCC>\n";
f.write(pre);
- for (auto file : m_exportedFiles) {
+ for (const auto &file : qAsConst(m_exportedFiles)) {
QString line = QString(QStringLiteral(" <file>%1</file>\n")).arg(file);
f.write(line.toUtf8());
}
@@ -1594,7 +1597,7 @@ void GLTFExporter::delNode(GLTFExporter::Node *n)
{
if (!n)
return;
- for (auto *c : n->children)
+ for (auto *c : qAsConst(n->children))
delNode(c);
delete n;
}
@@ -1604,7 +1607,7 @@ QString GLTFExporter::exportNodes(GLTFExporter::Node *n, QJsonObject &nodes)
QJsonObject node;
node["name"] = n->name;
QJsonArray children;
- for (auto c : n->children)
+ for (auto c : qAsConst(n->children))
children << exportNodes(c, nodes);
node["children"] = children;
if (auto transform = m_transformMap.value(n))
@@ -2060,7 +2063,7 @@ void GLTFExporter::setVarToJSonObject(QJsonObject &jsObj, const QString &key, co
jsObj[key] = var.value<float>();
break;
case QMetaType::QSize:
- jsObj[key] = size2jsvec(var.value<QSize>());
+ jsObj[key] = size2jsvec(var.toSize());
break;
case QMetaType::QVector2D:
jsObj[key] = vec2jsvec(var.value<QVector2D>());
diff --git a/src/plugins/sceneparsers/sceneparsers.pro b/src/plugins/sceneparsers/sceneparsers.pro
index befe08e41..cb274b472 100644
--- a/src/plugins/sceneparsers/sceneparsers.pro
+++ b/src/plugins/sceneparsers/sceneparsers.pro
@@ -1,5 +1,11 @@
TEMPLATE = subdirs
# QNX is not supported, and Linux GCC 4.9 on ARM chokes on the assimp
# sources (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66964).
-config_assimp|!cross_compile: SUBDIRS += assimp
-SUBDIRS += gltf gltfexport
+QT_FOR_CONFIG += 3dcore-private
+qtConfig(assimp):if(qtConfig(system-assimp)|!cross_compile): \
+ SUBDIRS += assimp
+SUBDIRS += gltf
+
+qtConfig(temporaryfile):qtConfig(regularexpression) {
+ SUBDIRS += gltfexport
+}