Game Development Community

Chaning Material per object instance in one client only [SOLVED]

by Francisco Montanes · in Torque 3D Professional · 03/15/2013 (11:02 am) · 3 replies

Hi there! I have a client who is a thermal camera, so it has to show a different IR texture. I want to change the material of every object instance but only in that client. Is it possible? I tried with changeMaterial() but It doesn't work.

#1
03/18/2013 (3:50 am)
I think the best way will be modifying the engine... I could give access to function void ShapeBase::reSkin() to the client from script...
#2
03/18/2013 (5:32 am)
Very simple! I've made minor changes in source:

From this:
void ShapeBase::setSkinName(const char* name)
{
   if (!isGhost()) {
      if (name[0] != '\0') {
         // Use tags for better network performance
         // Should be a tag, but we'll convert to one if it isn't.
         if (name[0] == StringTagPrefixByte)
            mSkinNameHandle = NetStringHandle(U32(dAtoi(name + 1)));
         else
            mSkinNameHandle = NetStringHandle(name);
      }
      else
         mSkinNameHandle = NetStringHandle();
      setMaskBits(SkinMask);
   }
}
To this:
void ShapeBase::setSkinName(const char* name)
{
	if (name[0] != '\0') {
		// Use tags for better network performance
		// Should be a tag, but we'll convert to one if it isn't.
		if (name[0] == StringTagPrefixByte)
			mSkinNameHandle = NetStringHandle(U32(dAtoi(name + 1)));
		else
			mSkinNameHandle = NetStringHandle(name);
	}
	else
		mSkinNameHandle = NetStringHandle();

   if (!isGhost())
      setMaskBits(SkinMask);
   else
	  reSkin();	     
}

Just call setSkinName in a ghost object.
%obj.setSkinName("Camo");

#3
03/19/2013 (9:06 am)
Inserting this only on the client that we choose, it will have thermal skins in all vehicles.

function GameBase::onAddOnClient(%this)
{
   if (%this.getType() & $TypeMasks::VehicleObjectType){
      //%this.setSkinName("base");
      %this.setSkinName("IR");
   }
}

In other to make execute this function on client I had to mod the source code adding this to GameBase::onAdd():
if( isClientObject() && isMethod("onAddOnClient") )
	   Con::executef( this, "onAddOnClient" );

That's the result: