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 > 3D Exporter for NDS?

#146095 - S7ARBVCK - Wed Nov 28, 2007 10:25 pm

Hey, Folks,

I'm an old-skool (professional) GBA Coder, and I decided I'd like to get into NDS coding just as a hobby. Loads of really useful information here!

Anyway - my primary area of interest is in 3D on NDS. Has anyone written a converter for 3D files (particularly 3DS or MAX files) or an exporter for Max?

If not, how are you guys getting your models into your NDS games?

Thanks, in advance for any help!

SB

#146123 - M3d10n - Thu Nov 29, 2007 3:29 am

At least two posters made converters which can generate DS display lists and are available for download.

But it isn't that hard to load models on the DS. If you use immediate mode you can render theorically any file format you got the specs for. It's like drawing models in OpenGL. Using LibFAT you can open files using standard fopen/fread/fclose.

The display list thing is just a way to pack drawing commands into a buffer which can be DMA'ed into the graphics chip, saving a bit CPU time. Since it's just an array of 32-bit integers, you can conveniently store it in a file.

#146193 - S7ARBVCK - Fri Nov 30, 2007 10:27 am

M3d10n wrote:
At least two posters made converters which can generate DS display lists and are available for download.

But it isn't that hard to load models on the DS. If you use immediate mode you can render theorically any file format you got the specs for. It's like drawing models in OpenGL. Using LibFAT you can open files using standard fopen/fread/fclose.

The display list thing is just a way to pack drawing commands into a buffer which can be DMA'ed into the graphics chip, saving a bit CPU time. Since it's just an array of 32-bit integers, you can conveniently store it in a file.


Thanks, man - that's a really useful reply! :) Pleased to see the DMA dumping of graphics data has carried across from GBA.

My reason for asking about an exporter is for 3 reasons, though -

1) There is a lot of unnecessary guff in 3D Model files (3DS is probably what I'd be using) which isn't needed when you have a closed system (the DS)
2) Even though I have documentation on the 3DS Model file format, I'd have no idea how to generate the strips of quads I believe it's possible to do with the DS (understand the theory, don't really understand what describes a valid strip)
3) I was planning to use Multi-Sub materials in 3DS Max to do my texturing - this is probably a lot more difficult if you don't have an exporter to handle the necessary conversion, as I understand that the NDS only supports one texture per model, right?

Anyway - thanks for the heads up about being able to use any format. Don't suppose you could point me in the direction of a) Some information about the construction of Draw Lists and b) where I might be able to find the downloadable exporters you speak of?

Thanks very much, so far! :)

SB

#146196 - kusma - Fri Nov 30, 2007 10:48 am

S7ARBVCK wrote:

3) I was planning to use Multi-Sub materials in 3DS Max to do my texturing - this is probably a lot more difficult if you don't have an exporter to handle the necessary conversion, as I understand that the NDS only supports one texture per model, right?

Luckily, 3DS Max already have the render to texture support needed to make a baked material out of any complex one. It is better to use this directly because it allows more artist-control, yet is simple to use.

#146326 - M3d10n - Sun Dec 02, 2007 8:51 pm

S7ARBVCK wrote:

1) There is a lot of unnecessary guff in 3D Model files (3DS is probably what I'd be using) which isn't needed when you have a closed system (the DS)

Instead of loading the 3DS files directly on the DS, you could write an offline tool that converts them into a binary format that is easier for you to render (as example, you could store the vertex coordinates in the correct fixed point format that way).

S7ARBVCK wrote:

2) Even though I have documentation on the 3DS Model file format, I'd have no idea how to generate the strips of quads I believe it's possible to do with the DS (understand the theory, don't really understand what describes a valid strip)

Don't bother with strips (or even quad strips) before you get to draw triangles/quads first. I recommend you grab GLUT and do a small OpenGL app to render your model. You can then port the code the DS without much trouble and you'll have better debugging tools and a faster development cycle while coding it.

S7ARBVCK wrote:

3) I was planning to use Multi-Sub materials in 3DS Max to do my texturing - this is probably a lot more difficult if you don't have an exporter to handle the necessary conversion, as I understand that the NDS only supports one texture per model, right?


I think you're confusing multiple materials with multitexturing. The first one means having different textures on different triangles. The 2nd one means having multiple, layered, textures on a single triangle.

The DS doesn't support multiple textures. But of course you can use different textures on different triangles:
- bind a texture
- draw all polygons which use it
- bind another texture
- draw all polygons which use it
- etc.

When loading/converting a model file, you do this by storing polygons in a different list for each material. Some people refer to that as a "primitive" (a bunch of polygons which shares the same material).

S7ARBVCK wrote:

Anyway - thanks for the heads up about being able to use any format. Don't suppose you could point me in the direction of a) Some information about the construction of Draw Lists and b) where I might be able to find the downloadable exporters you speak of?


One of the LibNDS examples has a short make up of a display list. LibNDS has a bunch of macros for creating the display list data.

There is an display list exporter for Maya: http://forum.gbadev.org/viewtopic.php?t=11828&highlight=exporter

This .X converter:
http://forum.gbadev.org/viewtopic.php?t=5665&highlight=exporter

If you look for the original Maya Exporter thread you'll find lots of info on building the display lists. But basically, they are a list of 32-bit integers.

The first item in the array is the list size (number of 32-bit ints in it) minus 1. This is used by the glCallList() command, to know how much data it must pass using the DMA.

Then you write 4 8-bit command IDs packed in a uint32 (they start with FIFO_ and there is a macro to convert nearly any GPU call into a command ID, look into the libnds display_list example), and write the data for each command (all packed in 32-bit ints)

Some commands need more data then others. As example, the data for a FIFO_TEX_COORD command is two 16-bit values (U and V) which are packed into a single 32-bit int (so it only uses 1 "slot" in the display list). But the FIFO_VERTEX16 command (vertex coordinate) needs 3 16-bit values, so X and Y are packed in an int and Z goes into another. Size the data must be 32-bits aligned, the Z component gets padded to fill 32-bits.

I wrote my own converter, which unfortunately I can't release (yet), which converts FBX files into my own mini-format (which uses display lists plus some header info, like texture names and etc). When converting I use a vector to accumulate the commands headers and data, and when the list is complete I write the size at its beginning.