If you don’t mind three.js loading all the shape keys at step (2), then you probably don’t need separate GLBs. At step (3), can you remove the shape keys you don’t need before passing the model into GLTFExporter? Or clone()
first if you need to keep the original. Something like:
const morphAttributeNames = ['position', 'normal'];
const morphTargetsNeeded = ['Happy', 'Sad'];
const morphTargetNameDictionary = {};
// Create lookup table from target index to target name.
for (const targetName in mesh.morphTargetDictionary {
morphTargetNameDictionary[mesh.morphTargetDictionary[targetName]] = targetName;
}
// Remove unwanted morph target attributes.
for (const k of morphAttributeNames) {
const geometry = mesh.geometry;
geometry.morphAttributes[k] = geometry.morphAttributes[k].filter((attribute, index) => {
const targetName = morphTargetNameDictionary[index];
attribute.name = targetName; // Ensures .updateMorphTargets() gets the right name.
return morphTargetsNeeded.includes(targetName);
});
}
// Update mesh properties.
mesh.updateMorphTargets();