Difference between revisions of "User:Daemonika Nightfire/Scripts/*DS* Resize Script"

From Second Life Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==*DS* Resize Script (m/c/t) v2.0.01==
==*DS* Resize Example v3.0.00==
Single resize script for a complete linkset with save and restore option.
Single resize script for a complete linkset with save and restore option.
<lsl>
<source lang="lsl2">
/*
//
    ╔═════════════════════════════════════−−−­­­­­­→
//    ╔═════════════════════════════════════−−−­­­­­­→
    ║ *DS* Resize Script (m/c/t) by Daemonika Nightfire (daemonika.nightfire)
//    ║ *DS* Resize Example by Daemonika Nightfire (daemonika.nightfire)
    ╚══════════════════════−−−­­­→
//    ╚══════════════════════−−−­­­→
   
//
    Resize Script for rezzed Objects and Attachments.
//    Resize Script for rezzed Objects and Attachments.
    Single-script for a complete linkset with save and restore option.
//    Single-script for a complete linkset with save and restore option.
   
//   
        Featueres:
//        Featueres:
        • By the first run or reset of this script, it will ask you to save all parameters.
//        • By the first run or reset of this script, it will ask you to save all parameters.
          The parameters will be stored in the descriptionfield of each prim, that needs no script-memory :)
//          The parameters will be stored in the descriptionfield of each prim, that needs no script-memory :)
        • You can save, resize and restore individual prims or the complette linkset.
//        • You can save, resize and restore individual prims or the complette linkset.
        • Deleting this script from the object is not required because its only one.
//       
       
//        Important:
            Standby-Time ~ 0.004 ms
//        • Undersize is possible, but take care.
            Working-Time with 200 moving Prims ~ 4.000 up to 16.000 ms
//          if you are small your object and several prims already have minimum dimensions, they are not further reduced, but they are moved proportionally.
            after finalizing Standby-Time ~ 0.004 ms again
//        • Sculpted Prims are no problem, but take care.
   
//          Sculpties with moved Bounding Box perhaps moving optical not correct
        Note:
//          That is not true, they are moving correctly, but when the visible Sculptie is not the center of the Bounding Box, it will be looking wrong.
        • You have to stand on a posestand, if you want to edit attached attachments.
//   
          This is necessary because otherwise the linkset is misadjusted, if you move your avatar during the process.
//    Terms of use:
       
//    You can use, edit and sell this script inside your creations with the following permissions in Second Life:
        Important:
//    • MOD Yes • COPY Yes • TRANSFER Yes
        • Undersize is possible, but take care.
//   
          if you are small your object and several prims already have minimum dimensions, they are not further reduced, but they are moved proportionally.
//    Yes that means fullperm. Other settings, are against the following licenses.
        • Sculpted Prims are no problem, but take care.
//    The permission of your Object (prim), remain unaffected by these terms
          Sculpties with moved Bounding Box perhaps moving optical not correct
//   
          That is not true, they are moving correctly, but when the visible Sculptie is not the center of the Bounding Box, it will be looking wrong.
//    https://wiki.secondlife.com/wiki/User:Daemonika_Nightfire/Scripts/*DS*_Resize_Script
   
//    http://wiki.secondlife.com/wiki/Project:Terms_of_Service
    Terms of use:
//    http://creativecommons.org/licenses/by-sa/3.0/
    You can use, edit and sell this script inside your creations with the following permissions in Second Life:
//   
    • MOD Yes • COPY Yes • TRANSFER Yes
//    violation of this Terms are against the Second Life TOS at §7 Content Licenses and Intellectual Property Rights.
   
//    http://secondlife.com/corporate/tos.php
    Yes that means fullperm. Other settings, are against the following licenses.
//
    The permission of your Object (prim), remain unaffected by these terms
   
    https://wiki.secondlife.com/wiki/User:Daemonika_Nightfire/Scripts/*DS*_Resize_Script
    http://wiki.secondlife.com/wiki/Project:Terms_of_Service
    http://creativecommons.org/licenses/by-sa/3.0/
   
    violation of this Terms are against the Second Life TOS at §7 Content Licenses and Intellectual Property Rights.
    http://secondlife.com/corporate/tos.php
*/


key owner;
key owner;
integer new = TRUE;
integer New = 1;


