From bd1be872a8df25a114f16911a5432dd4a3cc85a3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 31 Aug 2020 21:31:55 +1200 Subject: [PATCH] Support using blendshapes in file without needing an FST --- libraries/fbx/src/GLTFSerializer.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 337c9d7f70..806fbd7619 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1544,25 +1544,33 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& // Build morph targets (blend shapes) if (!primitive.targets.isEmpty()) { - // Build list of blendshapes from FST + // Build list of blendshapes from FST and model. typedef QPair WeightedIndex; hifi::VariantHash blendshapeMappings = mapping.value("bs").toHash(); QMultiHash blendshapeIndices; for (int i = 0;; ++i) { - hifi::ByteArray blendshapeName = BLENDSHAPE_NAMES[i]; + auto blendshapeName = QString(BLENDSHAPE_NAMES[i]); if (blendshapeName.isEmpty()) { break; } - QList mappings = blendshapeMappings.values(blendshapeName); - foreach (const QVariant& mapping, mappings) { - QVariantList blendshapeMapping = mapping.toList(); - blendshapeIndices.insert(blendshapeMapping.at(0).toByteArray(), WeightedIndex(i, blendshapeMapping.at(1).toFloat())); + auto mappings = blendshapeMappings.values(blendshapeName); + if (mappings.count() > 0) { + // Use blendshape from mapping. + foreach(const QVariant& mapping, mappings) { + auto blendshapeMapping = mapping.toList(); + blendshapeIndices.insert(blendshapeMapping.at(0).toString(), + WeightedIndex(i, blendshapeMapping.at(1).toFloat())); + } + } else { + // Use blendshape from model. + if (_file.meshes[node.mesh].extras.targetNames.contains(blendshapeName)) { + blendshapeIndices.insert(blendshapeName, WeightedIndex(i, 1.0f)); + } } } - // glTF morph targets may or may not have names. if they are labeled, add them based on - // the corresponding names from the FST. otherwise, just add them in the order they are given + // Create blendshapes. mesh.blendshapes.resize((int)Blendshapes::BlendshapeCount); auto keys = blendshapeIndices.keys(); auto values = blendshapeIndices.values();