From ee1552661c4ab5f093c6e6eaac0adf38d9651229 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 31 Jan 2019 12:04:46 -0800 Subject: [PATCH] fix textures --- .../src/RenderableModelEntityItem.cpp | 13 +++++------ .../src/RenderableModelEntityItem.h | 2 +- libraries/entities/src/ModelEntityItem.cpp | 11 +++++----- libraries/entities/src/ModelEntityItem.h | 1 - libraries/shared/src/RegisteredMetaTypes.cpp | 22 +++++++++---------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 7e01af04dd..2e53fa4d57 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1264,7 +1264,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin return false; } - if (_lastTextures != entity->getTextures()) { + if (_textures != entity->getTextures()) { return true; } @@ -1418,15 +1418,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce entity->_originalTexturesRead = true; } - if (_lastTextures != entity->getTextures()) { + if (_textures != entity->getTextures()) { + QVariantMap newTextures; withWriteLock([&] { _texturesLoaded = false; - _lastTextures = entity->getTextures(); + _textures = entity->getTextures(); + newTextures = parseTexturesToMap(_textures, entity->_originalTextures); }); - auto newTextures = parseTexturesToMap(_lastTextures, entity->_originalTextures); - if (newTextures != model->getTextures()) { - model->setTextures(newTextures); - } + model->setTextures(newTextures); } if (entity->_needsJointSimulation) { entity->copyAnimationJointDataToModel(); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 16c3664f28..2a37e7107f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -181,7 +181,7 @@ private: bool _hasModel { false }; ModelPointer _model; - QString _lastTextures; + QString _textures; bool _texturesLoaded { false }; int _lastKnownCurrentFrame { -1 }; #ifdef MODEL_ENTITY_USE_FADE_EFFECT diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index ddbb028b6e..e365d0a7b6 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -43,14 +43,15 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID) : EntityItem( } const QString ModelEntityItem::getTextures() const { - QReadLocker locker(&_texturesLock); - auto textures = _textures; - return textures; + return resultWithReadLock([&] { + return _textures; + }); } void ModelEntityItem::setTextures(const QString& textures) { - QWriteLocker locker(&_texturesLock); - _textures = textures; + withWriteLock([&] { + _textures = textures; + }); } EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const { diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 8c9fbdc45f..649a6cb50f 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -163,7 +163,6 @@ protected: AnimationPropertyGroup _animationProperties; - mutable QReadWriteLock _texturesLock; QString _textures; ShapeType _shapeType = SHAPE_TYPE_NONE; diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 5394a0f448..ec1126c92f 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -1247,30 +1247,30 @@ void qVectorMeshFaceFromScriptValue(const QScriptValue& array, QVector } } -QVariantMap parseTexturesToMap(QString textures, const QVariantMap& defaultTextures) { +QVariantMap parseTexturesToMap(QString newTextures, const QVariantMap& defaultTextures) { // If textures are unset, revert to original textures - if (textures.isEmpty()) { + if (newTextures.isEmpty()) { return defaultTextures; } // Legacy: a ,\n-delimited list of filename:"texturepath" - if (*textures.cbegin() != '{') { - textures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}"; + if (*newTextures.cbegin() != '{') { + newTextures = "{\"" + newTextures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}"; } QJsonParseError error; - QJsonDocument texturesJson = QJsonDocument::fromJson(textures.toUtf8(), &error); + QJsonDocument newTexturesJson = QJsonDocument::fromJson(newTextures.toUtf8(), &error); // If textures are invalid, revert to original textures if (error.error != QJsonParseError::NoError) { - qWarning() << "Could not evaluate textures property value:" << textures; + qWarning() << "Could not evaluate textures property value:" << newTextures; return defaultTextures; } - QVariantMap texturesMap = texturesJson.toVariant().toMap(); - // If textures are unset, revert to original textures - if (texturesMap.isEmpty()) { - return defaultTextures; + QVariantMap newTexturesMap = newTexturesJson.toVariant().toMap(); + QVariantMap toReturn = defaultTextures; + for (auto& texture : newTexturesMap.keys()) { + toReturn[texture] = newTexturesMap[texture]; } - return texturesJson.toVariant().toMap(); + return toReturn; } \ No newline at end of file