Question

How to load a Mesh (3dmax) in Android OpenGL into a ByteBuffer ?

example:

float triangleCoords[] = {
    -0.5f, -0.25f      , 0, // 0,
 0.5f, -0.25f      , 0, // 1,
 0.0f, 0.559016994f, 0  // 2,
};

ByteBuffer vbb = ByteBuffer.allocateDirect(triangleCoords.length * _4_FLOAT_LENGTH);
vbb.order(ByteOrder.nativeOrder());
triangleVB = vbb.asFloatBuffer();
triangleVB.put(triangleCoords);
triangleVB.position(0);

how to load a mesh like an array or Coords or ineed a library for this job

Was it helpful?

Solution

It basically boils down to loading the data from the file into your data structures (like the vertex array from your code snippet) and providing these to OpenGL for rendering (in your case glDrawArrays, for example). This is generally the same procedure, no matter if working with Android, Windows, Plan9, OpenGL or Direct3D. Only the implementation details matter, therefore this question is a bit broad.

You can look at this description of the 3DS file format (hinted in your question), which also has links to tutorials for loading these files. Although the 3DS format is a quite easy to read binary format, for a start you might also look into the Wavefront OBJ format, a simple ASCII file format that nearly every modeling software can export to (but this should also hold for 3DS). Loading these formats into a bunch of simple vertex arrays should boil down to some few lines of code.

These should get you started. If you encounter any specific problems implementing these mesh loading functionalities on your particular platform, feel free to ask a more specific question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top