Page 1 of 1

Missing Model Support (Uber crappy)

Posted: Wed Jun 01, 2011 6:36 am
by Baker
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.

Re: Missing Model Support (Uber crappy)

Posted: Tue Jul 05, 2011 9:56 am
by Ranger366

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.

Posted: Tue Jul 05, 2011 9:15 pm
by r00k
Would be handy to embed a model in the engine.

Posted: Wed Jul 06, 2011 7:54 am
by revelator
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;
}

Posted: Wed Jul 06, 2011 9:26 am
by Ranger366
Nice reckless :D

Can i use this in the GL part of my engine?

Posted: Thu Jul 07, 2011 2:29 am
by mankrip
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.

Posted: Thu Jul 07, 2011 9:02 am
by revelator
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.

Re: Missing Model Support (Uber crappy)

Posted: Thu Jan 26, 2012 5:43 pm
by Rikku2000
Thats remamber me on the Hl2 error model thats show if there was a missing model. its a good idea :)

Re: Missing Model Support (Uber crappy)

Posted: Fri Feb 03, 2012 2:17 am
by Ghost_Fang
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?

Re: Missing Model Support (Uber crappy)

Posted: Fri Feb 03, 2012 2:37 pm
by Spike
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.

Re: Missing Model Support (Uber crappy)

Posted: Sat Feb 04, 2012 5:22 pm
by Ghost_Fang
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.