Support ReadyPlayerMe blendshapes in glTF files

This commit is contained in:
David Rowe 2021-04-19 11:10:25 +12:00
parent 71bcabfc0a
commit 0b536f0cae
2 changed files with 32 additions and 2 deletions

View file

@ -1550,7 +1550,6 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
typedef QPair<int, float> WeightedIndex;
hifi::VariantHash blendshapeMappings = mapping.value("bs").toHash();
QMultiHash<QString, WeightedIndex> blendshapeIndices;
for (int i = 0;; ++i) {
auto blendshapeName = QString(BLENDSHAPE_NAMES[i]);
if (blendshapeName.isEmpty()) {
@ -1561,7 +1560,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
// Use blendshape from mapping.
foreach(const QVariant& mapping, mappings) {
auto blendshapeMapping = mapping.toList();
blendshapeIndices.insert(blendshapeMapping.at(0).toString(),
blendshapeIndices.insert(blendshapeMapping.at(0).toString(),
WeightedIndex(i, blendshapeMapping.at(1).toFloat()));
}
} else {
@ -1572,6 +1571,19 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
}
}
// Augment list of blendshapes from synonyms in model.
QMap<QString, QPair<QString, float>>::const_iterator synonym = BLENDSHAPE_SYNONYMS_MAP.constBegin();
while (synonym != BLENDSHAPE_SYNONYMS_MAP.constEnd()) {
if (_file.meshes[node.mesh].extras.targetNames.contains(synonym.key())) {
auto blendshape = BLENDSHAPE_LOOKUP_MAP.find(synonym.value().first);
if (blendshape != BLENDSHAPE_LOOKUP_MAP.end()) {
blendshapeIndices.insert(synonym.key(),
WeightedIndex(blendshape.value(), synonym.value().second));
}
}
++synonym;
}
// Create blendshapes.
if (!blendshapeIndices.isEmpty()) {
mesh.blendshapes.resize((int)Blendshapes::BlendshapeCount);

View file

@ -113,6 +113,24 @@ enum class Blendshapes : int {
// * LipsUpperOpen (not in ARKit)
// * LipsLowerOpen (not in ARKit)
const QMap<QString, QPair<QString, float>> BLENDSHAPE_SYNONYMS_MAP {
// ReadyPlayerMe
{"browDownLeft", {"BrowsD_L", 0.5f}},
{"browDownRight", {"BrowsD_R", 0.5f}},
{"browInnerUp", {"BrowsU_C", 0.3f}},
{"browOuterUpLeft", {"BrowsU_L", 0.3f}},
{"browOuterUpRight", {"BrowsU_R", 0.3f}},
{"eyeBlinkLeft", {"EyeBlink_L", 1.0f}},
{"eyeBlinkRight", {"EyeBlink_R", 1.0f}},
{"eyeWideLeft", {"EyeOpen_L", 1.0f}},
{"eyeWideRight", {"EyeOpen_R", 1.0f}},
{"mouthLeft", {"MouthSmile_L", 0.6f}},
{"mouthOpen", {"JawOpen", 1.0f}},
{"mouthRight", {"MouthSmile_R", 0.6f}},
{"mouthShrugLower", {"LipsUpperClose", 0.1f}},
{"viseme_O", {"LipsFunnel", 0.5f}}
};
struct BlendshapeOffsetPacked {
glm::uvec4 packedPosNorTan;
};