Question

I am developing an application on libgdx and I am trying to play an animation I created on Blender but I continue to get the unknown animation error. I have this code in my create method:

model = modelLoader.loadModel(Gdx.files.getFileHandle("i1.g3db", FileType.Internal));
modelInstance = new ModelInstance(model);
modelInstance.transform.rotate(1, 0, 0, -90);
modelInstance.transform.translate(0, 0, -2);
controller = new AnimationController(modelInstance);  
controller.setAnimation("moveHand",1);

And this in my render method:

camera.update();
camController.update();
controller.update(Gdx.graphics.getDeltaTime());
modelBatch.begin(camera);
modelBatch.render(modelInstance, environment);
modelBatch.end();

I tried to cut out the pieces that are not relevant to the question. Here is a pic of the dopesheet in Blender which shows that I have named my animation appropriately:

enter image description here Anyone has an idea what might be the problem cause I've been stuck on this one for quite a while, thank you! I have the animation files (.g3db, .blender) uploaded here if anyone feels like opening them:

https://www.dropbox.com/s/xyx74tx5mbyj9i3/i1.zip

Was it helpful?

Solution

On a general note: avoid using uppercase (and spaces etc.) in animation names. Also check https://github.com/libgdx/libgdx/wiki/3D-animations-and-skinning for more information about animations and https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX for information about using Blender models in LibGDX.

Convert the file to .g3dj using the -o G3DJ command line option of fbx-conv, e.g. fbx-conv -f -o G3DJ i1.fbx (where -f is used to flip texture coordinates). Make sure to update your code to use this G3DJ file instead of the previous G3DB file. Next open the resulting .g3dj file using a text editor (e.g. notepad or the text editor of your ide/eclipse). The file should be easily readable (see http://blog.xoppa.com/behind-the-3d-scenes-part1/ for more info on how to read it) and contain a section (json key) called animations.

If there are no animations in the file, it should looks like "animations": [] at the bottom of the file. In that case make sure to check to export animations in blender. See also: https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX.

If there are animations in the file, they are included inside the array (between the "animations": [ and ]). Note that animations can take up a lot of space, so the actual line "animations": [ might be located somewhere in the middle of the file. In that case make sure that the name (id) of the animation exactly matches the string used to specify the animation.

If the animation is included in the file and the string matches, then enumerate all animations inside the model/modelinstance to ensure they are correctly loaded:

for (Animation anim : modelInstance.animations)
    Gdx.app.log("Animation", anim.id);

If the animation is not included in the ModelInstance replace modelInstance with model in this snippet to make sure it is included in the model. If it also isn't included in the Model, make sure to refresh/clean your workspace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top