Ever since the Blender Exporter added a MorphTarget Manager, I’ve been wondering what it might be capable of. A few years back when I was looking at Unity 3D I created this little test:
It used a free script to drive the morph animation (Metamorph), which I gather is not needed anymore.
Anyway I still have the old files, and wondered if it could be done with BJS and the morphs exported from Blender. So here is what I have managed so far:
Now while BJS Blender exporter will export the actual morphs(shapekeys), it will not export the morph animation - so I had to try to figure out a way to script the animation! And, to put it mildly, that is not exactly my strong point
So I started out with a sound file for which I had a text file for the visemes and phonemes that looks like this(151 frames that go 1,2,3,4 etc)):
[0.0, 0.0, 0.0]
[0.0804, 0.0385, 0.0461]
[0.303, 0.1519, 0.1813]
[0.5683, 0.3236, 0.3858]
…
…
[0.1341, 0.0, 0.0]
[0.0333, 0.0, 0.0]
[0.0, 0.0, 0.0]
So I had to create a script that played these frames synced with the sound file. This is what I came up with:
function createMotion(){
if(index === (activities.length -1)){
clearTimeout(id);
console.log(index);
return;
}
else{
//var aSpeed = 30*engine.getFps()/60;
//console.log(index);
aHead.morphTargetManager.getTarget(0).influence = activities[index][0];
aHead.morphTargetManager.getTarget(1).influence = activities[index][1];
aHead.morphTargetManager.getTarget(2).influence = activities[index][2];
++index;
id = setTimeout(createMotion, 30);
}
};
The morphs/shapekeys are loaded into a variable array “activities”.
This works pretty well if the fps is around sixty - but strange things happen with the animation and sound sync if the fps drops.
I can also create a morph file that looks like this, where the first number is the frame # and the 3 numbers in the brackets are the influence of the three morphs/shapekeys
1, [1,0.840,0.947]
8, [0.067,0.2,0.4]
23, [0.962,0,0.227]
37, [0.760,0,0]
So any thoughts about how I may create the animation so that it stays synced with the sound?
And just a couple of other thoughts. Each visemes/phoneme is based upon just the same three morphs/shapekey ( see the makeup of of the letters/sounds at ~ 24 secs of the video above). And when I look at the Morph Target Manager in my .babylon file, I see just “positions” - nothing about 'uvs, normals tangents" which I gather can be a limitation of morph targets.
Do I have to worry about them with the babylon file exported from Blender?
cheers, gryff