integer LinkSet = TRUE;
integer LinkSet = 1;
integer Prim;
integer Prim;
integer Links;
list Percent = ["-1%","-5%","-10%","+1%","+5%","+10%"];
list Ratio = [0.99,0.95,0.90,1.01,1.05,1.10];


integer Channel;
integer Channel;
Line 57: Line 51:
{
{
     llListenRemove(Listener);
     llListenRemove(Listener);
     Channel = (integer)(llFrand(999999.0) * -1);
     Channel = (integer)(llFrand(1) * -DEBUG_CHANNEL);
     Listener = llListen(Channel, "", owner, "");
     Listener = llListen(Channel, "", owner, "");
     llSetTimerEvent(60);
     llSetTimerEvent(60);
Line 65: Line 59:
{
{
     Chan();
     Chan();
     if(new)
     if(New)
     {
     {
         llDialog(owner, "\nYour first run or reset of this script.\nDo you whish to save current parameters?",
         llDialog(owner, "\nYour first run or reset of this script.\nDo you whish to save current parameters?",
Line 81: Line 75:
     Chan();
     Chan();
     llDialog(owner, "\n+ - = resize\nSave = record all parameters\nRestore = restore saved parameters",
     llDialog(owner, "\n+ - = resize\nSave = record all parameters\nRestore = restore saved parameters",
     ["Save","Restore","Done","-1%","-5%","-10%","+1%","+5%","+10%"], Channel);
     ["Save","Restore","Done"] + Percent, Channel);
}
}


Line 89: Line 83:
     {
     {
         owner = llGetOwner();
         owner = llGetOwner();
         llWhisper(0,"/me " + llGetScriptName() + " Free Memory: " + (string)llGetFreeMemory() + " bytes.");
         llOwnerSay("/me " + llGetScriptName() + " Free Memory: " + (string)llGetFreeMemory() + " bytes.");
     }
     }
      
      
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
        owner = llGetOwner();
         if(llDetectedKey(0) == owner)
         if(llDetectedKey(0) == owner)
         {
         {
             if(llGetAttached() != 0)
             Links = llGetNumberOfPrims();
            {
             Prim = llDetectedLinkNumber(0);
                if(llGetAgentInfo(owner) & AGENT_SITTING)
            menu1();
                {
                    Prim = llDetectedLinkNumber(0);
                    menu1();
                }
                else
                {
                    llOwnerSay("Please use a posing stand for resizing!");
                }
             }
            else
            {
                Prim = llDetectedLinkNumber(0);
                menu1();
            }
         }
         }
     }
     }
Line 119: Line 100:
     {
     {
         float shift = 0;
         float shift = 0;
        vector position;
        vector size;
        list link;
        integer i;
          
          
         if(msg == "This")
         if(msg == "Done" || msg == "Later")
        {
            LinkSet = FALSE;
            menu2();
        }
        else if(msg == "All")
        {
            LinkSet = TRUE;
            menu2();
        }
        else if(msg == "Done" || msg == "Later")
         {
         {
             llListenRemove(Listener);
             llListenRemove(Listener);
             llSetTimerEvent(0);
             llSetTimerEvent(0);
         }
         }
         else if(msg == "-1%")
       
         else if(~llListFindList(["This","All"], [msg]))
         {
         {
             shift = 0.99;
             integer i = llListFindList(["This","All"], [msg]);
            if(i != -1)
            {
                LinkSet = i;
                menu2();
            }
         }
         }
         else if(msg == "-5%")
       
         else if(~llListFindList(Percent, [msg]))
         {
         {
             shift = 0.95;
             integer i = llListFindList(Percent, [msg]);
        }
             if(i != -1)
        else if(msg == "-10%")
            {
        {
                shift = llList2Float(Ratio, i);
             shift = 0.9;
             }
        }
        else if(msg == "+1%")
        {
            shift = 1.01;
        }
        else if(msg == "+5%")
        {
             shift = 1.05;
        }
        else if(msg == "+10%")
        {
            shift = 1.1;
         }
         }
          
          
Line 168: Line 130:
         {
         {
             llOwnerSay("Please wait...");
             llOwnerSay("Please wait...");
             if(!LinkSet)
             integer i = 0;
            do
             {
             {
                 link = llGetLinkPrimitiveParams(Prim, [PRIM_SIZE , PRIM_POSITION]);
                 list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE , PRIM_POS_LOCAL]);
                 position = llList2Vector(link, 1);
                 vector size = llList2Vector(params, 0);
                 position = (position - llGetRootPosition()) / llGetRootRotation();
                 vector position = llList2Vector(params, 1);
                size = llList2Vector(link, 0);
                  
                  
                 llSetLinkPrimitiveParamsFast(Prim,[PRIM_DESC,(string)size + "#" + (string)position]);
                 if(i > 1)
            }
                {
            else
                    llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size + "#" + (string)position]);
            {
                }
                for(i = 0; i <= llGetNumberOfPrims(); i++)
                else
                 {
                 {
                     link = llGetLinkPrimitiveParams(i, [PRIM_SIZE , PRIM_POSITION]);
                     llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size]);
                    size = llList2Vector(link, 0);
                    position = llList2Vector(link, 1);
                    position = (position - llGetRootPosition()) / llGetRootRotation();
                   
                    if(i > 1)
                    {
                        llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size + "#" + (string)position]);
                    }
                    else
                    {
                        llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size]);
                    }
                 }
                 }
                new = FALSE;
             }
             }
             llOwnerSay("All parameters are stored");
            while(++i <= Links);
             menu2();
            New = 0;
           
             llOwnerSay("All parameters have been stored.");
             menu1();
         }
         }
          
          
