Hello, I have loaded a GLTF model which contains an animation. It have influences values which is the animation I need.
Then, I want using these values to update another 3D model using MorphTarget.
But, how can I set the influences of new model?
Load the first model got influcens
var gltfLoader = new GLTFLoader();
gltfLoader.setKTX2Loader(ktx2Loader)
gltfLoader.setMeshoptDecoder(MeshoptDecoder)
gltfLoader.load("/assets/facecap.glb", (gltf) => {
var mesh = gltf.scene.children[0];
mesh.position.set(1, 1, 0)
scene.add(mesh);
mixer = new THREE.AnimationMixer(mesh);
this.faceAnimation = gltf.animations[0]
console.log('faceAnimation1', this.faceAnimation)
mixer.clipAction(this.faceAnimation).play();
const head = mesh.getObjectByName("mesh_2");
const influences = head.morphTargetInfluences;
console.log('morphTargetDictionary1: ', head.morphTargetDictionary)
console.log('influences1: ', influences)
this.demoInfluences = influences
for (const [key, value] of Object.entries(
head.morphTargetDictionary
)) {
folderNormal
.add(influences, value, 0, 1, 0.01)
.name(key.replace("blendShape1.", ""))
.listen(influences);
}
});
I want set it in second model:
var head = mesh.getObjectByName("POLYWINK_Bella")
const influences = head.morphTargetInfluences;
console.log('influences: ', influences)
console.log('morphTargetDictionary: ', head.morphTargetDictionary)
const morphTargetDict = head.morphTargetDictionary
// util animation loaded
if (this.demoInfluences) {
console.log('demoInfluences', this.demoInfluences)
// var faceAnimationRetargeted = new Array(this.faceAnimation.length)
for (const [key, value] of Object.entries(morphTargetDict)) {
console.log(key, value);
var newKey = key.replace("BS_Node.", "")
newKey = newKey.replace("Left", "_L")
newKey = newKey.replace("Right", "_R")
if (newKey in this.morphTargetDictNormal) {
influences[value] = this.demoInfluences[this.morphTargetDictNormal[newKey]]
}
}
// this.faceAnimation.
// mixer2.clipAction(faceAnimationRetargeted).play();
}
console.log('now the influences: ', influences)
for (const [key, value] of Object.entries(morphTargetDict)) {
folder
.add(influences, value, 0, 1, 0.01)
.name(key.replace("BS_Node.", "B_"))
.listen(influences);
}
});
but the influcens values not update.
note, I don’t want set Animation directly, since I need to switch the animation blendshapes order by keys.
Is there a way to make it?