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!");
}
}