From f64481c5107ee9b1906e1fe40dfed23ca54a84a0 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 7 Jan 2016 16:47:48 +1300 Subject: [PATCH 1/4] Warn user if cannot evaluate model's textures property --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f5090cc20c..6ec77a17bf 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -129,7 +129,11 @@ void RenderableModelEntityItem::remapTextures() { QJsonObject currentTexturesAsJsonObject = currentTexturesAsJson.object(); QVariantMap currentTextureMap = currentTexturesAsJsonObject.toVariantMap(); - QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8()); + QJsonParseError error; + QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) { + qCWarning(entitiesrenderer) << "Could not evaluate textures property:" << _textures; + } QJsonObject texturesAsJsonObject = texturesAsJson.object(); QVariantMap textureMap = texturesAsJsonObject.toVariantMap(); From a6bfecf038be1acdea2d3068c2b3c2feaf08162e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 7 Jan 2016 16:52:29 +1300 Subject: [PATCH 2/4] Format original textures property string more properly --- .../model-networking/src/model-networking/ModelCache.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 4fd47affc2..f24a20266d 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -171,22 +171,22 @@ QStringList NetworkGeometry::getTextureNames() const { for (auto&& material : _materials) { if (!material->diffuseTextureName.isEmpty() && material->diffuseTexture) { QString textureURL = material->diffuseTexture->getURL().toString(); - result << material->diffuseTextureName + ":" + textureURL; + result << material->diffuseTextureName + ":\"" + textureURL + "\""; } if (!material->normalTextureName.isEmpty() && material->normalTexture) { QString textureURL = material->normalTexture->getURL().toString(); - result << material->normalTextureName + ":" + textureURL; + result << material->normalTextureName + ":\"" + textureURL + "\""; } if (!material->specularTextureName.isEmpty() && material->specularTexture) { QString textureURL = material->specularTexture->getURL().toString(); - result << material->specularTextureName + ":" + textureURL; + result << material->specularTextureName + ":\"" + textureURL + "\""; } if (!material->emissiveTextureName.isEmpty() && material->emissiveTexture) { QString textureURL = material->emissiveTexture->getURL().toString(); - result << material->emissiveTextureName + ":" + textureURL; + result << material->emissiveTextureName + ":\"" + textureURL + "\""; } } From 25309e84b33df7709aab540679afd902a9704f93 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 7 Jan 2016 17:30:28 +1300 Subject: [PATCH 3/4] Fix interpreting textures properties --- .../src/RenderableModelEntityItem.cpp | 28 +++++++++++-------- .../src/RenderableModelEntityItem.h | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 6ec77a17bf..06c7e1afef 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -101,6 +101,21 @@ int RenderableModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned c return bytesRead; } +QVariantMap RenderableModelEntityItem::parseTexturesToMap(QString textures) { + if (textures == "") { + return QVariantMap(); + } + + QString jsonTextures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}"; + QJsonParseError error; + QJsonDocument texturesAsJson = QJsonDocument::fromJson(jsonTextures.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) { + qCWarning(entitiesrenderer) << "Could not evaluate textures property value:" << _textures; + } + QJsonObject texturesAsJsonObject = texturesAsJson.object(); + return texturesAsJsonObject.toVariantMap(); +} + void RenderableModelEntityItem::remapTextures() { if (!_model) { return; // nothing to do if we don't have a model @@ -125,17 +140,8 @@ void RenderableModelEntityItem::remapTextures() { // since we're changing here, we need to run through our current texture map // and any textures in the recently mapped texture, that is not in our desired // textures, we need to "unset" - QJsonDocument currentTexturesAsJson = QJsonDocument::fromJson(_currentTextures.toUtf8()); - QJsonObject currentTexturesAsJsonObject = currentTexturesAsJson.object(); - QVariantMap currentTextureMap = currentTexturesAsJsonObject.toVariantMap(); - - QJsonParseError error; - QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8(), &error); - if (error.error != QJsonParseError::NoError) { - qCWarning(entitiesrenderer) << "Could not evaluate textures property:" << _textures; - } - QJsonObject texturesAsJsonObject = texturesAsJson.object(); - QVariantMap textureMap = texturesAsJsonObject.toVariantMap(); + QVariantMap currentTextureMap = parseTexturesToMap(_currentTextures); + QVariantMap textureMap = parseTexturesToMap(_textures); foreach(const QString& key, currentTextureMap.keys()) { // if the desired texture map (what we're setting the textures to) doesn't diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index eb7958ed47..99e5ecb097 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -80,6 +80,7 @@ public: virtual void resizeJointArrays(int newSize = -1) override; private: + QVariantMap parseTexturesToMap(QString textures); void remapTextures(); Model* _model = nullptr; From fc2bf8f5856ec0460a36b038b96d9e4ca1406fbb Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 8 Jan 2016 10:17:36 +1300 Subject: [PATCH 4/4] Miscellaneous code tidying, noticed in passing --- libraries/model-networking/src/model-networking/ModelCache.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index f24a20266d..2bbbbb35cc 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -72,7 +72,7 @@ void GeometryReader::run() { } else if (_url.path().toLower().endsWith(".obj")) { fbxgeo = OBJReader().readOBJ(_data, _mapping, _url); } else { - QString errorStr("usupported format"); + QString errorStr("unsupported format"); emit onError(NetworkGeometry::ModelParseError, errorStr); } emit onSuccess(fbxgeo); @@ -149,7 +149,6 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u if (_meshes.size() > 0) { auto textureCache = DependencyManager::get(); for (auto&& material : _materials) { - QSharedPointer matchingTexture = QSharedPointer(); if (material->diffuseTextureName == name) { material->diffuseTexture = textureCache->getTexture(url, DEFAULT_TEXTURE); } else if (material->normalTextureName == name) {