Difference between revisions of "Curtain script"

From Second Life Wiki
Jump to navigation Jump to search
(replaced example script with three example scripts, one for each axis.)
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
== About these scripts: ==
== About this script: ==


Drop these scripts into the prim you want to use as a curtain. The script will change the length of the prim on one of the three axis. There's one script each for x, y and z.
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.
You can use these scripts with any prim type.


== Curtain script to change length on x-axis ==
<source lang="lsl2">
<lsl>
// Prim Resizer (shrink/expand) by Omei Qunhua
float maxScaleX;
// e.g. Roll a blind from the top. (use a prim with slice end = 50%)
float minScaleX;
float time;
integer direction;


init()
// Note: This script can rescale a prim on any or all axes
{
    maxScaleX = 4.00;
    minScaleX = 0.50;
    time = 2.0;
 
    direction = 1;
}
 
OperateBlind()
{
    vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
    {
        i = llGetTime()/time;
        if (direction == 1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <maxScaleX - i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
                PRIM_POSITION, startPos + i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
        else if (direction == -1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <minScaleX + i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
                PRIM_POSITION, startPos - i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <maxScaleX - i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
            PRIM_POSITION, startPos + i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <minScaleX + i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
            PRIM_POSITION, startPos - i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    direction *= -1;
}
 
default
{
    state_entry()
    {
        init();
    }
 
    touch_start(integer num_detected)
    {
        OperateBlind();
    }
}
</lsl>
== Curtain script to change length on y-axis ==
<lsl>
float maxScaleY;
float minScaleY;
float time;
integer direction;
 
init()
{
    maxScaleY = 4.00;
    minScaleY = 0.50;
    time = 2.0;


    direction = 1;
// 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>;


OperateBlind()
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
    vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
    {
        i = llGetTime()/time;
        if (direction == 1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, maxScaleY - i*(maxScaleY-minScaleY), startScale.z>,
                PRIM_POSITION, startPos + i*<0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
        else if (direction == -1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, minScaleY + i*(maxScaleY-minScaleY), startScale.z>,
                PRIM_POSITION, startPos - i*<0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, maxScaleY - (maxScaleY-minScaleY), startScale.z>,
            PRIM_POSITION, startPos + <0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, minScaleY + (maxScaleY-minScaleY), startScale.z>,
            PRIM_POSITION, startPos - <0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    direction *= -1;
}


default
default
Line 117: Line 27:
     state_entry()
     state_entry()
     {
     {
        init();
llSetScale(gScaleLarge);
     }
     }


     touch_start(integer num_detected)
     on_rez(integer x)
     {
     {
        OperateBlind();
llResetScript();
     }
     }
}
</lsl>
== Curtain script to change length on z-axis ==
<lsl>
float maxScaleZ;
float minScaleZ;
float time;
integer direction;
init()
{
    maxScaleZ = 4.00;
    minScaleZ = 0.50;
    time = 2.0;
    direction = 1;
}


OperateBlind()
     touch_start(integer total_number)
{
     vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
     {
     {
        i = llGetTime()/time;
vector ScaleStep = (gScaleLarge - gScaleSmall) / gSteps; // Compute the scale augment per step
        if (direction == 1)
vector wscale = llGetScale();
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
gSwitch *= -1;  // Switch between stretch and contract
                PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - i*(maxScaleZ-minScaleZ)>,
integer i;
                PRIM_POSITION, startPos + i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
for ( ; i < gSteps; ++i )
        else if (direction == -1)
{
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
    // It is more lag-friendly to incorporate a sleep per step
                PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + i*(maxScaleZ-minScaleZ)>,
    // Rather than greatly increasing the number of steps
                PRIM_POSITION, startPos - i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    llSleep(0.1);
    llSetScale(wscale + ScaleStep * (float) i * gSwitch);  
}
     }
     }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - (maxScaleZ-minScaleZ)>,
            PRIM_POSITION, startPos + <0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + (maxScaleZ-minScaleZ)>,
            PRIM_POSITION, startPos - <0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    direction *= -1;
}
}


default
</source>
{
    state_entry()
    {
        init();
    }
 
    touch_start(integer num_detected)
    {
        OperateBlind();
    }
}
</lsl>
{{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); 
	}
    }
}