Fix Small Prims

From Second Life Wiki
Revision as of 17:14, 5 November 2007 by Emma Nowhere (talk | contribs) (New page: {{LSL Header}}{{RightToc}} <div id="box"> == About == <div style="padding: 0.5em"> Fix Small Prims by Emma Nowhere Shrinking linked prims is difficult because no pri...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

About

Fix Small Prims by Emma Nowhere

Shrinking linked prims is difficult because no prim in the linked set can be smaller that .01 meters in any dimension. This script finds the smallest prims and increases their size slightly so that the link set can be sized down.

1. Install this script in the root prim of a linked set of prims (aka "linkset") 2. Type /1fspsetup to copy copy scripts into all the prims in the linkset 3. Take the linkset into inventory 4. Re-rez the linkset from inventory 5. Select the linkset and choose "Set Scripts to Running in Selection" under the Tools menu 6. Type /1fsprun to fix all the small prims 7. Resize the linkset object to the desired size 8. Type /1fspcleanup to remove the scripts from the linkset

UpdateServer

///////////////////////////////////////////////////////////////////////////////
// FixSmallPrims
// by Emma Nowhere
//
// How to use:
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 2. Type /1fspsetup to copy copy scripts into all the prims in the linkset
// 3. Take the linkset into inventory
// 4. Re-rez the linkset from inventory
// 5. Select the linkset and choose "Set Scripts to Running in Selection" under the Tools menu
// 6. Type /1fsprun to fix all the small prims
// 7. Resize the linkset object to the desired size
// 8. Type /1fspcleanup to remove the scripts from the linkset

integer CHANNEL = 1;

vector backupScale = ZERO_VECTOR;
integer backupStored = FALSE;

integer rescaleX = FALSE;
integer rescaleY = FALSE;
integer rescaleZ = FALSE;

backup() {
    if (!backupStored) {
        backupScale = llGetScale();
        backupStored = TRUE;
    }
}

restore() {
    if (backupStored) {
        llSetScale(backupScale);
    }
    rescaleX = FALSE;
    rescaleY = FALSE;
    rescaleZ = FALSE;
}

cleanup() {
    vector scale = llGetScale();

    if (rescaleX) {
        scale.x = backupScale.x;
    }

    if (rescaleY) {
        scale.y = backupScale.y;
    }

    if (rescaleZ) {
        scale.z = backupScale.z;
    }

    if (rescaleX || rescaleY || rescaleZ) {
        llSay(0, "Cleaning scale of linked prim #" + (string)llGetLinkNumber());
        llSetScale(scale);
    }

    llRemoveInventory(llGetScriptName()); 
}

process() {
    restore();
    backup();

    vector scale = llGetScale();

    if (scale.x < .015) {
        scale.x = .015;
        rescaleX = TRUE;
    }

    if (scale.y < .015) {
        scale.y = .015;
        rescaleY = TRUE;
    }

    if (scale.z < .015) {
        scale.z = .015;
        rescaleZ = TRUE;
    }

    if (rescaleX || rescaleY || rescaleZ) {
        llSay(0, "Fixing size of linked prim #" + (string)llGetLinkNumber());
        llSetScale(scale);
    }
}

GiveScriptToLinkedPrims()
{
    integer p = llGetNumberOfPrims();
    integer i = 0;
    for (i = 2; i <= p; i++)
    {
        key prim = llGetLinkKey(i);
        llGiveInventory(prim, llGetScriptName());
    }
}

default
{
    state_entry() 
    {
        integer linkNum = llGetLinkNumber();
        if (linkNum < 2) llListen(CHANNEL, "", llGetOwner(), "");
    }

    on_rez(integer start_param) {
        integer linkNum = llGetLinkNumber();
        if (linkNum < 2) llSay(0, "FixSmallPrims Installed");
   }    
    
    listen(integer channel, string name, key id, string message) 
    {
        if (message == "fspsetup")
        {
            GiveScriptToLinkedPrims();
        }
        else
        {
            llMessageLinked(LINK_SET, 0, message, NULL_KEY);
        }
    }
    
    link_message(integer sender_num, integer num, string str, key id)
    {
        integer linkNum = llGetLinkNumber();
        
        if (str == "fsptest") {
            llSay(0, "Script is installed and running in linked prim #" + (string)linkNum);            
        }
        else if (str == "fspbackup") {
            backup();
        }
        else if (str == "fsprestore") {
            restore();
        }
        else if (str == "fspcleanup") {        
            cleanup();                    
        }
        else if (str == "fsprun") {
            process();            
        }

    }
}