我在使用libgdx加载模型时遇到了问题,无论是哪种格式的模型,纹理都无法正确显示。我不确定是什么原因导致了这个问题。
例如:在3ds max或blender中,它看起来像这样:
但是当我将其放入libgdx项目中时,它看起来像这样:
我的代码基于http://blog.xoppa.com/loading-models-using-libgdx/,我已经尝试过有光源和没有光源的情况,但都没有成功。
代码:
例如:在3ds max或blender中,它看起来像这样:
![](https://istack.dev59.com/fwVsa.webp)
![](https://istack.dev59.com/Owbh8.webp)
代码:
//Loading the model
assetManager = new AssetManager();
assetManager.load("data/models/M4A1 SOPMOD/M4A1 SOPMOD.g3db", Model.class);
//..................................................
//Calling to an object and drawing it
public void create()
modelBatch = new ModelBatch();
box = Assets.assetManager.get("data/models/M4A1 SOPMOD/M4A1 SOPMOD.g3db", Model.class);
//box = Assets.getModelByName("M4");
//box = modelBuilder.createBox(1f, 1f, 1f, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
boxInstance = new ModelInstance(box);
lights = new Lights();
lights.ambientLight.set(1f, 1f, 1f, 1f);
lights.add(new DirectionalLight().set(1f, 1f, 1f, -1f, -0.8f, -0.2f));
}
public void Update(float deltaTime)
{
dotd.camera.rotateAround(Vector3.Zero, new Vector3(0, 1, 0), deltaTime* 50.0f);
dotd.camera.update();
}
public void Render()
{
modelBatch.begin(dotd.camera);
modelBatch.render(boxInstance, lights);
modelBatch.end();
}