TSE Static Shape material swap
by Bryan Stroebel · 08/17/2006 (12:11 pm) · 1 comments
This code allows you to swap materials/skins on static objects. This is a TSE modified version of the TGE reskin functionality. You NEED to implement this resource first or the following code will not work.
Open game/tsStatic.h
add the following around lin e18. right after the resmanager stuff
now add this around line 93 right after Vector mLOSDetails;
now add this to the end of the class right after unpackUpdate(line 115)
Open game/tsStatic.cpp. add the following to the end of the file:
find the TSStatic::packUpdate method and add this right before return retMask;
Now find the TSStatic::unpackUpdate method and add this to the end of the methos before the closing bracket
To use this simply specify the orginal material and the new material.
Obj.setSkinName(original_Material_Name, New_Material_Name);
I designed it so you wouldn't have to keep track of the names as you swap them out. The original name is the original mapTo name. The new name
is the name of the new material. This works the same as the shapebase method above.
Open game/tsStatic.h
add the following around lin e18. right after the resmanager stuff
//BCS - added for swap material #ifndef _NETSTRINGTABLE_H_ #include "sim/netStringTable.h" #endif
now add this around line 93 right after Vector
//BCS - added for material swap U32 mSkinHash; StringHandle mSkinNameHandle; StringHandle mNewSkinNameHandle;
now add this to the end of the class right after unpackUpdate(line 115)
//BCS - added for swap material
enum MaskBits {
SkinMask = Parent::NextFreeMask,
NextFreeMask = Parent::NextFreeMask << 1
};
void setSkinName(const char*,const char*);Save this file.Open game/tsStatic.cpp. add the following to the end of the file:
//BCS - added for material swap
void TSStatic::setSkinName(const char* name,const char* newSkinName)
{
// this method gets the skin names ready for network passage
if (!isGhost()) {
if (name[0] != '[[60c1e3d5c8c00]]') {
if (name[0] == StringTagPrefixByte) {
mSkinNameHandle = StringHandle(U32(dAtoi(name + 1)));
}
else {
mSkinNameHandle = StringHandle(name);
}
}
else {
mSkinNameHandle = StringHandle();
}
if (newSkinName[0] != '[[60c1e3d5c8c00]]') {
if (newSkinName[0] == StringTagPrefixByte) {
mNewSkinNameHandle = StringHandle(U32(dAtoi(newSkinName + 1)));
}
else {
mNewSkinNameHandle = StringHandle(newSkinName);
}
}
else {
mNewSkinNameHandle = StringHandle();
}
setMaskBits(SkinMask);
}
}
//BCS - added for swap material
ConsoleMethod( TSStatic, setSkinName, void, 4, 4, "(materialName,newMaterialName)")
{
object->setSkinName(argv[2],argv[3]);
}find the TSStatic::packUpdate method and add this right before return retMask;
//BCS - added for material swap
if (stream->writeFlag(mask & SkinMask)) {
con->packStringHandleU(stream, mSkinNameHandle);
con->packStringHandleU(stream, mNewSkinNameHandle);
}Now find the TSStatic::unpackUpdate method and add this to the end of the methos before the closing bracket
mShapeName = stream->readSTString();
//BCS - added for material swap
if (stream->readFlag()) { // SkinMask
StringHandle skinDesiredNameHandle = con->unpackStringHandleU(stream);
StringHandle newskinDesiredNameHandle = con->unpackStringHandleU(stream);
if (mSkinNameHandle != newskinDesiredNameHandle) {
mSkinNameHandle = newskinDesiredNameHandle;
if (mShapeInstance) {
mShapeInstance->reSkin(skinDesiredNameHandle,newskinDesiredNameHandle);
if (mSkinNameHandle.isValidString()) {
mSkinHash = _StringTable::hashString(mSkinNameHandle.getString());
}
}
}
}Save and compile.To use this simply specify the orginal material and the new material.
Obj.setSkinName(original_Material_Name, New_Material_Name);
I designed it so you wouldn't have to keep track of the names as you swap them out. The original name is the original mapTo name. The new name
is the name of the new material. This works the same as the shapebase method above.
About the author

Torque 3D Owner iHugMedia