diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 7424180437..58c06fccfb 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -100,6 +100,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 @@ -124,13 +139,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(); - - QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8()); - 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; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 0bec7636b9..2b425351f1 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -70,7 +70,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); @@ -168,22 +168,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 + "\""; } }