Importing animations from GLB [SOLVED]

I am moving from importing .blend to .glb but am having trouble importing GLB files with animations and I’m hoping someone can give me a hint of where to look.

I’m exporting models from Blender 2.8 using a script. The relevant line (with GLTF export options):

bpy.ops.export_scene.gltf(filepath=filename, export_materials=False, check_existing=False)

I then read the file with a standard assetsManager.loadModel(modelKey)

When the models do not have animations this works fine. Whenever I add an animation, no matter how simple, I get an AssetLoadException with the error message “Inconsistent animation sampling”

Checking the code throwing the exception, it reads:

public void checkTimesConsistantcy() {
    if ((translations != null && times.length != translations.length)
            || (rotations != null && times.length != rotations.length)
            || (scales != null && times.length != scales.length)) {
        throw new AssetLoadException("Inconsistent animation sampling ");
    }
}

Which implies that the imported data has a mismatch in the animation keyframes. I suspect there is some set of options required in the Blender export operation to make the animations importable. I’ve tried various combinations of the timing and baking arguments but can’t seem to get it to work.

Reading back through the various topics about GLTF import I see a lot of discussion on importing animations and why it is hard. Has anyone had success export GLTF from Blender 2.8 then importing into JME? If so, do you have hints on what you know?

1 Like

yes, im using .gtlf to load models with animations.
you can see: Com.jme3.anim Skinning Help

well, about “Inconsistent animation sampling”

you just need sample animations to Linear in Blender:

in Animation -> dope sheet -> select animation -> all(a) and T -> Linear (there were something else to set Linear, but as i good remember the needed one was T -> Linear)

anyway i use .gtlf not .glb so not sure if it have some differences in animation load.

2 Likes

Thanks - that worked.

I feel it’d be worth having a section on the wiki about exporting GLTF scenes from Blender to JME to capture this information. There are equivalents for various other formats. I’d be happy to write it to make it easier for others - will start collecting findings as I go.

4 Likes

nice, wiki need updates :slight_smile:

here some i know in general:

  • this animation sampling
  • before export animated model need ctrl-a -> apply all transforms so it look proper in JME.
  • old Blender 2.79 or earlier use https://github.com/KhronosGroup/glTF-Blender-Exporter(old blender have issue with exporting materials so need apply the manually)
  • new blender 2.8 (already stable as i seen) it already have plugin in itself, but if require update then https://github.com/KhronosGroup/glTF-Blender-IO
  • Animations that have IK constrains to bones need first to be baked before export (at least even in new Blender it dont worked well with “autosampling exporter option”)
  • if you want use ShapeKeys from .gltf, you first need to have general animations in blender for it, otherwise Exporter do not export it.(so it would be not visible)

Thanks that a great start - you ok reviewing it if put something together?

sure, i can look from my side if it will be fine :slight_smile:

I have created a pull request for the wiki with the added page. I kept it pretty basic at this stage but if you could take a look and let me know if you agree with the content that’d be useful.

Pull request is https://github.com/jMonkeyEngine/wiki/pull/98

3 Likes

Well, look fine for me if its about informations. Good work! :slight_smile: Just some mentions:

“Ultimately all jME projects should use the .j3o format for storing assets. However during development a format is required to export scenes from Blender in a format suitable for conversion (either through the SDK or directly through code).”

  • well, i dont think this sentence is necessary. maybe others will say if it should be here.

  • cant confirm all about .glb because myself i always export to .gltf

At export time, force the export to create interpolated keyframes using sampling. This can be done in Python using export_force_sampling=True or selecting Always Sample Animations in the Animation tab of the export function. By default a sample is created from each frame of the animation. This can be changed in Python using export_frame_step=n where n is number of frames between samples or changing the sampling rate in the Animation tab of the export function.

  • well, if i remember correctly i dont needed use it for “non IK animations” and anyway it didnt work for me well so needed bake animations anyway as i remember. but maybe they fixed it in new versions. Because as i understand this should do something like “Bake on export thing” if im not wrong. On their github there just is “Apply sampling to all animations.” but not sure about what sampling it is.

  • because currently i needed create dupplicated skeleton, bake animations on it, and export it, instead of oryginal skeleton. But if this is doing something else than i think then dont listen me.