有没有办法将 3D 模型导入 Android?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/204363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:05:40  来源:igfitidea点击:

Is there a way to import a 3D model into Android?

android3dopengl-es

提问by Maciej Gryka

Is it possible to create a simple 3D model (for example in 3DS MAX) and then import it to Android?

是否可以创建一个简单的 3D 模型(例如在 3DS MAX 中)然后将其导入 Android?

采纳答案by Maciej Gryka

That's where I got to:

那就是我要去的地方:

  • I've used Google's APIDemos as a starting point - there are rotating cubes in there, each specified by two arrays: vertices and indices.
  • I've build my model using Blender and exported it as OFF file - it's a text file that lists all the vertices and then faces in terms of these vertices (indexed geometry)
  • Then I've created a simple C++ app that takes that OFF and writes it as two XMLs containing arrays (one for vertices and one for indices)
  • These XML files are then copied to res/values and this way I can assign the data they contain to arrays like this:
    int vertices[] = context.getResources().getIntArray(R.array.vertices);
  • I also need to manually change the number of faces to be drawn in here: gl.glDrawElements(GL10.GL_TRIANGLES, 212*6, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);- you can find that number (212 in this case) on top of the OFF file
  • 我使用 Google 的 APIDemos 作为起点 - 那里有旋转立方体,每个立方体由两个数组指定:顶点和索引。
  • 我已经使用 Blender 构建了我的模型并将其导出为 OFF 文件 - 它是一个文本文件,列出所有顶点,然后根据这些顶点(索引几何)
  • 然后我创建了一个简单的 C++ 应用程序,将它关闭并将其写为两个包含数组的 XML(一个用于顶点,一个用于索引)
  • 然后将这些 XML 文件复制到 res/values,这样我就可以将它们包含的数据分配给这样的数组:
    int vertices[] = context.getResources().getIntArray(R.array.vertices);
  • 我还需要在这里手动更改要绘制的面数:gl.glDrawElements(GL10.GL_TRIANGLES, 212*6, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);- 您可以在 OFF 文件顶部找到该数字(在本例中为 212)

Here you can find my project page, which uses this solution: Github project > vsiogap3d

在这里你可以找到我的项目页面,它使用了这个解决方案:Github project > vsiogap3d

回答by Maciej Gryka

you may export it to ASE format. from ASE, you can convert it to your code manually or programatically. You will need vertex for vertices array and faces for indices in Android. don't forget you have to set

您可以将其导出为 ASE 格式。从 ASE,您可以手动或以编程方式将其转换为您的代码。您将需要顶点数组的顶点和 Android 索引的面。不要忘记你必须设置

gl.glFrontFace(GL10.GL_CCW);

because 3ds max default is counter clockwise.

因为 3ds max 默认是逆时针。

回答by workmad3

It should be possible. You can have the file as a data file with your program (and as such it will be pushed onto the emulator and packaged for installation onto an actual device). Then you can write a model loader and viewer in java using the Android and GLES libraries to display the model.

应该是可以的。您可以将文件作为程序的数据文件(因此它将被推送到模拟器并打包以安装到实际设备上)。然后,您可以使用 Android 和 GLES 库在 Java 中编写模型加载器和查看器来显示模型。

Specific resources on this are probably limited though. 3ds is a proprietry format so 3rd party loaders are in shortish supply and mostly reverse engineered. Other formats (such as blender or milkshape) are more open and you should be able to find details on writing a loader for them in java fairly easily.

不过,这方面的具体资源可能有限。3ds 是一种专有格式,因此第 3 方加载程序供不应求,而且大多是逆向工程。其他格式(例如 Blender 或 Milkshape)更加开放,您应该能够很容易地找到有关在 Java 中为它们编写加载程序的详细信息。

回答by mrYogi

Have you tried min3d for android? It supports 3ds max,obj and md2 models.

你有没有试过 min3d for android?它支持 3ds max、obj 和 md2 模型。

回答by Ievgen Naida

You can do this also with 3D Object Converter

您也可以使用3D Object Converter执行此操作

http://web.t-online.hu/karpo/

http://web.t-online.hu/karpo/

This tool can convert 3ds object to text\xml format or c code.

该工具可以将 3ds 对象转换为 text\xml 格式或 c 代码。

Example of open gl 'c' output:

打开 gl 'c' 输出示例:

glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);

GLfloat Material_1[] = { 0.498039f, 0.498039f, 0.498039f, 1.000000f };

glBegin(GL_TRIANGLES);

  glMaterialfv(GL_FRONT,GL_DIFFUSE,Material_1
  glNormal3d(0.452267,0.000000,0.891883);
  glVertex3d(5.108326,1.737655,2.650969);
  glVertex3d(9.124107,-0.002484,0.614596);
  glVertex3d(9.124107,4.039649,0.614596);

glEnd();

or 'c' output

或 'c' 输出

Point3 Object1_vertex[] = {
       {5.108326,1.737655,2.650969},
       {9.124107,-0.002484,0.614596},
       {9.124107,4.039649,0.614596}};
long Object1_face[] = {
       3,0,1,2,
       3,3,4,5
       3,6,3,5};

Then you can just replace parts of this code by java code.

然后你可以用java代码替换部分代码。

P.s. This tool is not free and you can use it only for 30-day trial period. But 'c' code and xml converters is avaliable for this period.

Ps 这个工具不是免费的,你只能在 30 天的试用期内使用它。但是在此期间可以使用“c”代码和 xml 转换器。

回答by Guvante

Not sure about Android specifically, but generally speaking you need a script in 3DS Max that manually writes out the formatting you need from the model.

不确定 Android 的具体情况,但一般来说,您需要在 3DS Max 中编写一个脚本,该脚本可以手动从模型中写出您需要的格式。

As to whether one exists for Android or not, I do not know.

至于Android是否存在,我不知道。