Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

JinJo

Check my design for a multiple model loader

This topic is 5647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
  
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...
}

  
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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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..

      
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!