Difference between revisions of "Fix Small Prims"

From Second Life Wiki
Jump to navigation Jump to search
m (lsl code tagging)
(Updated to use LLGetLinkPrimitiveParams as per SVC-224)
Line 5: Line 5:
Fix Small Prims by [[User:Emma_Nowhere|Emma Nowhere]]
Fix Small Prims by [[User:Emma_Nowhere|Emma Nowhere]]


Shrinking linked prims is difficult because no prim in the linked set can be smaller than .01 meters in any dimension (length, width, or height).
Now updated to use [https://jira.secondlife.com/browse/SVC-224 | LLGetLinkPrimitiveParams].
This script finds the smallest prims and increases their size slightly so that the linkset can be sized down.


# Install this script in the root prim of a linked set of prims (aka "linkset")
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. 
# Type /1fspsetup to copy copy scripts into all the prims in the linkset
 
# Take the linkset into inventory
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.
# Re-rez the linkset from inventory
 
# Select the linkset and choose "Set Scripts to Running in Selection" under the Tools menu
If you're not familiar with how prims and linking work, please read the following wiki pages:
# Type /1fsprun to fix all the small prims
 
# Resize the linkset object to the desired size
[[Prim]]
# Type /1fspcleanup to remove the scripts from the linkset
 
[[Link]]
 
How to use:
 
#Install this script in the root prim of a linked set of prims (aka "linkset").
#Type /1fsprun to fix all the small prims
#Resize the linkset object to the desired size using the Second Life 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 /1fspcleanup to remove the scripts from the linkset
 
'''IMPORTANT:'''  You should always make a backup copy of the object before using this script.


</div></div>
</div></div>
Line 25: Line 35:
<lsl>
<lsl>
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// FixSmallPrims
// FixSmallPrims2
// by Emma Nowhere
// by Emma Nowhere
//
// Last modified: 4/26/2010
//
//
// How to use:
// How to use:
// 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 /1fspsetup to copy copy scripts into all the prims in the linkset
// 2. Type /1fsprun to fix all the small prims
// 3. Take the linkset into inventory
// 3. Resize the linkset object to the desired size
// 4. Re-rez the linkset from inventory
// 4. Type /1fsprestore to return them to their original sizes
// 5. Select the linkset and choose "Set Scripts to Running in Selection" under the Tools menu
// 5. Type /1fspcleanup to remove the scripts from the linkset
// 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;
integer CHANNEL = 1;


vector backupScale = ZERO_VECTOR;
list backupScales = [];
integer backupStored = FALSE;
integer backupStored = FALSE;


integer rescaleX = FALSE;
list rescaleFlags = [];
integer rescaleY = FALSE;
integer rescaleZ = FALSE;


backup() {
backup() {
     if (!backupStored) {
     if (!backupStored) {
         backupScale = llGetScale();
         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;
         backupStored = TRUE;
        llOwnerSay("Prim sizes backed up");
     }
     }
}
}
Line 56: Line 73:
restore() {
restore() {
     if (backupStored) {
     if (backupStored) {
         llSetScale(backupScale);
         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");
     }
     }
     rescaleX = FALSE;
     rescaleFlags = [];
    rescaleY = FALSE;
    rescaleZ = FALSE;
}
}


cleanup() {
cleanup() {
     vector scale = llGetScale();
     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 (rescaleX) {
        if (rescaleY) {
        scale.x = backupScale.x;
            scale.y = backupScale.y;
    }
        }


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


    if (rescaleZ) {
         if (rescaleX || rescaleY || rescaleZ) {
         scale.z = backupScale.z;
            llOwnerSay("Cleaning size of linked prim #" + (string)i);
    }
            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, scale]);
 
        }
    if (rescaleX || rescaleY || rescaleZ) {
        llSay(0, "Cleaning scale of linked prim #" + (string)llGetLinkNumber());
        llSetScale(scale);
     }
     }


    llOwnerSay("Deleting FixSmallPrims script");
     llRemoveInventory(llGetScriptName());  
     llRemoveInventory(llGetScriptName());  
}
}
Line 90: Line 127:
     backup();
     backup();


     vector scale = llGetScale();
     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);


    if (scale.x < .015) {
        integer rescaleX = FALSE;
        scale.x = .015;
        integer rescaleY = FALSE;
        rescaleX = TRUE;
        integer rescaleZ = FALSE;
    }
       
        if (scale.x < .015) {
            scale.x = .015;
            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) {
        llSay(0, "Fixing size of linked prim #" + (string)llGetLinkNumber());
            llOwnerSay("Fixing size of linked prim #" + (string)i);
        llSetScale(scale);
            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, scale]);
    }
        }
}
        rescaleFlags = rescaleFlags + [rescaleX, rescaleY, rescaleZ];
 
GiveScriptToLinkedPrims()
{
    integer p = llGetNumberOfPrims();
    integer i = 0;
    for (i = 2; i <= p; i++)
    {
        key prim = llGetLinkKey(i);
        llGiveInventory(prim, llGetScriptName());
     }
     }
    llOwnerSay("Done fixing prims");
}
}


Line 128: Line 168:
     state_entry()  
     state_entry()  
     {
     {
         integer linkNum = llGetLinkNumber();
         llListen(CHANNEL, "", llGetOwner(), "");
        if (linkNum < 2) llListen(CHANNEL, "", llGetOwner(), "");
        llOwnerSay("FixSmallPrims Ready");
     }
     }


     on_rez(integer start_param) {
     on_rez(integer start_param) {
         integer linkNum = llGetLinkNumber();
         llOwnerSay("FixSmallPrims Installed");
        if (linkNum < 2) llSay(0, "FixSmallPrims Installed");
    }     
  }     
      
      
     listen(integer channel, string name, key id, string message)  
     listen(integer channel, string name, key id, string message)  
     {
     {
         if (message == "fspsetup")
 
        {
         if (message == "fsptest") {
            GiveScriptToLinkedPrims();
            llOwnerSay("FixSmallPrims script is installed and ready");           
            if (backupStored) {
                llOwnerSay("Original prim sizes have been backed up");          
            }
         }
         }
         else
         else if (message == "fspbackup") {
        {
            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();
             backup();
         }
         }
         else if (str == "fsprestore") {
         else if (message == "fsprestore") {
             restore();
             restore();
         }
         }
         else if (str == "fspcleanup") {         
         else if (message == "fspcleanup") {         
             cleanup();                     
             cleanup();                     
         }
         }
         else if (str == "fsprun") {
         else if (message == "fsprun") {
             process();             
             process();             
         }
         }
Line 171: Line 200:
     }
     }
}
}





Revision as of 20:03, 26 May 2010

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 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 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:

  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 using the Second Life 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

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

FixSmallPrims

<lsl> /////////////////////////////////////////////////////////////////////////////// // FixSmallPrims2 // by Emma Nowhere // // Last modified: 4/26/2010 // // How to use: // 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 // 4. Type /1fsprestore to return them to their original sizes // 5. Type /1fspcleanup to remove the scripts from the linkset

integer CHANNEL = 1;

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

}

default {

   state_entry() 
   {
       llListen(CHANNEL, "", llGetOwner(), "");
       llOwnerSay("FixSmallPrims Ready");
   }
   on_rez(integer start_param) {
       llOwnerSay("FixSmallPrims Installed");
   }    
   
   listen(integer channel, string name, key id, string message) 
   {
       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") {        
           cleanup();                    
       }
       else if (message == "fsprun") {
           process();            
       }
   }

}


</lsl>