gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Anyone want to share their MD2 loader?

#127299 - FireSlash - Tue May 01, 2007 1:56 pm

I spent the better part of last night hacking away into code that, at no turn, has worked.

I've written loaders before, but I'm having trouble grasping a fast way to do it with the limited subset of commands libnds provides.

If anyone would like to float me a copy of a working one for the DS, It'd really speed things up on this project.
_________________
FireSlash.net

#127309 - Lord Graga - Tue May 01, 2007 4:37 pm

If you want single-frame stuff I can upload you a MD2->DisplayList converter.

#127345 - FireSlash - Tue May 01, 2007 8:41 pm

That'd be perfect. I can handle the animation, I just can't seem to get the data into an easily called structure. :)
_________________
FireSlash.net

#127349 - kusma - Tue May 01, 2007 9:59 pm

if you control your dataset, there's no big point in actually loading md2 on the ds. a pc-side converter would be my preferred choice.

#127362 - FireSlash - Tue May 01, 2007 11:11 pm

kusma wrote:
if you control your dataset, there's no big point in actually loading md2 on the ds. a pc-side converter would be my preferred choice.

Control?

Who said ANYTHING about control?
_________________
FireSlash.net

#127369 - Lick - Tue May 01, 2007 11:27 pm

I think he means, "Avoid loading MD2s on the DS if possible, but pre-convert them to something else."

FireSlash probably meant something like, "Hmm, I'm not sure what you mean by 'control', could you please repeat and rephrase?"
_________________
http://licklick.wordpress.com

#127372 - FireSlash - Tue May 01, 2007 11:46 pm

Lick wrote:
I think he means, "Avoid loading MD2s on the DS if possible, but pre-convert them to something else."

FireSlash probably meant something like, "Hmm, I'm not sure what you mean by 'control', could you please repeat and rephrase?"


No, I meant "Why convert to something else when a cheap, easy to decode and well supported format already exists with everything I need?" if that's what he meant.
_________________
FireSlash.net

#127375 - tepples - Wed May 02, 2007 12:46 am

If you are making all your work's models, then you control your dataset. If you allow users to import models, then others control your dataset.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#127377 - HyperHacker - Wed May 02, 2007 12:51 am

FireSlash wrote:
Why convert to something else when a cheap, easy to decode and well supported format already exists with everything I need?
Because you can convert to a cheaper, easier to decode format, and your converter would still provide support for those well-supported formats. (Assuming the user runs a compatible OS...)
_________________
I'm a PSP hacker now, but I still <3 DS.

#127393 - FireSlash - Wed May 02, 2007 5:06 am

tepples wrote:
If you are making all your work's models, then you control your dataset. If you allow users to import models, then others control your dataset.

Idea is for others to control it.

Yes, other formats might be cheaper, but MD2 is a very easy format to deal with. Since the loader is only used during the loading phase, it doesn't matter if MD2 might take a bit longer to load, but the cost is worth it for using a format that most mainstream modelers can directly export to.

Plus, a lot of my assets are currently in md2 :)

I love the input, but I'd just like someone's MD2 loader. if that's a problem, I'll write my own; I just didn't want to waste time trying to figure out a new way to do it when someone else had probably already done it.
_________________
FireSlash.net

#127409 - simonjhall - Wed May 02, 2007 8:04 am

Hang on, I just thought - Quake's models are in md2, right? Or is that a different md2?
If so, check out WinQuake/model.c in http://quake.drunkencoders.com/downloads/quakeds_source_290407_pre2.zip

The function you'll want is called Mod_AliasLoadModel. There's two versions of it in the file, the one I did (by tearing apart the existing code) which uses the bare minimum of memory (#ifdef LOWMEM_LOADER) and the one that Krazy Carmack wrote (that uses loads of memory). His is much easier to follow, but it's still a pretty tricky piece of code.
You ought to be able to just rip either one out and replace all the wrapped file calls with stdio...

Or is Q2 in md2...?
_________________
Big thanks to everyone who donated for Quake2

#127412 - kusma - Wed May 02, 2007 8:45 am

Quote:
Or is Q2 in md2...?

Yup. Quake 1 is mdl iirc.

Quote:
Idea is for others to control it.

That doesn't necessarily matter. Just supply them with your converter ;). I was more thinking if you had a strict spec saying "this dataset should be in format XXX" you had to conform to.

Quote:
Plus, a lot of my assets are currently in md2 :)

Again, this shouldn't matter much. Make a loader, but don't put it on the DS. Less file-format parsing code on the target platform means less memory required.

#127416 - simonjhall - Wed May 02, 2007 9:11 am

kusma wrote:
Again, this shouldn't matter much. Make a loader, but don't put it on the DS. Less file-format parsing code on the target platform means less memory required.
And it makes it much easier to debug!
_________________
Big thanks to everyone who donated for Quake2

#127458 - FireSlash - Wed May 02, 2007 5:57 pm

The thing is, I don't want to have to supply a converter.

