Sign in to follow this  
Phredo

my idea for a mesh class

Recommended Posts

So I'm playing around with loading up MilkShade 3D files (they provide the source) and I thought that maybe making my own mesh class could be an interesting exercise. I was trying to rationalize the best way to do it and essentially I ended up with an object that takes care of loading and rendering. The caller is responsible for setting up render states but other wise the mesh class does all the heavy lifting of getting the vertex/face data into the vertex/index buffers as well as managing the materials/textures as well. So all you have to do is call the Render method inside your render loop. At the same time, I would have methods that return the vertex/index buffers as well as materials so you could do your own rendering. I'm sure alot of you have done this kind of stuff before so... any insight?

Share this post


Link to post
Share on other sites
The general concept is reasonable (our engine does something similar), but I would suggest that you design the class to do what your current code needs, rather than trying to handle every possible contingency. That will help keep the design (and implementation) lean and simple.

Frankly, a mesh loading/rendering class is fairly trivial code - not the kind of thing you'd need to worry about reusing between engines, for example. As such, it isn't really worth emphasizing reuse/genericity too much.

But the idea is definitely solid.

Share this post


Link to post
Share on other sites
I would keep the renderer separate from the mesh class. That way you can just create a number of renderer classes, each conveniently stored in a separate DLL (eg OpenGL, D3D, Software) and not update every class that needs to be rendered to render itself. Instead, make sure your mesh class organizes data in the best possile way for all renderers to access and provides the functionality needed to easily copy, delete and texture map the mesh. Furthermore, I would also keep the loaders separate, forming a hierarchy, such as this.


MShapeLoader AutodeskLoader WavefrontLoader
| | |
| | |
|_____________________|______________________|
|
|
|
generic mesh format
|
|
Generic Mesh Class ____________________________
(for optimized access) |
| Editor
| |
_______________________|________________________________________|
| | | |
| | | |
| | | |
OpenGL D3D Software Export to HDD


This is what I've done before and once you get it up and running it works like a charm and is really easy to blackbox (which also means it's easy to change).

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