I had a talk about MD2 vertex interpolation with Robert Green from Battery Powered Games a week back. He implemented the interpolation as a JNI method for maximum performance. I knew that Dalvik is not the fastest VM on the planet and wanted to see how fast a pure Java MD2 renderer gets on Android.
That’s 15 instances of a single MD2 Model, for each instance i interpolate a seperate vertex array each frame. There’s a total of 365 vertices in the mesh, and 634 indexed triangles. That’s 356 * 15 * 3 = 16020 Flops per frame. On my Milestone i achieve a steady 30fps while rendering the scene above which is pretty good in my opinion. The interpolation code alone takes 9ms for the 15 instances. I use floats throughout my code as fixed point math doesn’t seem to be a lot faster and thus not worth the trouble and pain maintaining it. Here’s the code for interpolating the vertices:
private void interpolateFrame(int frameIdx, float alpha)
float frame = mesh.getVertices();
float src = frames[frameIdx].vertices;
float dst = frames[frameIdx+1].vertices;
for( int i = 0; i < frame.length; i++ )
float d = dst[i];
float s = src[i];
frame[i] = s + (d - s) * alpha;
The MD2 format uses indexed triangle lists. The animation is encoded as keyframes, much like you’d do when drawing an animated cartoon. The keyframes are set apart by some time span. To get smooth animation we have to interpolate between two keyframes to arrive at the current vertex list. The above code does just that.
I have yet to try it on my Hero, but i suspect it just doesn’t have the horsepower. Neither the CPU nor the GPU will be able to handle this “massive” set of vertices/triangles. Just drop me a line if you want the full code.