Well - OK then, you've twisted my arm. Example source is at Tutorial 5. The fundamentals here are creating a file that contains four things - vertex positions, normals, texture coordinates, and triangle indices - and then importing it in Java. I used Blender, but you should be able to use 3D Studio, Lightwave or your favourite modeler. I'm not going to go into detail about using the modeler but I will point you to these fine Blender tutorials:
Once you have your texture mapped, normal applied model, we need to save it in a format that contains the above mentioned four sets of data in a reasonable format. Even though we're using OpenGL, the DirectX .x format is a reasonable choice. It contains all of the above in a nice plain text format that's easy to read in. A hint though: in Blender, go back to Object mode and select the object you wish to export before using the .x exporter. Using the exporter in Edit mode ignores the normals and provides different texture coords, at least for me.
If you want to skip the model creation bit, you can use the very simple model I created. Just don't laugh too much.
To load the model, I've rolled the input and rendering into a class called XModel. It *very* lazily parses the .x file, and I can't guarantee that it will work for anything but the simplest models produced by the blender exporter. The key points to watch are the parse*() methods, which each take a portion of the file and fill an ArrayList with data. Then these are cut down to size by deduplicate(), which merges identical vertices, and finally passed to fillbuffer():
private void fillBuffer() {
b = BufferUtil.newFloatBuffer(triangleCount * 3 * vertexstride);
int index;
Vector8 v;
for (int i = 0; i < indices.size(); i++) {
index = indices.get(i);
v = vertices.get(index);
b.put(v.x);
b.put(v.y);
b.put(v.z);
b.put(v.nx);
b.put(v.ny);
b.put(v.nz);
b.put(v.tx);
b.put(v.ty);
}
}
This just gives us a plain old FloatBuffer that we can pass to glDrawArrays. After loading and enabling the texture (using TextureIO which I suppose is sort of cheating ;o) we get:

I said don't laugh! By the way, I'm open to assistance with the graphics and models for JavaPop. Any aspiring artists out there who want to draw 5 or so frames of walking and a dozen or so houses please leave a comment!
No comments:
Post a Comment