Difference between revisions of "Key Frame Animator"

From Second Life Wiki
Jump to navigation Jump to search
m (cleanup)
Line 5: Line 5:


<lsl>
<lsl>
integer channel=0;
// MODE:
integer MODE=0;  // 0 NonInit 1 Init 2 Run
//     0 = NonInit
list keys=[];
//      1 = Init
vector last_pos;
//      2 = Run
 
integer  MODE;
list     keys;
 
rotation start_rot;
vector   start_pos;
 
rotation last_rot;
rotation last_rot;
vector  last_pos;


vector start_pos;
integer dialogChannel;
rotation start_rot;
integer dialogHandle;
 
init()
{
    say("Welcome to the KeyFrame Setter v1.0 by Jasper Flossberg");
    say("Touch to get started!");
}
 
update_start()
{
    start_pos = llGetPos();
    start_rot = llGetRot();
}
 
update_last()
{
    last_pos = llGetPos();
    last_rot = llGetRot();
}
 
open_menu(key id, string dialogString, list dialogButtons)
{
    close_menu();// make sure it's closed before (re-)opening
 
    dialogChannel = (integer)llFrand(4000000);
    dialogHandle  = llListen(dialogChannel, "", id, "");
 
    llDialog(id, dialogString, dialogButtons, dialogChannel);
 
    llSetTimerEvent(30.0);
}
 
close_menu()
{
    // disable timer by setting 0.0
    llSetTimerEvent((float)FALSE);
    llListenRemove(dialogHandle);
}


update_loc()
say(string message)
{
{
     last_pos=llGetPos();
     llSay(PUBLIC_CHANNEL, message);
    last_rot=llGetRot();
}
}


default
default
{
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Welcome to the KeyFrame Setter v1.0 by Jasper Flossberg");
         init();
        llListen(0,"",NULL_KEY,"");
     }
     }


     touch_start(integer total_number)
     touch_start(integer num_detected)
     {
     {
         channel=(integer)llFrand(4000000);
         key id = llDetectedKey(0);
         llDialog(llDetectedKey(0),"Please choose option",["Init","Run","Export"],channel);
         open_menu(id, "Please choose option", ["Init", "Run", "Export"]);
        llListen(channel,"",NULL_KEY,"");
     }
     }
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         if(message=="Init")
        //  ignore spam
         if (channel != dialogChannel)
         {
         {
             llSay(0,"Intializing KeyFrame Setter");
             return;
            llSetKeyframedMotion([],[]);
        }
            keys=[];
            update_loc();
            start_pos=llGetPos();
            start_rot=llGetRot();
            MODE=1;


        //  all info we could need is in the event params, so close early
        close_menu();
        if (message == "Init")
        {
            MODE = 1;
            say("Intializing KeyFrame Setter");
            llSetKeyframedMotion([], []);
            keys = [];
            update_last();
            update_start();
         }
         }
         if(llGetSubString(message,0,2)=="set")
         if (llGetSubString(message, 0, 2) == "set" && MODE == 1)
         {
         {
             if(MODE==1)
             list  params = llParseString2List(message,[" "], []);
            {
            string time  = llList2String(params, 1);
                string time=llList2String(llParseString2List(message,[" "],[]),1);
 
                llSay(0,"Setting new KeyFrame with "+time);
            say("Setting new KeyFrame with "+time);
                keys+=[llGetPos()-last_pos,llGetRot()/last_rot,(integer)time];
 
                update_loc();
            keys += [llGetPos()-last_pos,llGetRot()/last_rot,(integer)time];
            }
 
             
            update_last();
         }
         }
         if(message=="Run")
         if (message == "Run")
         {
         {
             MODE=2;
             MODE = 2;
             llSetPrimitiveParams([PRIM_POSITION,start_pos,PRIM_ROTATION,start_rot]);
 
             llSetKeyframedMotion(keys,[KFM_MODE,KFM_LOOP]);
             llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_POSITION, start_pos,
                PRIM_ROTATION, start_rot]);
 
             llSetKeyframedMotion(keys, [
                KFM_MODE, KFM_LOOP]);
         }
         }
         if(message=="Export")
         if (message == "Export")
         {
         {
             llSay(0,(string)keys);
             say((string)keys);
         }
         }
        if(channel!=0)
    }
         llListenRemove(channel);
 
    timer()
    {
         close_menu();
     }
     }
}
}
</lsl>
</lsl>

Revision as of 13:33, 31 July 2013

This is a KeyFrame Animator Script to simplify construction of keyframed animations. To get the much better PRO version with after frame editing features and more, contact --Jasper Flossberg

<lsl> // MODE: // 0 = NonInit // 1 = Init // 2 = Run

integer MODE; list keys;

rotation start_rot; vector start_pos;

rotation last_rot; vector last_pos;

integer dialogChannel; integer dialogHandle;

init() {

   say("Welcome to the KeyFrame Setter v1.0 by Jasper Flossberg");
   say("Touch to get started!");

}

update_start() {

   start_pos = llGetPos();
   start_rot = llGetRot();

}

update_last() {

   last_pos = llGetPos();
   last_rot = llGetRot();

}

open_menu(key id, string dialogString, list dialogButtons) {

   close_menu();// make sure it's closed before (re-)opening
   dialogChannel = (integer)llFrand(4000000);
   dialogHandle  = llListen(dialogChannel, "", id, "");
   llDialog(id, dialogString, dialogButtons, dialogChannel);
   llSetTimerEvent(30.0);

}

close_menu() {

   // disable timer by setting 0.0
   llSetTimerEvent((float)FALSE);
   llListenRemove(dialogHandle);

}

say(string message) {

   llSay(PUBLIC_CHANNEL, message);

}

default {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   state_entry()
   {
       init();
   }
   touch_start(integer num_detected)
   {
       key id = llDetectedKey(0);
       open_menu(id, "Please choose option", ["Init", "Run", "Export"]);
   }
   listen(integer channel, string name, key id, string message)
   {
       //  ignore spam
       if (channel != dialogChannel)
       {
           return;
       }
       //  all info we could need is in the event params, so close early
       close_menu();
       if (message == "Init")
       {
           MODE = 1;
           say("Intializing KeyFrame Setter");
           llSetKeyframedMotion([], []);
           keys = [];
           update_last();
           update_start();
       }
       if (llGetSubString(message, 0, 2) == "set" && MODE == 1)
       {
           list   params = llParseString2List(message,[" "], []);
           string time   = llList2String(params, 1);
           say("Setting new KeyFrame with "+time);
           keys += [llGetPos()-last_pos,llGetRot()/last_rot,(integer)time];
           update_last();
       }
       if (message == "Run")
       {
           MODE = 2;
           llSetLinkPrimitiveParamsFast(LINK_THIS, [
               PRIM_POSITION, start_pos,
               PRIM_ROTATION, start_rot]);
           llSetKeyframedMotion(keys, [
               KFM_MODE, KFM_LOOP]);
       }
       if (message == "Export")
       {
           say((string)keys);
       }
   }
   timer()
   {
       close_menu();
   }

} </lsl>