1) I use three different OSs, windows OSX and Linux. I don't feel like writing three converters or porting one to all three systems.
2) I don't feel the need to re-invent the wheel. MD2 does EXACTLY what I need it to. Sure, a loader requires more code (hence more memory) but my own loader will require code as well. Since I'm confident that I can't write a format and loader that would, in the end, achieve the same goal without either bloating the model files or bloating the loader, I don't see why spending the time to write an entirely new system is such a great idea.

Yes, It does open the chance for a more efficient method, but this game isn't going to be pushing the limits of the DS in any respect. I could probably write the same thing under the GBA's specs, so I don't feel guilty wasting a bit of ram and CPU here and there to get a result that can be developed in less time and is a bit easier to deal with.
_________________
FireSlash.net

#127461 - tepples - Wed May 02, 2007 6:28 pm

FireSlash wrote:
1) I use three different OSs, windows OSX and Linux. I don't feel like writing three converters or porting one to all three systems.

Java: Write once, run anywhere, in theory.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#127466 - Dark Knight ez - Wed May 02, 2007 6:58 pm

Or you can let the converter run on your DS as seperate program. How's that for portability?
_________________
AmplituDS website

#127651 - Sausage Boy - Thu May 03, 2007 8:31 pm

Making a portable command line program is simple as pie. Just avoid compiler or OS specific commands. When GUI's are involved, things get more interesting :D.
_________________
"no offense, but this is the gayest game ever"

#127656 - M3d10n - Thu May 03, 2007 9:38 pm

FireSlash wrote:

2) I don't feel the need to re-invent the wheel. MD2 does EXACTLY what I need it to. Sure, a loader requires more code (hence more memory) but my own loader will require code as well. Since I'm confident that I can't write a format and loader that would, in the end, achieve the same goal without either bloating the model files or bloating the loader, I don't see why spending the time to write an entirely new system is such a great idea.


Oh, but you will have to re-invent the wheel regardless. You'll need to load the MD2 into a more DS-friendly structure even when loading directly on the DS, since you'll not be able to render the MD2 structure directly to the screen.

What everyone is suggesting, is that you perform that conversion offline (aka: using a tool outside the DS) and dump the output on a binary file. Then all you need is to directly load that output into the DS RAM and render it right away.

This will make your life much, much easier, even if you need to port the tool for different OS'es, since debugging a PC program is much easier than debugging DS ones. You also can be very lazy on your conversion code, since it won't be done in real-time anyway, and you may even write it in a different language other than C/C++. As example, you could code your converter in Python and it would become cross platform from the get go.

#127659 - simonjhall - Thu May 03, 2007 10:48 pm

I say roll with loading the md2 directly on the DS. The file format isn't too hard to load - it's easy code, and there aren't too many sections in the file which need loading. It's not slow to load either.

Just make sure that you have a PC version first which just dumps all the vertex positions and face ids to stdout (to ensure you've got it working). Then rebuild for the DS, and render.

It's not like he's trying to parse a model in XML! Now that I wouldn't risk doing on a DS ;-)
_________________
Big thanks to everyone who donated for Quake2

#127661 - Lick - Thu May 03, 2007 11:00 pm

XML for 3D data? COLLADA! Seriously, I'd not even use XML on the PC, ever. Piece of rubbish.
_________________
http://licklick.wordpress.com

#127676 - Dood77 - Fri May 04, 2007 12:43 am

<br />
Oh GREAT! Now to please the W3C I gotta add two more keystrokes to like half of the html tags!
_________________
If I use a term wrong or something then feel free to correct, I?m not much of a programmer.

Original DS Phat obtained on day of release + flashme v7
Supercard: miniSD, Kingston 1GB, Kingston 2GB
Ralink chipset PCI NIC

#127701 - HyperHacker - Fri May 04, 2007 5:03 am

I'm pretty sure <br/> is acceptable. ;-)
_________________
I'm a PSP hacker now, but I still <3 DS.

#127741 - Lick - Fri May 04, 2007 12:25 pm

HyperHacker wrote:
I'm pretty sure <br/> is acceptable. ;-)

The XHTML 1.0 document tells you to leave a space between the tagname and the slash, so older browsers don't flip out. [Appendix C.2]

#128038 - syncope - Mon May 07, 2007 11:45 pm

Voil? here's someone's md2 loader

http://www.box.net/shared/zkaffvemdz
[Possibly using an outdated version of PAlib]

// PA_md2 Loader by jandujar
// Based on Webez md2 loader


Aditional/Way too many details follow:

Stumbled upon it a year ago on this Spanisch DS Forum, couldn't find the exact post again though >>
http://www.elotrolado.net/forumdisplay.php?s=6b3f39cf7f6176c4fa0f4415e105cb92&forumid=125

Author Homepage:
http://jandujar.homelinux.com/antigua/index.php?option=com_content&task=blogcategory&id=23&Itemid=38

relevant threads
http://forum.gbadev.org/viewtopic.php?t=10248

#128076 - Daniel[Nordigic] - Tue May 08, 2007 11:15 am

This page might also be of interest, it contains all kind of stuff...

http://tfc.duke.free.fr/