LacunaSL

  • Archive
  • RSS
  • Comments

Texture parameter changer

// -------------------------------------------------------------------------------------------------
// texture_params_changer.lsl version 1.0 by Lacuna Arado
// -------------------------------------------------------------------------------------------------
// This script saved me a lot of time by avoiding the need to adjust several prims individually. In
// this instance, I needed to proportionally adjust the texture repeats and offsets for all of the
// wooden posts (cylinder prims) within a big barn object. This script can be easily modified to
// suit other similar purposes. Try it on a test object before you monkey with your favorite castle.
// -------------------------------------------------------------------------------------------------
// Here is the run-down of what this particular script does:
// Scope: only face #1 of cylinder prims within the linkset are affected
// Scope: the cylinder prims must have the planks04 texture on face #1
// Scope: only cylinder prims sized larger than <0.125, 0.125, 1.0> are affected
// Action: sets horizontal repeats to 0.5
// Action: sets vertical repeats to the prim's side z length divided by 2
// Action: sets horizontal offset to 0.5
// Limitation: texture UUIDs are grid-specific and thus are hard-coded
// -------------------------------------------------------------------------------------------------
// This script is distributed as "FREEWARE" and is available as a public domain asset for any and
// all to use and modify as they deem fitting. The author of this software accepts no
// responsibility for damages resulting from the use of this script and makes no warranty or
// representation, either express or implied, including but not limited to, any implied warranty of
// merchantability or fitness for a particular purpose. This script is provided "AS IS", and you,
// its user, assume ALL risks and liabilities when using it.

default
{
    
    state_entry()
    {
    }
    
    touch_end(integer num)
    {
        integer i;
        llOwnerSay("Please wait while I set the texture parameters...");
        i = llGetNumberOfPrims();
        for (; i >= 0; --i) // loop through all prims of the linkset
        {
            list typeParams = llGetLinkPrimitiveParams(i,[PRIM_TYPE]);
            if (llList2Integer(typeParams, 0) == 1) // prim type = 1 for cylinder
            {
            	// get texture of face #1
                list textureParams = llGetLinkPrimitiveParams(i, [PRIM_TEXTURE, 1]);
                key id = llList2Key(textureParams, 0);
                if (id == "1d00b7b0-9e12-4398-b3f1-e52e39a6fa72") // planks04 texture
                {
                    list sizeParams = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
                    vector size = llList2Vector(sizeParams, 0);
                    // only do this to prims greater than this size:
                    if ((size.x > 0.125) && (size.y > 0.125) && (size.z > 1.0))
                    {
                        // vector repeats = llList2Vector(textureParams, 1);
                        // vector offset = llList2Vector(textureParams, 2);
                        vector repeats = <0.5, size.z/2, 0>;
                        vector offset = <0.5, 0, 0>;
                        float rot = llList2Float(textureParams, 3) * RAD_TO_DEG;
                        llSetLinkPrimitiveParamsFast(i, [PRIM_TEXTURE, 1, id, repeats, offset, rot]);
                        // uncomment the line below if you want run-time debug info
                        // llOwnerSay("link # " + (string) i + " set to " + (string) repeats);
                    }
                }   
        
            }
        }
        llOwnerSay("Done!");
        llRemoveInventory(llGetScriptName());                
    }

}

    • #LSL
    • #OpenSim
    • #Second Life
    • #gaming
    • #prim
    • #scripting
    • #texture
  • 1 year ago
  • 10
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

OpenSim bad texture rotation detector

// -------------------------------------------------------------------------------------------------
// OpenSim_bad_texture_rotation_detector.lsl version 1.1 by Lacuna Arado
// -------------------------------------------------------------------------------------------------
// The purpose of this script is to detect a bug involving texture rotations that occurs in OpenSim.
// This bug only occurs in OpenSim and thus this script is not needed in SL. The script detects prim
// faces with bogus texture rotations, sets the texture rotation of the bad face to 0, and paints
// the face red. Simply add the script to the object's root prim and then click on the object. You
// may need to iteratively run this script until all of your bad rotations are resolved; read on if
// you are interested in more gory details about the phenomenon.

// The glitch seems to occurs when a prim's texture rotation is set to a negative value for
// degrees. The exact root cause of this bug is unknown (at least to me), but it appears to be
// related to radian maths. What happens is somehow the texture ends up getting rotated to a value
// far beyond 360 degrees. The problem is exacerbated when further texture actions (such as color
// changing) are performed on the object, causing the afflicted face's texture rotation to
// gradually drift with each subsequent texture action (that is, the texture rotation drift
// accumulates with each such texture change action, becoming ever-more noticeable).

