You must be logged in to post

Game Development Community

TSE Auto Material Mapper

by Erik Madison · 02/03/2005 (3:51 pm) · 3 comments

Testing new interiors in TSE can be a bit of a pain, having to code a material for each and every texture. If you have normals, masks, bumps, etc your grunt work is even more.
Eventually TSE may adopt a simpler method of adding them, but for now this small snippet will do the work for you. Just add all your textures to one single test directory (QuArK does this for you), and make sure your normals all use the same naming system. In my case, thats texturename_Normal.tga.
When you later decide the interior is a keeper, your console.log will contain a nicely formatted output of the mapping, ready for you to cut/paste into a more permanent home.
I've also considered this method should work well for adding sounds to the materials, simply by making sure all wood textures contain the name wood. That aspect however is not in this code, as sound is not finished for TSE. Just something to consider in the future.

Add this function to the end of materials.cs, adjust the %dir as needed, and you're good to go.
function AutoMaterialMapper()
{
   %dir = "starter.fps/data/interiors/tmpQuArK/";
   for(%filePath = findFirstFile(%dir @ "*"); %filePath !$= ""; %filePath = findNextFile(%dir @ "*")) {
      %fileName = fileName(%filePath);
      %fileBase = fileBase(%fileName);
      %fileExt  = fileExt(%fileName);
      // I use jpg, png and tga exclusively. Adjust as needed.
      if (!strcmp(%fileExt, ".jpg") || !strcmp(%fileExt, ".tga") || !strcmp(%fileExt, ".png")) {
               %fileNormal = %fileBase @ "_Normal";
               %fileTest = %dir @ %fileNormal;
               %com = "datablock Material(" @ %fileBase @ ") {\n";
               %com = %com @ "   baseTex[0] = \"" @ %dir @ %fileBase @ "\";\n";
               // Is there a normal corresponding to this texture?
               if (isFile(%fileTest @ ".jpg") || isFile(%fileTest @ ".tga") || isFile(%fileTest @ ".png"))
                  %com = %com @ "   bumpTex[0] = \"" @ %dir @ %fileNormal @ "\";\n";
               %com = %com @ "   pixelSpecular[0] = false;\n";
               %com = %com @ "   specular[0] = \"1.0 1.0 1.0 0.1\";\n";
               %com = %com @ "   specularPower[0] = 4.0;\n";
               %com = %com @ "};\n";
               echo(%com);
               eval(%com);
               addMaterialMapping(%fileBase, "material: "@%fileBase);
            }
   }
}
AutoMaterialMapper();
Note: There are probably a few ways to optimize this, but I prefered to keep it very readable and expandable. It's only run once, and then only for your testing directory, so you won't notice any slowness. It's also just a temporary hack until TSE figures out its final direction.

#1
02/03/2005 (4:18 pm)
A good chunk of this was based on the demoMaterial script, already in TSE. So, credit where credit is due.
#2
02/03/2005 (5:34 pm)
whoo hoo!
#3
02/05/2005 (3:59 am)
Useful little script :)

I actually create a whole mod folder and had a GUI. Selected a png (auto populated list), then gave that a mapping name. Then simply ticked boxes for the materials features. Then selected a script file you wanted the whole lot to be saved to (this would be auto executed too).