Showing the changes to interface/src/renderer/GeometryCache.cpp (1 of 2 files). Show all
Unified · Split
| @@ -547,7 +547,8 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe · 546 unmodified lines | ||
| 547 | 547 | Resource(url, delayLoad), |
| 548 | 548 | _mapping(mapping), |
| 549 | 549 | _textureBase(textureBase.isValid() ? textureBase : url), |
| 550 | − _fallback(fallback) { | |
| 550 | + _fallback(fallback) | |
| 551 | +{ | |
| 551 | 552 | |
| 552 | 553 | if (url.isEmpty()) { |
| 553 | 554 | // make the minimal amount of dummy geometry to satisfy Model |
| @@ -562,6 +563,8 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe · 8 unmodified lines | ||
| 562 | 563 | _geometry.leftHandJointIndex = -1; |
| 563 | 564 | _geometry.rightHandJointIndex = -1; |
| 564 | 565 | } |
| 566 | + | |
| 567 | + connect(this, &Resource::loaded, this, &NetworkGeometry::replaceTexturesWithPendingChanges); | |
| 565 | 568 | } |
| 566 | 569 | |
| 567 | 570 | bool NetworkGeometry::isLoadedWithTextures() const { |
| @@ -710,27 +713,33 @@ void NetworkGeometry::clearLoadPriority(const QPointer<QObject>& owner) { · 142 unmodified lines | ||
| 710 | 713 | } |
| 711 | 714 | |
| 712 | 715 | void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) { |
| 713 | − for (int i = 0; i < _meshes.size(); i++) { | |
| 714 | − NetworkMesh& mesh = _meshes[i]; | |
| 715 | − for (int j = 0; j < mesh.parts.size(); j++) { | |
| 716 | − NetworkMeshPart& part = mesh.parts[j]; | |
| 717 | − | |
| 718 | − QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>(); | |
| 719 | − if (part.diffuseTextureName == name) { | |
| 720 | − part.diffuseTexture = | |
| 716 | + if (_meshes.size() > 0) { | |
| 717 | + for (int i = 0; i < _meshes.size(); i++) { | |
| 718 | + NetworkMesh& mesh = _meshes[i]; | |
| 719 | + for (int j = 0; j < mesh.parts.size(); j++) { | |
| 720 | + NetworkMeshPart& part = mesh.parts[j]; | |
| 721 | + | |
| 722 | + QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>(); | |
| 723 | + if (part.diffuseTextureName == name) { | |
| 724 | + part.diffuseTexture = | |
| 721 | 725 | Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE, |
| 722 | 726 | _geometry.meshes[i].isEye, QByteArray()); |
| 723 | − part.diffuseTexture->setLoadPriorities(_loadPriorities); | |
| 724 | − } else if (part.normalTextureName == name) { | |
| 725 | − part.normalTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE, | |
| 726 | − false, QByteArray()); | |
| 727 | − part.normalTexture->setLoadPriorities(_loadPriorities); | |
| 728 | − } else if (part.specularTextureName == name) { | |
| 729 | − part.specularTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE, | |
| 730 | − false, QByteArray()); | |
| 731 | − part.specularTexture->setLoadPriorities(_loadPriorities); | |
| 727 | + part.diffuseTexture->setLoadPriorities(_loadPriorities); | |
| 728 | + } else if (part.normalTextureName == name) { | |
| 729 | + part.normalTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE, | |
| 730 | + false, QByteArray()); | |
| 731 | + part.normalTexture->setLoadPriorities(_loadPriorities); | |
| 732 | + } else if (part.specularTextureName == name) { | |
| 733 | + part.specularTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE, | |
| 734 | + false, QByteArray()); | |
| 735 | + part.specularTexture->setLoadPriorities(_loadPriorities); | |
| 736 | + } | |
| 732 | 737 | } |
| 733 | 738 | } |
| 739 | + } else { | |
| 740 | + qDebug() << "Adding a name url pair to pending" << name << url; | |
| 741 | + // we don't have meshes downloaded yet, so hold this texture as pending | |
| 742 | + _pendingTextureChanges.insert(name, url); | |
| 734 | 743 | } |
| 735 | 744 | } |
| 736 | 745 | |
| @@ -760,6 +769,15 @@ QStringList NetworkGeometry::getTextureNames() const { · 23 unmodified lines | ||
| 760 | 769 | return result; |
| 761 | 770 | } |
| 762 | 771 | |
| 772 | +void NetworkGeometry::replaceTexturesWithPendingChanges() { | |
| 773 | + | |
| 774 | + QHash<QString, QUrl>::Iterator it = _pendingTextureChanges.begin(); | |
| 775 | + while (it != _pendingTextureChanges.end()) { | |
| 776 | + setTextureWithNameToURL(it.key(), it.value()); | |
| 777 | + it = _pendingTextureChanges.erase(it); | |
| 778 | + } | |
| 779 | +} | |
| 780 | + | |
| 763 | 781 | /// Reads geometry in a worker thread. |
| 764 | 782 | class GeometryReader : public QRunnable { |
| 765 | 783 | public: |
| @@ -807,6 +825,7 @@ void NetworkGeometry::init() { · 41 unmodified lines | ||
| 807 | 825 | _geometry = FBXGeometry(); |
| 808 | 826 | _meshes.clear(); |
| 809 | 827 | _lods.clear(); |
| 828 | + _pendingTextureChanges.clear(); | |
| 810 | 829 | _request.setUrl(_url); |
| 811 | 830 | Resource::init(); |
| 812 | 831 | } |