SetSkinName for multiple skins on a single object.
by Steve Lamperti · in Torque Game Engine · 10/25/2004 (2:34 pm) · 16 replies
I'm trying to setup setting several skins on the same object using SetSkinName. I have the base.name.pgn concept down, and can set both the clothes and skin of a player, for example, using the function to change the base part, but what I'm looking for now, is the next step. I.E. being able to mix and match skins and clothes. So, for example, I could use the blue.clothes.png, and the red.skin.png, at the same time, instead of just blue.clothes.png and blue.skin.png, or red.clothes.png and red.skin.png. Before I start writing code to do this, I was wondering if I missed a resource or something, and there might be something already available that I could use.
If I didn't describe the question well, or anyone has any suggestions, I would appreciate hearing about it.
If I didn't describe the question well, or anyone has any suggestions, I would appreciate hearing about it.
#2
Thanks for the search suggestion, but that resource is overkill, and also requires art changes. I just want to be able to set the clothes/skin independently. I will look into writing some code, and post it here if anyone wants to see it.
10/26/2004 (8:12 am)
@TedThanks for the search suggestion, but that resource is overkill, and also requires art changes. I just want to be able to set the clothes/skin independently. I will look into writing some code, and post it here if anyone wants to see it.
#3
10/26/2004 (8:36 am)
I'd like to see it :0D
#4
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4051
This is the resource I was looking at by David "RM" Michael. I don't know if it works in any recent versions of Torque. It might get you going as far as coding is concerned.
Oh, and by the way, I would definitely like to see your code if you get anything. If you would like me to check out your code, I would be happy to do that also.
Thanks, Joe
10/26/2004 (8:47 am)
Steve, this feature will be integral to my project also.http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4051
This is the resource I was looking at by David "RM" Michael. I don't know if it works in any recent versions of Torque. It might get you going as far as coding is concerned.
Oh, and by the way, I would definitely like to see your code if you get anything. If you would like me to check out your code, I would be happy to do that also.
Thanks, Joe
#5
10/26/2004 (8:49 am)
If I come up with some good code, I will post it here.
#6
10/26/2004 (12:49 pm)
Got this code working. I'll post in a little bit. Unfortunately the changes are a bit scattered through the codebase, so it'll take me a little while to come up with the complete post.
#7
here's the main routine:
The following code goes in unpackupdate. It replaces the whole // skinMask section.
(I removed the check to see if the handle had changed. On my project the skinmask shouldn't get set unless the handles are different, I don't think.)
The following code goes in packupdate. right after the line
TorqueStringHandle skinDesiredNameHandle = con->unpackStringHandleU(stream);
lastly in shapebase, but not leastly, calls to reSkin need 'this' added to them.
this one is from onnewdatablock.
to be continued
10/26/2004 (1:31 pm)
First off, changes in shapebase.cchere's the main routine:
// JSL - Specific skin
void ShapeBase::setSkinSpecific(const char* name, const char *skinLocation)
{
long which = -1;
if (!isGhost())
{
if (name[0] != '[[628152b789664]]')
{
which = mShapeInstance->whichMaterial(skinLocation);
if (which < 0 || which > 5)
return;
// Use tags for better network performance
// Should be a tag, but we'll convert to one if it isn't.
if (name[0] == StringTagPrefixByte)
mSkinNameSpecific[which] = TorqueStringHandle(U32(dAtoi(name + 1)));
else
mSkinNameSpecific[which] = TorqueStringHandle(name);
}
else
mSkinNameSpecific[which] = TorqueStringHandle();
setMaskBits(SkinMask);
}
}The following code goes in unpackupdate. It replaces the whole // skinMask section.
(I removed the check to see if the handle had changed. On my project the skinmask shouldn't get set unless the handles are different, I don't think.)
if (stream->readFlag()) { // SkinMask
TorqueStringHandle skinDesiredNameHandle = con->unpackStringHandleU(stream);
// JSL - specific skin
mSkinNameSpecific[0] = con->unpackStringHandleU(stream);
mSkinNameSpecific[1] = con->unpackStringHandleU(stream);
mSkinNameSpecific[2] = con->unpackStringHandleU(stream);
mSkinNameSpecific[3] = con->unpackStringHandleU(stream);
mSkinNameSpecific[4] = con->unpackStringHandleU(stream);
mSkinNameHandle = skinDesiredNameHandle;
if (mShapeInstance)
{
mShapeInstance->reSkin(mSkinNameHandle, this); // JSL - specific skin
if (mSkinNameHandle.isValidString())
mSkinHash = _StringTable::hashString(mSkinNameHandle.getString());
}
}The following code goes in packupdate. right after the line
TorqueStringHandle skinDesiredNameHandle = con->unpackStringHandleU(stream);
// JSL - specific skin
con->packStringHandleU(stream, mSkinNameSpecific[0]);
con->packStringHandleU(stream, mSkinNameSpecific[1]);
con->packStringHandleU(stream, mSkinNameSpecific[2]);
con->packStringHandleU(stream, mSkinNameSpecific[3]);
con->packStringHandleU(stream, mSkinNameSpecific[4]);lastly in shapebase, but not leastly, calls to reSkin need 'this' added to them.
this one is from onnewdatablock.
mShapeInstance->reSkin(mSkinNameHandle, this); // JSL - specific skin
to be continued
#8
I added the following right below the defination of mSkinNameHandle.
and the following right below the def of getSkinName
There are two calls to reSkin in shapeImage.cc that need to have ',this' added to them as a second argument. (I'm passing in this to reSkin as an easy way to get to my specific skin variables, there's probably a better way to do this. If anyone wants to suggest it, I'd love to improve the code.)
TsShapeInstance.cc
the reskin function now looks like this:
add the following to the declarations at the top of the reSkin function.
and the following above the comment that reads
// Make our own copy of the materials list from the resource
// if necessary.
right before the comment that reads:
// Make a texture file pathname with the new root if this name
// has the old root in it; otherwise just make a path with the
// original name.
add the following code:
Here's a new routine for tsShapeInstance, that I added right below reSkin:
tsshapeInstance.h
New proto for reSkin, and the proto for whichMaterial:
I think that's everything. I'm sure I'll hear if it's not. If anyone thinks of ways to do pieces of this better, please post them here.
10/26/2004 (1:31 pm)
Shapebase.hI added the following right below the defination of mSkinNameHandle.
public: TorqueStringHandle mSkinNameSpecific[5]; // JSL - Specific skin
and the following right below the def of getSkinName
void setSkinSpecific(const char* name, const char *skinLocation); // JSL - specific skin
There are two calls to reSkin in shapeImage.cc that need to have ',this' added to them as a second argument. (I'm passing in this to reSkin as an easy way to get to my specific skin variables, there's probably a better way to do this. If anyone wants to suggest it, I'd love to improve the code.)
TsShapeInstance.cc
the reskin function now looks like this:
void TSShapeInstance::reSkin(TorqueStringHandle& newBaseHandle, ShapeBase *theShape) // JSL - specific skin
add the following to the declarations at the top of the reSkin function.
const char* saveBaseName; // JSL specific skin
and the following above the comment that reads
// Make our own copy of the materials list from the resource
// if necessary.
saveBaseName = newBaseName; // JSL specific skin
right before the comment that reads:
// Make a texture file pathname with the new root if this name
// has the old root in it; otherwise just make a path with the
// original name.
add the following code:
// JSL - V7.0 specific skin code
if (j<5 && theShape->mSkinNameSpecific[j].isNull() == false)
newBaseName = theShape->mSkinNameSpecific[j].getString();
else
newBaseName = saveBaseName;Here's a new routine for tsShapeInstance, that I added right below reSkin:
// JSL - for specific skin code
long TSShapeInstance::whichMaterial(const char *skinLoc)
{
char *period, *specificName;
// Make our own copy of the materials list from the resource if necessary.
setMaterialList(mShape->materialList);
if (ownMaterialList() == false)
cloneMaterialList();
// Cycle through the materials.
TSMaterialList* pMatList = getMaterialList();
for (S32 j = 0; j < pMatList->mMaterialNames.size(); j++)
{
// Get the name of this material.
const char* pName = pMatList->mMaterialNames[j];
// Bail if no name.
if (pName == NULL)
continue;
// find the second part of the material name
period = dStrchr((char *) pName, '.');
if (period == NULL)
continue;
specificName = period+1;
// if they compare, that's our material.
if (dStrcmp(specificName, skinLoc) == 0)
return(j);
}
return(-1);
}tsshapeInstance.h
New proto for reSkin, and the proto for whichMaterial:
void reSkin(TorqueStringHandle& newBaseHandle, ShapeBase *theShape); // JSL - specific skin long whichMaterial(const char *skinLoc); // JSL - specific Skin
I think that's everything. I'm sure I'll hear if it's not. If anyone thinks of ways to do pieces of this better, please post them here.
#9
10/26/2004 (3:50 pm)
Edited in a fix for reSkin, checking to see if j < 5.
#10
Is it still base.skinname.ext compatible, so I can have texture sets, or do I have to change something? This looks like an awesome resource and would solve a lot of my problems flat out... but I don't see any usage notes so I'm a touch afraid...
How do you use this exactly please? It looks easy enough to modify in and compile... :)
02/10/2005 (7:42 am)
So what texture naming convention do you need to use in order to use these changes?Is it still base.skinname.ext compatible, so I can have texture sets, or do I have to change something? This looks like an awesome resource and would solve a lot of my problems flat out... but I don't see any usage notes so I'm a touch afraid...
How do you use this exactly please? It looks easy enough to modify in and compile... :)
#11
I have models setup correctly and all seems fine but the reSkin isn't doing it's job.
If you have time could you contact me?
Ari
10/04/2006 (11:35 pm)
I'm having a bit of trouble with this.I have models setup correctly and all seems fine but the reSkin isn't doing it's job.
If you have time could you contact me?
Ari
#12
This was posted quite a while ago, and I am not sure if the code as posted is still up to date, but I am still using it in my project, and it's working fine there. Let me know more about what is not working for you, and I will try to see if I have anything to offer.
@Gregory,
Sorry, I didn't see your post. The naming convention is as described in my first post on this thread. In my case:
base.maleclothes.png, and base.maleskin.png.
10/05/2006 (9:00 am)
@Ari,This was posted quite a while ago, and I am not sure if the code as posted is still up to date, but I am still using it in my project, and it's working fine there. Let me know more about what is not working for you, and I will try to see if I have anything to offer.
@Gregory,
Sorry, I didn't see your post. The naming convention is as described in my first post on this thread. In my case:
base.maleclothes.png, and base.maleskin.png.
#13
Can you post or email the modified files?
I've been struggling on this for some time. :/
Ari
10/14/2006 (12:16 am)
I thought I got through the code and now I'm getting segfaults on the reSkin.Can you post or email the modified files?
I've been struggling on this for some time. :/
Ari
#14
I looked through the code, and didn't see any changes from what was posted that look significant. I think you will have to do some debugging on your end. If you find something that seems to be missing and can point me to a more specific part of the code, I will be glad to look into it and see if something changed.
10/16/2006 (9:27 am)
@ari,I looked through the code, and didn't see any changes from what was posted that look significant. I think you will have to do some debugging on your end. If you find something that seems to be missing and can point me to a more specific part of the code, I will be glad to look into it and see if something changed.
#15
11/16/2006 (9:48 am)
Nice resource! thanks
#16
Hopefully I can take you up on that when I have some time.
11/16/2006 (10:13 am)
Been real busy, thank you much for the offer! :)Hopefully I can take you up on that when I have some time.
Torque 3D Owner Ted Southard