Changing Interior(dif) textures on the fly - TGE
by Duncan Gray · 09/01/2006 (3:03 pm) · 21 comments
Download Code File
I needed this solution for putting street names on roads for my current game. A search of the forums showed that other people needed a similar solution but had not found an answer. There were conflicting reports about the problems of changing textures affecting ALL interiors which use that texture.
I'm happy to report that none of that is true. Here is why.
bool InteriorInstance::onAdd() is where the material gets instanciated. Near the end of this method you will find...
That call creates a new instance of the material list which is unique to that interior instance. It does, however, copy the list of material pointers passed as a parameter to the constructor. But if you take any Interior instance and point one of it's material pointers to another texture, it will use that new material for that interior instance only.
It does not make unique copies of the material. It's just a matter of taking the current Interior instance and pointing an item in it's material list to some other material.
Try it and see. Here is how to use it.
Unzip the files into your game/interior folder. Do a rebuild all. Yes, rebuild ALL.
To change a skin when the object is first created, do the following. (in script)
%obj = new InteriorInstance() {
position = %myposition;
rotation = %rot;
scale = "1 1 1";
OldSkin = "dirty_old_skin";
NewSkin = "Shiny_new_skin";
interiorFile = "~/data/interiors/awesome.dif";
};
If you then want to update the skin on the fly, during a game, perhaps after an explosion...
%obj.setSkinBase("dirty_old_skin", "Shiny_new_skin" );
You can then swop back again by doing...
%obj.setSkinBase("dirty_old_skin", "dirty_old_skin" );
The format of the setSkinBase call is to have the 1st parameter as the name of the skin you wish to replace and the second parameter must be the skin/texture name you want it replaced with.
Texture/skin names must not have the path or the file extension attached.
i.e. just OLD_BROWN_LEATHER not ~/data/bla/OLD_BROWN_LEATHER.jpg
Yes, it's fully networked as well.
I needed this solution for putting street names on roads for my current game. A search of the forums showed that other people needed a similar solution but had not found an answer. There were conflicting reports about the problems of changing textures affecting ALL interiors which use that texture.
I'm happy to report that none of that is true. Here is why.
bool InteriorInstance::onAdd() is where the material gets instanciated. Near the end of this method you will find...
// Install material list
mMaterialMaps.push_back(new MaterialList(pInterior->mMaterialList));That call creates a new instance of the material list which is unique to that interior instance. It does, however, copy the list of material pointers passed as a parameter to the constructor. But if you take any Interior instance and point one of it's material pointers to another texture, it will use that new material for that interior instance only.
It does not make unique copies of the material. It's just a matter of taking the current Interior instance and pointing an item in it's material list to some other material.
Try it and see. Here is how to use it.
Unzip the files into your game/interior folder. Do a rebuild all. Yes, rebuild ALL.
To change a skin when the object is first created, do the following. (in script)
%obj = new InteriorInstance() {
position = %myposition;
rotation = %rot;
scale = "1 1 1";
OldSkin = "dirty_old_skin";
NewSkin = "Shiny_new_skin";
interiorFile = "~/data/interiors/awesome.dif";
};
If you then want to update the skin on the fly, during a game, perhaps after an explosion...
%obj.setSkinBase("dirty_old_skin", "Shiny_new_skin" );
You can then swop back again by doing...
%obj.setSkinBase("dirty_old_skin", "dirty_old_skin" );
The format of the setSkinBase call is to have the 1st parameter as the name of the skin you wish to replace and the second parameter must be the skin/texture name you want it replaced with.
Texture/skin names must not have the path or the file extension attached.
i.e. just OLD_BROWN_LEATHER not ~/data/bla/OLD_BROWN_LEATHER.jpg
Yes, it's fully networked as well.
About the author

Torque Owner Santosh Pillai
Default Studio Name