Struggling with importing animations from Blender into BJS

Hi all,

I’m sure you’re all sick of this sort of query but I’m afraid I’m going to have to contribute yet another one. I’m just plain struggling to get any sort of skeleton or animation attached to my Blender exports working correctly, and it seems that no skeletons or animations are being pulled in at all.

Here’s my code:

    BABYLON.SceneLoader.ImportMesh("testo", "models/characters/", "cubeAnim.babylon", scene, function (Armature, particle2, Armature) {      
       // scene.beginAnimation(skele[0], 0, 25, true, 1.0);

       //cube[0].scaling.y = 50;

        console.log("mesh: "+cube);
        console.log("particle: "+particle2);
        console.log("skeleton: "+Armature);
    });

And here’s the setup in Blender:

In case it helps, here’s the log file after exporting:

Exporter version: 6.1.2, Blender version: 2.80 (sub 75)
========= Conversion from Blender to Babylon.js =========
	Scene settings used :
		inline textures     :  false
		Material Type       :  PBR
		Positions Precision :  4
		Normals Precision   :  3
		UVs Precision       :  3
		Vert Color Precision:  3
		Mat Weight Precision:  2
		texture directory   :  (redacted for now due to client information)
	Python World class constructor completed
	WARNING: No active camera has been assigned, or is not in a currently selected Blender layer
	processing begun of skeleton:  Armature, id:  0
		processing begun of bone:  Bone, index:  0
		processing action ArmatureAction:  in[0 - 25], out[0 - 25]
	processing begun of mesh:  testo
		processing begun of material:  Material
		num positions      :  30
		num normals        :  30
		num tangents       :  0
		num uvs            :  60
		num uvs2           :  0
		num colors         :  0
		num indices        :  36
========= Writing of JSON file started =========
========= Writing of JSON file completed =========
========= end of processing =========
elapsed time:  0 min, 0.024 secs

Now here’s how it’s looking in Babylon:

As you can see, the mesh doesn’t even register as having a skeleton. I’ve used the same code to bring in the “Dude” (aka “him” in the console) that’s seen in various BJS examples and as you can see he’s running perectly (also please excuse me from having to exclude some client information in the screenshot).

This is happening with whatever models I export from Blender 2.80. I’ve ensured that the cube is parented by the armature, and there are certainly no un-applied transformations within the scene. I’m still unsure if naming the armature or the cube itself has any bearing on things (it’s been tricky to surmise just from the documentation). I’ve been looking at this all day but if anyone can help ease my looking around it would be greatly appreciated. Thank you very much!

Adding our own Blender Master : @JCPalmer

Welcome to the forum !!!

First, just pushed version 6.2.0. It has a fix for meshes with armatures. No effect here, but could create a .babylon file with nan values or possibly an ACCESS EXCEPTION that crashes Blender.

From the log file, my preferred attachment, there is an armature, named ‘Armature’, with one bone, and one action, named ‘ArmatureAction’. What I do not see is a section right after that like:

Skeleton stats:  
    Total Influencers:  13694
    Avg # of influencers per vertex:  3.156
    Highest # of influencers observed:  6, num vertices with this:  59
    exported as 6 influencers
    num skeletonWeights and skeletonIndices:  34712

If you go to the Modifiers properties tab (the wrench icon) with the mesh selected, you are probably going to see no armature modifier on the mesh. Add it.

The downstream problem you are going to have in your code if you have more than one action, e.g. ‘run, walk, sit’, is you need to tell which action you want to execute this way.

skele[0].beginAnimation("sit", false); //  true, when you wish to loop

You might also check Only currently Assigned Actions from World properties, if the scene has multiple actions, but you do not care about the others.

One last note, is armature animation cannot be run in the sandbox. You can do this with glTF exports, but do not think you get named, distinct animations. Even if you did, not sure sandbox would let you tell which one. Sandbox is not a deployable environment for 99% of people anyway.

2 Likes

Hi, thanks very much for your input as well as updating the BJS exporter.

I’ve installed the latest version of the BJS exporter and selected Only currently Assigned Actions. I’ve also attached the armature modifier to the cube as you recomended:

babylon1

Unfortunately the log is looking rather the same:

Exporter version: 6.2.0, Blender version: 2.80 (sub 75)
========= Conversion from Blender to Babylon.js =========
	Scene settings used :
		inline textures     :  false
		Material Type       :  PBR
		Positions Precision :  4
		Normals Precision   :  3
		UVs Precision       :  3
		Vert Color Precision:  3
		Mat Weight Precision:  2
		texture directory   :  (redacted due to client information)
	Python World class constructor completed
	WARNING: No active camera has been assigned, or is not in a currently selected Blender layer
	processing begun of skeleton:  Armature, id:  0
		processing begun of bone:  Bone, index:  0
		processing action ArmatureAction:  in[0 - 25], out[0 - 25]
	processing begun of mesh:  testo
		processing begun of material:  Material
		num positions      :  30
		num normals        :  30
		num tangents       :  0
		num uvs            :  60
		num uvs2           :  0
		num colors         :  0
		num indices        :  36
========= Writing of JSON file started =========
	writing mesh:  testo
========= Writing of JSON file completed =========
========= end of processing =========
elapsed time:  0 min, 0.035 secs

And the behviour when imported back into BJS is basically the same as in my initial post.

This is occuring if I either do not specify a name for the mesh in Sceneloader.ImportMesh (i.e. leave it blank) or specify the name of the armature or cube.

A couple of observations:

babylon2

These XML errors seem to be occring for everything that I bring in. I don’t know if they have any bearing on the ability to bring in animations. However, this is also happening for the Dude.

babylon3

The Dude (represented as “him”) appears to have been brought in a different way to the cube (represented as “testo”). I’m not sure what the symbol means or what to really make of this but you can see the sub-meshes are parented to “him”. This isn’t the case with the cube.

I’ve attached the .blend file for the cube if anyone wants to take a look to see what it is missing.

cubeAnim.zip (106.5 KB)

Just to clarify, would I change “sit” for the name of the animation in Blender? Going off the screenshot of the Blender file above, I would just use “Animation”?

hey, i exported your .blend as a .glb from Blender and it seems to be behaving as expected (in https://sandbox.babylonjs.com). One thing i notice is that you repeat a param name (Armature, particle2, Armature) in your import code. That can’t be right…but maybe unrelated.

Glb.zip (1.2 KB)

1 Like

Hi there, sorry about that, I already fixed that bit of code. However, you have just informed me about .glb/.gltf. Exporting as this seems to be doing the job! I’m going to have to tinker with it a little more just to check everything is working on the models that aren’t just for the tests.

Thanks very much! I think this constitutes a solution even though the issue with exporting as .babylon doesn’t seem to have been resolved. It might have to be on the mods if they think the thread can be marked as solved or not (if it isn’t I’ll have a look).

edit: Solution button right there. D’oh!

1 Like

I assumed you would re-add the armature as the parent to the mesh, & select automatic weights, via right-click.
Edit: select the mesh first, then shift click the armature second, then right click.

You could also just manually weight paint that bone, but this is only practical for every low bone counts. Manual weight painting is best for just cleanup from automatic weighting.

weight_paint
Either got me an assigned armature with weights.

Also, yes the name of the action goes in the first arg of beginAnimation.

2 Likes

Thanks very much, this is the true solution. Now the cube is animating perfectly. On closer examination, the .babylon animation was true to the original animation within Blender, while the .gltf animation was somewhat off, so it’s great I’ve been able to finally sort this.

1 Like