Difference between revisions of "Curtain script"

From Second Life Wiki
Jump to navigation Jump to search
(Replace 3 rambling scripts with one concise multi-purpose script)
m (Tweak)
Line 2: Line 2:
== About this script: ==
== About this script: ==


Drop this script into the prim you want to use as a curtain etc.  
Drop this script into the prim you want to use as a curtain etc.  
The script will change the length of the prim on one or more axes.  
The script will change the length of the prim on one or more axes.  
Use sliced or path-cut prims to keep an edge stationary, e.g. in a blind.
Use sliced or path-cut prims to keep an edge stationary, e.g. in a blind.
For a Mesh prim, arrange for the pivot point to be on one edge.
For a Mesh prim, arrange for the pivot point to be on one edge.


You can use these scripts with any prim type.
You can use these scripts with any prim type.
Line 17: Line 17:
// Define the large and small sizes of the prim here:-
// Define the large and small sizes of the prim here:-
// (if the prim is sliced or path cut, it will appear to be half size on the affected dimension)
// (if the prim is sliced or path cut, it will appear to be half size on the affected dimension)
vector  ScaleLarge = <0.1, 3.0, 6.0>;
vector  gScaleLarge = <0.1, 3.0, 6.0>;
vector  ScaleSmall = <0.1, 3.0, 1.2>;
vector  gScaleSmall = <0.1, 3.0, 1.2>;


integer gSteps  = 20;  // Number of steps in the shrink/expand process
integer gSteps  = 20;  // Number of steps in the shrink/expand process
Line 27: Line 27:
     state_entry()
     state_entry()
     {
     {
llSetScale(ScaleLarge);
llSetScale(gScaleLarge);
     }
     }


Line 37: Line 37:
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
vector ScaleStep = (ScaleLarge - ScaleSmall) / gSteps;  // Compute the scale augment per step
vector ScaleStep = (gScaleLarge - gScaleSmall) / gSteps;  // Compute the scale augment per step
vector wscale = llGetScale();
vector wscale = llGetScale();
gSwitch *= -1;  // Switch between stretch and contract
gSwitch *= -1;  // Switch between stretch and contract
integer i;
integer i;
for (i = 0; i < gSteps; i++)
for ( ; i < gSteps; ++i )
{
{
    // It is more lag-friendly to incorporate a sleep per step
    // It is more lag-friendly to incorporate a sleep per step
    // Rather than greatly increasing the number of steps
    // Rather than greatly increasing the number of steps
    llSleep(0.1); 
    llSleep(0.1); 
    llSetScale(wscale + ScaleStep * i * gSwitch);  
    llSetScale(wscale + ScaleStep * (float) i * gSwitch);  
}
}
     }
     }

Revision as of 15:20, 17 February 2013

About this script:

Drop this script into the prim you want to use as a curtain etc. 
The script will change the length of the prim on one or more axes. 
Use sliced or path-cut prims to keep an edge stationary, e.g. in a blind.
For a Mesh prim, arrange for the pivot point to be on one edge.

You can use these scripts with any prim type.

<lsl> // Prim Resizer (shrink/expand) by Omei Qunhua // e.g. Roll a blind from the top. (use a prim with slice end = 50%)

// Note: This script can rescale a prim on any or all axes

// Define the large and small sizes of the prim here:- // (if the prim is sliced or path cut, it will appear to be half size on the affected dimension) vector gScaleLarge = <0.1, 3.0, 6.0>; vector gScaleSmall = <0.1, 3.0, 1.2>;

integer gSteps = 20; // Number of steps in the shrink/expand process float gSwitch = 1.0; // Action on first touch. +1.0 = shrink, -1.0 = expand

default {

   state_entry()
   {

llSetScale(gScaleLarge);

   }
   on_rez(integer x)
   {

llResetScript();

   }
   touch_start(integer total_number)
   {

vector ScaleStep = (gScaleLarge - gScaleSmall) / gSteps; // Compute the scale augment per step vector wscale = llGetScale(); gSwitch *= -1; // Switch between stretch and contract integer i; for ( ; i < gSteps; ++i ) { // It is more lag-friendly to incorporate a sleep per step // Rather than greatly increasing the number of steps llSleep(0.1); llSetScale(wscale + ScaleStep * (float) i * gSwitch); }

   }

}

</lsl>