diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 107dac62f5..c34a5a8d7a 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -405,6 +405,7 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { } QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { + qDebug() << "Getting a resource at" << url; return getResource(url, fallback, delayLoad).staticCast(); } @@ -727,18 +728,21 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) { networkPart.diffuseTexture = Application::getInstance()->getTextureCache()->getTexture( _textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE, mesh.isEye, part.diffuseTexture.content); + networkPart.diffuseTexture->setName(part.diffuseTexture.name); networkPart.diffuseTexture->setLoadPriorities(_loadPriorities); } if (!part.normalTexture.filename.isEmpty()) { networkPart.normalTexture = Application::getInstance()->getTextureCache()->getTexture( _textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE, false, part.normalTexture.content); + networkPart.normalTexture->setName(part.normalTexture.name); networkPart.normalTexture->setLoadPriorities(_loadPriorities); } if (!part.specularTexture.filename.isEmpty()) { networkPart.specularTexture = Application::getInstance()->getTextureCache()->getTexture( _textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE, false, part.specularTexture.content); + networkPart.specularTexture->setName(part.specularTexture.name); networkPart.specularTexture->setLoadPriorities(_loadPriorities); } networkMesh.parts.append(networkPart); diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index e0ada10e5b..1f45825c61 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -136,7 +136,7 @@ private: /// The state associated with a single mesh part. class NetworkMeshPart { -public: +public: QSharedPointer diffuseTexture; QSharedPointer normalTexture; diff --git a/interface/src/renderer/TextureCache.h b/interface/src/renderer/TextureCache.h index 11ce312fa3..29740621e3 100644 --- a/interface/src/renderer/TextureCache.h +++ b/interface/src/renderer/TextureCache.h @@ -145,6 +145,9 @@ public: /// Returns the lazily-computed average texture color. const QColor& getAverageColor() const { return _averageColor; } + + const QString& getName() const { return _name; } + void setName(const QString& name) { _name = name; } protected: @@ -156,7 +159,7 @@ protected: virtual void imageLoaded(const QImage& image); private: - + QString _name; TextureType _type; bool _translucent; QColor _averageColor; diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index e735e2e47b..2a51a83ab8 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -984,10 +984,13 @@ public: QVector values; }; -FBXTexture getTexture(const QString& textureID, const QHash& textureFilenames, - const QHash& textureContent) { +FBXTexture getTexture(const QString& textureID, + const QHash& textureNames, + const QHash& textureFilenames, + const QHash& textureContent) { FBXTexture texture; texture.filename = textureFilenames.value(textureID); + texture.name = textureNames.value(textureID); texture.content = textureContent.value(texture.filename); return texture; } @@ -1012,6 +1015,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QHash models; QHash clusters; QHash animationCurves; + QHash textureNames; QHash textureFilenames; QHash textureContent; QHash materials; @@ -1278,6 +1282,11 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QByteArray filename = subobject.properties.at(0).toByteArray(); filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1); textureFilenames.insert(getID(object.properties), filename); + } else if (subobject.name == "TextureName") { + // trim the name from the timestamp + QString name = QString(subobject.properties.at(0).toByteArray()); + name = name.left(name.indexOf('[')); + textureNames.insert(getID(object.properties), name); } } } else if (object.name == "Video") { @@ -1612,12 +1621,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) FBXTexture diffuseTexture; QString diffuseTextureID = diffuseTextures.value(childID); if (!diffuseTextureID.isNull()) { - diffuseTexture = getTexture(diffuseTextureID, textureFilenames, textureContent); + diffuseTexture = getTexture(diffuseTextureID, textureNames, textureFilenames, textureContent); // FBX files generated by 3DSMax have an intermediate texture parent, apparently foreach (const QString& childTextureID, childMap.values(diffuseTextureID)) { if (textureFilenames.contains(childTextureID)) { - diffuseTexture = getTexture(diffuseTextureID, textureFilenames, textureContent); + diffuseTexture = getTexture(diffuseTextureID, textureNames, textureFilenames, textureContent); } } } @@ -1625,14 +1634,14 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) FBXTexture normalTexture; QString bumpTextureID = bumpTextures.value(childID); if (!bumpTextureID.isNull()) { - normalTexture = getTexture(bumpTextureID, textureFilenames, textureContent); + normalTexture = getTexture(bumpTextureID, textureNames, textureFilenames, textureContent); generateTangents = true; } FBXTexture specularTexture; QString specularTextureID = specularTextures.value(childID); if (!specularTextureID.isNull()) { - specularTexture = getTexture(specularTextureID, textureFilenames, textureContent); + specularTexture = getTexture(specularTextureID, textureNames, textureFilenames, textureContent); } for (int j = 0; j < extracted.partMaterialTextures.size(); j++) { @@ -1658,7 +1667,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) materialIndex++; } else if (textureFilenames.contains(childID)) { - FBXTexture texture = getTexture(childID, textureFilenames, textureContent); + FBXTexture texture = getTexture(childID, textureNames, textureFilenames, textureContent); for (int j = 0; j < extracted.partMaterialTextures.size(); j++) { int partTexture = extracted.partMaterialTextures.at(j).second; if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) { diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index cbf0cfcca6..49b0534438 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -95,7 +95,7 @@ public: /// A texture map in an FBX document. class FBXTexture { public: - + QString name; QByteArray filename; QByteArray content; };