class Model
{
bool Load(char *filename);
void *RenderFunc;
}
bool Model::Load(char *filename)
{
char *fileExtension;
if(fileExtension == "MD2")
{
LoadMD2Model(filename);
RenderFunc = RenderMD2Model;
}
if(fileExtension == "MD3")
{
LoadMD3Model(filename);
RenderFunc = RenderMD3Model;
}
etc...
}
Check my design for a multiple model loader
I am planning to do more to my 3D engine and just finished reading some tutorials on GameTutorials.com for loading some well known model types.
What I thought would be a good idea was to make a generic class for a model, which doesnt worry about what type of model you want to use, the class will load a model and render it, simple.
So i thought when I load a model i pass in the filename, the function then checks the file extension then calls the appropriate loading routine depending on the model type.
In the class there is a pointer to a rendering function which is asigned properly after the model is loaded, so if i load an .md2 modelthen the rendering function will be set to something like RenderMD2Model().
Heres a sample of the class i wrote down on paper.
this sample doesn''t show how I would normally code or anything (syntax/layout wise just typed it in quickly)
The main thing I was wondering though is all the specific rendering and loading functions like LoadMD2Model, LoadMD3Model etc, where should these go I was thinking of just putting them inthis model class.
I dont know if that was actually a problem cos it sounds logical to me, anyway if u can see any flaws or ways to improve this design please let me know.
If u read all this thanks and sorry if i wasted your time.
I think everyone developing a game engine (and who isn''t these days?) does something similar (re: generic model class).
One thing to note is that the Quake 3 player model consists of multiple MD3 files (lower/upper/head/weapon) from which you must construct a simple hiearhical model. So it''s probably best to store each model in its own directory (with its components, textures, animation config file, copyright info unless you made it, sounds, etc.) and take a directory-based approach to your model reader.
One thing to note is that the Quake 3 player model consists of multiple MD3 files (lower/upper/head/weapon) from which you must construct a simple hiearhical model. So it''s probably best to store each model in its own directory (with its components, textures, animation config file, copyright info unless you made it, sounds, etc.) and take a directory-based approach to your model reader.
I would instead of having one generic model class that was able to load all kinds off supported models make a (virtual) base-class that the other model-classes inherit, something like..
And on top of that you probably want a resource handler that keeps track of which models you've loaded to memory so if two game objects uses the same model, you don't want to load the same model twice, ratcher just give each object a pointer to a loaded model..
/* Everything IMHO */
-Luctus
[edited by - Luctus on December 7, 2002 10:49:49 AM]
class Model{ .. virtual bool Load( char *filename ) = 0; virtual bool SetAnimation( int anim ) = 0; virtual bool AdvanceAnimation( float delta_time ) = 0; virtual bool Render( void ) = 0; ..}class MD2Model : public Model{ bool Load( .. ..}class MD3Model : public Model{ ..}
And on top of that you probably want a resource handler that keeps track of which models you've loaded to memory so if two game objects uses the same model, you don't want to load the same model twice, ratcher just give each object a pointer to a loaded model..
/* Everything IMHO */
-Luctus
[edited by - Luctus on December 7, 2002 10:49:49 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement