Loading a model

In a game, we need an actual model exported from Blender or any other 3D animation software.

Note

The assets for our example are provided with the code bundle of this chapter.

Copy these three files to the assets folder of the android project:

  • car.g3dj: This is the model file to be used in our example
  • tiretext.jpg and yellowtaxi.jpg: These are the materials for the model

Replacing the ModelBuilder class in our ModelTest.java file, we add the following code:

          assets = new AssetManager();
          assets.load("car.g3dj", Model.class);
          assets.finishLoading();
          model = assets.get("car.g3dj", Model.class);
          instance = new ModelInstance(model);

Additionally, a camera input controller is also added to inspect the model from various angles as follows:

 camController ...

Get Learning LibGDX Game Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.