mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 12:23:24 +02:00
Merge pull request #3781 from birarda/texture-load
handle texture replacement if model hasn't yet loaded
This commit is contained in:
commit
7b7fda5f1d
2 changed files with 42 additions and 19 deletions
|
@ -547,7 +547,8 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe
|
|||
Resource(url, delayLoad),
|
||||
_mapping(mapping),
|
||||
_textureBase(textureBase.isValid() ? textureBase : url),
|
||||
_fallback(fallback) {
|
||||
_fallback(fallback)
|
||||
{
|
||||
|
||||
if (url.isEmpty()) {
|
||||
// make the minimal amount of dummy geometry to satisfy Model
|
||||
|
@ -562,6 +563,8 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe
|
|||
_geometry.leftHandJointIndex = -1;
|
||||
_geometry.rightHandJointIndex = -1;
|
||||
}
|
||||
|
||||
connect(this, &Resource::loaded, this, &NetworkGeometry::replaceTexturesWithPendingChanges);
|
||||
}
|
||||
|
||||
bool NetworkGeometry::isLoadedWithTextures() const {
|
||||
|
@ -710,27 +713,33 @@ void NetworkGeometry::clearLoadPriority(const QPointer<QObject>& owner) {
|
|||
}
|
||||
|
||||
void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) {
|
||||
for (int i = 0; i < _meshes.size(); i++) {
|
||||
NetworkMesh& mesh = _meshes[i];
|
||||
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||
NetworkMeshPart& part = mesh.parts[j];
|
||||
|
||||
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
|
||||
if (part.diffuseTextureName == name) {
|
||||
part.diffuseTexture =
|
||||
if (_meshes.size() > 0) {
|
||||
for (int i = 0; i < _meshes.size(); i++) {
|
||||
NetworkMesh& mesh = _meshes[i];
|
||||
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||
NetworkMeshPart& part = mesh.parts[j];
|
||||
|
||||
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
|
||||
if (part.diffuseTextureName == name) {
|
||||
part.diffuseTexture =
|
||||
Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||
_geometry.meshes[i].isEye, QByteArray());
|
||||
part.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.normalTextureName == name) {
|
||||
part.normalTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.normalTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.specularTextureName == name) {
|
||||
part.specularTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.specularTexture->setLoadPriorities(_loadPriorities);
|
||||
part.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.normalTextureName == name) {
|
||||
part.normalTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.normalTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.specularTextureName == name) {
|
||||
part.specularTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.specularTexture->setLoadPriorities(_loadPriorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Adding a name url pair to pending" << name << url;
|
||||
// we don't have meshes downloaded yet, so hold this texture as pending
|
||||
_pendingTextureChanges.insert(name, url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -760,6 +769,15 @@ QStringList NetworkGeometry::getTextureNames() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
void NetworkGeometry::replaceTexturesWithPendingChanges() {
|
||||
QHash<QString, QUrl>::Iterator it = _pendingTextureChanges.begin();
|
||||
|
||||
while (it != _pendingTextureChanges.end()) {
|
||||
setTextureWithNameToURL(it.key(), it.value());
|
||||
it = _pendingTextureChanges.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads geometry in a worker thread.
|
||||
class GeometryReader : public QRunnable {
|
||||
public:
|
||||
|
@ -807,6 +825,7 @@ void NetworkGeometry::init() {
|
|||
_geometry = FBXGeometry();
|
||||
_meshes.clear();
|
||||
_lods.clear();
|
||||
_pendingTextureChanges.clear();
|
||||
_request.setUrl(_url);
|
||||
Resource::init();
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public:
|
|||
|
||||
void setTextureWithNameToURL(const QString& name, const QUrl& url);
|
||||
QStringList getTextureNames() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void init();
|
||||
|
@ -122,6 +122,8 @@ protected:
|
|||
|
||||
Q_INVOKABLE void setGeometry(const FBXGeometry& geometry);
|
||||
|
||||
private slots:
|
||||
void replaceTexturesWithPendingChanges();
|
||||
private:
|
||||
|
||||
friend class GeometryCache;
|
||||
|
@ -139,6 +141,8 @@ private:
|
|||
QWeakPointer<NetworkGeometry> _lodParent;
|
||||
|
||||
QHash<QWeakPointer<Animation>, QVector<int> > _jointMappings;
|
||||
|
||||
QHash<QString, QUrl> _pendingTextureChanges;
|
||||
};
|
||||
|
||||
/// The state associated with a single mesh part.
|
||||
|
|
Loading…
Reference in a new issue