3

So basically I'm trying to display a .obj 3D Model with an OrthographicCamera in 2D rather than in 3D with a PerspectiveCamera.

Everything works fine when I render with the PerspectiveCamera, however if I switch it to Orthographic, nothing displays, just the blank background.

Below is the code I'm using with the PerspectiveCamera stuff commented out. I'm not sure if there is a different way that I need to setup the OrthographicCamera, or if I need to use a PerspectiveCamera with some modified to views to achieve this. At this point it really doesn't matter which axis I "eliminate".

Essentially what I want to achieve is being able to use Blender for my 2D animation. I've figured this out on the Blender side and it works very well, however they must be imported as .obj(or .fbx) into LibGDX, these are loaded into LibGDX as Models, and as such must be rendered with a ModelBatch using a ModelInstance and an Environment. I need a way to view this object using a 2D Orthographic projection rather than a 3D Perspective projection.

Anyone got any suggestions for this?

public class Test extends ApplicationAdapter {

//public PerspectiveCamera cam;
public OrthographicCamera cam;
public CameraInputController camController;

public ModelBatch modelBatch;

public ModelInstance ship;

public Environment environment;

@Override
public void create() {
    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.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

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

    cam = new OrthographicCamera();
    cam.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.update();

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

    ObjLoader loader = new ObjLoader();
    Model model = loader.loadModel(Gdx.files.internal("data/invader.obj"));
    ship = new ModelInstance(model);
}

@Override
public void render() {
    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(ship, environment);
    modelBatch.end();
}

@Override
public void dispose() {
    modelBatch.dispose();
}
}
Darren
  • 1,774
  • 4
  • 21
  • 32
  • Have you tried using a smaller viewport size? I don't know about the units you've used for your model, but you might try `cam.setToOrtho(16, 9)`. Otherwise you probably need to zoom in a lot. Maybe you should also translate your camera a bit, because like this both the camera and the model should be located at (0,0,0). – noone Aug 22 '14 at 05:46
  • @Darren I face same issue. have you solve the problem? – LunaVulpo Jun 21 '16 at 08:02
  • @LunaVulpo I'm sorry but no I never did end up solving my issue. In the end I decided to use [Spine](http://esotericsoftware.com/) for my animations and they have a very full featured library for LibGDX(the developer of Spine is also a developer of LibGDX). – Darren Jun 28 '16 at 04:00
  • I've had something similar to this happen to me -- I think the ortho camera was either inside of, or in front of, the model. So fiddling with the Z position of your model might help. – Max Sep 12 '16 at 02:05
  • guys. any idea for this issue? i face same problem :( – axunic Feb 04 '19 at 06:29

0 Answers0