pipe texture names through to NetworkTexture

This commit is contained in:
Stephen Birarda 2014-10-21 12:20:12 -07:00
parent 1949a47c33
commit 047ee0a513
5 changed files with 26 additions and 10 deletions

View file

@ -405,6 +405,7 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) {
}
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
qDebug() << "Getting a resource at" << url;
return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();
}
@ -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);

View file

@ -136,7 +136,7 @@ private:
/// The state associated with a single mesh part.
class NetworkMeshPart {
public:
public:
QSharedPointer<NetworkTexture> diffuseTexture;
QSharedPointer<NetworkTexture> normalTexture;

View file

@ -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;

View file

@ -984,10 +984,13 @@ public:
QVector<float> values;
};
FBXTexture getTexture(const QString& textureID, const QHash<QString, QByteArray>& textureFilenames,
const QHash<QByteArray, QByteArray>& textureContent) {
FBXTexture getTexture(const QString& textureID,
const QHash<QString, QString>& textureNames,
const QHash<QString, QByteArray>& textureFilenames,
const QHash<QByteArray, QByteArray>& 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<QString, FBXModel> models;
QHash<QString, Cluster> clusters;
QHash<QString, AnimationCurve> animationCurves;
QHash<QString, QString> textureNames;
QHash<QString, QByteArray> textureFilenames;
QHash<QByteArray, QByteArray> textureContent;
QHash<QString, Material> 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)) {

View file

@ -95,7 +95,7 @@ public:
/// A texture map in an FBX document.
class FBXTexture {
public:
QString name;
QByteArray filename;
QByteArray content;
};