Line 204: Line 156:
         else if(msg == "Restore")
         else if(msg == "Restore")
         {
         {
             if(!new)
             if(!New)
             {
             {
                 llOwnerSay("Please wait...");
                 llOwnerSay("Please wait...");
                 if(!LinkSet)
                 if(!LinkSet)
                 {
                 {
                     link = llGetLinkPrimitiveParams(Prim, [PRIM_DESC]);
                     list params = llGetLinkPrimitiveParams(Prim, [PRIM_DESC]);
                     list parsed = llParseString2List(llList2CSV(link), ["#"], []);
                     list parsed = llParseString2List(llList2CSV(params), ["#"], []);
                     string vect = llList2String(parsed, 0);
                     string vect = llList2String(parsed, 0);
                     size = (vector)vect;
                     vector size = (vector)vect;
                      
                      
                     llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
                     llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
Line 218: Line 170:
                 else
                 else
                 {
                 {
                     for(i = 0; i <= llGetNumberOfPrims(); i++)
                     integer i = 0;
                    do
                     {
                     {
                         link = llGetLinkPrimitiveParams(i, [PRIM_DESC]);
                         list params = llGetLinkPrimitiveParams(i, [PRIM_DESC]);
                         list parsed = llParseString2List(llList2CSV(link), ["#"], []);
                         list parsed = llParseString2List(llList2CSV(params), ["#"], []);
                         string vect = llList2String(parsed, 0);
                         string vect = llList2String(parsed, 0);
                         size = (vector)vect;
                         vector size = (vector)vect;
                         string posi = llList2String(parsed, 1);
                         string posi = llList2String(parsed, 1);
                         position = (vector)posi;
                         vector position = (vector)posi;
                          
                          
                         if(i > 1)
                         if(i > 1)
                         {
                         {
                             llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POSITION, position]);
                             llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POS_LOCAL, position]);
                         }
                         }
                         else
                         else
Line 236: Line 189:
                         }
                         }
                     }
                     }
                    while(++i <= Links);
                 }
                 }
                 llOwnerSay("All stored parameters restored.");
                 llOwnerSay("All stored parameters have been restored.");
                 menu2();
                 menu2();
             }
             }
             else if(new)
             else if(New)
             {
             {
                 llOwnerSay("Please first save all paremeters to use this.");
                 llOwnerSay("Please first save all paremeters to use this.");
Line 249: Line 203:
         if(shift != 0)
         if(shift != 0)
         {
         {
            llOwnerSay("Please wait...");
             if(!LinkSet)
             if(!LinkSet)
             {
             {
                 link = llGetLinkPrimitiveParams(Prim, [PRIM_SIZE]);
                 list params = llGetLinkPrimitiveParams(Prim, [PRIM_SIZE]);
                 size = llList2Vector(link, 0) * shift;
                 vector size = llList2Vector(params, 0) * shift;
                  
                  
                 llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
                 llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
Line 259: Line 212:
             else
             else
             {
             {
                 for(i = 0; i <= llGetNumberOfPrims(); i++)
                 integer i = 0;
                do
                 {
                 {
                     link = llGetLinkPrimitiveParams(i, [PRIM_SIZE, PRIM_POSITION]);
                     list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE, PRIM_POS_LOCAL]);
                     size = llList2Vector(link, 0) * shift;
                     vector size = llList2Vector(params, 0) * shift;
                     position = llList2Vector(link, 1);
                     vector position = llList2Vector(params, 1) * shift;
                    position = (position - llGetRootPosition()) / llGetRootRotation() * shift;
                      
                      
                     if(i > 1)
                     if(i > 1)
                     {
                     {
                         llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POSITION, position]);
                         llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POS_LOCAL, position]);
                     }
                     }
                     else
                     else
Line 275: Line 228:
                     }
                     }
                 }
                 }
                while(++i <= Links);
             }
             }
            llOwnerSay("Finish.");
             menu2();
             menu2();
         }
         }
