three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Exporting multiple Animations

Open MKHenson opened this issue 13 years ago • 23 comments

Hi guys

This is partly for others who might be searching for this topic as well as a feature request.

From what I understand three supports the playback of 1 animation at a time. Using the provided exporter for Blender we can export either a single skinned mesh and its single animation, or we can create a single morph mesh with multiple morph animations using an obj export method (can someone clarify if this method has changed?). I cant find any tutorials on creating multi animation files from blender... I think this would be a very useful thing to add if its actually possible.

Here are two tutorials I found for the above situations: Skinned animation: http://www.kadrmasconcepts.com/blog/2012/01/24/from-blender-to-threefab-exporting-three-js-morph-animations/

morph animations: http://catchvar.com/threejs-animating-blender-models

Firstly, I just want to double check if my above assertions were correct?

Secondly, I was wondering if there was any work towards creating a more robust skinning solution? Ideally with some kind of method to export those files with multiple animations.

If its a case of providing an animated blender asset, I can certainly help you create an asset with multiple animations on the timeline.

Any guidance or recommendations you might have are greatly appreciated

Regards Mat

MKHenson avatar Jan 08 '13 00:01 MKHenson

Hi guys

I am going to make an attempt to modify the blender exporter to try and get it to support exporting multiple animations. I was thinking about how to do this and have recently gone over the export script (I'm not an expert on this, but I get the jist of it). I have a proposition which I think might work without too much effort.

So in blender you can add markers to the timeline. Could we not use these to name and identify different sections of an animation? So for example lets say I create an asset that's 100 frames long. Lets say that from 0 to 50 the character plays an idle animation and then from 51 too 100 it plays a walk cycle. Could we not add 2 markers to the timeline to define the animations? So first we would add a marker to frame 0 and name it 'idle' and then one on frame 51 and name it 'walk'.

Then when we export we keep a list of all timeline markers. We would define each animation as the frames from the start of one marker up until the previous frame of the very next marker on the timeline. So in the above example, three would understand there to be two animations, 'idle' and 'walk'. Idle would be from frame 0 to 50 and walk from 51 to 100.

What do you think?

Mat

MKHenson avatar Jan 08 '13 13:01 MKHenson

Hi,

I modified the exporter to export all actions. Here it is. https://gist.github.com/4484676

This change add "all animations" option on the GUI. When the option be checked, exported JSON has new "animations" property of an array of all animation data.

And, to load the property, it's necessary to add the following code in JSONLoader:

geometry.bones = json.bones;
geometry.animation = json.animation;
geometry.animations = json.animations; // add

This exporter based blender 2.64 exporter but still works on 2.65. It's an quick-and-dirty work but I hope this helps.

kontan avatar Jan 08 '13 16:01 kontan

Hi Kontan, thanks for the heads up :) I must admit I've not yet tried to work with actions in Blender, so I wouldn't really know which method is best.

I've actually just finished modifying the exporter with the technique I proposed earlier. It seems to work nicely and doesn't conflict with any of the data that is already being exported. I'll post it up later for everyone's review. The idea is that you can use markers on the timeline and in the export process it does a check when exporting the morph at a particular frame. If that frame is within the boundaries of two markers on the timeline, it creates an animation with the name of the first marker and associates the morph with it.

This could also be expanded upon to work with bones too.

I think ideally the exporter would have to be expanded up to include a little animation manager, but this seems to work pretty well too. Anyone have any input on the subject?

Regards Mat

MKHenson avatar Jan 08 '13 17:01 MKHenson

Any more work on this? Being able to export more than one animation is a useful feature.

Digitoxin avatar Sep 16 '13 16:09 Digitoxin

I'll just jump the gun on this one, since kontan's changes seem to work fine.

Digitoxin avatar Sep 18 '13 15:09 Digitoxin

Is this about layered animation?

kaanozcan avatar Sep 19 '13 09:09 kaanozcan

That too. One part of the problem is solved: more than one action can be exported from Blender. Getting three.js to play more than one animation at once is a little tougher.

Something like...

runAnim = new THREE.Animation(mesh, "run");
waveAnim = new THREE.Animation(mesh, "waveArm");
runAnim.play();
waveAnim.play();

