Game Development Community

Changing skin on-fly

by Funky Diver · in Torque Game Engine · 12/12/2004 (10:30 am) · 11 replies

Greetings!

I would like to change a player's skin on fly. I've tried this code snipit, but it wont work for me. It's just doesnt change the player's skin, the player appears with the default skin.

The %player.getSkinName() returns the correct skin tag just after %player.setSkinName(%skin)...
It seems that the skin tag was set correctly, but engine does not change the skin...

I'm using 1.3 build and would llke to change the player's skin only by script.

Can anybody help with a small working example for version 1.3?
Thank you a lot!

#1
12/13/2004 (11:41 am)
Anyone? :)
#2
12/13/2004 (5:53 pm)
It should work in 1.3, just be sure that you are following the naming conventions for the textures mentioned in the tutorial.
#3
04/07/2005 (12:01 pm)
Hi all;
I couldn't make this resourse work!! Ca anyone post a working example?

thanks in advance.
#4
04/07/2005 (12:05 pm)
No offence, but people tend to offer assitance when you give them something more... like a list of errors that the console is spitting at you, or compilation errors... It sounds like you tried to get it going, on the first sign of trouble you ran here hoping someone would fix it for you.

Once again, no offence
#5
04/07/2005 (12:15 pm)
I havent used the resource you mentioned but i have added this this one so it shoud work.. like josh said make sure the textures are named correctly
#6
04/07/2005 (12:23 pm)
Pre-Script:
Sometimes I fire too quickly, but what the heck. This data should be easily found now. 'Kevin Johnson' posted a link above, which re-iterates (or would that be pre-iterates) what I've said here. ALSO, it is the resource I mentioned in my PS regarding fixing multi-skin.

Hopefully this with the resources and prior posts will answer all subsequent queries on this matter.


@Alexander,

To get setSkinName() to work, you need to follow these steps:

1. Create a single skin (texture) with the following naming convention:
base.setName.suffix, where

base - Special string that the engine looks for. This tells the engine that the next part of the name is the group name for this 'set' of textures.
setName - This string is the 'set' name. It is used to group a set of textures. The engine associates all textures in this group with the mesh that the initial texture is applied to.
suffix - PNG, JPG, etc.


2. Apply this skin to your model.


3. Create a set of skins (textures) with the following naming convention:
skinName.setName.suffix, where

skinName - This is the name that the skin will be referenced by later when re-skinning.
setName - Must match base skin's setName.
suffix - PNG, JPG, etc.


4. Later in script you can change the skin of the shapeBase object (did I' mention this only works for shapeBase derived objects) by using this code:
%obj.setSkinName("skinName");
, or better yet if you are going to do this often, use a tag:
%obj.setSkinName('skinName');



To be absolutely clear, a sample of the base skin texture name would be:

base.skin.png

, and the skins I might use would be named like this:

skin0.skin.png
skin1.skin.png
skin2.skin.png


Hope this helps.

Also, for your's and others information, all kinds of topics like this are completely covered in the upcoming EGTGE Volumes 1 & 2.

Cheers,

www.hallofworlds.com/how.ico Hall Of Worlds, LLC
EdM|EGTGE



PS - Before you ask. You can do this for multiple textures on the same model, BUT if you do so without making the approriate fix to the engnie, setting one skin name will reset all other skins to the base skin (on that model). i.e. If you have two re-skinabble skins A and B on model myModel, doing setSkin() for A will reset B to its base skin and vice-versa. For cases like this you must make a code fix to the engine (there is a resouce for this I'm pretty sure), or use IFLs instead.

You probably want to use an IFL anyways if you intend to change the skin quickly and frequently. Yes, IFLs are also covered in the guide. :)


-EFM
#7
04/07/2005 (1:04 pm)
@Chris - Yes you are right I should have given more info. but I didnt post this after only one try of that resource.
@Kevin and Edward. thanks for the info. I've seen that resource but haven't tried yet as I'm currently working on changing texture of a simple cube during the game and always thought that resource would only good for player objects.

I'm just trying to test if this works for changing texture. So wrote a simple script to spawn a healthKit with different .jpg eveytime it's used, and it wasnt working. I'll try to implement Edward's post...

Thanks,
#8
04/07/2005 (1:07 pm)
@Architect,

Yes, the tricky parts are:

A. Using the right skin name when making your model.
B. Correctly naming your 'alternate' skins.


www.hallofworlds.com/how.ico Hall Of Worlds, LLC
EdM|EGTGE
#9
04/07/2005 (1:29 pm)
Ok. I'll implement this to test changing cube texture with right name conventions..etc.. and hope for the best...

Thanks again Edward...
#10
04/09/2005 (10:58 am)
@Architect,

You got that licked? i.e. Any probs getting that to work? Any other questions?
www.hallofworlds.com/how.ico Hall Of Worlds, LLC
EdM|EGTGE
#11
06/22/2009 (2:21 am)
I want to change the image of the material,not use one image to replace another one .So I must get the bitmap of the material ,but I don't know how to do it.I have wrote a function in the materialDefinition.cpp ,but it doesn't work.

void Material::mixWithColor(ColorI &cor)
{
String filename = mPath + mBaseTexFilename[0];
Resource<GBitmap> bitmap = GBitmap::load(filename);

ColorI resCor(0 , 0 , 0);
GBitmap bitmapMirr(*bitmap);
for(U32 x = 0 ; x < bitmapMirr.getHeight() ; ++x)
{
for(U32 y = 0 ; y < bitmapMirr.getWidth() ; ++y)
{
bitmapMirr.getColor(x ,y ,resCor);
if(resCor.alpha != 0)
{
resCor &= cor;
bitmapMirr.setColor(x , y , resCor);
}
}
}
MatInstance* pMat = dynamic_cast<MatInstance*>(MaterialManager::get()->createMatInstance(mMapTo));
GFXMaterialFeatureData::FeatureListHandle f = MaterialManager::get()->getDefaultFeatureData().codify();
pMat->processMaterial(f);
//GFXTexHandle handle = this->mStages[0].mTex[0];
GFXTexHandle handle = pMat->getProcessedMaterial()->mStages[0].mTex[0];

//GBitmap* pBitmap = handle.getBitmap();
handle.set(&bitmapMirr , &GFXDefaultRenderTargetProfile , true , "material image");
}

Anybody can help thanks!