Sign in to follow this  
PumpkinPieman

Best way to implement a simple mesh?

Recommended Posts

I'm still not quite sure what I need to do to construct a simple mesh. This is what I have thought of, but are there other ways of doing it?
Object
	Mesh[]	
		Vertices[] of Vertex3D
			pos(xyz)
			norm(xyz)
			colour(int32)
			textcoords(2*float)
	
		Indices[] of WORD

	Material[] of sMaterial
		diffuse(rgba)
		ambient(rgba)
		emissive(rgba)
		specular(rgba)
		shininess(int32)
		Texture1*
		Texture2*
			

Share this post


Link to post
Share on other sites
That looks reasonable, but what you actually want depends on what you're going to do with it:

- if you want to render the mesh using something like DirectX, you'll probably want to use compatible Vertex and Index buffer formats, so you can pass them to the library for rendering.

- if you're going to manipulate the mesh (e.g. a modelling program or computational geometry algorithm) you might find that storing additional connectivity information helps a lot.

- if you're going to ray-trace the mesh you might want connectivity information and / or spatial partitioning of some kind.

etc.

What did you have in mind?

Share this post


Link to post
Share on other sites
Then my first point stands. You'd do well to think about how you're going to render these meshes now, and make sure your format fits. If it doesn't, you'll probably have to change it later.

Are you going to use a library such as DirectX or OpenGL for rendering? If not, what's your plan?

Share this post


Link to post
Share on other sites
Oh, I'm using DirectX at the moment. With the array class I made I can return a pointer to the vertex data as well as the index data. I can easily lock and unlock the data into standard directx buffers, so I don't see that being an issue. I'm also planning on using this for collision detection with oct tree's. Rendering is one thing that's puzzling me, and how I can optimize it with something like this. :\

Share this post


Link to post
Share on other sites
Well, it sounds like you've thought it through quite well.

I'm not sure what concern you're trying to express about rendering. If you're thinking about VB's and IB's you're already on the right track. The order you render objects in will also be important, but that shouldn't greatly impact the design of this class.

As for collision detection, I don't have much experience here so I'll have to defer to someone else...

Share this post


Link to post
Share on other sites
Well, that's the structures I've made. I'm guessing the DirectX structures will be quite similar when trying to render it.


Object
Mesh[]
Vertices of LPDIRECT3DVERTEXBUFFER8
Indices of LPDIRECT3DINDEXBUFFER8

Material[] of D3DMATERIAL8
Texture[]
texture1 of LPDIRECT3DTEXTURE8
texture2 of LPDIRECT3DTEXTURE8




Is it good to keep the texture in combination with the Material? Assuming of course that the texture will have the same lighting no matter what it's rendered with.

Share this post


Link to post
Share on other sites
If you need some source code to reference, try checking out the code to DirectMesh v1.0. It's pretty simple, but it does support keyframe animation and some basic material properties.

Instead of having a set structure of materials (ie sMaterial has diffuse, ambient, and specular members), you may want to make it extensible. This way, you can add custom shader-specific properties.

Collision detection can be a pain in the neck. I found this article to be pretty helpful. Also, this site and this site have a lot of info, too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this