且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

加载中Libgdx OBJ文件不工作的机器人

更新时间:2023-11-19 11:04:04

我想你指的是 model.render(GL10.GL_TRIANGLES); 。我相信你有两个问题。首先,模式是空,因为你正在追赶一个FileNotFoundException异常,而忽略它。我建议你​​不要赶FileNotFoundException异常,现在,让它崩溃,并期待在堆栈跟踪。这会给你一个更好的指示为什么这个失败的。需要注意的是e.printStackTrace()是没有用的调试Android上,尝试使用GDX日志。

I assume you are referring to model.render(GL10.GL_TRIANGLES);. I believe you have two problems. First, model is null because you are catching a FileNotFoundException and ignoring it. I suggest you don't catch the FileNotFoundException right now, let it crash, and look at the stack trace. That will give you a better indication of why this failing. Note that e.printStackTrace() is not useful for debugging on android, try using the gdx log.

第二个问题是,我怀疑路径/流实际上是将错误的地方。而不是创建一个FileInputStream,请使用FileHandle.read()函数。它返回一个java.io.InputStream对象,你可以传递给ObjLoader.loadObj()。

The second problem is that I suspect the path/stream is actually going to the wrong place. Instead of creating a FileInputStream, use the FileHandle.read() function. It returns a java.io.InputStream that you can pass to ObjLoader.loadObj().

in = Gdx.files.internal("data/torus.obj").read();
model ObjLoader.loadObj(in);
in.close();

这和你的code之间的不同之处在于FileHandle.read()在libgdx的Andr​​oid后端采用的是Android AssetManager打开捆绑在一起的程序文件。

The difference between this and your code is that FileHandle.read() in libgdx's android backend uses the android AssetManager to open files that are bundled with the program.

最后,复制torus.obj文件到< YourAndroidProject>。/assets/data/torus.obj

Finally, copy the torus.obj file to <YourAndroidProject>/assets/data/torus.obj.

旁白:如果指定的行号,请提供完整的文件,否则该行将熄灭。你所提供的code 52行是: lastTouchY = Gdx.input.getY(); 。请注意导入......在你的code开头。这些进口影响的行号。

An aside: if you specify the line number, please provide the full file otherwise the line will be off. Line 52 of the code you have provided is: lastTouchY = Gdx.input.getY();. Note the "import ..." at the beginning of your code. Those imports affect the line number.