User:Hidenori Glushenko/FaceTextureSetter

From Second Life Wiki
Jump to navigation Jump to search

Face Texture Setter

You can change/toggle the texture/alpha setting on a specified face only touching on its face.

  • blank texture and alpha 0%
  • blank texture and alpha 100%
  • transparent texture and alpha 0%
  • invisible texture and alpha 0%

NOTE : Server 1.24 or later / Viewer 1.21 or later are required.

<lsl> ///////////////////////////////////////////////////////////////////// // FaceTextureSetter string VERSION = "1.1"; // 2008/08/30 // Updated 2008/10/17 (add support 1.20 viewer) ///////////////////////////////////////////////////////////////////// // Released into the public domain by Hidenori Glushenko /////////////////////////////////////////////////////////////////////

//=================================================================== // GLOBAL VARIABLES //=================================================================== list TEXTURE_SETTINGS;

//=================================================================== // LOCAL FUNCTIONS //=================================================================== init() {

   integer i;
   integer max = 9;
   TEXTURE_SETTINGS    = [];
   for ( i = 0; i < max; ++i ) {
       TEXTURE_SETTINGS += 0;
       TEXTURE_SETTINGS += llGetTexture( i );
       TEXTURE_SETTINGS += llGetAlpha( i );
   }   

}

//=================================================================== // MAIN PROCEDURE //=================================================================== default {

   state_entry() {
       init();
   }

   touch_start(integer total_number) {
       //  only owner
       if ( llDetectedKey( 0 ) != llGetOwner() ) {
           return; 
       }

       integer face    = llDetectedTouchFace( 0 );
       if ( face < 0 ) {
           llOwnerSay( "1.21 or later version only." );
           return; //  not 1.21 viewer 
       }
       integer setting = llList2Integer( TEXTURE_SETTINGS, face * 3 );

       ++setting;
       if ( setting > 4 ) {
           setting = 0;    
       }

       if ( setting == 0 ) {
           //  original texture and alpha
           llOwnerSay( "face " + (string)face + ": set to original texture and alpha." );
           llSetTexture( llList2Key( TEXTURE_SETTINGS, face * 3 + 1 ), face );
           llSetAlpha( llList2Float( TEXTURE_SETTINGS, face * 3 + 2 ), face );
       } else if ( setting == 1 ) {
           //  set alpha 0% & blank texture
           llOwnerSay( "face " + (string)face + ": set to blank texture and alpha 0%." );
           llSetTexture( TEXTURE_BLANK , face );
           llSetAlpha( 1.0, face );
       } else if ( setting == 2 ) {
           //  set alpha 100% & blank texture
           llOwnerSay( "face " + (string)face + ": set to blank texture and alpha 100%." );
           llSetTexture( TEXTURE_BLANK , face );
           llSetAlpha( 0.0, face );
       } else if ( setting == 3 ) {
           //  set alpha 0% & transparent texture
           llOwnerSay( "face " + (string)face + ": set to transparent texture and alpha 0%." );
           llSetTexture( TEXTURE_TRANSPARENT , face );
           llSetAlpha( 1.0, face );
       } else if ( setting == 4 ) {
           //  set alpha 0% & invisible texture
           llOwnerSay( "face " + (string)face + ": set to invisible texture and alpha 0%." );
           llSetTexture( "e97cf410-8e61-7005-ec06-629eba4cd1fb" , face );
           llSetAlpha( 1.0, face );        
       }

       TEXTURE_SETTINGS = llListReplaceList( TEXTURE_SETTINGS, [ setting ], face * 3, face * 3 );
   }

} </lsl>