From a431268815411201fb0b72eb8da8a1eb64cc5477 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 9 Dec 2013 15:21:20 -0800 Subject: [PATCH] Somewhat inefficient take on allowing blendshapes coefficients to apply multiple blendshapes. --- interface/src/renderer/FBXReader.cpp | 37 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index 61c0ae775b..42192e6b50 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -780,7 +780,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QVector jointRightFingertipIDs(jointRightFingertipNames.size()); QVariantHash blendshapeMappings = mapping.value("bs").toHash(); - QHash > blendshapeIndices; + typedef QPair WeightedIndex; + QMultiHash blendshapeIndices; for (int i = 0;; i++) { QByteArray blendshapeName = FACESHIFT_BLENDSHAPES[i]; if (blendshapeName.isEmpty()) { @@ -788,16 +789,16 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) } QList mappings = blendshapeMappings.values(blendshapeName); if (mappings.isEmpty()) { - blendshapeIndices.insert(blendshapeName, QPair(i, 1.0f)); + blendshapeIndices.insert(blendshapeName, WeightedIndex(i, 1.0f)); } else { foreach (const QVariant& mapping, mappings) { QVariantList blendshapeMapping = mapping.toList(); blendshapeIndices.insert(blendshapeMapping.at(0).toByteArray(), - QPair(i, blendshapeMapping.at(1).toFloat())); + WeightedIndex(i, blendshapeMapping.at(1).toFloat())); } } } - QHash > blendshapeChannelIndices; + QMultiHash blendshapeChannelIndices; foreach (const FBXNode& child, node.children) { if (child.name == "Objects") { @@ -1033,7 +1034,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) // try everything after the dot name = name.mid(name.lastIndexOf('.') + 1); } - blendshapeChannelIndices.insert(getID(object.properties), blendshapeIndices.value(name)); + QString id = getID(object.properties); + foreach (const WeightedIndex& index, blendshapeIndices.values(name)) { + blendshapeChannelIndices.insert(id, index); + } } } } @@ -1059,20 +1063,21 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) // assign the blendshapes to their corresponding meshes foreach (const ExtractedBlendshape& extracted, blendshapes) { QString blendshapeChannelID = parentMap.value(extracted.id); - QPair index = blendshapeChannelIndices.value(blendshapeChannelID); QString blendshapeID = parentMap.value(blendshapeChannelID); QString meshID = parentMap.value(blendshapeID); ExtractedMesh& extractedMesh = meshes[meshID]; - extractedMesh.mesh.blendshapes.resize(max(extractedMesh.mesh.blendshapes.size(), index.first + 1)); - FBXBlendshape& blendshape = extractedMesh.mesh.blendshapes[index.first]; - for (int i = 0; i < extracted.blendshape.indices.size(); i++) { - int oldIndex = extracted.blendshape.indices.at(i); - for (QMultiHash::const_iterator it = extractedMesh.newIndices.constFind(oldIndex); - it != extractedMesh.newIndices.constEnd() && it.key() == oldIndex; it++) { - blendshape.indices.append(it.value()); - blendshape.vertices.append(extracted.blendshape.vertices.at(i) * index.second); - blendshape.normals.append(extracted.blendshape.normals.at(i) * index.second); - } + foreach (const WeightedIndex& index, blendshapeChannelIndices.values(blendshapeChannelID)) { + extractedMesh.mesh.blendshapes.resize(max(extractedMesh.mesh.blendshapes.size(), index.first + 1)); + FBXBlendshape& blendshape = extractedMesh.mesh.blendshapes[index.first]; + for (int i = 0; i < extracted.blendshape.indices.size(); i++) { + int oldIndex = extracted.blendshape.indices.at(i); + for (QMultiHash::const_iterator it = extractedMesh.newIndices.constFind(oldIndex); + it != extractedMesh.newIndices.constEnd() && it.key() == oldIndex; it++) { + blendshape.indices.append(it.value()); + blendshape.vertices.append(extracted.blendshape.vertices.at(i) * index.second); + blendshape.normals.append(extracted.blendshape.normals.at(i) * index.second); + } + } } }