Seems to be impossible at the moment, as both of the animations fight for control and keep resetting the bone positions even though they're not supposed to affect all of the bones.

Digitoxin avatar Sep 19 '13 11:09 Digitoxin

Just realized I'm doing it wrong. My update function is calling

runAnim.update(delta);
waveAnim.update(delta);

Where this should be

THREE.AnimationHandler.update(delta);

I have no idea if three.js supports this yet or not. The way AnimationHandler is built would seem to imply as much. I'll check if this is possible as soon as I can.

Digitoxin avatar Sep 19 '13 11:09 Digitoxin

Nevermind, I'm still getting the same behaviour.

Digitoxin avatar Sep 19 '13 15:09 Digitoxin

Hi guys, so I was able create a modified exporter that exported multiple animations based on markers. I have not proposed it to be included as I don't think what I've got is a great implementation... It works, but is not ideal as I am only exporting morph animations.

The last I was told, was the Three did not support playing multiple animations. Don't know if this has since changed...?

MKHenson avatar Sep 19 '13 15:09 MKHenson

What needs to be done to make this possible? because developing games are allmost impossible without this feature.

kaanozcan avatar Sep 19 '13 19:09 kaanozcan

It could be as simple as getting AnimationHandler not to reset bone positions for each playing animation which would allow performing skinning additively or then it could involve doing complex multi-frame interpolation for all playing animations. It would be great if the former was the case.

Digitoxin avatar Sep 20 '13 00:09 Digitoxin

By the way, why does three.js have a giant singleton that has to contain all animations for all meshes?

With an update loop like this:

    that.update = function( deltaTimeMS ) {

        for( var i = 0; i < playing.length; i ++ )
            playing[ i ].update( deltaTimeMS );

    };

I'm not entirely sure what AnimationHandler is supposed to be handling.

The directory structure src/extras/animation/ is a little telling as to why things are a little weird/half-baked in this area.

Digitoxin avatar Sep 20 '13 12:09 Digitoxin

That code was written by @empaempa in a rush for rome and I haven't found time yet to clean that up.

mrdoob avatar Sep 20 '13 22:09 mrdoob

Funny, I thought ro.me mostly used morph target animation. Is that why it's less developed though?

Does AnimationHandler also do morph target animation? The source seems to reference them, but all the examples I've found involve either using Animation + AnimationHandler for skeletal animation, or then setting morph target influences manually for morph targets.

I'm curious about what the longer term plans for animations in three.js are.

Amazing work on ro.me, by the way. Pure magic.

Digitoxin avatar Sep 20 '13 23:09 Digitoxin

Correct, it's a rushed piece of code and we used morph targets for ROME in the end. If I where you, I'd start over from scratch and do a proper channel based animation system that supports multiple layers of animations and with bone filters - so you can filter an animation to kick through on the legs only or not update the neck of your character so you can control it from code :)

empaempa avatar Sep 21 '13 16:09 empaempa

I think you got this the wrong way around: if I were you, I'd start over from scratch building a fancy new animation system. I am not however, so it's a bit beyond my abilities at the moment. Whatever I'd come up with would probably be much messier.

I can do with playing singular animations for now, with the script rotating bones for simple things like head or arm rotation as I need them.

Digitoxin avatar Sep 21 '13 21:09 Digitoxin

I wish I had time to help you but unfortunately I'm (more than) fully booked for a couple of months ahead :)

empaempa avatar Sep 22 '13 18:09 empaempa

No apology needed, I'm glad there's something that works. I'd just love to get my hands dirty on this if I could. In fact I might make a few tweaks there, but something on the scale of a new animation system seems massive starting from scratch.

Digitoxin avatar Sep 22 '13 22:09 Digitoxin

This actually sounds like a fun undertaking, though.

Starting from the low hanging fruit: As far as I can tell, AnimationHandler ended up just being a bunch of helper functions rather than an animation system in itself so keeping track of an animation library doesn't really make sense. Would a refactor from AnimationHandler into AnimationUtils be a good call?

Digitoxin avatar Sep 22 '13 23:09 Digitoxin