Web Update 19.10.2024

Texture Replacement

You are here:
Estimated reading time: 1 min
In this article

The Texture-Replacement effect kind is a named effect container within a “mesh-table” Container. It can be used within the load subcontainer to provide alternative textures. The name of the texture-replacement effects subcontainer is selected by the content developer. It may be used as a reference in a script file to identify a specific effect. 

The name of the texture that is to be replaced. This is the name of the texture file as used in the asset’s config.txt, without the .txt extension. For instance, if the texture to be replaced is identified in the ‘load-map.texture.txt’ file, then the texture tag in the effect container is “load-map.texture”.

A texture-replacement effect is often used when the texture of an asset should be changed during game play. For instance, when the load texture is to be replaced then this texture will be replaced by the texture contained in the product referenced in the current active product queue, as defined by the allowed-categories subcontainer in the queue. For instance, if a coal hopper loads at an industry asset that produces a bulk-load other than its default load (eg woodchips at a lumbermill), then the woodchip product texture will replace the default coal product texture

Config
script                                  "house.gs"
class                                   "eHouse"

obsolete-table
{
}

mesh-table
{
  mesh
  {
    auto-create                         1
    mesh                                "lod.lm"
    
    effects
    {
      parameter-windows_and_dors_parameters
      {
        kind                            "texture-replacement"
        texture                         "windows_and_dors_parameters.texture"
      }
    }
  }
}
Script

This script switches textures based on game time. So it switches between night and day mode.

include "asset.gs"
include "buildable.gs"
include "gs.gs"

class eHouse isclass Buildable
{
    thread void CheckTime();

    int isDay;
    int lastSet = -1;

    void Init(Asset asset)
    {
        // call the parent
        inherited(asset);
        CheckTime();
    }

    thread void CheckTime()
    {
        while (true)
        {
            if(World.GetGameTime() * 24 > 6 and World.GetGameTime() * 24 < 18)
            {
                isDay = 0;
            }
            else
            {
                isDay = 1;
            }
            
            if(lastSet != isDay)
            {
                if(isDay == 1)
                {
                    Interface.Log("NOW UNLIT");
                    SetFXTextureReplacementTexture("parameter-windows_and_dors_parameters", "windows_and_dors_parameters.texture");
                    lastSet = 1;
                }
                if(isDay == 0)
                {
                    Interface.Log("NOW LIT");
                    SetFXTextureReplacementTexture("parameter-windows_and_dors_parameters", "windows_and_dors_n_parameters.texture");
                    lastSet = 0;
                }
            }
            
            Sleep(10);
        }
    }

};
Texture-replacement can be used by content developers to achieve a range of interesting and novel scripted effects, though there are some considerations that should be noted. Whether performance will be adversely affected is dependant upon numerous variables. When it comes to predicting the performance impact of a particular texture-replacement implementation, the only reliable answer is: test it and see.
Was this article helpful?
Dislike 0 2 of 2 found this article helpful.
Views: 24
Alpinetrainz
Logo
Shopping cart