SImple fix to the case of multiple material in a mesh with different opacity

This commit is contained in:
Sam Gateau 2015-08-06 18:51:44 -07:00
parent 0947bf2cd0
commit f0f141a2b4
4 changed files with 39 additions and 3 deletions

View file

@ -976,6 +976,8 @@ ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex) {
data.extracted.mesh.meshIndex = meshIndex++;
QVector<int> materials;
QVector<int> textures;
bool isMaterialPerPolygon = false;
foreach (const FBXNode& child, object.children) {
if (child.name == "Vertices") {
data.vertices = createVec3Vector(getDoubleVector(child));
@ -1105,8 +1107,19 @@ ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex) {
foreach (const FBXNode& subdata, child.children) {
if (subdata.name == "Materials") {
materials = getIntVector(subdata);
if (materials.size() > 1) {
}
} else if (subdata.name == "MappingInformationType") {
if (subdata.properties.at(0) == "ByPolygon") {
isMaterialPerPolygon = true;
} else {
isMaterialPerPolygon = false;
}
}
}
} else if (child.name == "LayerElementTexture") {
foreach (const FBXNode& subdata, child.children) {
if (subdata.name == "TextureId") {
@ -1116,6 +1129,12 @@ ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex) {
}
}
bool isMultiMaterial = false;
if (isMaterialPerPolygon) {
isMultiMaterial = true;
}
// convert the polygons to quads and triangles
int polygonIndex = 0;
QHash<QPair<int, int>, int> materialTextureParts;
@ -2104,6 +2123,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
if (type.contains("diffuse")) {
diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
} 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));
} else if (type.contains("bump") || type.contains("normal")) {
bumpTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));

View file

@ -2239,10 +2239,17 @@ bool NetworkMeshPart::isTranslucent() const {
return diffuseTexture && diffuseTexture->isTranslucent();
}
bool NetworkMesh::isPartTranslucent(const FBXMesh& fbxMesh, int partIndex) const {
assert(partIndex >= 0);
assert(partIndex < parts.size());
return (parts.at(partIndex).isTranslucent() || fbxMesh.parts.at(partIndex).opacity != 1.0f);
}
int NetworkMesh::getTranslucentPartCount(const FBXMesh& fbxMesh) const {
int count = 0;
for (int i = 0; i < parts.size(); i++) {
if (parts.at(i).isTranslucent() || fbxMesh.parts.at(i).opacity != 1.0f) {
if (isPartTranslucent(fbxMesh, i)) {
count++;
}
}

View file

@ -398,6 +398,7 @@ public:
QVector<NetworkMeshPart> parts;
int getTranslucentPartCount(const FBXMesh& fbxMesh) const;
bool isPartTranslucent(const FBXMesh& fbxMesh, int partIndex) const;
};
#endif // hifi_GeometryCache_h

View file

@ -1827,12 +1827,18 @@ void Model::segregateMeshGroups() {
// Debug...
int totalParts = mesh.parts.size();
for (int partIndex = 0; partIndex < totalParts; partIndex++) {
// this is a good place to create our renderPayloads
if (translucentMesh) {
if (networkMesh.isPartTranslucent(mesh, partIndex)) {
_transparentRenderItems << std::make_shared<MeshPartPayload>(true, this, i, partIndex);
} else {
_opaqueRenderItems << std::make_shared<MeshPartPayload>(false, this, i, partIndex);
}
// this is a good place to create our renderPayloads
/* if (translucentMesh) {
_transparentRenderItems << std::make_shared<MeshPartPayload>(true, this, i, partIndex);
} else {
_opaqueRenderItems << std::make_shared<MeshPartPayload>(false, this, i, partIndex);
}*/
}
}
_meshGroupsKnown = true;