A brand new system has been introduced that is compatible with animation clips (starting from r74 as far as I know).
Check out this example of my Blender-exported JSON models.
var mixer;
var actions = {};
var loader = new THREE.JSONLoader();
loader.load( "webgl/models/model.json", function ( geometry, materials ) {
model = new THREE.SkinnedMesh( geometry, materials, false );
for(var x=0;x<materials.length();x++) materials[x].skinning = true;
mixer = new THREE.AnimationMixer(model );
//idle
actions.idle = mixer.clipAction(geometry.animations[0]);
actions.idle.setLoop(THREE.LoopRepeat);
actions.idle.clampWhenFinished = true;
actions.idle.play();
//walk
actions.walk = mixer.clipAction(geometry.animations[1]);
actions.walk.setLoop(THREE.LoopRepeat);
actions.walk.clampWhenFinished = true;
scene.add( model );
}
Each exported animation is stored in the geometry.animations array.
I know explicitly which index corresponds to which animation in my example, but it can also be easily mapped manually by name: (geometry.animations[x].name
).
In the animation loop, you need to update the mixer regularly
if(typeof mixer != "undefined") mixer.update(delta);
I found my information from
Also, here is the corresponding source code for an animation action: https://github.com/mrdoob/three.js/blob/ab93512c7a44bd98e669592b3db441c04a2057f4/src/animation/AnimationAction.js
Exporting from Blender can have many potential pitfalls, especially when dealing with Skeletal mesh animations (!= morphs).
- Ensure scale values of all bones / Armature / mesh are exactly "1" and never modified again :)
(Keyframes should only have keying set to LocRot)
- Using the "apply modifiers" button during export always caused distortions for me
- Only select the mesh while exporting (not the armature or bones)
Here are my export settings:
https://i.sstatic.net/quowk.png
Hopefully, this information will be helpful for future explorers :)