Author Topic: Just a few animation questions.  (Read 4930 times)

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Just a few animation questions.
« on: January 09, 2013, 10:58:25 AM »
First off, I want to say I'm really impressed with how many features are in this library, as well as the performance on my device, so thank you for making this available!

That being said, I've got a few questions that I can't seem to find an answer to via the various examples, that I'm hoping you could assist me with.

1) I've converted a fbx model to the Bonzai Engine native format, which stores about 10 animations consecutively on a single timeline.  However, that animation is at index 1, as there's a "bind_pose" animation sitting at index 0. The problem comes in when attempting to make use of AnimationSplitInfo, which despite referencing the example, doesn't seem to work. Now, I'm thinking this might be because it's attempting to apply the splits to the animation at index 0? If this is the case, is there some way to specify which animation should be split?

2) the last two fields of AnimaitonSplitInfo are a little unclear to me - in the example, all the instances of loopIndex, are set at -1, and loopDuration at 0. I take it that this means the animations don't loop? If the intention was to have them loop, would that then be set at "1"? and does loopDurration mean how many times it should loop?

3) Finally, the model I'm working with - a character, has a blink animation - which consists of 8 frames, that would be played every 6 seconds or so, and should be entirely independent of the other animations. Does Bonzai Engine support this? And if so, how would you recommend I go about doing this?

Thanks again, and I really hope you can help me - I'll probably (eventually) figure it out on my own - through trial and error; but I'd (understandably) hope to limit that as much as possible :)

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #1 on: January 09, 2013, 11:53:02 AM »
1) AnimationSplitInfo is applied to the first motion of the skeleton, but is ignored when the skeleton has more than one animation (still not counting the bind pose).
Skeleton bind pose and motions are counted separatly. Accessing Skeleton.getMotion(0) does not return the bind-pose but the first actual motion.

If getMotion(0) returns a motion named "bind_pose", this mean your fbx have two animations which explains why animation split is not performed.
In this case, the best would be re-export the fbx without this first motion and with the other one splitted. Alternately, I can also publicly expose the split method to allow more control on which motion the split is performed.

2) The tutorial setup animation that don't loop.
To loop, you have to set the loopIndex (or time). When arrived to the end, the animation will rewind to loopIndex. If you want to replay all, set it to start. Or if you want to loop over a piece of the sanimation set it to a value between start and end.
When loopDuration is set to 0, the animation will rewind instantly to loop index. Setting a value greater than 0 will define the time to goes/interpolate from the animation end frame to the loop frame.

3) Model animation is controlled by getAnimationContext(). You can use an AnimGraph (basically a motion state machine) or may be just two AnimationTrack.

There's no tutorial written yet about that, but I can provide one if you need. I'll suggest to get a quick look at the video 3 (AnimGraph) and 4 (AnimationTrack).
Let me know if you're blocked with anything. AnimGraph and AnimationTrack are not fully shipped (advanced node/controls are not yet fully available).
« Last Edit: January 09, 2013, 11:54:29 AM by jerome_j »

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Re: Just a few animation questions.
« Reply #2 on: January 11, 2013, 03:20:09 AM »
Thanks for such a quick reply! The good news is that getMotion(0) returns "Track 001", so that means the split should be performed on the correct animation. Unfortunately, on the first drawFrame(), getNumAnimations still returns 2, and getNumMotions returns 1. Maybe there's a better place to perform this check? Because after looking through AnimationSplit.Java, the only real difference I see is the fact that all the animation related code (AnimationContext, animID, etc) is taking place within the processInput function. While that makes sense for the purpose of that example, most of the animation in my project will be scripted.

Here's some code - because I'm becoming more certain that I'm doing something wrong here:

1) settings.animationSplit

2) Animation assignment/debug


jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #3 on: January 11, 2013, 09:43:02 AM »
I don't see anything wrong in your code. Running the tutorial code with your fbx and AnimationSplitInfo array must work.

The only I see would be that you've converted the fbx into jmf/jma and later trying to load it with animationSplit setting. In that case, animationSplit (like other post process settings) is ignored to keep jmf/jma loading the fastest (animationSplit must be used when converting fbx).

If you're converting using the viewer, tutorial 16 shows how to convert by code. If you don't want to waste time for now, there will be a new dev build by end of week exposing the split method which you can call outside the reading process.

If you can't figure out what's going wrong, if you wish you can send me your fbx model (use our contact email) and I'll check there's no bug
« Last Edit: January 11, 2013, 09:53:09 AM by jerome_j »

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Re: Just a few animation questions.
« Reply #4 on: January 11, 2013, 11:35:52 AM »
The only I see would be that you've converted the fbx into jmf/jma and later trying to load it with animationSplit setting. In that case, animationSplit (like other post process settings) is ignored to keep jmf/jma loading the fastest (animationSplit must be used when converting fbx).

Ah, that would be it then - it's because I'm attempting to do this on an already converted model. So, the general process would be to create some code to open the fbx, using the appropriate settings (including animationSplit and optimize), and then use JmfWriter to export it into jmf format - as this way the jmf would have the multiple animations. Or, of course, use the 3D modeling program used to export to fbx,  to use that format's multiple animation support to pre-split the animations before converting via the viewer (or the other code) to jmf. Do I have that correct, now?

I'm fairly certain the model is fine in that case. I'm not quite sure how to save multiple animations to an fbx file using 3ds Max, but from the looks of it, it'll probably be a lot quicker to just take care of it with the engine. But I'm sure if I run into any further issues, I'll be back. Thanks for clearing that up for me.


jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #5 on: January 11, 2013, 12:18:39 PM »
Yes, this is exactly what to do.

