ozRocker Posted April 10, 2016 Share Posted April 10, 2016 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? Quote Link to comment Share on other sites More sharing options...
ozRocker Posted April 10, 2016 Author Share Posted April 10, 2016 It looks like this guy had a similar problem Quote Link to comment Share on other sites More sharing options...
satguru Posted April 10, 2016 Share Posted April 10, 2016 I think the exporter looks at the action editor rather than the nla editor. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted April 10, 2016 Author Share Posted April 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted April 10, 2016 Author Share Posted April 10, 2016 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? Quote Link to comment Share on other sites More sharing options...
satguru Posted April 10, 2016 Share Posted April 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted April 10, 2016 Author Share Posted April 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted April 10, 2016 Author Share Posted April 10, 2016 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 Quote Link to comment Share on other sites More sharing options...
satguru Posted April 10, 2016 Share Posted April 10, 2016 In blenders do your actions start with frame 0 or frame 1? If frame 0, shift them to start with frame 1. I had issues with actions starting with frame 0 so this might help. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 10, 2016 Share Posted April 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
satguru Posted April 10, 2016 Share Posted April 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 10, 2016 Share Posted April 10, 2016 One final check, now manually edit the exported .babylon, setting the last range end to 1000. Run it. If the crazy frame runs it is a BJS error, else a Blender error. Quote Link to comment Share on other sites More sharing options...
satguru Posted April 10, 2016 Share Posted April 10, 2016 Ok did that. Crazy frame does not run. Instead i get the following error TypeError: this._keys[s] is undefined Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.