From 44e70db4cdec308439ff387c884968f276647b25 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 19 Feb 2019 15:02:36 -0800 Subject: [PATCH] WE DID IT FOLKS --- .../src/material-networking/TextureCache.cpp | 31 +++++++++++++------ .../src/material-networking/TextureCache.h | 4 +-- .../src/model-networking/ModelCache.cpp | 4 +-- libraries/networking/src/ResourceCache.cpp | 4 +-- libraries/networking/src/ResourceCache.h | 2 +- libraries/shared/src/RegisteredMetaTypes.cpp | 9 +++++- .../shared/src/VariantMapToScriptValue.cpp | 4 +-- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/libraries/material-networking/src/material-networking/TextureCache.cpp b/libraries/material-networking/src/material-networking/TextureCache.cpp index 9a9720c87d..43f467266a 100644 --- a/libraries/material-networking/src/material-networking/TextureCache.cpp +++ b/libraries/material-networking/src/material-networking/TextureCache.cpp @@ -354,7 +354,8 @@ NetworkTexture::NetworkTexture(const NetworkTexture& other) : _originalHeight(other._originalHeight), _width(other._width), _height(other._height), - _maxNumPixels(other._maxNumPixels) + _maxNumPixels(other._maxNumPixels), + _content(other._content) { if (_width == 0 || _height == 0 || other._currentlyLoadingResourceType == ResourceType::META || @@ -368,17 +369,30 @@ static bool isLocalUrl(const QUrl& url) { return (scheme == HIFI_URL_SCHEME_FILE || scheme == URL_SCHEME_QRC || scheme == RESOURCE_SCHEME); } -void NetworkTexture::setExtra(void* extra, bool isNewExtra) { +void NetworkTexture::setExtra(void* extra) { const TextureExtra* textureExtra = static_cast(extra); - _type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; _maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; - _sourceChannel = textureExtra ? textureExtra->sourceChannel : image::ColorChannel::NONE; - if (isNewExtra && !_loaded) { + bool needsNewTextureSource = false; + auto type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; + auto sourceChannel = textureExtra ? textureExtra->sourceChannel : image::ColorChannel::NONE; + if (type != _type || sourceChannel != _sourceChannel) { + needsNewTextureSource = true; + } + _type = type; + _sourceChannel = sourceChannel; + + auto content = textureExtra ? textureExtra->content : QByteArray(); + if (_content.isEmpty() && !content.isEmpty()) { + _content = content; + needsNewTextureSource = true; + } + + if (needsNewTextureSource) { _startedLoading = false; } - if (!_textureSource || isNewExtra) { + if (!_textureSource || needsNewTextureSource) { _textureSource = std::make_shared(_url, (int)_type); } _lowestRequestedMipLevel = 0; @@ -405,10 +419,9 @@ void NetworkTexture::setExtra(void* extra, bool isNewExtra) { } // if we have content, load it after we have our self pointer - auto content = textureExtra ? textureExtra->content : QByteArray(); - if (!content.isEmpty()) { + if (!_content.isEmpty()) { _startedLoading = true; - QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(const QByteArray&, content)); + QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(const QByteArray&, _content)); } } diff --git a/libraries/material-networking/src/material-networking/TextureCache.h b/libraries/material-networking/src/material-networking/TextureCache.h index a8b152c40e..dcab527e4a 100644 --- a/libraries/material-networking/src/material-networking/TextureCache.h +++ b/libraries/material-networking/src/material-networking/TextureCache.h @@ -64,7 +64,7 @@ public: Q_INVOKABLE void setOriginalDescriptor(ktx::KTXDescriptor* descriptor) { _originalKtxDescriptor.reset(descriptor); } - void setExtra(void* extra, bool isNewExtra) override; + void setExtra(void* extra) override; signals: void networkTextureCreated(const QWeakPointer& self); @@ -136,12 +136,12 @@ private: // mip offsets to change. ktx::KTXDescriptorPointer _originalKtxDescriptor; - int _originalWidth { 0 }; int _originalHeight { 0 }; int _width { 0 }; int _height { 0 }; int _maxNumPixels { ABSOLUTE_MAX_TEXTURE_NUM_PIXELS }; + QByteArray _content; friend class TextureCache; }; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index b2645d20c8..581196b2cc 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -309,7 +309,7 @@ public: virtual void downloadFinished(const QByteArray& data) override; - void setExtra(void* extra, bool isNewExtra) override; + void setExtra(void* extra) override; protected: Q_INVOKABLE void setGeometryDefinition(HFMModel::Pointer hfmModel, QVariantHash mapping); @@ -320,7 +320,7 @@ private: bool _combineParts; }; -void GeometryDefinitionResource::setExtra(void* extra, bool isNewExtra) { +void GeometryDefinitionResource::setExtra(void* extra) { const GeometryExtra* geometryExtra = static_cast(extra); _mapping = geometryExtra ? geometryExtra->mapping : QVariantHash(); _textureBaseUrl = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl(); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 8ad1b41020..7345081380 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -355,7 +355,7 @@ QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& } else if (resourcesWithExtraHash.size() > 0.0f) { // We haven't seen this extra info before, but we've already downloaded the resource. We need a new copy of this object (with any old hash). resource = createResourceCopy(resourcesWithExtraHash.begin().value().lock()); - resource->setExtra(extra, true); + resource->setExtra(extra); resource->setExtraHash(extraHash); resource->setSelf(resource); resource->setCache(this); @@ -375,7 +375,7 @@ QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& if (!resource) { resource = createResource(url); - resource->setExtra(extra, false); + resource->setExtra(extra); resource->setExtraHash(extraHash); resource->setSelf(resource); resource->setCache(this); diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 62800a6ac2..2096213273 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -417,7 +417,7 @@ public: unsigned int getDownloadAttempts() { return _attempts; } unsigned int getDownloadAttemptsRemaining() { return _attemptsRemaining; } - virtual void setExtra(void* extra, bool isNewExtra) {}; + virtual void setExtra(void* extra) {}; void setExtraHash(size_t extraHash) { _extraHash = extraHash; } size_t getExtraHash() const { return _extraHash; } diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index ec1126c92f..47549b639a 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -1269,7 +1269,14 @@ QVariantMap parseTexturesToMap(QString newTextures, const QVariantMap& defaultTe QVariantMap newTexturesMap = newTexturesJson.toVariant().toMap(); QVariantMap toReturn = defaultTextures; for (auto& texture : newTexturesMap.keys()) { - toReturn[texture] = newTexturesMap[texture]; + auto newURL = newTexturesMap[texture]; + if (newURL.canConvert()) { + toReturn[texture] = newURL.toUrl(); + } else if (newURL.canConvert()) { + toReturn[texture] = QUrl(newURL.toString()); + } else { + toReturn[texture] = newURL; + } } return toReturn; diff --git a/libraries/shared/src/VariantMapToScriptValue.cpp b/libraries/shared/src/VariantMapToScriptValue.cpp index 1a747a4e5b..437f60a2ed 100644 --- a/libraries/shared/src/VariantMapToScriptValue.cpp +++ b/libraries/shared/src/VariantMapToScriptValue.cpp @@ -26,10 +26,10 @@ QScriptValue variantToScriptValue(QVariant& qValue, QScriptEngine& scriptEngine) case QVariant::Double: return qValue.toDouble(); break; - case QVariant::String: { + case QVariant::String: + case QVariant::Url: return scriptEngine.newVariant(qValue); break; - } case QVariant::Map: { QVariantMap childMap = qValue.toMap(); return variantMapToScriptValue(childMap, scriptEngine);