User:Opensource Obscure/Reflexive llSetLinkPrimitiveParamsFast

From Second Life Wiki
Jump to navigation Jump to search

Go back to Opensource Obscure's userpage



  • this needs server 1.38
  • put it in the root prim
  • add child prims to the linkset as needed

<lsl> float rate = 1;

vector NEAR_COL = <0.9, 0.8, 0.0>; vector FAR_COL = <0.2, 0.0, 0.7>;


vector NEAR_SIZE = <1.0, 0.3, 0.4>; vector FAR_SIZE = <.3, .5, 2>;

float NEAR = 0.5; float FAR = 10.0;

float DIFF; vector COL_DIFF; vector SIZE_DIFF; vector pos_init; rotation rot_init; integer prim_number;

vector GetLinkLocalPos(integer link) {//This function may not produce a perfect result, expect there to be some drift. This will not work in attachments.

   //vector pos = llGetRootPosition();
   return (llList2Vector(llGetObjectDetails(llGetLinkKey(link), (list)OBJECT_POS) + pos_init, 0) - pos_init) / rot_init;

}

default {

   state_entry()
   {
       pos_init = llGetPos();
       rot_init = llGetRootRotation();
       prim_number = llGetObjectPrimCount( llGetKey() );
       DIFF = FAR - NEAR;
       COL_DIFF = FAR_COL - NEAR_COL;
       SIZE_DIFF = FAR_SIZE - NEAR_SIZE;
       llSensorRepeat("", NULL_KEY, AGENT, FAR, PI, rate);        
   }
   
   sensor(integer total_number)
   {
       vector pos_det = llDetectedPos(0);
       integer i;      
       for(i=1; i<=prim_number; ++i)
       {
           vector pos_local = (pos_init + GetLinkLocalPos(i));
           float distance_local = llVecMag(pos_det - pos_local);
           float scale_local = (distance_local - NEAR) / (DIFF);            
           if (scale_local < 0.0) scale_local = 0.0;      
           llSetLinkPrimitiveParamsFast(i, [
           PRIM_COLOR, ALL_SIDES, NEAR_COL + ((COL_DIFF) * scale_local),1,
           PRIM_SIZE, NEAR_SIZE + ((SIZE_DIFF) * scale_local)
           ]);
       }        
   }    

} </lsl>