02-18-2013, 02:18 AM
PHP Code:
vector vSize;
vector vPos1;
vector vPos;
string sPctP3 = "5";
string sPctP2 = "2";
string sPctP1 = "1";
string sPctM3 = "5";
string sPctM2 = "2";
string sPctM1 = "1";
string sPct;
list lSortPrims;
list lSizes;
list lPos;
list lName;
list lElem;
integer iSens;
integer iNumberOfPrims;
integer iNoMoreMax;
integer iNbPasses;
integer iMenuOn;
integer iLast;
integer iIdx;
integer iHugeUsed;
integer iFirst;
integer iFin;
integer iError;
integer iEcouteMenu;
integer iDeb;
integer iCurrentMenu;
integer iCanalMenu;
integer iCanalComm = -8547548;
integer iBcl;
integer iAllowResizeHugePrims = -1;
float fTmp;
float fMin;
float fMax;
float fLimiteMax;
float fFactor;
float fDefault;
integer TestError()
{
if( fMax > fLimiteMax )
ControlSizePos( vSize, vPos );
return( iError );
}
float MinMaxVal( integer iOperation )
{
return( llListStatistics( iOperation, [ vSize.x, vSize.y, vSize.z ] ) );
}
GoBackToGoodSize()
{
llOwnerSay( "Error, back to previous good size..." );
sPct = "aborted";
if( llRound( fFactor * 100.0 ) == 101 )
iNoMoreMax = TRUE;
fMin /= fFactor;
fMax /= fFactor;
iFin = iDeb - iSens;
iDeb = iIdx;
iSens *= -1;
fFactor = 1.0;
iNbPasses = 3;
if( iNoMoreMax )
fLimiteMax = fMax;
do
{
Booster();
iError = FALSE;
for( iIdx = iDeb; iIdx != iFin; iIdx += iSens )
{
iBcl = llList2Integer( lSortPrims, iIdx );
lElem = [ PRIM_SIZE, llList2Vector( lSizes, iIdx ) ];
if( iBcl != iFirst )
{
vPos = llList2Vector( lPos, iIdx );
lElem += [ PRIM_POSITION, vPos ];
}
llSetLinkPrimitiveParamsFast( iBcl, lElem );
llSetLinkPrimitiveParamsFast( iBcl, lElem );
llSetLinkPrimitiveParamsFast( iBcl, lElem );
}
ControlBuild( FALSE );
}
while( iError && --iNbPasses );
if( iError )
llOwnerSay( "Sorry, the build is broken and can't be repaired." );
}
GetSizePos()
{
vSize = llList2Vector( llGetLinkPrimitiveParams( iBcl, [ PRIM_SIZE ] ), 0 ) * fFactor;
if( iBcl == iFirst )
{
if( llGetAttached() )
vPos = llGetLocalPos();
else
vPos = llGetRootPosition();
}
else
vPos = ( ( llList2Vector( llGetLinkPrimitiveParams( iBcl, [ PRIM_POSITION ] ), 0 ) - llGetRootPosition() ) / llGetRootRotation() ) * fFactor;
}
ControlSizePos( vector vRefSize, vector vRefPos )
{
if( llVecDist( llList2Vector( llGetLinkPrimitiveParams( iBcl, [ PRIM_SIZE ] ), 0 ), vRefSize ) > 0.001 )
iError = TRUE;
else if( iBcl != iFirst )
{
if( llVecDist( ( llList2Vector( llGetLinkPrimitiveParams( iBcl, [ PRIM_POSITION ] ), 0 ) - llGetRootPosition() ) / llGetRootRotation(),
vRefPos ) > 0.001 )
iError = TRUE;
}
}
ControlBuild( integer iBoost )
{
if( iBoost )
Booster();
for( iIdx = iDeb; iIdx != iFin; iIdx += iSens )
{
iBcl = llList2Integer( lSortPrims, iIdx );
ControlSizePos( llList2Vector( lSizes, iIdx ) * fFactor, llList2Vector( lPos, iIdx ) * fFactor );
if( iError )
{
if( iBoost )
iIdx = iFin - iSens;
return;
}
}
}
ChangeSizePos()
{
Booster();
for( iIdx = iDeb; iIdx != iFin; iIdx += iSens )
{
iBcl = llList2Integer( lSortPrims, iIdx );
GetSizePos();
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_SIZE, vSize, PRIM_POSITION, vPos ] );
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_POSITION, vPos ] );
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_POSITION, vPos ] );
if( TestError() )
return;
}
}
ChangeSize( integer iCorrect )
{
Booster();
for( iIdx = iDeb; iIdx != iFin; iIdx += iSens )
{
iBcl = llList2Integer( lSortPrims, iIdx );
GetSizePos();
if( iCorrect )
vPos /= fFactor;
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_SIZE, vSize ] );
if( TestError() )
return;
}
}
ChangePos( integer iCorrect )
{
Booster();
for( iIdx = iDeb; iIdx != iFin; iIdx += iSens )
if( ( iBcl = llList2Integer( lSortPrims, iIdx ) ) != iFirst )
{
GetSizePos();
vPos1 = vPos / fFactor;
if( iCorrect )
vSize /= fFactor;
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_POSITION, vPos ] );
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_POSITION, vPos ] );
llSetLinkPrimitiveParamsFast( iBcl, [ PRIM_POSITION, vPos ] );
if( TestError() )
return;
}
}
Booster()
{
for( iBcl = 0; iBcl < 5000; iBcl++ );
}
AlreadyAt( integer iMess, string sMess )
{
if( iMess )
{
llOwnerSay( "Already at " + sMess + " size." );
Menu();
}
}
init()
{
Booster();
iNumberOfPrims = llGetNumberOfPrims();
iFirst = (integer)( iNumberOfPrims > 1 );
iLast = iNumberOfPrims - (integer)( iNumberOfPrims == 1 );
llOwnerSay( "Searching min/max prim size..." );
fMin = 10.0;
fMax = 0.01;
fFactor = 1.0;
for( iBcl = iFirst; ( fMax <= 10.0 || iAllowResizeHugePrims ) && iBcl <= iLast; iBcl++ )
{
GetSizePos();
if( iBcl == iFirst )
{
fDefault = vSize.x;
lElem = [ 0.0, iFirst ];
}
else
lElem += [ llVecDist( ZERO_VECTOR, vPos ), iBcl ];
fTmp = MinMaxVal( LIST_STAT_MIN );
if( fTmp < fMin )
fMin = fTmp;
fTmp = MinMaxVal( LIST_STAT_MAX );
if( fTmp > fMax )
fMax = fTmp;
}
if( fMax > 10.0 && ! iAllowResizeHugePrims )
{
iHugeUsed = TRUE;
llOwnerSay( "Script not active, object uses huge prim." );
}
else
{
llOwnerSay( "Size range : " + (string)fMin + " -> " + (string)fMax );
iNoMoreMax = FALSE;
iHugeUsed = FALSE;
llOwnerSay( "Sorting prims..." );
lElem = llListSort( lElem, 2, TRUE );
lSortPrims = [];
for( iBcl = 1; iBcl < llGetListLength( lElem ); iBcl += 2 )
lSortPrims += [ llList2Integer( lElem, iBcl ) ];
llOwnerSay( (string)iNumberOfPrims + " prim" + llList2String( [ "", "s" ], (integer)(iNumberOfPrims > 1) ) + " sorted." );
fLimiteMax = llListStatistics( LIST_STAT_MAX, [ 10.0, fMax ] );
llOwnerSay( "Storing size/pos of each prim..." );
SaveSizePos();
}
llOwnerSay( "Init. complete." );
}
SaveSizePos()
{
Booster();
fFactor = 1.0;
lSizes = [];
lPos = [];
for( iIdx = 0; iIdx != iNumberOfPrims; iIdx++ )
{
iBcl = llList2Integer( lSortPrims, iIdx );
GetSizePos();
lSizes += [ vSize ];
lPos += [ vPos ];
}
}
Resize( integer iMess )
{
fMin *= fFactor;
fMax *= fFactor;
sPct = "done";
if( fFactor < 1.0 )
{
iDeb = llGetListLength( lSortPrims ) - 1;
iFin = -1;
iSens = -1;
}
else
{
iDeb = 0;
iFin = llGetListLength( lSortPrims );
iSens = 1;
}
iError = FALSE;
if( fFactor < 0.5 )
ChangePos( FALSE );
else if( fFactor > 2.0 )
ChangeSize( FALSE );
else
ChangeSizePos();
if( ! iError )
{
if( fFactor < 0.5 )
ChangeSize( TRUE );
else if( fFactor > 2.0 )
ChangePos( TRUE );
}
if( ! iError )
ControlBuild( TRUE );
if( iError )
GoBackToGoodSize();
else
{
SaveSizePos();
if( fMax == 10.0 && ! iAllowResizeHugePrims )
{
iNoMoreMax = TRUE;
fLimiteMax = fMax;
}
}
if( fMax > fLimiteMax )
fLimiteMax = fMax;
llResetTime();
if( iMess )
{
llOwnerSay( "Resize " + sPct + "." );
Menu();
}
}
MinimumSize( integer iMess )
{
if( ( fFactor = 0.01 / fMin ) != 1.0 )
{
if( iMess )
{
sPct = (string)llRound( ( fFactor - 1.0 ) * 100.0 );
if( fFactor > 1.0 )
sPct = "+" + sPct;
llOwnerSay( "Minimum size (" + sPct + "%)..." );
}
Resize( iMess );
}
else
AlreadyAt( iMess, "minimum" );
}
Menu()
{
llSetTimerEvent( 30.0 );
llDialog( llGetOwner(),
"Resizer action :\n" +
"Quit : Leave this menu.\n" +
"Options : Current size becomes default.\n" +
">> : Next set of percentages.\n" +
"Min : Resize to minimum size.\n" +
"Default : Return to initial size.\n" +
"Max : Resize to maximum size.",
[ "Quit", "Options", ">>",
"-" + sPctM1 + "%", "Min", "+" + sPctP1 + "%",
"-" + sPctM2 + "%", "Default", "+" + sPctP2 + "%",
"-" + sPctM3 + "%", "Max", "+" + sPctP3 + "%" ],
iCanalMenu );
}
MaximumSize( integer iMess )
{
if( ( fFactor = fLimiteMax / fMax ) != 1.0 )
{
if( iMess )
{
sPct = (string)llRound( ( fFactor - 1.0 ) * 100.0 );
if( fFactor > 1.0 )
sPct = "+" + sPct;
llOwnerSay( "Maximum size (" + sPct + "%)..." );
}
Resize( iMess );
}
else
AlreadyAt( iMess, "maximum" );
}
FinMenu( integer iAlert )
{
iMenuOn = FALSE;
llSetTimerEvent( 0.0 );
llListenRemove( iEcouteMenu );
if( iAlert )
llOwnerSay( "Menu timeout." );
}
DefaultSize( integer iMess )
{
vSize = llList2Vector( llGetLinkPrimitiveParams( iFirst, [ PRIM_SIZE ] ), 0 );
if( ( fFactor = fDefault / vSize.x ) != 1.0 )
{
if( iMess )
{
sPct = (string)llRound( ( fFactor - 1.0 ) * 100.0 );
if( fFactor > 1.0 )
sPct = "+" + sPct;
llOwnerSay( "Default size (" + sPct + "%)..." );
}
Resize( iMess );
}
else
AlreadyAt( iMess, "default" );
}
default
{
state_entry()
{
if( iAllowResizeHugePrims < 0 )
iAllowResizeHugePrims = (integer)( llSubStringIndex( llGetSimulatorHostname(), ".lindenlab.com" ) < 0 );
init();
llListen( iCanalComm, "", NULL_KEY, "" );
}
changed( integer iChange )
{
if( ( iChange & CHANGED_LINK ) ||
( ( iChange & CHANGED_SCALE ) &&
llGetTime() > 5.0 / llList2Float( [ llGetRegionTimeDilation(), 0.01 ],
(integer)( llGetRegionTimeDilation() < 0.01 ) ) ) )
init();
}
listen( integer iChannel, string sName, key kId, string sMess )
{
if( iChannel == iCanalMenu )
{
llSetTimerEvent( 0.0 );
if( sMess == ">>" )
{
if( (++iCurrentMenu) == 3 )
iCurrentMenu = 0;
if( ! iCurrentMenu )
{
sPctM1 = "1";
sPctM2 = "2";
sPctM3 = "5";
sPctP1 = "1";
sPctP2 = "2";
sPctP3 = "5";
}
else if( iCurrentMenu == 1 )
{
sPctM1 = "10";
sPctM2 = "25";
sPctM3 = "50";
sPctP1 = "10";
sPctP2 = "25";
sPctP3 = "50";
}
else
{
sPctM1 = "75";
sPctM2 = "85";
sPctM3 = "95";
sPctP1 = "75";
sPctP2 = "100";
sPctP3 = "200";
}
Menu();
}
else if( sMess == "Options" || sMess == " " )
{
llSetTimerEvent( 30.0 );
llDialog( llGetOwner(),
"\nResizer options :\n \n" +
"Quit : Leave this menu.\n" +
"BACK : To main menu.\n" +
"Set default : Current size is default.\n" +
"Remove : Remove the script.",
[ "Quit", " ", "BACK",
"Set default", " ", "Remove" ],
iCanalMenu );
}
else if( sMess == "BACK" )
Menu();
else if( sMess == "Set default" )
{
vSize = llList2Vector( llGetLinkPrimitiveParams( iFirst, [ PRIM_SIZE ] ), 0 );
fDefault = vSize.x;
if( llGetAttached() )
llSay( iCanalComm, (string)llGetOwner() + "|Default|" + (string)fDefault );
llOwnerSay( "This size is now the default size." );
Menu();
}
else if( sMess == "Remove" )
{
llSetTimerEvent( 30.0 );
llDialog( llGetOwner(),
"\nSure to remove the script from this object ?",
[ "Yes", "No" ],
iCanalMenu );
}
else if( sMess == "Default" )
DefaultSize( TRUE );
else if( sMess == "Min" )
MinimumSize( TRUE );
else if( sMess == "Max" )
MaximumSize( TRUE );
else if( ( iBcl = llListFindList( [ "+", "-" ], [ llGetSubString( sMess, 0, 0 ) ] ) ) >= 0 )
{
fFactor = 1.0 + (float)llGetSubString( sMess, 0, -2 ) / 100.0;
fTmp = llList2Float( [ llList2Float( [ 10.0, 10000.0 ], iAllowResizeHugePrims ), fLimiteMax ], iNoMoreMax );
if( fMin * fFactor < 0.01 )
fFactor = 0.01 / fMin;
else if( fMax * fFactor > fTmp )
fFactor = fTmp / fMax;
if( fMin * fFactor >= 0.01 && fMax * fFactor <= fTmp && llRound( fFactor * 100.0 ) != 100 )
{
sPct = (string)llRound( ( fFactor - 1.0 ) * 100.0 ) + "%";
if( fFactor > 1.0 )
sPct = "+" + sPct;
llOwnerSay( llList2String( [ "Increas", "Reduc" ], iBcl ) + "ing size : " +
sPct + llList2String( [ " (" + sMess + " asked)", "" ], (integer)(sMess == sPct) ) + "..." );
if( llGetAttached() )
llSay( iCanalComm, (string)llGetOwner() + "|Factor|" + (string)fFactor );
Resize( TRUE );
}
else
{
llOwnerSay( "Out of size range." );
Menu();
}
}
else
{
FinMenu( FALSE );
if( sMess == "Yes" )
{
if( llGetAttached() )
llSay( iCanalComm, (string)llGetOwner() + "|Remove" );
llRemoveInventory( llGetScriptName() );
}
}
}
else if( llGetAttached() && sName != llGetObjectName() )
{
lElem = llParseString2List( sName, [ " " ], [ "" ] );
if( llGetListLength( lElem ) < 2 )
return;
lName = llParseString2List( llGetObjectName(), [ " " ], [ "" ] );
if( llGetListLength( lName ) < 2 )
return;
if( llDumpList2String( llList2List( lElem, 0, -2 ), " " ) !=
llDumpList2String( llList2List( lName, 0, -2 ), " " ) )
return;
lElem = llParseString2List( sMess, [ "|" ], [ "" ] );
if( llList2String( lElem, 0 ) == (string)llGetOwner() )
{
if( llList2String( lElem, 1 ) == "Remove" )
llRemoveInventory( llGetScriptName() );
else if( llList2String( lElem, 1 ) == "Factor" )
{
fFactor = llList2Float( lElem, 2 );
Resize( FALSE );
llResetTime();
}
else if( llList2String( lElem, 1 ) == "Min" )
MinimumSize( FALSE );
else if( llList2String( lElem, 1 ) == "Max" )
MaximumSize( FALSE );
else if( llList2String( lElem, 1 ) == "Default" )
{
if( llGetListLength( lElem ) == 2 )
DefaultSize( FALSE );
else
fDefault = llList2Float( lElem, 2 );
}
}
}
}
timer()
{
FinMenu( TRUE );
}
touch_start( integer iNum )
{
if( llDetectedKey( 0 ) == llGetOwner() && ! iMenuOn && ! iHugeUsed )
{
iMenuOn = TRUE;
iCanalMenu = iCanalComm - 10 - (integer)llFrand( 124578 );
iEcouteMenu = llListen( iCanalMenu, "", llGetOwner(), "" );
Menu();
}
}
}