Reputation: 13
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
Reputation: 1612
This can be a fiddly thing to accomplish, below are the things I've come up against before:
Ensure you are setting the fbx export scale to 0.01
in blender. This is because libgdx imports objects in centimetres.
Make sure you flip the y axis when using fbx-conv. (add the -f
option).
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