Difference between revisions of "Fix Small Prims"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(6 intermediate revisions by 2 users not shown)
Line 7: Line 7:
Now updated to use [https://jira.secondlife.com/browse/SVC-224 LLGetLinkPrimitiveParams].
Now updated to use [https://jira.secondlife.com/browse/SVC-224 LLGetLinkPrimitiveParams].


In Second Life, no prim can be less that .01 meters in any given dimension (width, length, or height).  When you try to resize an object, you often find you can't shrink it below a certain size.  This is because one of the prims in the object is already at it's minimum size in one of it's dimensions.  This script checks every prim in an object and slightly increases the sizes of the prims which are already at their smallest possible sizes, so that the overall object that the prim is part of can be scaled down.  This usually lets you reduce the object in size by an additional 20%.  You can repeat the process several times if you're not able to shrink the object enough on the first try.   
In Second Life, no prim can be less that .01 meters in any given dimension (width, length, or height).  When you try to resize an object, you often find you can't shrink it below a certain size.  This is because one of the prims in the object is already at its minimum size in one of it's dimensions.  This script checks every prim in an object and slightly increases the sizes of the prims which are already at their smallest possible sizes, so that the overall object that the prim is part of can be scaled down.  This usually lets you reduce the object in size by an additional 20%.  You can repeat the process several times if you're not able to shrink the object enough on the first try.   


In the instructions below, we'll refer to your object that you want to resize, such as a necklace or a tree, as a "linkset".  We call it this because the object consists of a linked set of prims, rather than one single prim.
In the instructions below, we'll refer to your object that you want to resize, such as a necklace or a tree, as a "linkset".  We call it this because the object consists of a linked set of prims, rather than one single prim.
Line 17: Line 17:
[[Link]]
[[Link]]


How to use:
How to use with menu:
 
#Install this script in the root prim of a linked set of prims (aka "linkset")
#Type /1fsp to show the menu
#Hit the "Fix" button to fix all the small prims
#Resize the linkset object to the desired size with the Viewer Editing Tools
#Type /1fsp to show the menu again
#Hit the "Finish" button to remove the script and finalize prim sizes
 
 
(Advanced) How to use with chat commands:


#Install this script in the root prim of a linked set of prims (aka "linkset").
#Install this script in the root prim of a linked set of prims (aka "linkset").
#Type /1fsprun to fix all the small prims
#Type /1fsprun to fix all the small prims
#Resize the linkset object to the desired size using the Second Life editing tools
#Resize the linkset object to the desired size with the Viewer Editing Tools
#Type /1fsprestore if you need to return them to their original sizes (you should only use this for no-copy objects, otherwise make a copy before you start)
#Type /1fsprestore if you need to return them to their original sizes (you should only use this for no-copy objects, otherwise make a copy before you start)
#Type /1fspcleanup to remove the scripts from the linkset
#Type /1fspcleanup to remove the scripts from the linkset and finalize prim sizes
 


'''IMPORTANT:'''  You should always make a backup copy of the object before using this script.
'''IMPORTANT:'''  You should always make a backup copy of the object before using this script.


</div></div>
</div></div>
Line 33: Line 45:
== FixSmallPrims ==
== FixSmallPrims ==
<div style="padding: 0.5em">
<div style="padding: 0.5em">
<lsl>
<source lang="lsl2">
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// FixSmallPrims2
// FixSmallPrims2
// by Emma Nowhere
// by Emma Nowhere
//
//
// Last modified: 4/26/2010
// Last modified: 5/30/2010
//
// How to use with menu:
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 2. Type /1fsp to show the menu
// 3. Hit the "Fix" button to fix all the small prims
// 4. Resize the linkset object to the desired size with the Editing Tools
// 5. Type /1fsp to show the menu again
// 6. Hit the "Finish" button to remove the script and finalize prim sizes
//
//
// How to use:
// (Advanced) How to use via chat commands:
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 2. Type /1fsprun to fix all the small prims
// 2. Type /1fsp to show the menu
// 3. Resize the linkset object to the desired size
// 3. Type /1fsprun to fix all the small prims
// 4. Type /1fsprestore to return them to their original sizes
// 4. Resize the linkset object to the desired size with the Editing Tools
// 5. Type /1fspcleanup to remove the scripts from the linkset
// 5. Type /1fsprestore to return them to their original sizes
 
// 6. Type /1fspcleanup to remove the script and finalize prim sizes
integer CHANNEL = 1;
integer CHANNEL = 1;
 
integer MENU_CHANNEL = -1001;
list backupScales = [];
list backupScales = [];
integer backupStored = FALSE;
integer backupStored = FALSE;
 
list rescaleFlags = [];
list rescaleFlags = [];
 
backup() {
backup() {
     if (!backupStored) {
     if (!backupStored) {
Line 70: Line 92:
     }
     }
}
}
 
restore() {
restore() {
     if (backupStored) {
     if (backupStored) {
Line 85: Line 107:
     rescaleFlags = [];
     rescaleFlags = [];
}
}
 
cleanup() {
cleanup() {
     llOwnerSay("Cleaning up FixSmallPrims data and finalizing prim sizes");
     llOwnerSay("Cleaning up FixSmallPrims data and finalizing prim sizes");
Line 97: Line 119:
         integer rescaleY = llList2Integer(rescaleFlags, rescaleI + 1);
         integer rescaleY = llList2Integer(rescaleFlags, rescaleI + 1);
         integer rescaleZ = llList2Integer(rescaleFlags, rescaleI + 2);
         integer rescaleZ = llList2Integer(rescaleFlags, rescaleI + 2);
       
         list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
         list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
         vector scale = llList2Vector(params, 0);
         vector scale = llList2Vector(params, 0);
       
         if (rescaleX) {
         if (rescaleX) {
             scale.x = backupScale.x;
             scale.x = backupScale.x;
         }
         }
 
         if (rescaleY) {
         if (rescaleY) {
             scale.y = backupScale.y;
             scale.y = backupScale.y;
         }
         }
 
         if (rescaleZ) {
         if (rescaleZ) {
             scale.z = backupScale.z;
             scale.z = backupScale.z;
         }
         }
 
         if (rescaleX || rescaleY || rescaleZ) {
         if (rescaleX || rescaleY || rescaleZ) {
             llOwnerSay("Cleaning size of linked prim #" + (string)i);
             llOwnerSay("Cleaning size of linked prim #" + (string)i);
Line 118: Line 140:
         }
         }
     }
     }
 
     llOwnerSay("Deleting FixSmallPrims script");
     llOwnerSay("Deleting FixSmallPrims script");
     llRemoveInventory(llGetScriptName());  
     llRemoveInventory(llGetScriptName());  
}
}
 
process() {
process() {
     restore();
     restore();
     backup();
     backup();
 
     llOwnerSay("Starting fixing prims");
     llOwnerSay("Starting fixing prims");
     rescaleFlags = [];
     rescaleFlags = [];
Line 135: Line 157:
         list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
         list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
         vector scale = llList2Vector(params, 0);
         vector scale = llList2Vector(params, 0);
 
         integer rescaleX = FALSE;
         integer rescaleX = FALSE;
         integer rescaleY = FALSE;
         integer rescaleY = FALSE;
         integer rescaleZ = FALSE;
         integer rescaleZ = FALSE;
       
         if (scale.x < .015) {
         if (scale.x < .015) {
             scale.x = .015;
             scale.x = .015;
             rescaleX = TRUE;
             rescaleX = TRUE;
         }
         }
 
         if (scale.y < .015) {
         if (scale.y < .015) {
             scale.y = .015;
             scale.y = .015;
             rescaleY = TRUE;
             rescaleY = TRUE;
         }
         }
 
         if (scale.z < .015) {
         if (scale.z < .015) {
             scale.z = .015;
             scale.z = .015;
             rescaleZ = TRUE;
             rescaleZ = TRUE;
         }
         }
 
         if (rescaleX || rescaleY || rescaleZ) {
         if (rescaleX || rescaleY || rescaleZ) {
             llOwnerSay("Fixing size of linked prim #" + (string)i);
             llOwnerSay("Fixing size of linked prim #" + (string)i);
Line 161: Line 183:
         rescaleFlags = rescaleFlags + [rescaleX, rescaleY, rescaleZ];
         rescaleFlags = rescaleFlags + [rescaleX, rescaleY, rescaleZ];
     }
     }
     llOwnerSay("Done fixing prims");
     llOwnerSay("Done fixing prims\n\nResize your object and type /" + (string)CHANNEL + "fsp for menu when done.\n\n");
}
}


menu() {
    llDialog(llGetOwner(),
    "Fix Small Prims\n\nMake a backup of your object first.\n\nPlease choose an option:\n",
    ["Fix", "Finish"], MENU_CHANNEL);
}
default
default
{
{
Line 169: Line 197:
     {
     {
         llListen(CHANNEL, "", llGetOwner(), "");
         llListen(CHANNEL, "", llGetOwner(), "");
        llListen(MENU_CHANNEL, "", llGetOwner(), "");
         llOwnerSay("FixSmallPrims Ready");
         llOwnerSay("FixSmallPrims Ready");
        llOwnerSay("Type /" + (string)CHANNEL + "fsp for menu");
     }
     }
 
     on_rez(integer start_param) {
     on_rez(integer start_param) {
         llOwnerSay("FixSmallPrims Installed");
         llOwnerSay("FixSmallPrims Installed");
        llOwnerSay("Type /" + (string)CHANNEL + "fsp for menu");
     }     
     }     
   
     listen(integer channel, string name, key id, string message)  
     listen(integer channel, string name, key id, string message)  
     {
     {
 
        if (message == "fsp") {
         if (message == "fsptest") {
            menu();
        }
         else if (message == "fsptest") {
             llOwnerSay("FixSmallPrims script is installed and ready");             
             llOwnerSay("FixSmallPrims script is installed and ready");             
             if (backupStored) {
             if (backupStored) {
Line 191: Line 224:
             restore();
             restore();
         }
         }
         else if (message == "fspcleanup") {         
         else if ((message == "fspcleanup") || (message == "Finish")) {         
             cleanup();                     
             cleanup();                     
         }
         }
         else if (message == "fsprun") {
         else if ((message == "fsprun") || (message == "Fix")) {
             process();             
             process();             
         }
         }
 
     }
     }
}
}




</lsl>
</source>
</div></div>
</div></div>
{{#vardefine:sort|Fix Small Prims}}{{LSLC|Library}}
{{#vardefine:sort|Fix Small Prims}}{{LSLC|Library}}

Latest revision as of 19:22, 24 January 2015

About

Fix Small Prims by Emma Nowhere

Now updated to use LLGetLinkPrimitiveParams.

In Second Life, no prim can be less that .01 meters in any given dimension (width, length, or height). When you try to resize an object, you often find you can't shrink it below a certain size. This is because one of the prims in the object is already at its minimum size in one of it's dimensions. This script checks every prim in an object and slightly increases the sizes of the prims which are already at their smallest possible sizes, so that the overall object that the prim is part of can be scaled down. This usually lets you reduce the object in size by an additional 20%. You can repeat the process several times if you're not able to shrink the object enough on the first try.

In the instructions below, we'll refer to your object that you want to resize, such as a necklace or a tree, as a "linkset". We call it this because the object consists of a linked set of prims, rather than one single prim.

If you're not familiar with how prims and linking work, please read the following wiki pages:

Prim

Link

How to use with menu:

  1. Install this script in the root prim of a linked set of prims (aka "linkset")
  2. Type /1fsp to show the menu
  3. Hit the "Fix" button to fix all the small prims
  4. Resize the linkset object to the desired size with the Viewer Editing Tools
  5. Type /1fsp to show the menu again
  6. Hit the "Finish" button to remove the script and finalize prim sizes


(Advanced) How to use with chat commands:

  1. Install this script in the root prim of a linked set of prims (aka "linkset").
  2. Type /1fsprun to fix all the small prims
  3. Resize the linkset object to the desired size with the Viewer Editing Tools
  4. Type /1fsprestore if you need to return them to their original sizes (you should only use this for no-copy objects, otherwise make a copy before you start)
  5. Type /1fspcleanup to remove the scripts from the linkset and finalize prim sizes


IMPORTANT: You should always make a backup copy of the object before using this script.


FixSmallPrims

///////////////////////////////////////////////////////////////////////////////
// FixSmallPrims2
// by Emma Nowhere
//
// Last modified: 5/30/2010
//
// How to use with menu:
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 2. Type /1fsp to show the menu
// 3. Hit the "Fix" button to fix all the small prims
// 4. Resize the linkset object to the desired size with the Editing Tools
// 5. Type /1fsp to show the menu again
// 6. Hit the "Finish" button to remove the script and finalize prim sizes
//
// (Advanced) How to use via chat commands:
// 1. Install this script in the root prim of a linked set of prims (aka "linkset")
// 2. Type /1fsp to show the menu
// 3. Type /1fsprun to fix all the small prims
// 4. Resize the linkset object to the desired size with the Editing Tools
// 5. Type /1fsprestore to return them to their original sizes
// 6. Type /1fspcleanup to remove the script and finalize prim sizes
 
integer CHANNEL = 1;
integer MENU_CHANNEL = -1001;
 
list backupScales = [];
integer backupStored = FALSE;
 
list rescaleFlags = [];
 
backup() {
    if (!backupStored) {
        llOwnerSay("Backing up prim sizes");
        backupScales = [];
        integer p = llGetNumberOfPrims();
        integer i = 0;
        for (i = 1; i <= p; i++)
        {
            list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
            vector scale = llList2Vector(params, 0);
            backupScales = backupScales + [scale];
        }
        backupStored = TRUE;
        llOwnerSay("Prim sizes backed up");
    }
}
 
restore() {
    if (backupStored) {
        llOwnerSay("Restoring previously backed up prim sizes");
        integer p = llGetNumberOfPrims();
        integer i = 0;
        for (i = 1; i <= p; i++)
        {
            vector scale = llList2Vector(backupScales, i - 1);
            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, scale]);
        }
        llOwnerSay("Previously backed up prim sizes restored");
    }
    rescaleFlags = [];
}
 
cleanup() {
    llOwnerSay("Cleaning up FixSmallPrims data and finalizing prim sizes");
    integer p = llGetNumberOfPrims();
    integer i = 0;
    for (i = 1; i <= p; i++)
    {
        vector backupScale = llList2Vector(backupScales, i - 1);
        integer rescaleI = (i - 1) * 3;
        integer rescaleX = llList2Integer(rescaleFlags, rescaleI);
        integer rescaleY = llList2Integer(rescaleFlags, rescaleI + 1);
        integer rescaleZ = llList2Integer(rescaleFlags, rescaleI + 2);
 
        list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
        vector scale = llList2Vector(params, 0);
 
        if (rescaleX) {
            scale.x = backupScale.x;
        }
 
        if (rescaleY) {
            scale.y = backupScale.y;
        }
 
        if (rescaleZ) {
            scale.z = backupScale.z;
        }
 
        if (rescaleX || rescaleY || rescaleZ) {
            llOwnerSay("Cleaning size of linked prim #" + (string)i);
            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, scale]);
        }
    }
 
    llOwnerSay("Deleting FixSmallPrims script");
    llRemoveInventory(llGetScriptName()); 
}
 
process() {
    restore();
    backup();
 
    llOwnerSay("Starting fixing prims");
    rescaleFlags = [];
    integer p = llGetNumberOfPrims();
    integer i = 0;
    for (i = 1; i <= p; i++)
    {
        list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE]);
        vector scale = llList2Vector(params, 0);
 
        integer rescaleX = FALSE;
        integer rescaleY = FALSE;
        integer rescaleZ = FALSE;
 
        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) {
            llOwnerSay("Fixing size of linked prim #" + (string)i);
            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, scale]);
        }
        rescaleFlags = rescaleFlags + [rescaleX, rescaleY, rescaleZ];
    }
    llOwnerSay("Done fixing prims\n\nResize your object and type /" + (string)CHANNEL + "fsp for menu when done.\n\n");
}

