Archived

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

Fuzztrek

Creating a 3D file format

Recommended Posts

Fuzztrek    572
Hello all, I am trying to create a 3D file format, so that I can load meshes into a "game" i am creating. I would like to create my own because I think that I will understand and learn much more than I would if I just used something like the .X file. I think that this is not going to be very easy.. hehe.. but could someone please point me in the right direction? I have searched a bit on the internet but I havn''t found that much. Any ideas? Thanks in advance, Fuzztrek ¬_¬

Share this post


Link to post
Share on other sites
g    135
Well, I've created my own format based on wavefront '.obj' files; it's quite simple, basically you define vertices by something like

V x y z
Each vertex is numbered (the first one is 1, second is 2, ... it would be better to name them). You can create triangular faces from them by specifying which three vertices are used, e.g.

F 1 2 3

This allows the same vertices to be shared between multiple faces, thus ultimately reducing the size of your vertex buffer and increasing speed.

There are quite a lot of details to think about, even for storing very simple (non animated) objects
- decide which way to have them facing, e.g. towards
positive z. This will avoid confusion later.
- how to apply textures and materials to faces
- texture co-ordinates for vertices, which can be problematic
- vertex normals
- functionality to combine existing things into a larger model rather than repeatedly copying the data (e.g. a four-engined starship)
- possible compression, the format I'm using is unnecessarily large

Well, I hope some of that is helpful.

[edited by - g on October 3, 2002 10:55:07 PM]

Share this post


Link to post
Share on other sites
Fuzztrek    572
Oh, thats very intersting and thank you for your post g. Unfortunatly, while that information will help me in the future, I think I''m at a more primal state at this point. However I do have some questions for you.. How did you figure out how to create your own file format? I really don''t know anything about making my own format.. but I assume that it would be something like.. you make something to convert.. say a 3D max file, and then you just.. disect it and convert it to your own format? Or do you do it when you actually save the file?


I have no idea O_O.. maybe i''m asking too much.. can you recommend a website or a book?


Thanks again!!

Fuzztrek

¬_¬

Share this post


Link to post
Share on other sites
g    135
> How did you figure out how to create your own file format?

Creating your own file format is easy. Reading and writing the files is trickier.

> make something to convert.. say a 3D max file, and then you just.. disect it and convert it to your own format?

Well, you can do that, but you''ll need to know a lot about the 3D max file format. It isn''t likely to be simple. It''s also _possible_ you might be able to write a plug-in to save files in your format. I don''t know anything about 3D max I''m afraid.

At the moment I''m making my models by hand, i.e. with notepad. One day I might write a model editor of my own.

> I have no idea O_O.. maybe i''m asking too much.. can you recommend a website or a book?

Erm, no, sorry. I''ve never read any books about it, I''ve just meddled around a bit. To be honest, I expect someone else here can give you better advice that I am.

What I will say, though, is that you should make sure you are familiar with file I/O in C (or whatever language you''re using), and you understand what you are going to do with the data from your file (e.g. I had to learn a lot about DirectX vertex buffers before I could load and use the vertex data from my files).

Share this post


Link to post
Share on other sites
Fuzztrek    572
quote:
Original post by g
At the moment I''m making my models by hand, i.e. with notepad. One day I might write a model editor of my own.



eep.


heheh. well, thank you SO much. I will try to learn a lot about file IO.. I don''t know if i should be, but I''m surprised this isn''t a bigger subject. Your information was very helpful (thanks for replying!!) but I do hope that more people respond. Surely SOMEONE else has created their own file format..



¬_¬

Share this post


Link to post
Share on other sites
mickey    100
hiya,

just put in stuffs that you want into that file, if you like vertices positions only then put in vertices positions only, if you want vertices plus texture coordinates then put it in your file format. It''s really upto you what kind of ''file format'' you want. g is correct, reading and writing the file is what''s hard.

It''s also upto you if you want to save is as charaters or as bytes etc,

you have to know the ''structure'' of your file so you can load/read it properly later on,

Share this post


Link to post
Share on other sites
chris_graham    122
My first 3D format was one I made myself. But I think I've actually learn't much more using other peoples (not about formats, but about the engines that must be behind the formats given the data in the format and its organisation).

But to start off, do something very simple like the following binary format. The analogy between C types and structures is very strong. Really binary file formats can be dealt with by simply reading and writing your actual game structures. I don't do this though, as I like to store on disk in a different way to how I store in memory.

Some psuedo C ...

// Lame format

char format[4]={'L','A','M','E'};

// Vertices
int no_vertices;
struct
{
float x,y,z;
} vertices[no_vertices]

// Polygons are all triangles
int no_triangles;
struct
{
int vertices[3];
char texturefile[30]; // The path to the texture (eg. mytex.pcx).

// For each of the 3 vertices, store its 2D positional mapping to the texture (range 0-1, where 0 is left/top and 1 is right/bottom)
float u[3];
float v[3];
} triangles[no_triangles];


Thats a very simple format, but should be enough to get some decent models working. As your 3D skills improve, extend the format, or try experimenting with other peoples.

To read in just use fread() and for loops: easy.

Of course, you will need to find a way to actually get stuff into this format, which either means making your own editor, or a plugin for someone elses (eg. milkshape).


[edited by - chris_graham on October 4, 2002 12:34:20 PM]

Share this post


Link to post
Share on other sites
Fuzztrek    572
ah.. very interestin =) I actually ahve been looking into a couple articles over at gamastura on how to create your own exporter plugin thing for 3ds max.

I shall see if i can find more info on the subject.. thanks for responding!!

¬_¬

Share this post


Link to post
Share on other sites