Fix for transparent textures not being rendered with opacity

This commit is contained in:
ericrius1 2016-01-20 16:22:49 -08:00
parent eb5a950f85
commit 0ffcf437e9
5 changed files with 25 additions and 6 deletions

View file

@ -1035,7 +1035,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
} else if (type.contains("transparentcolor")) { // it should be TransparentColor...
// THis is how Maya assign a texture that affect diffuse color AND transparency ?
diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
opacityTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
} else if (type.contains("bump")) {
bumpTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
} else if (type.contains("normal")) {

View file

@ -402,6 +402,7 @@ public:
QHash<QString, QString> specularTextures;
QHash<QString, QString> emissiveTextures;
QHash<QString, QString> ambientTextures;
QHash<QString, QString> opacityTextures;
QHash<QString, FBXMaterial> _fbxMaterials;

View file

@ -70,8 +70,7 @@ void FBXReader::consolidateFBXMaterials() {
FBXTexture diffuseTexture;
QString diffuseTextureID = diffuseTextures.value(material.materialID);
if (!diffuseTextureID.isNull()) {
diffuseTexture = getTexture(diffuseTextureID);
diffuseTexture = getTexture(diffuseTextureID);
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
foreach (const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) {
if (_textureFilenames.contains(childTextureID)) {
@ -80,10 +79,16 @@ void FBXReader::consolidateFBXMaterials() {
}
material.diffuseTexture = diffuseTexture;
material.opacityTexture = diffuseTexture;
detectDifferentUVs = (diffuseTexture.texcoordSet != 0) || (!diffuseTexture.transform.isIdentity());
}
FBXTexture opacityTexture;
QString opacityTextureID = opacityTextures.value(material.materialID);
if (!opacityTextureID.isNull()) {
opacityTexture = getTexture(opacityTextureID);
material.opacityTexture = opacityTexture;
}
FBXTexture normalTexture;
QString bumpTextureID = bumpTextures.value(material.materialID);

View file

@ -155,6 +155,8 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
material->specularTexture = textureCache->getTexture(url);
} else if (material->emissiveTextureName == name) {
material->emissiveTexture = textureCache->getTexture(url);
} else if (material->opacityTextureName == name) {
material->opacityTexture = textureCache->getTexture(url);
}
}
} else {
@ -285,7 +287,16 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const
diffuseMap->setTextureTransform(material.diffuseTexture.transform);
material._material->setTextureMap(model::MaterialKey::DIFFUSE_MAP, diffuseMap);
material._material->setTextureMap(model::MaterialKey::TRANSPARENT_MAP, diffuseMap);
}
if (!material.opacityTexture.filename.isEmpty()) {
networkMaterial->opacityTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.opacityTexture.filename)), DEFAULT_TEXTURE, material.opacityTexture.content);
networkMaterial->opacityTextureName = material.opacityTexture.name;
auto opacityMap = model::TextureMapPointer(new model::TextureMap());
opacityMap->setTextureSource(networkMaterial->opacityTexture->_textureSource);
opacityMap->setTextureTransform(material.opacityTexture.transform);
material._material->setTextureMap(model::MaterialKey::TRANSPARENT_MAP, opacityMap);
}
if (!material.normalTexture.filename.isEmpty()) {
networkMaterial->normalTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.normalTexture.filename)), (material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE), material.normalTexture.content);

View file

@ -182,6 +182,8 @@ public:
QSharedPointer<NetworkTexture> specularTexture;
QString emissiveTextureName;
QSharedPointer<NetworkTexture> emissiveTexture;
QString opacityTextureName;
QSharedPointer<NetworkTexture> opacityTexture;
};