menu() {
    llDialog(llGetOwner(),
    "Fix Small Prims\n\nMake a backup of your object first.\n\nPlease choose an option:\n",
    ["Fix", "Finish"], MENU_CHANNEL);
}
 
default
{
    state_entry() 
    {
        llListen(CHANNEL, "", llGetOwner(), "");
        llListen(MENU_CHANNEL, "", llGetOwner(), "");
        llOwnerSay("FixSmallPrims Ready");
        llOwnerSay("Type /" + (string)CHANNEL + "fsp for menu");
    }
 
    on_rez(integer start_param) {
        llOwnerSay("FixSmallPrims Installed");
        llOwnerSay("Type /" + (string)CHANNEL + "fsp for menu");
    }    
 
    listen(integer channel, string name, key id, string message) 
    {
        if (message == "fsp") {
            menu();
        }
        else if (message == "fsptest") {
            llOwnerSay("FixSmallPrims script is installed and ready");            
            if (backupStored) {
                llOwnerSay("Original prim sizes have been backed up");            
            }
        }
        else if (message == "fspbackup") {
            backup();
        }
        else if (message == "fsprestore") {
            restore();
        }
        else if ((message == "fspcleanup") || (message == "Finish")) {        
            cleanup();                    
        }
        else if ((message == "fsprun") || (message == "Fix")) {
            process();            
        }
 
    }
}