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

Android3dOpengl Es

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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

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

Solution 2 - Android

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

gl.glFrontFace(GL10.GL_CCW);

because 3ds max default is counter clockwise.

Solution 3 - Android

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.

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.

Solution 4 - Android

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

Solution 5 - Android

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.

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

Solution 6 - Android

You can also convert 3DS MAX model with the 3D Object Converter

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

This tool can convert 3ds object to text\xml format or c code. Please note that the tool is not free. You can try for a 30-day trial period. 'C' code and XML converters are available.

'c' OpenGL output example:

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 direct 'c' output:

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};

You can migrate than those collections of objects to your Java code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaciej GrykaView Question on Stackoverflow
Solution 1 - AndroidMaciej GrykaView Answer on Stackoverflow
Solution 2 - AndroidR0b3rt2View Answer on Stackoverflow
Solution 3 - Androidworkmad3View Answer on Stackoverflow
Solution 4 - AndroidmrYogiView Answer on Stackoverflow
Solution 5 - AndroidGuvanteView Answer on Stackoverflow
Solution 6 - AndroidIevgenView Answer on Stackoverflow