Difference between revisions of "Curtain script"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
General no frills script to retract and stretch back out a prim for use in curtains, blinds, bed covers and more. Choose local axis and direction for move/size change. Works both in unlinked and linked prims, but must not be root prim.
== About this script: ==


<lsl>
Drop this script into the prim you want to use as a curtain etc.  
//When touched the prim is retracted towards one end and when touched again stretched back out.
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.
//Prim moves/changes size along the local coordinate specified in the offset vector below.
  For a Mesh prim, arrange for the pivot point to be on one edge.
//
//To change the overall size, edit the prim when stretched out and reset the script when done.  
//
//The script works both in unlinked and linked prims.
//
// Copyright (C) 2008 Zilla Larsson
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License version 3, as
//    published by the Free Software Foundation.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>


You can use these scripts with any prim type.


vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
<source lang="lsl2">
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?         
// Prim Resizer (shrink/expand) by Omei Qunhua
                            //The one with the higher (local) coordinate?
// e.g. Roll a blind from the top. (use a prim with slice end = 50%)
float min = 0.2; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change


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


default {
// Define the large and small sizes of the prim here:-
    state_entry() {
// (if the prim is sliced or path cut, it will appear to be half size on the affected dimension)
        offset *= ((1.0 - min) / ns) * (offset * llGetScale());
vector  gScaleLarge = <0.1, 3.0, 6.0>;
        hi_end_fixed -= 0.5;
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);
     }
     }
      
 
     touch_start(integer detected) {
     on_rez(integer x)
        integer i;
    {
        do  llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
llResetScript();
                PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
    }
        while ((++i) < ns);          
 
        offset = - offset;
     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>


</source>
{{LSLC|Library}}
{{LSLC|Library}}

Latest revision as of 14:08, 22 January 2015

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.

// 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); 
	}
    }
}