Model class design questions

Started by
0 comments, last by DroxXodia 16 years, 7 months ago
I've got a few questions related with class storing models (meshes) data. I started with something like this:
	
class cModel : public cObject {
	struct sMesh {
		/// number of different vertexes
		int diffVertexNum;
		float *vertex;	// *3
		float *normal;	// *3

// texture coordinates etc will be here

		int realVertexNum;
		int *index;
	};

	int meshNum;
	sMesh *mesh;
public:
	cModel();
	int load(const char *file);
	void free();
	void draw();
};
And after this part of code I started to think and wonder ;p My problem is not loading or free'ing models, but drawing with high performance and not using too much memo. 1) I want to use indexed vertex arrays - and here the first question - is this the best way ? I want my models to be modifiable, so display lists are not good enough for me, begin/end is slow (but easy to use, this is my other problem (2)). Are there any other (better) methods of drawing geometry? 2) In each tutorial I found model was stored like this:

// pseudocode
struct vertex {
	...
};

struct triangle {
	int *vertexIndexes;
	int normalNum;
	vector3 *normal;
	...
};

struct mesh {
	int triangleNum;
	triangle *triArray;
	...
};

class model {
	int vertexNum;
	vertex *vertArray;

	int meshNum;
	mesh *meshArray;

	...
};
Something similar I is in nehe #31, in many net resources, even in Hugi. Is there a method to draw something organized like this really fast (not using glVertex3f / glNormal3f ... in a loop? 3) I think that my model class problem is memory needed to store it. For example - if the model is a cube - each vertex has to be stored three times due to different normal values. (cube isn't smooth). In such not-smooth cases I loose memo on storing vertexes and the NeHe-like model is much better (but still question of drawing it). Is there a way to connect this to styles? I'll be happy to receive any suggestions, any advice.
Advertisement
I'm at work so I don't have my source with me.

I use opengl VBO's.

I read in all the data I need from either a .3ds file or a .obj file, temporarily storing that data, in chunks.

Each chunk is grouped by the texture it uses.

After I load a chunk, I create the VBO right then and there. I then move on to the next chunk, creating the next VBO.

At the end, each model could have any amount of VBO's.

Now, you can do whatever you want from there. You can either use interpolating for animation, or you could use 3d page flipping for animation. page flipping is easier, but takes up a lot more memory, and interpolating is one of the best ways, but is far more complex.

Either way, you never need to permanantly store the vertex/texture/normal data in an array. read it, then store it in a VBO or normal vertex buffer.

This topic is closed to new replies.

Advertisement