// One way to overcome this glitch is to ensure that no negative-degree texture rotations are used.
// This can be accomplished by cleverly flipping the textures &/or changing them to positive
// degrees, etc. FWIW, it also seems that fixing these prims reduces lag (although I have no
// empirical evidence of this). This script can also normalize texture rotations of other prims to
// proper angles in 45 degree increments. Simply uncomment the "bonus fixes" section below to
// enable this behavior. Alternately if you intend for a texture rotation to be something oddball
// like 94.15 degrees then for gosh sakes don't enable the "bonus fixes" as they will most
// certainly quash those types of settings and cause considerable frustration, hair-pulling, teeth
// gnashing, random outbursts of profanity, etc., etc.

// Sidebar digression: In reviewing the code, you will notice a hard-coded integer f = 7 for number
// of faces. This is because the function "llGetLinkNumberOfSides()" is not implemented in OpenSim
// (as version 0.7.1.1), and attempting to run that function in OpenSim will result in the following
// error message: "Error CS0103: The name 'llGetLinkNumberOfSides' does not exist in the current
// context".

// So f*ck and alas, this handy-dandy glitch finder is hindered by this second pesky OpenSim bug...
// (incidentally, this script works correctly in SL without this hardcoding kludge, but since the
// problem only seems to exist in OpenSim the value of this script in SL is negligable, except
// perhaps as a tutorial). The good news is that llGetLinkNumberOfSides was added to the OpenSim
// development codebase circa May 2011, so we are very likely to see it in an upcoming release.
// Better late than never, I s'pose... --L4cun4

// -------------------------------------------------------------------------------------------------
// This script is distributed as "FREEWARE" and is available as a public domain asset for any and
// all to use and modify as they deem fitting. The author of this software accepts no
// responsibility for damages resulting from the use of this script and makes no warranty or
// representation, either express or implied, including but not limited to, any implied warranty of
// merchantability or fitness for a particular purpose. This script is provided "AS IS", and you,
// its user, assume ALL risks and liabilities when using it.

default
{
    state_entry()
    {
    }
    
    touch_end (integer num)
    {
        llOwnerSay("Please wait while I look for bad texture rotations...");
        integer i = llGetNumberOfPrims();
        for (; i >= 0; --i)
        {
	        // integer f = llGetLinkNumberOfSides(i); // commented out for now
	        integer f = 7;  // hardcoded kludge until the above function is available
	        for (; f >= 0; --f)
	        {
	            list b = llGetLinkPrimitiveParams(i,[PRIM_TEXTURE, f]);
	            key id = llList2Key(b, 0);
	            vector repeats = llList2Vector(b, 1);
	            vector offset = llList2Vector(b, 2);
	            float p = llList2Float(b, 3) * RAD_TO_DEG;
	            float fixr = p; // initialize fixr to be p each time
	            if (p > 360)
	            {
	            	fixr = 0;
	            	llSetLinkColor(i, <1,0,0>, f);
	            	llOwnerSay("Found a naughty prim face!");
	            }
	            // ** BEGIN of bonus fixes; leave commented out if you don't want these **
	            // if ((p < 10)   && (p != 0.0))                {fixr = 0;}
	            // if ((p > 40)   && (p < 50)   && (p != 45))   {fixr = 45;}
	            // if ((p > 85)   && (p < 95)   && (p != 90))   {fixr = 90;}
	            // if ((p > 130)  && (p < 140)  && (p != 135))  {fixr = 135;}
	            // if ((p > 175)  && (p < 185)  && (p != 180))  {fixr = 180;}
	            // if ((p > 220)  && (p < 230)  && (p != 225))  {fixr = 225;}
	            // if ((p > 265)  && (p < 275)  && (p != 270))  {fixr = 270;}
	            // if ((p > 310)  && (p < 320)  && (p != 315))  {fixr = 315;}
	            // if ((p > 350)  && (p < 360))                 {fixr = 0;}
	            // ** END of bonus fixes **
	            if (p != fixr)
	            {
	                    llSetLinkPrimitiveParamsFast
	                    (
	                     i, [PRIM_TEXTURE, f, id, repeats, offset, fixr * DEG_TO_RAD]
	                    );
	            }
            }
        }
        llOwnerSay("Done!");
    }

}

    • #LSL
    • #OpenSim
    • #Second Life
    • #llGetLinkNumberOfSides
    • #prim
    • #rotation
    • #scripting
    • #texture
    • #gaming
  • 1 year ago
  • 9
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Avatar

Top

  • RSS
  • Random
  • Archive
  • Comments
  • Mobile
Effector Theme by Pixel Union