Line 290: Line 243:
     on_rez(integer Dae)
     on_rez(integer Dae)
     {
     {
         if(new)
         if(New)
         {
         {
             llResetScript();
             llResetScript();
Line 296: Line 249:
     }
     }
}
}
</lsl>
</source>

Latest revision as of 11:30, 17 March 2023

*DS* Resize Example v3.0.00

Single resize script for a complete linkset with save and restore option.

//
//    ╔═════════════════════════════════════−−−­­­­­­→
//    ║ *DS* Resize Example by Daemonika Nightfire (daemonika.nightfire)
//    ╚══════════════════════−−−­­­→
//
//    Resize Script for rezzed Objects and Attachments.
//    Single-script for a complete linkset with save and restore option.
//    
//        Featueres:
//        • By the first run or reset of this script, it will ask you to save all parameters.
//          The parameters will be stored in the descriptionfield of each prim, that needs no script-memory :)
//        • You can save, resize and restore individual prims or the complette linkset.
//        
//        Important:
//        • Undersize is possible, but take care.
//          if you are small your object and several prims already have minimum dimensions, they are not further reduced, but they are moved proportionally.
//        • Sculpted Prims are no problem, but take care.
//          Sculpties with moved Bounding Box perhaps moving optical not correct
//          That is not true, they are moving correctly, but when the visible Sculptie is not the center of the Bounding Box, it will be looking wrong.
//    
//    Terms of use:
//    You can use, edit and sell this script inside your creations with the following permissions in Second Life:
//    • MOD Yes • COPY Yes • TRANSFER Yes
//    
//    Yes that means fullperm. Other settings, are against the following licenses.
//    The permission of your Object (prim), remain unaffected by these terms
//    
//    https://wiki.secondlife.com/wiki/User:Daemonika_Nightfire/Scripts/*DS*_Resize_Script
//    http://wiki.secondlife.com/wiki/Project:Terms_of_Service
//    http://creativecommons.org/licenses/by-sa/3.0/
//    
//    violation of this Terms are against the Second Life TOS at §7 Content Licenses and Intellectual Property Rights.
//    http://secondlife.com/corporate/tos.php
//

key owner;
integer New = 1;

integer LinkSet = 1;
integer Prim;
integer Links;
list Percent = ["-1%","-5%","-10%","+1%","+5%","+10%"];
list Ratio = [0.99,0.95,0.90,1.01,1.05,1.10];

integer Channel;
integer Listener;
Chan()
{
    llListenRemove(Listener);
    Channel = (integer)(llFrand(1) * -DEBUG_CHANNEL);
    Listener = llListen(Channel, "", owner, "");
    llSetTimerEvent(60);
}

menu1()
{
    Chan();
    if(New)
    {
        llDialog(owner, "\nYour first run or reset of this script.\nDo you whish to save current parameters?",
        ["Save","Later"], Channel);
    }
    else
    {
        llDialog(owner, "\nselect an option\nThis = touched Prim\nAll = complete Object",
        ["This","All","Done"], Channel);
    }
}

