LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Rainer on May 20, 2008, 10:50:27

Title: model loading
Post by: Rainer on May 20, 2008, 10:50:27
Hi there

Until now, my engine supported just static .obj models.
I now need to get animations into the engine, but i'm not sure how.
What model format would you recommend? What i read til now, md2 would be easy?
Unfortunately i did not find any simple example.
I work with blender, blender can export to md2 by deault, other idea is to support .blend files directly, has someone done this already?
How would you proceed?
Title: Re: model loading
Post by: Rainer on May 20, 2008, 19:48:18
i need to display a lot of enemys at the same time, so my solution should have a good performance.
how should the rendering be done? one displaylist per animationframe? vertexbufferobject and then switching buffers? or rendering directly with opengl commands?
Title: Re: model loading
Post by: paulscode on May 20, 2008, 20:56:50
I do not have any experience with this myself, but I do know that the jpct engine uses the .md2 format for animations.  Egon might be able to give you some ideas.  His website is at http://www.jpct.net (http://www.jpct.net)
Title: Re: model loading
Post by: bobjob on May 21, 2008, 01:37:40
Just continue on what you are currently using.

I personally fiddle with md2 in blender then export the keyframes (as animation) to .obj

also you can generate between frames, to give it a smoother look when animating. by finding the difference between the points.

display lists are fine. but i tend 2 use vbo's and only fall back on display lists if vbo's are'nt supported.

just create a seperate displayList, or VBO, for each frame. anything more than that tends to be a big perforamce hit. if your going to have plenty of enemies the last thing you want is to be using is skeletons.
Title: Re: model loading
Post by: Rainer on May 21, 2008, 07:49:27
Thanks for the hints.
I also thougt about a solution like you are suggesting, just had e bit fear from the time it takes to export all de keyframes for a complex animation.
But since its possible to write blender export plugins this could be solved.
So I would export the keyframes to .obj, then calculate subframes to smooth the animation, and put every frame into a display list.
What was your intention to use vbo instead of display lists?
Title: Re: model loading
Post by: bobjob on May 21, 2008, 09:17:18
For some reason laptop Radeon spikes when i use Display Lists. So by default i use speedy VBO's.
Title: Re: model loading
Post by: Rainer on May 21, 2008, 22:20:29
Quote from: bobjob on May 21, 2008, 01:37:40
also you can generate between frames, to give it a smoother look when animating. by finding the difference between the points.
how did you do this with the normals?
for the vertices/faces it seems to work fine, but my normals totally get messed up  ???
Title: Re: model loading
Post by: bobjob on May 22, 2008, 08:58:36
This is the code for the normals, i use floatbuffers to store all my points


for (int b = 0; b < start.nor.capacity(); b++) {
nor.put(b, start.nor.get(b) + (((end.nor.get(b) - start.nor.get(b)) / (frames+1)) * (currentFrame+1)));
}
normalize(objData.nor);




  public static void normalize(FloatBuffer v){
  int total = v.capacity() / 3;
  for (int i = 0; i < total; i+=3) {
  float length = (float)Math.sqrt(
  (v.get(i)  *v.get(i)  )
  + (v.get(i+1)*v.get(i+i))
  + (v.get(i+2)*v.get(i+2)) );
    if(length <.00001f) {
    v.put(i, 0);
    v.put(i+1, 0);
    v.put(i+1, 0);
    } else {
    v.put(i, v.get(i)/length);
    v.put(i+1, v.get(i+1)/length);
    v.put(i+2, v.get(i+2)/length);
    }
  }
  }


I use that for normals
Title: Re: model loading
Post by: Rainer on May 22, 2008, 09:31:46
seems we're basically doing the same thing.

i now exportet every single frame from blender, and noticed that the number of normals in the files is diffrent, how can this happen?
Maybe the bug i get is just because of an indexing error?
Title: Re: model loading
Post by: bobjob on May 22, 2008, 09:37:37
if you are exporting for some quake 2 md2's the normals should be equal in each frame.
Title: Re: model loading
Post by: Rainer on May 22, 2008, 11:16:54
i tryed to export directly from my .blend to .obj, not converting first to md2.
exporting my model to md2 fails with "Model has a face without texture map", but i don't know why, guess i have to investigate my model...
Title: Re: model loading
Post by: bobjob on May 22, 2008, 11:39:32
oh, i have never made an md2, i just fiddle with the objects that are md2, then export as a obj animation. i got a whole bunch of old quake2 models
Title: Re: model loading
Post by: Rainer on May 22, 2008, 11:49:51
well, since blender 2.46 changed the uv unwrapping i anyway have to re-learn this :p
hope i get it to work somehow.