The limitation of the viewer/editor is they did not currently exposes animationSplit option in the ui right now. I'll give a look to add that in one of the next dev builds.

Some 3d modeler can export multiple animation in fbx, but I don't know about 3ds max.
There is may be an option for that in the fbx export panel.

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Re: Just a few animation questions.
« Reply #6 on: January 11, 2013, 10:03:24 PM »
Yeah, that would definitely be helpful if the viewer supported animationSplit in some way - but even as is, the small amount of code necessary to do the optimization/conversion isn't really much of a hassle. I just wasn't really expecting a conversion  feature.

At any rate, this was definitely the solution! After loading the fbx, splitting, and writing to jmf - I opened up the jmf in the viewer, and all the animations are there. Next step is that blink animation.

Just looking at the Javadoc, I'm seeing AnimationContext with the method setTracks, which takes an AnimationTrack array. I also see that AnimationTrack, has a method named useAnimation, which appropriately, takes an Animation.

So.. would it work something like this?


I took a look at the videos you linked; (removed)

Edit: Never mind about the viewer - I see what I had to do :) I'll update this if I run into any further issues. 
« Last Edit: January 12, 2013, 09:32:04 AM by Digital_Utopia »

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #7 on: January 12, 2013, 09:31:36 AM »
I'm so used to the way the viewer that I'm never thought it could be seen as a bug.
Basically when a panel is disabled means nothing as been selected. Use the left tree to select a model, mesh, material, texture, shader and the panel will enable and shows info.

The animation track editor of the first video has been extended with more features.
It is now in the graph tab: add a MultiTrackNode. In the inputs set some AnimGraph and select some animation. You can then expend the tracks with the button arrow bellow.

All animation played is backed with an AnimGraph, so basically if you use AnimationContext.setAnimation to play a single animation it will internally create an AnimGraph with an AnimNode with your animation.
Using AnimationContext.setTracks will create it with a MultiTrackNode. setTracks is broken since the major anim graph refactor (setTracks needs Animation array, which I've just fixed).

Some code below to use AnimGraph directly:


MultiTrackNode is only able to blend between track.
So it will work if you want to play the blink animation every 6 seconds and other 6 seconds another animation (with eventually some blending between the two). If you want to play the blink animation on top of another animation instead of blending, the animation graph node to do that is not currently implemented as far as I remember (let me know if you need that).
« Last Edit: January 12, 2013, 09:40:12 AM by jerome_j »

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #8 on: January 13, 2013, 07:01:16 PM »
There's a new build with support of animation split from the viewer (+ some other fixes/features).

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Re: Just a few animation questions.
« Reply #9 on: January 18, 2013, 02:31:49 PM »
Okay, great! That definitely makes things more streamlined.

Right now, I'm struggling with getting the animations to export correctly from Max. to both loop correctly and work with multi-track or blend nodes on the AnimationGraph. It appears that, the blink animation has somehow keyframed all the bones, as none of the full body animations are showing through when blended or used as a multi-track. Only using it with Directional Blending seems to do any blending at all. This is obviously something that's more likely on my end - so I'll continue working on fixing that.

That being said, the video on AnimationTrack shows the appropriate options in the Animation tab, under what appears to be a "Context" heading. However, when I look at the Viewer, there is no second heading, nor is there anything after the (blank) Target field. Was this moved somewhere else? Or does the imported model have to be of a certain type, or contain something beyond a normally animated mesh?

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #10 on: January 18, 2013, 10:17:50 PM »
What was before under context is now in the graph tab, which is the anim graph editor.
Create a multi track node and add some anim graph input. You can then expand the track editor with the button at the bottom of the panel. By default all weights will be 1, so you'll want to zero'd or reduce some weights (the sum of the weights must be one, otherwise the engine will ignore track after weights of one has been reached).

About your blink animation, and all motion in general, all bones are keyframed. Even if a bone is not moving, there will be at least one key which define the 'static' pose of the motion.
If you blend, for exemple, a run animation and a blink animation. The static pose of your blink animation will be blended with the run motion. If you want to superpose the two animations to have a result such as the body running and the face blinking. This would be different to what the multi track or the blend node ar doing. This feature is planned by the BlendPerJointNode, not yet implemented but is in my todo list as well as some other advanced nodes (just let me know if you need that).
« Last Edit: January 18, 2013, 10:20:17 PM by jerome_j »

Digital_Utopia

  • Jr. Member
  • **
  • Posts: 6
Re: Just a few animation questions.
« Reply #11 on: January 19, 2013, 09:54:30 AM »
Ah, ok - now I understand. Correct me if I'm wrong; but it seems that the best solution, in order to make blinking independent from the rest of the animations, is to turn it into a Morph Target then?

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #12 on: January 19, 2013, 10:38:34 AM »
Yes morph target and skinning are independent, you can superpose facial animation (face morphed) to any body motion (body skinned).

This is possible the easiest right now to use. But you'll certainly have to check if it's fine in term of compatibility and performance with the device you target (and what you need to render on screen). There's more vertex attributes to send to gpu, seems fine on high end android gpu but not tested on older (there's some possible opti engine side).
Also, if you later need to superpose a different motion for lower and upper body (or the arm ...), using morph target for the head may not solve everything.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Just a few animation questions.
« Reply #13 on: January 26, 2013, 07:27:51 PM »
The latest build adds implementation for BlendPerJointNode.

This node blends two animations from a specific joint/bone of the skeleton and all of its childs (the other joints are untouch). Using a blend amount of 1 will therefore replace an animation on top of another for a specific set of joints (ie pretty much what you seem to need for blinking).

There's still some other node to implement or add more functionnality, let me know if you need anything.