Material Based Effects - Lookup

From TDN

So ok, at this point, if you've followed the steps outlined in: Material Based Effects - Material Detection you've got a way to grab the material from an object. Time to make that mean something, by adding some meaningfull data:

Nasty Hack Alert:

You really probably shouldn't use an array as we'll be setting up here, but for now, it's a quick, simple, and above all else, *clear* method for setting up a material functionality index.

materials.h:

#define MAX_MAT_FX 32

class Material : public SimObject

   S32 mFXIndex;

(you'll notice that says FX, not sound, not gfx, ect. the reason for that will becme clear at a later date. Also note that at the moment, the index uses up to 32 possible material settings. I've never had call to use more than 32 types of material on a level, when you get right down to it, but if you absolutely positively *need* more, well, at least it's as simple as changing it in one spot)


initialisation

Material::Material()
{
...
   mFXIndex = 0;
...
}

script hook:

void Material::initPersistFields()
{
...
   addField("FXIndex", TypeS32, Offset(mFXIndex, Material));
...
}

basicly what this boils on down to, is during the material creation process, alongside the bitmap name, translucent blends, glow, ect, you've now got the possibility for an FXIndex entry, wich we'll later be using for an array lookup. (could also use similar methodologies for a friction or restitution modifier, though at time of initial writing that was only aplicable when running from a client-server aplication, *not* a dedicated environment.

Backtrace: Material Based Effects Projects