From c625d36bd8ee2f37ae84c68729d0c75df157e54b Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 24 Mar 2016 19:18:38 -0700 Subject: [PATCH] Persist material transform/params --- .../src/model-networking/ModelCache.cpp | 22 ++++++++++--------- .../src/model-networking/ModelCache.h | 4 ++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 586990db09..6c7c98047d 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -355,8 +355,9 @@ model::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& url, Textu } NetworkMaterial::NetworkMaterial(const NetworkMaterial& material, const QVariantMap& textureMap) : - _textures(material._textures), _isOriginal(false) + NetworkMaterial(material) { + _isOriginal = false; setTextures(textureMap); } @@ -366,7 +367,8 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur _textures = Textures(MapChannel::NUM_MAP_CHANNELS); if (!material.albedoTexture.filename.isEmpty()) { auto map = fetchTextureMap(textureBaseUrl, material.albedoTexture, DEFAULT_TEXTURE, MapChannel::ALBEDO_MAP); - map->setTextureTransform(material.albedoTexture.transform); + _albedoTransform = material.albedoTexture.transform; + map->setTextureTransform(_albedoTransform); if (!material.opacityTexture.filename.isEmpty()) { if (material.albedoTexture.filename == material.opacityTexture.filename) { @@ -414,8 +416,10 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur if (!material.lightmapTexture.filename.isEmpty()) { auto map = fetchTextureMap(textureBaseUrl, material.lightmapTexture, LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP); - map->setTextureTransform(material.lightmapTexture.transform); - map->setLightmapOffsetScale(material.lightmapParams.x, material.lightmapParams.y); + _lightmapTransform = material.lightmapTexture.transform; + _lightmapParams = material.lightmapParams; + map->setTextureTransform(_lightmapTransform); + map->setLightmapOffsetScale(_lightmapParams.x, _lightmapParams.y); setTextureMap(MapChannel::LIGHTMAP_MAP, map); } } @@ -431,9 +435,9 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) { if (!albedoName.isEmpty() && textureMap.contains(albedoName)) { auto map = fetchTextureMap(textureMap[albedoName].toUrl(), DEFAULT_TEXTURE, MapChannel::ALBEDO_MAP); - map->setTextureTransform(getTextureMap(MapChannel::ALBEDO_MAP)->getTextureTransform()); + map->setTextureTransform(_albedoTransform); // when reassigning the albedo texture we also check for the alpha channel used as opacity - map->setUseAlphaChannel(true); + map->setUseAlphaChannel(true); setTextureMap(MapChannel::ALBEDO_MAP, map); } @@ -466,10 +470,8 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) { if (!lightmapName.isEmpty() && textureMap.contains(lightmapName)) { auto map = fetchTextureMap(textureMap[lightmapName].toUrl(), LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP); - auto oldMap = getTextureMap(MapChannel::LIGHTMAP_MAP); - map->setTextureTransform(oldMap->getTextureTransform()); - glm::vec2 offsetScale = oldMap->getLightmapOffsetScale(); - map->setLightmapOffsetScale(offsetScale.x, offsetScale.y); + map->setTextureTransform(_lightmapTransform); + map->setLightmapOffsetScale(_lightmapParams.x, _lightmapParams.y); setTextureMap(MapChannel::LIGHTMAP_MAP, map); } } diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index 0832478648..01a5e2165e 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -167,6 +167,10 @@ private: TextureType type, MapChannel channel); model::TextureMapPointer fetchTextureMap(const QUrl& url, TextureType type, MapChannel channel); + Transform _albedoTransform; + Transform _lightmapTransform; + vec2 _lightmapParams; + bool _isOriginal; };