isuckatprogramming
isuckatprogramming

Reputation: 13

How to load 3d models from blender into latest version of LibGDX?

I'm trying to upload my 3d gun model from blender into Libgdx's latest version and I am unable to see my model. This project is due in two weeks and I really need some help here.

public static Entity loadGun(float x, float y, float z) {    
    ModelLoader<?> modelLoader = new G3dModelLoader(new JsonReader());    
    ModelData modelData = modelLoader.loadModelData(Gdx.files.internal("data/GUNMODEL.g3dj"));
    Model model = new Model(modelData, new TextureProvider.FileTextureProvider());
    ModelComponent modelComponent = new ModelComponent(model, x, y, z);
    modelComponent.instance.transform.rotate(0, 1, 0, 180);
    Entity gunEntity = new Entity();
    gunEntity.add(modelComponent);
    gunEntity.add(new GunComponent());
    gunEntity.add(new AnimationComponent(modelComponent.instance));
    return gunEntity;
}

Upvotes: 1

Views: 1097

Answers (1)

Keval
Keval

Reputation: 1612

This can be a fiddly thing to accomplish, below are the things I've come up against before:

  1. Ensure you are setting the fbx export scale to 0.01 in blender. This is because libgdx imports objects in centimetres.

  2. Make sure you flip the y axis when using fbx-conv. (add the -f option).

  3. Loading using the LibGDX AssetManager is usually preferred to manually using readers e.g.

AssetManger am = new AssetManager();
am.load("data/GUNMODEL.g3dj", Model.class);
am.finishLoading();
Model model = am.get("data/GUNMODEL.g3dj");

N.B. regarding your code, the ModelLoader should be disposed of at the end of the program.

Upvotes: 1

Related Questions