I am having trouble rendering a model in libGdx.
I have created a simple car model in blender but, when i render it in libGdx, it renders incorrectly.
This is what it looks in blender(how it is supposed to look):
This is how it looks in libGdx:
As you can see, the wheels are all pointing the wrong direction which doesn't make sense as i am not turning them at all.
It works when there is only 1 object in the model but when i add more objects such as the wheels, this happens.
Here is my create() method:
public void create () {
camera=new PerspectiveCamera(67,800,480);
camera.position.set(0f, 0f, 20f);
camera.lookAt(0f, 0f, 0f);
camera.near=1f;
camera.far=100f;
batch=new ModelBatch();
builder=new ModelBuilder();
UBJsonReader jsonreader=new UBJsonReader();
G3dModelLoader modelloader=new G3dModelLoader(jsonreader);
cubemodel=modelloader.loadModel(Gdx.files.getFileHandle("carmodel.g3db", Files.FileType.Internal));
cube=new ModelInstance(cubemodel,0,0,0);
environment=new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight,0.65f,0.65f,0.65f,1f));
}
Here is my render() Method:
public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
camera.update();
batch.begin(camera);
batch.render(cube, environment);
batch.end();
camera.rotateAround(new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), 0.5f);
}
Here is my model: carmodel.g3db
If you need anything else then ask and i will post it.
Thanks in advance!
It's been a while since I used Blender, but these are the settings I used to get the model orientation to match in LibGDX. This sets it up so if you use the same orientation and position for your LibGDX camera as your Blender camera, the scenes will be identical.