我试图加载模型并在我的窗口中显示它大约2个小时,但现在我投降了。我尝试了从https://sketchfab.com下载的10种不同型号,但没有显示,我只是得到一个黑色的窗口。我现在又在网上搜索了20分钟的帮助,但由于我在libgdx方面不是很有经验,所以我无法适应我在程序中找到的“解决方案”。我希望你能帮助我!
我的另一个问题是,如果有任何方法可以使用索引多于short
值的模型。
我使用过的模型:https://sketchfab.com/models/042201dac61041fabb88f483368daa3f
我的代码:
public class Game extends ApplicationAdapter
{
private PerspectiveCamera cam;
private CameraInputController camController;
private ModelBatch modelBatch;
private AssetManager assets;
private Array<ModelInstance> instances = new Array<ModelInstance>();
private Environment environment;
private boolean loading;
@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 PointLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f, 1f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(1f, 1f, 1f);
cam.lookAt(0,0,0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
assets = new AssetManager();
assets.load("basic.g3db", Model.class);
loading = true;
}
private void doneLoading() {
Model ship = assets.get("basic.g3db", Model.class);
ModelInstance shipInstance = new ModelInstance(ship);
instances.add(shipInstance);
loading = false;
}
@Override
public void render () {
if (loading && assets.update())
doneLoading();
camController.update();
Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(instances, environment);
modelBatch.end();
}
@Override
public void dispose () {
modelBatch.dispose();
instances.clear();
assets.dispose();
}
public void resume () {
}
public void resize (int width, int height) {
}
public void pause () {
}
}