Game Development Community

SetSkinName only works the first time - with fix

by Pete Patterson · in Torque Game Engine Advanced · 02/26/2007 (1:01 pm) · 10 replies

I was able to skin a character, but it only worked the first time. Subsequent attempts did not change the skin.

Quote:
Void TSShapeInstance::reSkin(StringHandle& newBaseHandle)
{
#define NAME_BUFFER_LENGTH 256
static char pathName[NAME_BUFFER_LENGTH];
const char* defaultBaseName = "base"; <<------- this line here only allows skin to be done on base

Fix follows:

Quote:
void TSShapeInstance::reSkin(StringHandle& newBaseHandle)
{
#define NAME_BUFFER_LENGTH 256
static char pathName[NAME_BUFFER_LENGTH];
static char curBaseName[NAME_BUFFER_LENGTH]; << -- added this
...
Quote:
curBaseName[0] = 0;
dStrcat(curBaseName, pName);
if ((ptr = strchr(curBaseName, '.')) != NULL)
{
*ptr = 0;
}


// 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.
bool replacedRoot = makeSkinPath(pathName, NAME_BUFFER_LENGTH, resourcePath,
pName, curBaseName, newBaseName);

#1
03/21/2009 (4:38 am)
Thanks Pete. This works in TGEA 1.81 as well. I can't believe GG haven't implemented a fix yet.
#2
03/21/2009 (4:46 am)
I might be mistaken, but won't this change the texture on the material? And, so in effect, change the skin of every object using the same material?
#3
03/21/2009 (6:19 am)
You're probably right Konrad. I implemented this in order for each character in a game to be able to set their skin multiple times, and I arranged things so that each character had their own material so it wasn't an issue. Only one object in the game was using any of the materials I wanted to change the skin on.
#4
03/23/2009 (4:23 am)
I would probably be helpful if someone could just update the reskin code resource that is already out there and would solve this issue. It worked fine with 1.7.1 but due to the significant changes in 1.8.1 it cannot with out some major revisions.
#5
05/31/2009 (7:12 pm)
any can tell me to use this code?

if ((ptr = strchr(curBaseName, '.')) != NULL)
{
*ptr = 0;
}

i don´t find the ptr variable in my code. I'm working on TGEA 1.8.1

someone can help me? thanks
#6
06/04/2009 (8:15 pm)
I also can't find that variable.
Still trying to figure out.
If anyone got it working, please reply.
Thanks
#7
06/04/2009 (8:36 pm)
OK. I got it working.
You need to declare that pointer yourself. :D

char *ptr = strchr(curBaseName, '.');
if (ptr != NULL)
{
*ptr = 0;
}
#8
08/24/2009 (1:12 am)
good catch @Haider, works like a charm, this is the final function:
void TSShapeInstance::reSkin(NetStringHandle& newBaseHandle)
{
#define NAME_BUFFER_LENGTH 256
   static char pathName[NAME_BUFFER_LENGTH];
   //const char* defaultBaseName = "base"; // reskin, dont needed  
   static char curBaseName[NAME_BUFFER_LENGTH]; // reskin

   String newBaseName;

   if (newBaseHandle.isValidString())
   {
      newBaseName = String(newBaseHandle.getString());
      if (newBaseName.isEmpty())
         return;
   }
   else 
      return; // reskin //newBaseName = tring(defaultBaseName);	  
  

   // Make our own copy of the materials list from the resource
   // if necessary.
   if (ownMaterialList() == false)
      cloneMaterialList();

   Torque::Path   shapePath = hShape.getPath();
   const String   resourcePath = shapePath.getPath();

   // Cycle through the materials.
   TSMaterialList* pMatList = getMaterialList();
   const Vector<String> &materialNames = pMatList->getMaterialNameList();

   for (S32 j = 0; j < materialNames.size(); j++) 
   {
      // Get the name of this material.
      const String &pName = materialNames[j];
      
      if (pName.isEmpty())
         continue;

	  curBaseName[0] = 0;
	  dStrcat(curBaseName, pName);
	  char *ptr = strchr(curBaseName, '.');
	  if (ptr != NULL)
	  {
		  *ptr = 0;
	  } 

      // 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.
     
	  // reskin
	  //bool replacedRoot = makeSkinPath(pathName, NAME_BUFFER_LENGTH, resourcePath,
      //                    pName, defaultBaseName, newBaseName);
	  bool replacedRoot = makeSkinPath(pathName, NAME_BUFFER_LENGTH, 
		  resourcePath, pName, curBaseName, 
		  newBaseName);

	  // end 

      if (!replacedRoot) 
      {
         // If this wasn't in the desired format, set the material's
         // texture handle (since that wasn't copied over in the
         // cloning) and continue.
         pMatList->setMaterial(j, pathName);
         continue;
      }

      // OK, it is a skin texture.  Get the handle.
      // Do a sanity check; if it fails, use the original skin instead.
      if (!pMatList->setMaterial(j, pathName))
      {
         makeSkinPath(pathName, NAME_BUFFER_LENGTH, resourcePath, pName, NULL, NULL);
         pMatList->setMaterial(j, pathName);
      }
   }

}
#9
08/27/2009 (3:05 am)
Tested and working perfectly in AFX 1.8.1.
#10
09/16/2009 (7:43 am)
Thanks. It works perfectly fine for me.

Regards,
Diane
Pret travaux