From a262d9960cce3b02ce014197c257f5dded9e5504 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 25 Mar 2016 11:47:33 -0700 Subject: [PATCH] Mind differently tex'ed instances --- .../src/model-networking/ModelCache.cpp | 20 +++++++------------ .../src/model-networking/ModelCache.h | 3 +-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index de4409a5a3..7c692f1565 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -250,12 +250,11 @@ void Geometry::setTextures(const QVariantMap& textureMap) { [&textureMap](const NetworkMaterial::Textures::value_type& it) { return it.texture && textureMap.contains(it.name); })) { if (material->isOriginal()) { - // On first mutation, copy the material to avoid altering the cache - material = std::make_shared(*material, textureMap); - } else { - // On later mutations, we can mutate in-place - material->setTextures(textureMap); + // Copy the material to avoid mutating the cached version + material = std::make_shared(*material); } + + material->setTextures(textureMap); _areTexturesLoaded = false; } } @@ -359,15 +358,8 @@ model::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& url, Textu return map; } -NetworkMaterial::NetworkMaterial(const NetworkMaterial& material, const QVariantMap& textureMap) : - NetworkMaterial(material) -{ - _isOriginal = false; - setTextures(textureMap); -} - NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textureBaseUrl) : - model::Material(*material._material), _isOriginal(true) + model::Material(*material._material) { _textures = Textures(MapChannel::NUM_MAP_CHANNELS); if (!material.albedoTexture.filename.isEmpty()) { @@ -430,6 +422,8 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur } void NetworkMaterial::setTextures(const QVariantMap& textureMap) { + _isOriginal = false; + const auto& albedoName = getTextureName(MapChannel::ALBEDO_MAP); const auto& normalName = getTextureName(MapChannel::NORMAL_MAP); const auto& roughnessName = getTextureName(MapChannel::ROUGHNESS_MAP); diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index 01a5e2165e..166ad128f2 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -139,7 +139,6 @@ public: using MapChannel = model::Material::MapChannel; NetworkMaterial(const FBXMaterial& material, const QUrl& textureBaseUrl); - NetworkMaterial(const NetworkMaterial& material, const QVariantMap& textureMap); protected: friend class Geometry; @@ -171,7 +170,7 @@ private: Transform _lightmapTransform; vec2 _lightmapParams; - bool _isOriginal; + bool _isOriginal { true }; }; class NetworkShape {