I'm creating a game in Android using OpenGL ES 2.0. I have modeled all the required objects in Blender and exported them into an OBJ file. The OBJ file contains vertex data and faces of the objects similar to this:
....
v 0.007322 -0.046194 -0.007322
v 0.005866 -0.046194 0.000000
v -0.000000 -0.042275 0.000000
v -0.000000 -0.040898 -0.010355
....
f 5 1 4
f 1 2 3
f 89 88 105
f 103 104 89
....
This data is quite large for some objects. So my question is, what is the fastest way to load it into my application so that I can use it in a FloatBuffer object?
Upon searching little, I have found the following ways:
- Copy the OBJ file into the application's resources folder, parse it every time during runtime and load it into the FloatBuffer object.
- Parse the vertex data from the OBJ file and persistently store it in another file using ObjectOutputStream or any other method. Then copy this newly generated file into the resources folder to load it during runtime.
- Copy the vertex Data from the OBJ file directly into the application code
Example
public class ObjectData {
public float[] vertices = new float[] {
0.007322f, -0.046194f, -0.007322f, ..... // Can be more than 1000 elements!
}
}
But this method creates another problem, the code sometimes exceeds the Java 64K code_length limit.
Can anyone please give me some suggestions on which method would be the most appropriate, or if there is any other better approach to solve this problem?