diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 7cfb1f6bc8..9bf6c31784 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1074,15 +1074,11 @@ int Model::getLastFreeJointIndex(int jointIndex) const { void Model::setTextures(const QVariantMap& textures) { if (isLoaded()) { - _needsUpdateTextures = true; + _pendingTextures.clear(); _needsFixupInScene = true; _renderGeometry->setTextures(textures); } else { - // FIXME(Huffman): Disconnect previously connected lambdas so we don't set textures multiple - // after the geometry has finished loading. - connect(&_renderWatcher, &GeometryResourceWatcher::finished, this, [this, textures]() { - _renderGeometry->setTextures(textures); - }); + _pendingTextures = textures; } } @@ -1106,7 +1102,8 @@ void Model::setURL(const QUrl& url) { } _needsReload = true; - _needsUpdateTextures = true; + // One might be tempted to _pendingTextures.clear(), thinking that a new URL means an old texture doesn't apply. + // But sometimes, particularly when first setting the values, the texture might be set first. So let's not clear here. _visualGeometryRequestFailed = false; _needsFixupInScene = true; invalidCalculatedMeshBoxes(); @@ -1123,6 +1120,8 @@ void Model::setURL(const QUrl& url) { void Model::loadURLFinished(bool success) { if (!success) { _visualGeometryRequestFailed = true; + } else if (!_pendingTextures.empty()) { + setTextures(_pendingTextures); } emit setURLFinished(success); } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 4180288106..67e6d178ea 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -457,7 +457,7 @@ protected: bool _needsFixupInScene { true }; // needs to be removed/re-added to scene bool _needsReload { true }; bool _needsUpdateClusterMatrices { true }; - mutable bool _needsUpdateTextures { true }; + QVariantMap _pendingTextures { }; friend class ModelMeshPartPayload; Rig _rig;