Jump to content

Blender animations out of order


ozRocker
 Share

Recommended Posts

I'm trying to create an animation sequence of idle, walk and run in Blender to use in babylon.js.  I can't seem to get it right though.  I've attached a video of my Blender setup:

You can also download the Blender file from here: http://www.punkoffice.com/animtest/sequence.blend

I'm using the NLA editor here.  My sequence is set up like this:

  • Idle - frames 1 to 47
  • Walk - frames 48 to 72
  • Run - frames 73 to 87

However, the exported .babylon file lists the animations like this:

"ranges":[{"name":"Idle","from":1,"to":47},{"name":"Run","from":48,"to":62},{"name":"Walk","from":63,"to":86}]

If you want to see the final result go to the page here: http://www.punkoffice.com/animtest

My code is very simple.  I'm just doing the basic setup:

BABYLON.SceneLoader.Load("3D/", "main.babylon", engine, function (newScene) {	
	newScene.executeWhenReady(function () {
		var scene = newScene;
		var camera = new BABYLON.FreeCamera ("FreeCamera", new BABYLON.Vector3 (0, 1, -5), scene);										
		camera.attachControl(canvas, true);

		var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);

		mesh = scene.meshes[0];

		// to view it correctly
		mesh.rotate (BABYLON.Axis.X, -Math.PI / 2, BABYLON.Space.LOCAL);

		skeleton = newScene.getSkeletonById(0);
		animations = newScene.beginAnimation(skeleton, 0, 87, true, 1);

		engine.runRenderLoop(function () {
			scene.render();
		});
	});
}, function (evt) {
});

Does anyone know what I might be doing wrong?

Link to comment
Share on other sites

26 minutes ago, satguru said:

I think the exporter looks at the action editor rather than the nla editor.

Yep, you're right about that.  I cleared out the NLA editor and it got the right animations. It warps a bit though.  I cleared the mesh parent and re-parented mesh to armature but it still warps.  I updated my code so you can see what it looks like now.

Link to comment
Share on other sites

turns out I forgot to separately apply rotation to mesh and armature.  Well that made the animations look better, but they are still a bit warped.  Definitely different to the original Blender animation.  Is there an up-to-date tutorial on exporting multiple animations for one mesh in Blender?

Link to comment
Share on other sites

Looks like there is a small bug in blender exporter 4.4.3. The from and to range are off by 1. There is a new version out , 4.4.4 which seems to have fixed this.

If you exported using 4.4.3 then make sure that in your code you increment the "range.to" and "range.from" by 1 for each animationrange.

Another thing to keep in mind is the  issue of "rest position" of your mesh / skeleton.

A workflow which works for me is

1) I create an action containing at least two frames in which the skeleton is in rest position (all transform is set to zero). In my case this normally results in the skeleton in T-Pose.

(why two frames ? Seems like babylonjs cannot play an animation containing just 1 frame. bug?)

2) just before I start the export I make sure the action in action editor is set to this "rest position" action and thus my mesh / skeleton are in rest position.

 

 

Link to comment
Share on other sites

26 minutes ago, satguru said:

Looks like there is a small bug in blender exporter 4.4.3. The from and to range are off by 1. There is a new version out , 4.4.4 which seems to have fixed this.

sweet!  I didn't realise 4.4.4 was out.  I installed that and it actually fixed the warping problem.  If you try out my page now use W,A,S,D and SHIFT to run (  http://www.punkoffice.com/animtest ).  The animations look how they are meant to.  Looping isn't perfect though.  Not sure why.  I got the anims from Mixamo and they also have perfectly looping anims.

Link to comment
Share on other sites

Hmm...this doesn't seem right.  The ranges are missing a frame in-between

"ranges":[{"name":"Idle","from":1,"to":46},{"name":"Run","from":48,"to":61},{"name":"Walk","from":63,"to":85}]}]

If I change Run to 47 - 62 that seems to fix it but I've tried adjusting the Walk range (start and end) and I just can't get the perfect loop.  I think the very last walk frame hadn't been exported

Link to comment
Share on other sites

First, 4.4.2 & 4.4.3 had skeleton animation problems introduced by action support & inverse kinematics tolerance in 4.4.0.  Took me a while to figure out what went wrong.  It did not show up in my tests.

There should be a 1 frame gap between each action.  I put that in just sanity purposes.  The ranges SHOULD match up to the frames of most of the bones though.  FYI, if a given bone does not move for a given frame, there is no frame for it generated.

There were line breaks put in for 4.4.3, so you can easily view the frames of each bone on separate lines.  Verify that there is no frame 47.

AnimationRanges is new as of 2.3.  Blender is the only exporter which currently supports them.  Very little testing has been done.  It needs to be verified whether the export has all the frames, or it BJS is just not playing the last one.  Try a really crazy last frame.  Might help more to determine if it is a export / BJS / or user problem.  Might also be only be visible on the last range, where the first frames of the next range sort of fix it.  Maybe I should change the gap to 10, 100, or 1000.

Might also be relevant to the 2 frame animation problem.

Link to comment
Share on other sites

I think the last frame of each action is being dropped.

and like you mentioned this issue is masked for all actions except the last one.

I created a two frame action. In the second frame I positioned the bones at crazy angles.

I then copied the action to create another action. 

Kept one as the last action and the other as second last.

Exported it

In each action the second frame got dropped.

 

Another issue.

Not directly linked to the above discussion.

This has to do with serialization.

The babylon file exported from blender has one AnimationRange Array and  that is "attached" to the skeleton, I think.

The babylon file created by serializing the scene (containing the animation exported from blender) has multiple AnimationRange Arrays, one attached to each bone.

 

 

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...