No no man maybe I should have expressed myself a bit better;
What I’m trying to say here is using NIO buffers will seriously speed up your loader.
As a matter of fact, your 3DS loader is a critical part in creating a model with my format specifications.
A better thing would be explaining how I create the JCD format:
First of all I load a 3DS model using your loader, which is a magnificent piece of code.
Second I retrieve the IndexedGeometry as well as the normals, textureCoordinates, indices and the number of unique vertices.
After that, I generate the TBN matricies which require over 5 normalizations per vertex, and yet is done at a litte over 0.01 s for a > 5000 vertex model.
Finally I save the newly created model using the following function:
public static void saveJCDModel(Tuple3f[] ve , Tuple3f[] no,
Tuple3f[] ta , Tuple3f[] bi,
Tuple3f[] te , int[] indices ,
int validVertexCount, String name){
ByteBuffer modelInfo = ByteBuffer.allocateDirect(ve.length*60 +
indices.length *4 + 8);
modelInfo.putInt(indices.length).putInt(validVertexCount);
for(int i = 0; i < validVertexCount; i++){
modelInfo.putFloat(ve[i].x).putFloat(ve[i].y).putFloat(ve[i].z);
modelInfo.putFloat(no[i].x).putFloat(no[i].y).putFloat(no[i].z);
modelInfo.putFloat(ta[i].x).putFloat(ta[i].y).putFloat(ta[i].z);
modelInfo.putFloat(bi[i].x).putFloat(bi[i].y).putFloat(bi[i].z);
modelInfo.putFloat(te[i].x).putFloat(te[i].y).putFloat(te[i].z);
}
int size = indices.length/3;
for(int i = 0; i < size; i++)
modelInfo.putInt(indices[i*3 + 0]).
putInt(indices[i*3 + 1]).
putInt(indices[i*3 + 2]);
modelInfo.flip();
try{
new FileOutputStream(name + "JCD.jcd").getChannel().write(modelInfo);
}
catch(Exception e){}
}
All those steps take a little over 1 s with the new version of your loader.
Now if you were to load your meshes with an NIO buffer, the speed of all the mentioned operations will definitely fall below 1 s, I’m positive.
PS: Here’s how I load my format, it might help you out tweaking your loader
public static GeometryArray readJCDModel(String name){
FileInputStream fileStream = null;
ByteBuffer modelInfo = null;
byte fileContents[] = null;
try{
fileStream = new FileInputStream(name + "JCD.jcd");
fileContents = new byte[fileStream.available()];
fileStream.read(fileContents);
modelInfo = ByteBuffer.wrap(fileContents);
}
catch(Exception e){}
int[] indices = new int [modelInfo.getInt()];
Point3f[] vertices = new Point3f [modelInfo.getInt()];
Vector3f[] normals = new Vector3f [vertices.length ];
TexCoord3f[] tangents = new TexCoord3f[vertices.length ],
binormals = new TexCoord3f[vertices.length ],
texcoords3f = new TexCoord3f[vertices.length ];
for(int i = 0; i< vertices.length; i++){
vertices [i]= new Point3f (modelInfo.getFloat(),
modelInfo.getFloat(),
modelInfo.getFloat());
normals [i]= new Vector3f (modelInfo.getFloat(),
modelInfo.getFloat(),
modelInfo.getFloat());
tangents [i]= new TexCoord3f(modelInfo.getFloat(),
modelInfo.getFloat(),
modelInfo.getFloat());
binormals [i]= new TexCoord3f(modelInfo.getFloat(),
modelInfo.getFloat(),
modelInfo.getFloat());
texcoords3f[i]= new TexCoord3f(modelInfo.getFloat(),
modelInfo.getFloat(),
modelInfo.getFloat());
}
for(int i = 0; i< indices.length; i++)
indices[i] = modelInfo.getInt();
TriangleArray newGeometry = new TriangleArray(indices.length,
GeometryArray.TEXTURE_COORDINATE_3 |
GeometryArray.COORDINATES |
GeometryArray.NORMALS,
3,
new int[]{0,1,2});
for(int i=0; i<indices.length; i++){
newGeometry.setNormal ( i, normals [indices[i]]);
newGeometry.setCoordinate ( i, vertices [indices[i]]);
newGeometry.setTextureCoordinate(0,i, texcoords3f[indices[i]]);
newGeometry.setTextureCoordinate(1,i, tangents [indices[i]]);
newGeometry.setTextureCoordinate(2,i, binormals [indices[i]]);
}
return newGeometry;
}
PS2: I convert IndexedGeometry into non-Indexed because of a bug in the shadow generation. I will try to look into that and maybe fix it.
Thanks again for the help 