Change items skin (texture)
by Leslie Young · 03/31/2003 (11:11 am) · 10 comments
This will work with the latest head as of writing this (I don't know if the previous versions did something different with the skins, but you could try anycase)
The first thing you want to do is have some naming convention for your files.
If you are to make a shape called ITEM.DTS you need some textures like BASE.ITEM.PNG and other (for the different textures you want to use with this shape). The BASE.ITEM.PNG file is the one you use as diffuse map in 3d studio when creating the item shape.
So if you have say 2 more textures for the same shape you would call 'em TEX1.ITEM.PNG and TEX2.ITEM.PNG
Now, in the shape's datablock you could add an extra variable called: skin like this:
Now to actually make the engine use TEX1.ITEM.PNG as the texture (skin) and not BASE.ITEM.PNG we need to add a few more lines of code in item.cs (we will also come back to this datablock)
In item.cs I made the follwing change:
and add a new class-function (you can do this in item.cs too)
and lastly go back to the item's DataBlock and add
like this
And that should do it :)
The first thing you want to do is have some naming convention for your files.
If you are to make a shape called ITEM.DTS you need some textures like BASE.ITEM.PNG and other (for the different textures you want to use with this shape). The BASE.ITEM.PNG file is the one you use as diffuse map in 3d studio when creating the item shape.
So if you have say 2 more textures for the same shape you would call 'em TEX1.ITEM.PNG and TEX2.ITEM.PNG
Now, in the shape's datablock you could add an extra variable called: skin like this:
datablock ItemData(MyItem1)
{
...
shapeFile = "~/data/shapes/items/item.dts"; // <-- our model
...
// Dynamic properties defined by the scripts
skin = "TEX1"; // <-- look here
// another Item DataBlock might use skin = "TEX2";
...
};Now to actually make the engine use TEX1.ITEM.PNG as the texture (skin) and not BASE.ITEM.PNG we need to add a few more lines of code in item.cs (we will also come back to this datablock)
In item.cs I made the follwing change:
function ItemData::create(%data)
{
// The mission editor invokes this method when it wants to create
// ...
%obj = new Item() {
dataBlock = %data;
static = true;
rotate = true;
};
[b]%obj.setSkinName(%data.skin); // <-- add this to change the skin when the editor adds the item[/b]
return %obj;
}and add a new class-function (you can do this in item.cs too)
function MMItem::onAdd(%data, %obj)
{
%obj.setSkinName(%data.skin);
}and lastly go back to the item's DataBlock and add
className = "MMItem";
like this
datablock ItemData(MyItem1)
{
...
shapeFile = "~/data/shapes/items/item.dts"; // <-- our model
className = "MMItem"; // <-- look here
...
// Dynamic properties defined by the scripts
skin = "TEX1"; // <-- look here
// another Item DataBlock might use skin = "TEX2";
...
};And that should do it :)
About the author
Recent Blogs
• TGEA GroundCover Terrain Surface Reference• Still around
• KBM update
• Finally some updates
• KBM.. More update
#2
-----------------------------------------------
// in the script
%sphere = new StaticShape() {
position = "0 0 0";
datablock = SphereData;
};
%sphere.setName(Sphere);
MiscGroup.add(%sphere);
------------------------------------------------
// in the code
StaticShape *sphere = dynamic_cast(WorldData::lookup("ServerGroup/MiscGroup","Sphere"));
if(sphere != NULL)
sphere->setSkinName("tex1");
-------------------------------------
Naming convention:
For the example above you must put a texture file named tex1.sphere.jpg or tex1.sphere.png in the same folder with the .dts file.
-------------------------------------
Notes:
* Texture name must be in the form of.. and then you can set the texture of the object inside the code with objectPtr->setSkinName("");
* It looks first for .jpg and then .png extension in the folder of the .dts file.
05/24/2004 (3:05 am)
Thanks for the basic info. To "on the fly" change texture/skin, to code below works:-----------------------------------------------
// in the script
%sphere = new StaticShape() {
position = "0 0 0";
datablock = SphereData;
};
%sphere.setName(Sphere);
MiscGroup.add(%sphere);
------------------------------------------------
// in the code
StaticShape *sphere = dynamic_cast
if(sphere != NULL)
sphere->setSkinName("tex1");
-------------------------------------
Naming convention:
For the example above you must put a texture file named tex1.sphere.jpg or tex1.sphere.png in the same folder with the .dts file.
-------------------------------------
Notes:
* Texture name must be in the form of
* It looks first for .jpg and then .png extension in the folder of the .dts file.
#3
I've tried this tip using only scripting, but it wont work for me :( I'm using version 1.3. Is it working as well for the recent code base?
BTW, I was applying it to the player class.
Thank you!
12/12/2004 (10:22 am)
Hello, Leslie!I've tried this tip using only scripting, but it wont work for me :( I'm using version 1.3. Is it working as well for the recent code base?
BTW, I was applying it to the player class.
Thank you!
#4
12/07/2005 (7:01 pm)
I love it when methods are simple and work well. I added objects and played with changing the skins from the console! Very cool!
#5
If objects are to be re-skinned when shot (to indicate damage, etc), then go to the shootable's .cs and add this bit of code to the "thing::damage" function:
%obj.setSkinName( "LMN");
This replaces "base.thing.png" for "LMN.thing.png"
05/21/2006 (10:27 pm)
An easy method for reskinning shootables as described in the Game Progammer's Guide to Torque;If objects are to be re-skinned when shot (to indicate damage, etc), then go to the shootable's .cs and add this bit of code to the "thing::damage" function:
%obj.setSkinName( "LMN");
This replaces "base.thing.png" for "LMN.thing.png"
#6
06/25/2007 (12:11 pm)
Does this need the object to have the skins in it's skin list? I'm trying to do something like this with an object derived of TSStatic and it's not working
#7
08/09/2008 (5:20 am)
Awesome...
#8
You really have to pay attention to your naming conventions when creating the .dts.
When you create the .dts file, your base texture HAS to be named properly.
For example, I created a bottle.dts and I used a texture of base.bottle.jpg
Then my various bottle textures are
tex1.bottle.jpg
tex2.bottle.jpg
tex3.bottle.jpg
Also, I should note that I use
datablock ItemData(bottle1Shape)
NOT
datablock StaticShapeData(bottle1Shape)
I'm not sure what the difference is, but Item worked where StaticShape did not.
Tony
I3D
09/09/2008 (2:34 pm)
It works in TGE1.5.2You really have to pay attention to your naming conventions when creating the .dts.
When you create the .dts file, your base texture HAS to be named properly.
For example, I created a bottle.dts and I used a texture of base.bottle.jpg
Then my various bottle textures are
tex1.bottle.jpg
tex2.bottle.jpg
tex3.bottle.jpg
Also, I should note that I use
datablock ItemData(bottle1Shape)
NOT
datablock StaticShapeData(bottle1Shape)
I'm not sure what the difference is, but Item worked where StaticShape did not.
Tony
I3D
#9
Is that more or less efficient than just having a dozen different .dts files "pre-skinned" with different textures? Does it use more resources to load the multiple datablocks or the multiple .dts?
Tony
I3D
09/17/2008 (12:51 pm)
I just realized that you have to write a datablock and a function for each and every texture/skin you want to use.Is that more or less efficient than just having a dozen different .dts files "pre-skinned" with different textures? Does it use more resources to load the multiple datablocks or the multiple .dts?
Tony
I3D
#10
I came across this very interesting thread, and would like to ask the ppl involved - is it possible to change some texture of an avatar in the same manner? I would be VERY thankful for your response - I would like to change the clothes of an avatar in realtime..
Best and thx in advance
Nina
12/09/2008 (8:31 am)
Hello! I came across this very interesting thread, and would like to ask the ppl involved - is it possible to change some texture of an avatar in the same manner? I would be VERY thankful for your response - I would like to change the clothes of an avatar in realtime..
Best and thx in advance
Nina

Torque 3D Owner Jorge Luis Gandulfo
Well i want to make dinamic textures but i have to manage in a different way, i want the player to be able to switch clothes, anyway this is the basic for that, thanks!