Difference between revisions of "LlScaleByFactor"

From Second Life Wiki
Jump to navigation Jump to search
(Documenting the actual function)
Line 1: Line 1:
{{LSL_Function|mode=request
{{LSL_Function
|inject-2=
|inject-2=
|func_id=|func_sleep=0.0|func_energy=10.0
|func_id=|func_sleep=0.0|func_energy=10.0
Line 6: Line 6:
|p1_type=float|p1_name=scaling_factor|p1_desc=The multiplier to be used with the prim sizes and their local positions.
|p1_type=float|p1_name=scaling_factor|p1_desc=The multiplier to be used with the prim sizes and their local positions.
|func_desc=Attempts to resize the entire object by {{LSLP|scaling_factor}}, maintaining the size-position ratios of the prims.
|func_desc=Attempts to resize the entire object by {{LSLP|scaling_factor}}, maintaining the size-position ratios of the prims.
Resizing is subject to prim scale limits and linkability limits. This function can not resize the object if the linkset is physical, a pathfinding character, in a keyframed motion, or if resizing would cause the parcel to overflow.
|return_type=integer
|return_type=integer
|return_subtype=boolean
|return_subtype=boolean
|return_text=[[TRUE]] if it succeeds, [[FALSE]] if it fails.
|return_text=[[TRUE]] if it succeeds, [[FALSE]] if it fails.
|spec
|spec
|caveats
|caveats=
* Rescaling fails if the linkset is physical, a pathfinding character, in a keyframed motion, or if rescaling would cause the parcel to overflow.
*Due to floating point precision issues (because sqrt(x*x) != x), avoid rescaling by the values returned by [[llGetMinScaleFactor]] and [[llGetMaxScaleFactor]].  To guarantee successful rescaling, use values slightly within the limits returned by those functions).
* Due to floating point precision issues (because sqrt(x*x) != x), avoid rescaling by the values returned by [[llGetMinScaleFactor]] and [[llGetMaxScaleFactor]].  To guarantee successful rescaling, use values slightly within the limits returned by those functions).
|constants
|constants
|examples
|examples=
<lsl>// Touching this script causes the object to double or halve in size.
integer growing = FALSE;
default
{
    state_entry()
    {
        llSay(0, "Touch to toggle scale");
    }
    touch_start(integer total_number)
    {
        float min_factor = llGetMinScaleFactor();
        float max_factor = llGetMaxScaleFactor();
        integer success;
        llSay(0, "min_scale_factor = " + (string)min_factor + "  max_scale_factor = " + (string)max_factor);
        growing = !growing;
        if (growing)
        {
            success = llScaleByFactor(2.0);
        }
        else
        {
            success = llScaleByFactor(0.5);
        }
        if (!success)
        {
            llSay(0, "Scaling failed!");
        }
    }
}</lsl>
|helpers
|helpers
|also_functions=
|also_functions=

Revision as of 14:56, 6 January 2014

Summary

Function: integer llScaleByFactor( float scaling_factor );
0.0 Forced Delay
10.0 Energy

Attempts to resize the entire object by scaling_factor, maintaining the size-position ratios of the prims.

Resizing is subject to prim scale limits and linkability limits. This function can not resize the object if the linkset is physical, a pathfinding character, in a keyframed motion, or if resizing would cause the parcel to overflow.
Returns a boolean (an integer) TRUE if it succeeds, FALSE if it fails.

• float scaling_factor The multiplier to be used with the prim sizes and their local positions.

Caveats

  • Due to floating point precision issues (because sqrt(x*x) != x), avoid rescaling by the values returned by llGetMinScaleFactor and llGetMaxScaleFactor. To guarantee successful rescaling, use values slightly within the limits returned by those functions).

Examples

<lsl>// Touching this script causes the object to double or halve in size. integer growing = FALSE;

default {

   state_entry()
   {
       llSay(0, "Touch to toggle scale");
   }

   touch_start(integer total_number)
   {
       float min_factor = llGetMinScaleFactor();
       float max_factor = llGetMaxScaleFactor();
       integer success;
       llSay(0, "min_scale_factor = " + (string)min_factor + "  max_scale_factor = " + (string)max_factor);
       growing = !growing;
       if (growing)
       {
           success = llScaleByFactor(2.0);
       }
       else
       {
           success = llScaleByFactor(0.5);
       }
       if (!success)
       {
           llSay(0, "Scaling failed!");
       }
   }
}</lsl>

See Also

Deep Notes

This function is roughly equivalent to the following: <lsl> float VectorAbsStatistics(integer flag, vector a){

   return llListStatistics(flag, [llFabs(a.x), llFabs(a.y), llFabs(a.z)]);

}

integer ScaleByFactor(float scale) {

   vector root = llGetScale() * scale;
   if(VectorAbsStatistics(LIST_STAT_MAX, root) > 64

History

Signature

function integer llScaleByFactor( float scaling_factor );