0
votes

Hi Blender & libGDX Gurus,

I am trying to load an blender animation into libGDX for an android app. So I created an animation using Blenders action editor, I exported this into .fbx format. I then ran the fbx-conv tool to create a .G3DB file. I then proceeded to upload this file into libGDX using the modelLoader.

Everything seems to work fine (I am not receiving any error messages) except that the screen is blank. I can't see any animations or the model.

I have run this code in a Samsung galaxy tablet running kitkat, nexus phone running marshmallow and an emulator, but the same result.

I went thru the tutorials and am using some of the code to upload one of my blender models. I still can't figure this out and I need help figuring this out.

Any help will be greatly appreciated.

Here is the link to the Blender file: Animated Low-Poly Horse No Lights and no Camera

Here is my code where I am uploading the model in libGDX. I basically am using the code from the tutorials.

@Override
public void create () {

    // Create camera sized to screens width/height with Field of View of 75 degrees
    camera = new PerspectiveCamera(
            75,
            Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

    // Move the camera 5 units back along the z-axis and look at the origin
    camera.position.set(0f,0f,7f);
    camera.lookAt(0f,0f,0f);

    // Near and Far (plane) represent the minimum and maximum ranges of the camera in, um, units
    camera.near = 0.1f;
    camera.far = 300.0f;
    camera.update();

    // A ModelBatch  to batch up geometry for OpenGL
    modelBatch = new ModelBatch();

    // Model loader needs a binary json reader to decode
    UBJsonReader jsonReader = new UBJsonReader();
    // Create a model loader passing in our json reader
    G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
    // Now load the model by name
    // Note, the model (g3db file ) and textures need to be added to the assets folder of the Android proj
    model = modelLoader.loadModel(Gdx.files.getFileHandle("AnimatedLowPolyHorseStageFenced_Ver5.g3db", Files.FileType.Internal));
    // Now create an instance.  Instance holds the positioning data, etc of an instance of your model
    modelInstance = new ModelInstance(model);

    //fbx-conv is supposed to perform this rotation for you... it doesnt seem to
    modelInstance.transform.rotate(1, 0, 0, -90);
    //move the model down a bit on the screen ( in a z-up world, down is -z ).
    modelInstance.transform.translate(0, 0, -2);

    // Finally we want some light, or we wont see our color.  The environment gets passed in during
    // the rendering process.  Create one, then create an Ambient ( non-positioned, non-directional ) light.
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    // You use an AnimationController to um, control animations.  Each control is tied to the model instance
    controller = new AnimationController(modelInstance);
    // Pick the current animation by name

    controller.setAnimation("Armature|ArmatureAction",1, new AnimationListener(){

        @Override
        public void onEnd(AnimationDesc animation) {
            // this will be called when the current animation is done.
            // queue up another animation called "balloon".
            // Passing a negative to loop count loops forever.  1f for speed is normal speed.
            //controller.queue("Armature|ArmatureAction",-1,1f,null,0f);
        }

        @Override
        public void onLoop(AnimationDesc animation) {
            // TODO Auto-generated method stub

        }

    });

}

@Override
public void resize(int width, int height) {
    super.resize(width, height);
}

@Override
public void render () {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    //Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    // For some flavor, lets spin our camera around the Y axis by 1 degree each time render is called

    // You need to call update on the animation controller so it will advance the animation.  Pass in frame delta
    controller.update(Gdx.graphics.getDeltaTime());
    // Like spriteBatch, just with models!  pass in the box Instance and the environment
    modelBatch.begin(camera);
    modelBatch.render(modelInstance, environment);
    modelBatch.end();
}
1

1 Answers

0
votes

When converting to G3DB with fbxconv you got a warning, "Mesh contains vertices with zero bone weights".

Try the following steps: - Add a a new bone to your blend - Connect it to non-animated (or all) vertices - Re-export & convert

If you still get the warning, repeat but connect the new bone to all vertices.

I know this is an old question, but i had a similar problem recently and this worked.