Forum

Missing Model Support (Uber crappy)

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Missing Model Support (Uber crappy)

Postby Baker » Wed Jun 01, 2011 6:36 am

Sometimes you are going for elegant. Sometimes you go for "works". This is that 2nd group.

Time matters and sometimes inelegant solutions take 10 minutes and proper ones take potentially days of planning. And in reality, a released mod will not have missing models. Missing model support is important because it allows you to more rapidly develop mods. It is one of the greatest features in DarkPlaces to make life easy on the modder. Sure this doesn't draw the OpenGL colored pyramid that DP does and does need some sort of fallback media, but if you are developing a mod you are really looking for a hack to allow you to merrily continue momentum and not something to cover a major omission in a mod release.

We begin ...

1. Open gl_model.c [model.c in WinQuakey clients or video_hardware_model.cpp in PSP ones and go to Mod_LoadModel function].

And find this ...

Code: Select all
//
// load the file
//
   buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
   <<<< INSERT CODE BELOW HERE>>>>
   if (!buf)
   {
      if (crash)
         Sys_Error ("Mod_LoadModel: %s not found", mod->name);
      return NULL;
   }


And paste this code in the place indicated above that says <<insert code here>> ...

Code: Select all
#define RUNS_WITH_MISSING_MODELS 1
#if RUNS_WITH_MISSING_MODELS
   if (!buf && crash)
   {
      // Reload with another .mdl
      buf = (unsigned *)COM_LoadStackFile("missing_model.mdl", stackbuf, sizeof(stackbuf));
      if (buf)
      {
         Con_Printf ("Missing model %s substituted\n", mod->name);
      }

   }
#endif


Make sure some model called missing_model.mdl is located in quake\id1\progs folder. :lol:

Don't worry, it'll still crash if it can't find the substitute model.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Missing Model Support (Uber crappy)

Postby Ranger366 » Tue Jul 05, 2011 9:56 am

Code: Select all
 buf = (unsigned *)COM_LoadStackFile("progs/missing_model.mdl", stackbuf, sizeof(stackbuf));


Would be correct if missing_model.mdl is supposed to be in the progs folder.

If someone is in need of a missing_model.mdl:
http://www.mediafire.com/?i9dsojjf9e6sk0w :wink:

Thanks Baker, i love small additions anyone can implement with ease.
User avatar
Ranger366
 
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Postby r00k » Tue Jul 05, 2011 9:15 pm

Would be handy to embed a model in the engine.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby revelator » Wed Jul 06, 2011 7:54 am

hmm bit like Q2's NULL model thingy ?

got it working on quake 1 and if no model it draws a pink square :lol:

the funny thing is it doesnt need a model instead it does something a bit like notexture.

Code: Select all
/*
=============
R_DrawNullModel
=============
*/
void R_DrawNullModel(entity_t *e)
{
    int i;

    glPushMatrix();
    R_RotateForEntity(e);

    glDisable(GL_TEXTURE_2D);
    glColor3f(1, 0, 1);

    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(0, 0, -8);
    for (i = 0; i <= 4; i++)
        glVertex3f(8 * cos(i * M_PI * 0.5f), 8 * sin(i * M_PI * 0.5f),
                    0);
    glEnd();

    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(0, 0, 8);
    for (i = 4; i >= 0; i--)
        glVertex3f(8 * cos(i * M_PI * 0.5f), 8 * sin(i * M_PI * 0.5f),
                    0);
    glEnd();

    glColor3f(1, 1, 1);
    glPopMatrix();
    glEnable(GL_TEXTURE_2D);
}


call it in R_DrawViewModel in the check for no model like this

if (!currententity->model)
{
R_DrawNullModel (currententity);
return;
}
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Ranger366 » Wed Jul 06, 2011 9:26 am

Nice reckless :D

Can i use this in the GL part of my engine?
User avatar
Ranger366
 
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Postby mankrip » Thu Jul 07, 2011 2:29 am

However, this could crash the engine if the wrong kind of model is used.

For example, the rendering code for beams and for viewmodels expects the model to be a MDL, and crashes if a BSP is used. Using MDLs would also not work when a solid BSP is expected.

[edit] Yeah, the nullmodel seems to be a better solution.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby revelator » Thu Jul 07, 2011 9:02 am

had a hunch it might be usefull :)

feel free to use the code is allmost straight from Q2 only diff is where you call it.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Missing Model Support (Uber crappy)

Postby Rikku2000 » Thu Jan 26, 2012 5:43 pm

Thats remamber me on the Hl2 error model thats show if there was a missing model. its a good idea :)
I am sorry for my English...
User avatar
Rikku2000
 
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany

Re: Missing Model Support (Uber crappy)

Postby Ghost_Fang » Fri Feb 03, 2012 2:17 am

Hmmm crappy as you say, but definitely works and I might definitely use this. Could this also be used for "model not precached" crash error on some (and PSP) engines? To spawn the "no model" model as well, if the model desired isnt precached?
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Re: Missing Model Support (Uber crappy)

Postby Spike » Fri Feb 03, 2012 2:37 pm

Ghost_Fang wrote:Hmmm crappy as you say, but definitely works and I might definitely use this. Could this also be used for "model not precached" crash error on some (and PSP) engines? To spawn the "no model" model as well, if the model desired isnt precached?

these are not the fixes you are looking for...

models not precached is purely a qc coder's error. note that in engines that do support late precaches you still get a warning or something from setmodel. basically placeholder models still require a valid precache.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Missing Model Support (Uber crappy)

Postby Ghost_Fang » Sat Feb 04, 2012 5:22 pm

Right, I know, I usually have no problems with that. But every once in a while I sometimes get a "X not precached" message, and I enjoy how convenient that is rather than crashing.
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest