Missing Model Support (Uber crappy)

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Missing Model Support (Uber crappy)

Post 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.
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 ..
Ranger366
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Re: Missing Model Support (Uber crappy)

Post 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.
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

Would be handy to embed a model in the engine.
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post 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;
}
Ranger366
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Post by Ranger366 »

Nice reckless :D

Can i use this in the GL part of my engine?
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Post 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.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Post 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.
Rikku2000
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany
Contact:

Re: Missing Model Support (Uber crappy)

Post by Rikku2000 »

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...
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Re: Missing Model Support (Uber crappy)

Post 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?
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Missing Model Support (Uber crappy)

Post 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.
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Re: Missing Model Support (Uber crappy)

Post 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.
Post Reply