OsSetTerrainTexture

From OpenSimulator

Jump to: navigation, search
osSetTerrainTexture(integer level, key texture)
Set the terrain texture of the estate to the texture given as key. The level can be 0, 1, 2 or 3.
Threat Level High
Permissions ESTATE_MANAGER,ESTATE_OWNER
Extra Delay 0 seconds
Example(s)
// Default Terrain Textures by djphil 2018
 
default
{
    state_entry()
    {
        osSetTerrainTexture(0, "b8d3965a-ad78-bf43-699b-bff8eca6c975");
        osSetTerrainTextureHeight(0, 10.0, 60.0);
        osSetTerrainTexture(1, "abb783e6-3e93-26c0-248a-247666855da3");
        osSetTerrainTextureHeight(1, 10.0, 60.0);
        osSetTerrainTexture(2, "179cdabd-398a-9b6b-1391-4dc333ba321f");
        osSetTerrainTextureHeight(2, 10.0, 60.0);
        osSetTerrainTexture(3, "beb169c7-11ea-fff2-efe5-0f24dc881df2");
        osSetTerrainTextureHeight(3, 10.0, 60.0);
    }
}
// Random Terrain Texture
 
integer gTimerInterval = 300;  // 300 seconds (5 minutes)
 
changeTextures()
{
    // Get the number of terrain textures in the prim inventory
    integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
 
    // If there is at least one terrain texture
    if (numTextures > 0)
    {
        // Loop through each corner
        integer i;
        for (i = 0; i < 4; ++i)
        {
            // Select a random terrain texture from the inventory
            string randomTextureName = llGetInventoryName(INVENTORY_TEXTURE, llFloor(llFrand(numTextures)));
 
            // Get the UUID
            key randomTextureUUID = llGetInventoryKey(randomTextureName);
 
            // Set the selected terrain texture for the current corner
            osSetTerrainTexture(i, randomTextureUUID);
 
            // Display the selected random texture UUID in chat
            llOwnerSay("Selected random terrain texture" + (string)i + ": " + randomTextureName + " - " + randomTextureUUID);
        }
    }
    else
    {
        llOwnerSay("No terrain textures found in the prim inventory.");
    }
}
 
default
{
    state_entry()
    {
        // Start the timer to change textures every xxx seconds
        llSetTimerEvent(gTimerInterval);
        // Initial texture change
        changeTextures();
    }
 
    timer()
    {
        // Change textures when the timer fires
        changeTextures();
    }
}
/*
osSetTerrainTexture(integer level, key texture)
osSetTerrainTextureHeight(integer corner, float low, float high) 
 
Material:
Base Color
Metallic-Roughness
Emissive
Normal
*/
 
// This line defines an integer variable 'currentTextureSet'.
// This variable is used to store the current texture set.
// The value 0 represents Texture Set A, and the value 1 represents Texture Set B.
integer currentTextureSet = 0;
float TextureLow = 10.0;
float TextureHigh = 60.0;
 
// Standard Texture Set A (Base color only)
key Terrain_Dirt_A = "b8d3965a-ad78-bf43-699b-bff8eca6c975";
key Terrain_Grass_A = "abb783e6-3e93-26c0-248a-247666855da3";
key Terrain_Mountain_A = "179cdabd-398a-9b6b-1391-4dc333ba321f";
key Terrain_Rock_A = "beb169c7-11ea-fff2-efe5-0f24dc881df2";
 
// PBR Texture Set B (Material)
key Terrain_Dirt_B = "8da1cb17-8ced-4a70-94e8-41b2c45d952d";
key Terrain_Grass_B = "4d1ec4f5-069a-4301-aa12-7d3cc5d46a70";
key Terrain_Mountain_B = "95b317e4-c671-46d3-818a-270641aeb463";
key Terrain_Rock_B = "f1bc94f2-f276-4aff-8687-5501e42148ac";
 
// This function sets the texture to Texture Set A.
// It is called to set the default texture set.
setTextureSetA()
{
    osSetTerrainTexture(0, Terrain_Dirt_A);
    osSetTerrainTextureHeight(0, TextureLow, TextureHigh);
    osSetTerrainTexture(1, Terrain_Grass_A);
    osSetTerrainTextureHeight(1, TextureLow, TextureHigh);
    osSetTerrainTexture(2, Terrain_Mountain_A);
    osSetTerrainTextureHeight(2, TextureLow, TextureHigh);
    osSetTerrainTexture(3, Terrain_Rock_A);
    osSetTerrainTextureHeight(3, TextureLow, TextureHigh);
}
 
// This function sets the texture to Texture Set B.
// It is called to set the alternative texture set.
setTextureSetB()
{
    osSetTerrainTexture(0, Terrain_Dirt_B);
    osSetTerrainTextureHeight(0, TextureLow, TextureHigh);
    osSetTerrainTexture(1, Terrain_Grass_B);
    osSetTerrainTextureHeight(1, TextureLow, TextureHigh);
    osSetTerrainTexture(2, Terrain_Mountain_B);
    osSetTerrainTextureHeight(2, TextureLow, TextureHigh);
    osSetTerrainTexture(3, Terrain_Rock_B);
    osSetTerrainTextureHeight(3, TextureLow, TextureHigh);
}
 
default
{
    state_entry()
    {
        // This function is called upon entering the state.
        // It sets the initial texture set to Texture Set A.
        setTextureSetA();
    }
 
    touch_start(integer total_number)
    {
        // This function is called when the object is touched.
        // It toggles between Texture Set A and B.
        if (currentTextureSet == 0)
        {
            setTextureSetB();
            currentTextureSet = 1;
        }
        else
        {
            setTextureSetA();
            currentTextureSet = 0;
        }
    }
}
Notes
This function was added in 0.7.4-post-fixes
Personal tools
General
About This Wiki