menu2()
{
    Chan();
    llDialog(owner, "\n+ - = resize\nSave = record all parameters\nRestore = restore saved parameters",
    ["Save","Restore","Done"] + Percent, Channel);
}

default
{
    state_entry()
    {
        owner = llGetOwner();
        llOwnerSay("/me " + llGetScriptName() + " Free Memory: " + (string)llGetFreeMemory() + " bytes.");
    }
    
    touch_start(integer total_number)
    {
        owner = llGetOwner();
        if(llDetectedKey(0) == owner)
        {
            Links = llGetNumberOfPrims();
            Prim = llDetectedLinkNumber(0);
            menu1();
        }
    }
    
    listen(integer channel, string name, key id, string msg)
    {
        float shift = 0;
        
        if(msg == "Done" || msg == "Later")
        {
            llListenRemove(Listener);
            llSetTimerEvent(0);
        }
        
        else if(~llListFindList(["This","All"], [msg]))
        {
            integer i = llListFindList(["This","All"], [msg]);
            if(i != -1)
            {
                LinkSet = i;
                menu2();
            }
        }
        
        else if(~llListFindList(Percent, [msg]))
        {
            integer i = llListFindList(Percent, [msg]);
            if(i != -1)
            {
                shift = llList2Float(Ratio, i);
            }
        }
        
        // Record
        else if(msg == "Save")
        {
            llOwnerSay("Please wait...");
            integer i = 0;
            do
            {
                list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE , PRIM_POS_LOCAL]);
                vector size = llList2Vector(params, 0);
                vector position = llList2Vector(params, 1);
                
                if(i > 1)
                {
                    llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size + "#" + (string)position]);
                }
                else
                {
                    llSetLinkPrimitiveParamsFast(i,[PRIM_DESC,(string)size]);
                }
            }
            while(++i <= Links);
            New = 0;
            
            llOwnerSay("All parameters have been stored.");
            menu1();
        }
        
        // Restore
        else if(msg == "Restore")
        {
            if(!New)
            {
                llOwnerSay("Please wait...");
                if(!LinkSet)
                {
                    list params = llGetLinkPrimitiveParams(Prim, [PRIM_DESC]);
                    list parsed = llParseString2List(llList2CSV(params), ["#"], []);
                    string vect = llList2String(parsed, 0);
                    vector size = (vector)vect;
                    
                    llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
                }
                else
                {
                    integer i = 0;
                    do
                    {
                        list params = llGetLinkPrimitiveParams(i, [PRIM_DESC]);
                        list parsed = llParseString2List(llList2CSV(params), ["#"], []);
                        string vect = llList2String(parsed, 0);
                        vector size = (vector)vect;
                        string posi = llList2String(parsed, 1);
                        vector position = (vector)posi;
                        
                        if(i > 1)
                        {
                            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POS_LOCAL, position]);
                        }
                        else
                        {
                            llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size]);
                        }
                    }
                    while(++i <= Links);
                }
                llOwnerSay("All stored parameters have been restored.");
                menu2();
            }
            else if(New)
            {
                llOwnerSay("Please first save all paremeters to use this.");
            }
        }
        
        // Resize
        if(shift != 0)
        {
            if(!LinkSet)
            {
                list params = llGetLinkPrimitiveParams(Prim, [PRIM_SIZE]);
                vector size = llList2Vector(params, 0) * shift;
                
                llSetLinkPrimitiveParamsFast(Prim, [PRIM_SIZE, size]);
            }
            else
            {
                integer i = 0;
                do
                {
                    list params = llGetLinkPrimitiveParams(i, [PRIM_SIZE, PRIM_POS_LOCAL]);
                    vector size = llList2Vector(params, 0) * shift;
                    vector position = llList2Vector(params, 1) * shift;
                    
                    if(i > 1)
                    {
                        llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size, PRIM_POS_LOCAL, position]);
                    }
                    else
                    {
                        llSetLinkPrimitiveParamsFast(i, [PRIM_SIZE, size]);
                    }
                }
                while(++i <= Links);
            }
            menu2();
        }
    }
    
    timer()
    {
        llSetTimerEvent(0);
        llListenRemove(Listener);
        llOwnerSay("Listener timeout, please touch again to use the menu.");
    }
    
    on_rez(integer Dae)
    {
        if(New)
        {
            llResetScript();
        }
    }
}