timetocode

importing and playing named animations from blender

Recommended Posts

How do I play animations created in the blender action editor? I'm trying to organize walk, run, idle, etc animations and start/stop them by name.

Also is there a particularly good way to import the blender objects that don't have any world position when the game begins? I noticed there are many different ways to load things. Objects in this game are spawned in after a receiving a network message, so there's no pre-existing concept of a scene (or my brain just isn't used to thinking about scenes). Even the terrain itself is chosen by the server. Which loading strategy should I employ?

Blender scene:

image.png.9742dd014a341a8474c55a6fe745aa1b.png

Action editor from under the dopesheet:

image.png.81b1a23989ca752ab97495acefd1c8a6.png

Loading and positioning the character (exported with blender/babylon exporter 5.6.4):

BABYLON.SceneLoader.LoadAssetContainer("./", "blocky.babylon", this.scene, function (container) {
    console.log('CONTAINER', container)
    var meshes = container.meshes
    var materials = container.materials
    
    // manually position the object somewhere that i can see it when the game starts up
    let whatever = meshes[0]
    whatever.position.y = 21
    whatever.position.z = 4

    container.addAllToScene() // can i just get rid of this somehow?
    // would prefer something like scene.add(new BlockyEntity()), executed later
})

When inspecting the loaded `container` object, none of the animations arrays are populated. There does appear to be a `container.skeletons[0]._ranges` that has properties that match the names of my animations  (crazy, walk, walkdss, etc). I'm not sure how to play them.

Here is the character (appears to be hovering on the last frame of one of one of the animations? or maybe this is just the pose it is in in blender not sure)

image.png.03dbddb34e6b512cb704aa159f89f5a0.png

Thanks :D

Share this post


Link to post
Share on other sites
1 hour ago, timetocode said:

There does appear to be a `container.skeletons[0]._ranges` that has properties that match the names of my animations  (crazy, walk, walkdss, etc). I'm not sure how to play them.

Have you tried this?

scene.beginAnimation(container.skeletons[0], 0, 100, true, 0.8);

There's a bunch of info on this page, too: https://doc.babylonjs.com/how_to/how_to_use_bones_and_skeletons

Share this post


Link to post
Share on other sites

Looks like it has something to do with applying transforms. I went into object mode and hit Ctrl + A and then "applied" transforms for location, rotation, and scale. I have no idea what that does... or rather I know that it sets the xyz, scale and rotation to 0, but I don't know what the implication is.

The end result for me is pretty much scrambled (like even the original is a mess now). HOWEVER, i think they now look the same between blender and babylon.js. So I think this is part of the equation of how to get these things working. Presumably there was a way to do this that didn't scramble the model.

The mesh+rig I was testing is a freely available "Minecraft Simple Rig" that comes from https://sites.google.com/view/boxscape-studios .

Perhaps someone could shine some light on how to make a rig+model from scratch that plays nicely with bablyon, or how to convert an existing mesh+rig+animation. (Maybe I just applied one transform too many..)

I'm going to be making these things from scratch anyways, so even if the answer is a lot of work, I'd like to know. :D

 

2018-08-20_23-02-42.gif.fa59b820eecb0c573e97253dc8f9f1b0.gif

2018-08-20_23-04-11.gif.3dc0dab0339f1961452e346cb2a726be.gif

Share this post


Link to post
Share on other sites

First, none of your attachments equals an export log file.

2nd, the exporter does nothing with NLA tracks.  It only exports actions.  You have the choice of exporting either the currently assigned action of every object that has one assigned, or all actions to every object which has a currently assigned action.  Things get a little messy when doing the later with multiple objects with an action.  In that case, if a certain action only applies to one of the objects, then use the name pattern 'object name-action' to isolate that action in the export to only one object.

3rd, babylonJS only supports one animation (though it can be against multiple properties).  When actions are exported, they are all contained in that one babylonJS animation.  There are some frame gaps between them for sanity purposes, but when exporting more than one action, you cannot just run all the frames of the scene or even the object.  You, however,  also do not need to know the range of frames where everything gets put.  You can start each BABYLON.AnimationRange by name, which is also the action name.

skeleton = scene.getSkeletonByName("bonesCharacter");
skeleton.beginAnimation("Walk");

You could also have other problems, but making these adjustments & checking what is actually happening in the log file is start.

Share this post


Link to post
Share on other sites

Thanks, that fixed everything!

It looks like the mesh and rig itself had been made in a way where a scale transform on the bones had not been applied, and applying it scrambled the whole thing. So I've now made a few custom meshes (essentially just chains of bones and cubes) with transforms applied, and I can certainly play the test animations by name.

I have a follow-up question regarding rotations that preserve volume, but I'll make a new topic for that.

 

Edit: new thread  

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.