Page 1 of 1

Displaying models in the menu with non-default skin

Posted: Tue Jul 26, 2011 4:01 am
by bludshot
I'm working on a weapon selection in-game menu (resuming a mod project I haven't worked on in quite some time), and I need to display the same model twice but with different skins.

So I have two of these itemDefs in my menu:

itemDef
{
name he_model
type ITEM_TYPE_MODEL
(etc, etc)
asset_model "models/weapons2/grenade/grenade.MD3"
(etc etc)
}

By default, this displays the grenade model with its default skin. But for one of them I want to display it with a different skin (one is a high explosive grenade, the other is a smoke grenade).

I sort of chased it down to Item_Model_Paint() but how to get it to display other skins is kind of blowing my mind right now, I just have no idea how.

It seems like ent.hModel is given an integer number that corresponds to some magical hidden array of assets that the game loads at runtime in the order that the menu tries to display them. So the closest I have guessed so far is that ent.customSkin also has a corresponding magical hidden spot with a value and it's that value I need to change.. or something?

Or maybe I'm way off track.

Any ideas?

Thanks

Re: Displaying models in the menu with non-default skin

Posted: Tue Jul 26, 2011 4:36 am
by bludshot
in Item_Model_Paint() under the existing line: ent.hModel = item->asset; I have added the line:
ent.customSkin = trap_R_RegisterSkin("models/weapons2/grenade/grenade_smoke.skin");

The compiler gives a warning that trap_R_RegisterSkin is undefined, (this is because Item_Model_Paint() is in ui_shared.c and that trap is in ui_local.h) yet it still seems to function at runtime regardless.

So now both my grenades show with the smoke grenade skin (as you would expect) and all my other weapons show the 'missing texture' texture (I actually expected them to show the smoke grenade skin all out of whack, but I guess because that skin is not meant for those other guns it just fails).

So now all I have to do is somehow do an if statement that says If this is the smoke grenade model, use this other skin. (Of course, that's very hackish and isn't remotely as nice as adding true support for multiple skins loaded right out of the menu with some new itemDef attribute, but, it would do for now since doing something that nice is definitely beyond me right now.)

But I don't know how to tell what model Item_Model_Paint is attempting to display... :shrug: The function receives (itemDef_t *item), but the itemDef_t struct doesn't contain a string with the model path and filename in it, it just has "qhandle_t asset" which is just an integer. I know what that integer is for any given model, so if I knew the method of accessing what the model name string was using that integer, then I could access it and see if it was a grenade. But then I still wouldn't know which grenade it was. So it seems I need some other way of knowing which itemDef is calling Item_Model_Paint... It seems there are some itemDef attributes that I could check to know which itemDef it is. You would THINK you could check the name! But no, it doesn't seem to be the case. EDIT: No wait, apparently you can. Looks like maybe I can get it like, itemDef -> window -> name. Guess that'll do it?

I'll post more later

Re: Displaying models in the menu with non-default skin

Posted: Tue Jul 26, 2011 10:52 pm
by bludshot
Yeah, here is the solution to my issue:

All I had to do was add this in Item_Model_Paint():

if (!Q_stricmp(item->window.name, "smoke_model")) {
ent.customSkin = trap_R_RegisterSkin( "models/weapons2/grenade/grenade_smoke.skin" ); }

"smoke_model" is the name of the itemDef in my menu that is 'calling' Item_Model_Paint() to display a model (of a smoke grenade).

It does however create a compiler warning: warning c4013: 'trap_R_RegisterSkin' undefined; assuming extern returning int
So I'd still like to fix that. My guess was that I could some how pre-register the skin with cgs.media, but it's out of scope for the UI. So I'm going to try to see if there's a UI equivalent

Re: Displaying models in the menu with non-default skin

Posted: Tue Jul 26, 2011 11:37 pm
by bludshot
There does not seem to be a UI equivalent of cgs.media. So what I did was I just copied the line: qhandle_t trap_R_RegisterSkin( const char *name ); from ui_local.h and stuck it on the end of ui_shared.h and that solved the compiler warning.

Is it ok to do that? I guess it totally is...