1

In my libGDX project i'd like to create a 3D background image as it can be found in ChessGDX (see. e.g. https://www.youtube.com/watch?feature=player_embedded&v=u0ezavUIsTU starting from second 31)

My example

public class Test implements ApplicationListener {
    ...
    @Override
    public void create() {
      ...
      Model cubeModel = modelBuilder.createBox(5f, 5f, 5f, 
           new Material(ColorAttribute.createDiffuse(Color.GREEN)),
           Usage.Position | Usage.Normal);
      cube = new ModelInstance(cubeModel);

      ...
      assetManager.load("background.g3db", Model.class);
      assetManager.finishLoading();
      Model backgroundModel = assetManager.get("background.g3db", Model.class);
      for (Material material : model.materials){
        material.remove(ColorAttribute.Emissive); 
      }
      background = new ModelInstance(backgroundModel);
    }

    @Override
    public void render() {
      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);
      if (background != null) {
        modelBatch.render(background);
      }
        
      modelBatch.render(cube);
      modelBatch.end();
    }

works fine if i use "background.g3db" from the ChessGDX project (from https://github.com/nkarasch/ChessGDX/tree/master/core/assets/3D/models).

Now i want to create a own background based on some image. I tried:

  1. Downloading precompiled binaries from https://github.com/libgdx/fbx-conv
  2. Create a g3db from a blender model
    export LD_LIBRARY_PATH=.
    ./fbx-conv -o G3DB test1.fbx test1.g3db

But using my "test1.g3db" shows only a black background. I'm pretty sure my blender model is wrong since i never used blender before...

My questions:

  1. Is there a tutorial to do exactly what i want? I know there are many good blender tutorials but i don't want to learn blender right now (sorry, maybe in the future)... (i have seen some tutorials creating a model, not a background as needed)
  2. Is it possible to create a own 3D background based on some image without using blender and fbx-conv?
  3. Is there some "predefined" blender-File which i could edit/change in a text-editor (e.g. replace some jpg/png) which i could use with fbx-conv?
someuser
  • 21
  • 1
  • 2
  • You could try this library that lets you use gltf format directly, which you can export from Blender. That saves the step of using a converter (fbx-converter). Although I suspect your issue is that the material in blender doesn't have a name that matches your texture file, so this problem would probably carry over to using a different format. https://github.com/mgsx-dev/gdx-gltf – Tenfour04 Aug 17 '20 at 14:47
  • If you use fbx-conv to create a g3dj instead of g3db, you can go in afterwards and edit it with a text editor and fix the material if it's name is wrong. – Tenfour04 Aug 17 '20 at 14:48
  • I tried the examples of gdx-gltf and EnvironmentUtil.createCubemap was exactly what i was searching for (even without blender). Do you know if it is possible to rotate the cubemap (something like cubemap.transform.rotate(Vector3.Y, 0.1f); in render-method)? Thank you very much for your help! – someuser Aug 18 '20 at 09:16
  • You can rotate the cubemap using the shader. Usually some `varying vec3` representing the look direction is passed from the vertex shader to the fragment shader, and this vector is used with the `textureCube` function to sample the cubemap. So you can rotate the look vector in the vertex shader before passing it. Are you using some built-in shader to render it? Maybe it exposes a parameter you can manipulate in your Java code so you won't have to modify the shader itself. – Tenfour04 Aug 18 '20 at 13:25
  • I have no knowledge about using specific shaders (new to libGDX) so i will have to look a bit deeper at this. Thank you again! At github i made a simple project which shows my example (if anyone wants to have a look [link](https://github.com/oliverbauer/examples)) – someuser Aug 18 '20 at 13:52

0 Answers0