format layout [Archive] - C Board

PDA

View Full Version : format layout


Shadow12345
12-31-2002, 02:58 PM
I've got a basic setup like this:

model class, each model has:
a 'heap' of vertices
a 'heap' of triangles
a 'heap' of meshes
and a 'heap' of materials

each mesh stores indices into the heap of materials and triangles
each triangle stores indices into the heap of vertices. This seems to be a pretty good way to store a model if you don't intend on using triangle strips of some variant to draw models (which I'm not). I was wondering if 'you people' think it would be too costly to instead of having indexes into the different 'heaps' if i should just copy the appropriate values themselves into the data structures and separating the large heaps of data into smaller heaps of data specific to each mesh and triangle. This will mean more memory will be used in the process but it seems it will make things a bit simpler.

Well post your thoughts. I'll probably implement skeletal animations before I make my final decision, I'm just throwing this out there to maybe see what to expect.

thanks

EDIT: Just to make things clear I am biased towards copying the same values into each individual structure instead of keeping the large heap. for example instead of having a triangle that indexes to vertices 1, 2, and 3, while having another triangle that indexes to triangles 2, 3, and 4 of the smae heap I would rather just copy 1, 2, and 3 to the first triangle and then copy 2, 3, and 4 to the other triangle. This means it would use 33% more memory but it would simplifiy things. Now that I think about it I might jsut try to find an effective way of just doing triangle strips, but I don't want to make things too difficult before I even get a chance to make anything. poly I expect you to reply to this post :)

no-one
01-02-2003, 03:24 AM
depends on what your goals are?

ease of use, or memory usage.

if you are learning on a complex format use the easy route and don't get bogged down on the memory.

Polymorphic OOP
01-02-2003, 08:28 AM
If you're just getting started, then be simple about it. The simple solution is usually the best, anyways.

If you don't want to do skeletal animation or anything it's just realy quick.

All you want is an array of vertices and an array of triangles -- where each vertex is a class with an x, y, and z coordinate and each triangle is a class with the INDICES of three vertices. You say you want to copy the vertex data to each triangle because it's "easier," but it's really just as simple (if not, more simple) to just use an index and you'll save yourself the trouble of having to go back later and changing everything to indices (because it's really pretty important that you do so, 1/3 the memory usage for triangles is pretty big and you get the added efect of being able to translate a vertex in the array and therefor changing the associated vertex in all the triangles. Besides, if you don't index the vertices from within the triangle, then there's really no sense at all in keeping an array of vertices in memory in the first place.

That's all you really need to get started. Don't bother with texture mapping or anything at first, those can be easily added later on.

Shadow12345
01-02-2003, 12:39 PM
All you want is an array of vertices and an array of triangles -- where each vertex is a class with an x, y, and z coordinate and each triangle is a class with the INDICES of three vertices. You say you want to copy the vertex data to each triangle because it's "easier," but it's really just as simple (if not, more simple) to just use an index and you'll save yourself the trouble of having to go back later and changing everything to indices (because it's really pretty important that you do so, 1/3 the memory usage for triangles is pretty big and you get the added efect of being able to translate a vertex in the array and therefor changing the associated vertex in all the triangles. Besides, if you don't index the vertices from within the triangle, then there's really no sense at all in keeping an array of vertices in memory in the first place.


I agree totally, it's pointless to copy the same vertices to specific triangles when you can easily just index into the vertex array. In fact this entire model loading routine consists of hierarchies of data structures indexing in to other data structures. I've already got the loading portion working (spent an hour at least debugging and making sure it loads correctly, did this by writing data items to disk over and over and checking and double checking). It gets kind of confusing but I've also finished writing the drawing routine (everything I've done is similar to tutorials, but honest to goodness I didn't copy anything, I took a lot of notes determining what should be done, and how, and I wrote everything on my own from my notes). This is how the drawing routine works, and this is where it gets somewhat confusing (for me) and will only get more confusing when I add texturing (which isn't all that hard in opengl) and animations (which will probably suck ass).

Draw():
Loop through each mesh of the model
-Loop through each triangle of the current mesh of the model
-Loop through each vertex of the current triangle of the current mesh

Do you want me to send the executable as soon as I've got it drawing a wireframe properly, or do you want me to hold off until I have texturing?

Shadow12345
01-03-2003, 12:34 PM
This is what I have so far, I added a background bitmap for no particular reason. It loads a static (non animated) model applying texture. It uses indices into arrays to access what it needs.

EDIT: i had to take out the background texture because cprog won't let me upload stuff over 195KB :(