Archived

This topic is now archived and is closed to further replies.

Fuzztrek

Loading MD2 files

Recommended Posts

Hey all! I''ve been really busy trying to figure out how to load MD2 files, but unfortunatly I have had no luck yet. I know I posted another thread a while ago, but I didn''t get much of a response so I decided to try again. I would like an alternate way of loading MD2 files! This means no DrawPrimitiveUP. I have read about the MD2 file format, and understand that it was optimized for OpenGL. However, since X files are not my friend, I have decided to explore another file format. If anyone has any information at all, please tell me! Thanks in advance!! Fuzztrek ¬_¬

Share this post


Link to post
Share on other sites
use vertex-buffers, I have an MD2 viewer written in VB at my homepage matrixvb.da.ru, it uses vertex-buffers for rendering but drawprimitiveUP would also be good for MD2 models because you have to tween the key-frames, this means you have to alter the vertex-data (vertex-buffers are static)

Share this post


Link to post
Share on other sites
Hi there!

I have looked at your code, however it is in VB and apparently vb uses a different method for copying data to the vertex buffer, which is not avalible in C++. I am NOT even going to think about using DrawPrimitiveUP, as stated in my first post.

Thanks anyway

Fuzztrek

¬_¬

Share this post


Link to post
Share on other sites
Just create a vb, using the discard and write only flags. Then interpolate and fill as required. Your only other option is dpUP.

Also, stop bumping your posts. If it''s that urgent try other game dev web sites and/or irc channels.

eb.

Share this post


Link to post
Share on other sites
Hum.. if your going to respond to my post please read it completly first! I know that I need a dynamic vertex buffer. Creating one is no problem. However, I do not know what to put into it once I have it (specifically). I have read a lot about MD2 files but i still can''t quite understand how to animate it etc.

Thanks anyways.

¬_¬

Share this post


Link to post
Share on other sites
Fuzz, people are only trying to help - please watch the ''tude.

To answer your question:

* An .MD2 file consists of multiple frames, which are the meshes.
* Create a mesh object for each frame in the file.
* Load the delta information for each frame then load each frame, scaling the vertex data appropriately by the delta values. Lock the appropriate mesh object''s vertex buffer and stuff in the data. If you are using index buffers, then repeat locking and stuffing data. Unlock all buffers when done.
* Repeat loading data for each frame (mesh) until all are loaded.

At this point, you should have a whole slew of mesh objects. To render the animation you''ll need to parse the frame names as they were stored in the .MD2 file. An animation is signified by a name followed by either 1 or 2 numbers. Frames that have a matching name with increasing number values indicate a sequence to order.

To animate:

* Get the source frame and target frame for a morphing render. You might want to check out the tween example for help.
* Figure the scalar to use based on the time and morph the vertex positions based on this scalar.
* Stuff each morphed vertex into your dynamic vertex buffer (or a static vertex buffer that has the same attributes as any of those loaded).
* Finish w/all vertices, unlock buffer and render.

Share this post


Link to post
Share on other sites
Firstly, I''m not posting here for my benefit.

My method I described is the one I have implemented in my own engine, and therefore I know it works. Also, vertex buffers need not neccessarily be considered static - you can change the data they contain. Specifying the write only and discard flags speeds up performance for the needs of md2 rendering.

Have a look at:
md2 spec
gametutorials.com md2 loading tutorial. It''s written in opengl but the loading and animation procedure is clear.

Good luck with it.

eb.

Share this post


Link to post
Share on other sites