my idea for a mesh class
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?
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.
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.
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 HDDThis 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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement