LibGDX import .obj and .g3db not showing textures

I have been spending hours trying to figure this out, but no tutorials that I’ve found have explained why this might be happening. I just started 3D modeling in Blender, and I’m finally starting to understand how to created models. I even managed to map a texture to my model in the program. The problem is importing the model into LibGDX. Whenever I do, the texture just doesn’t load. Here’s a picture of what happens when I try to load my models:

http://s30.postimg.org/3ngboq3j5/mylivinghell.png

Of course, a face texture should show up when there is a big rectangular blob. This is what the model looks like in Blender:

http://s12.postimg.org/3q8u8hspo/whycan_titlooklikethis.jpg

Here is a copy of my blender file, and a couple of exported versions if anyone is interested in sifting through my files:

Last, but not least, here is a copy of my rendering code:

package display;
import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.math.Matrix4;

import util.ResourceManager;

/**
 * Main screen used by project
 * @author William Andrew Cahill
 *
 */
public class DisplayScreen implements Screen
{
	// 3D environment variables
	private DisplayGame game;					// Reference to game
	private Environment environment;			// Environment of models
	private ModelBatch mBatch;					// Batch used for rendering models
	private PerspectiveCamera cam;				// Camera used
	private CameraInputController controller;	// Camera controller
	private AssetManager manager;				// Asset manager
	
	// Etc
	private List<Model> models;					// List of models loaded
	private List<ModelInstance>	instances;		// List of model instances loaded

	// Loading flag
	private boolean loading;
	
	/**
	 * Constructs a DisplayScreen
	 * @param game Game creating this Screen
	 */
	public DisplayScreen(DisplayGame game)
	{
		// Keeps reference of game
		this.game = game;
		
		// Constructs fields
        mBatch = new ModelBatch();
		environment = new Environment();
		environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, .5f));
        environment.add(new DirectionalLight().set(0.4f, 0.4f, 0.4f, -1f, -0.8f, -0.2f));
       
        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        cam.position.set(0f, 5f, 10f);
        //cam.lookAt(0,0,0);
        cam.near = 1f;
        cam.far = 300f;
        cam.update();
        
        controller = new CameraInputController(cam);
        Gdx.input.setInputProcessor(controller);
        
        // Loads main model
        manager = new AssetManager();
        manager.load("models/wigglesModel.g3db", Model.class);
        loading = true;
        
        // Constructs empty lists of models and their instances
        models = new ArrayList<Model>();
        instances = new ArrayList<ModelInstance>();
	}
	
	
	/**
	 * Finishes loading
	 */
	private void doneLoading()
	{
        // Loads models
        models.add(manager.get("models/wigglesModel.g3db", Model.class));
        
        // Particular instance
        ModelInstance instance;
        
        // Adds instances
        instance = new ModelInstance(models.get(0));
        instances.add(instance);
        instance = new ModelInstance(models.get(0));
        instance.transform.translate(5, 0, 0);
        instances.add(instance);
        loading = false;
	}
	
	@Override
	public void render(float delta)
	{
		// Brings in data to render whenever ready
		if(loading && manager.update())
			doneLoading();
		// Updates controller
		controller.update();
		
		// Camera clear data
		Gdx.gl.glViewport(0,  0,  Gdx.graphics.getWidth(),  Gdx.graphics.getHeight());
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
		
		// Begins rendering
		mBatch.begin(cam);
		mBatch.render(instances, environment);
		for(int i=0; i<instances.size(); i++)
			instances.get(i).transform.rotate(0, 1, 0, 1);
		mBatch.end();
	}

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

	
	@Override
	public void show()
	{
		
	}

	
	@Override
	public void hide()
	{
		
	}

	
	@Override
	public void pause()
	{
		
	}

	
	@Override
	public void resume()
	{
		
	}

	
	@Override
	public void dispose()
	{
		mBatch.dispose();
        instances.clear();
        manager.dispose();
	}
}

Halp?

I finally got it to work! It may have been because my UV mapping went outside the borders of the texture I was using. I still have one problem, though. The texture is applied upside down! How can I fix this?

Try multiplying all your UV normalized coordinates by -1

Ah, ok, so it’s something to do with how it’s created in Blender. Please excuse my ignorance, for I am new to Blender and LibGDX, but where can I find that in the UV editor? Scratch that, what does multiplying the UV nomalized coordinates mean, exactly? Will it flip the image in Blender? I want what I see in Blender to be what I see when I import it into LibGDX, or at least, roughly the same.

Edit: I want to specify that the model looks fine in Blender, but is flipped in the LibGDX rendering.

I haven’t worked with LibGDX Model’s yet, so I can’t give a definite answer, but inverting the y-component of the UV coords flips the texture on the y-axis.
This is, however, done by modifying y with [icode]y = 1 - y[/icode], not by multiplying with -1 :slight_smile:

It could also be, because libgdx loads the texture upside down, maybe there is an option when loading textures :slight_smile:

I figured it out. After exporting from blender, I have to convert the .fbx file to a .g3db file using fbx-con. I forgot to include the command line argument -f when converting. I SHOULD have typed…

fbx-conv -f wigglesModel.fbx

instead of…

fbx-conv wigglesModel.fbx

good to know actually :smiley: