4
votes

I've been trying to display a model on my screen (a simple UVSphere from Blender). I first exported it to .fbx format and then transformed to .g3db format with gdx-conv-win32.exe. I have this code so far, but all it shows me is a blank black screen... it only works with the model found in this tutorial (an .obj model) https://xoppa.github.io/blog/loading-models-using-libgdx/

package com.mygdx.game.screens;

/.../ imports

public class GameScreen extends MenuScreens {

public Environment environment;
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;

AssetManager manager = new AssetManager();
public boolean loading;
public Array<ModelInstance> instances;

public GameScreen(ProjectSurvival game){
    super();
    this.game = game;

    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 20f, 20f, 20f));
    environment.add(new PointLight().set(1, 1, 1, 20, 20, 20, 500));
    instances = new Array<ModelInstance>();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(1f, 1f, 1f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    manager = new AssetManager();
    manager.load("ship.g3db", Model.class);
    loading = true;
}

private void doneLoading() {
    Model test = manager.get("ship.g3db", Model.class);
    ModelInstance shipInstance = new ModelInstance(test);
    instances.add(shipInstance);
    loading = false;
}

@Override
public void show() {
}

@Override
public void render(float delta) {
    //super.render(delta);

    if (loading && manager.update()) {
        doneLoading();
        System.out.println("loaded");
    }
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}
@Override
public void resize(int width, int height) {
    super.resize(width, height);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
    super.dispose();
    modelBatch.dispose();
    model.dispose();
    instances.clear();
    manager.dispose();
}

}

There are several other similar topics, but none of them solves my problem... please I need help!

EDIT:

Here's my g3dj file ( I cut some parts of it cause it's extremely long):

{
"version": [  0,   1], 
"id": "", 
"meshes": [
    {
        "attributes": ["POSITION", "NORMAL", "TEXCOORD0"], 
        "vertices": [
            -0.724124,  0.035572, -0.598984, -0.742302, -0.159337, -0.650807,  0.028780,  0.420519, 
            -0.691568,  0.068115, -0.634070, -0.791498, -0.084201, -0.605335,  0.021021,  0.407816, 
            -0.694079,  0.034096, -0.634070, -0.878414,  0.254219, -0.404614,  0.026918,  0.405321, 
            // deleted (...)
            -0.846887, -0.041603, -0.403719, -0.887509, -0.132389, -0.441267,  0.051316,  0.489956, 
            -0.826199, -0.040587, -0.445113, -0.867977, -0.072359, -0.491256,  0.049283,  0.474874, 
            -0.803523, -0.039472, -0.485435, -0.859127, -0.022919, -0.511185,  0.047232,  0.459797
        ], 
        "parts": [
            {
                "id": "Mesh_part1", 
                "type": "TRIANGLES", 
                "indices": [
                      0,   1,   2,   1,   0,   3,   4,   2,   5,   2,   4,   0, 
                      2,   6,   7,   6,   2,   1,   5,   7,   8,   7,   5,   2, 
                      0,   9,   3,   3,   9,  10,   9,  11,  10,  11,   9,  12, 
                      9,   4,  13,   4,   9,   0,  12,  13,  14,  13,  12,   9, 
                     // deleted (...)
                     3610,  3613,  3614,  137,  3614,  3613,  3614,  137,  133,  3606,  3612,  3596, 
                     3612,  3606,  3613,  112,  3613,  3606,  3613,  112,  137,  3614,  3608,  3610, 
                     3608,  3614,  3615,  3615,  3539,  3608,  3539,  3615,  3543,  133,  3615,  3614, 
                     3615,  133,  134,  134,  3543,  3615,  3543,  134,  14
                ]
            }
        ]
    }
], 
"materials": [
    {
        "id": "Material.001", 
        "ambient": [ 0.200000,  0.200000,  0.200000], 
        "diffuse": [ 0.800000,  0.800000,  0.800000], 
        "emissive": [ 0.000000,  0.000000,  0.000000], 
        "opacity":  0.000000, 
        "specular": [ 0.200000,  0.200000,  0.200000], 
        "shininess":  20.000000
    }
], 
"nodes": [
    {
        "id": "Sphere", 
        "rotation": [-0.707107,  0.000000,  0.000000,  0.707107], 
        "scale": [ 100.000000,  100.000000,  100.000000], 
        "translation": [ 0.000000,  101.334976,  0.000000], 
        "parts": [
            {
                "meshpartid": "Mesh_part1", 
                "materialid": "Material.001", 
                "uvMapping": [[]]
            }
        ]
    }
], 
"animations": []

}

2
I searched on the internet a g3db file and placed it in the assets instead of mine, and it loads normally... I followed step by step a tutorial to transform a model from blender to fbx to g3db using a command line but it doesn't seem to work for me... does any one have an idea what I'm doing wrong?Vellyxenya
I mean it works fine for transforming the file, but I can't load these file I createVellyxenya
could you provide the g3db file and the g3dj (json version that you can generate using some options with gdx-conv) as well to see what is wrong ?mgsx-dev
@mgsx-dev I added the g3dj file to my post.Vellyxenya
Your opacity is zero (fully transparent), set it correctly in your modeling application. See also: github.com/libgdx/libgdx/wiki/…Xoppa

2 Answers

0
votes

Since there is no accepted answer:

As described by @Xoppa In you file the opacity is set to zero, set it to 1.0000 in the gd3j file

"opacity":  0.000000

// TODO 1: find what is the property of the material in blender

// TODO 2: add to troubleshooting guide

0
votes

Had the same problem but with converting LWO (Light Wave) objects to g3db / g3dj. Problem was that when LightWave is exporting to FBX format it doesn't add info about textures (I'm not actually sure if FBX format supports textures at all?). Then I switched exporting to .OBJ but again I had the problem that textures in png format are not supported. Only after using .jpg textures it started working. After that opacity was set correctly to 1. With textures it can't handle converter is setting opacity to 0.