Difference between revisions of "Key Frame Animator"

From Second Life Wiki
Jump to: navigation, search
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
--[[User:Jasper Flossberg|Jasper Flossberg]]
 
--[[User:Jasper Flossberg|Jasper Flossberg]]
  
<lsl>
+
<source lang="lsl2">
integer channel=0;
+
integer channel;
integer MODE=0;  // 0 NonInit 1 Init 2 Run
+
list     keys=[];
list keys=[];
+
vector   last_pos;
vector last_pos;
+
 
rotation last_rot;
 
rotation last_rot;
 
+
vector   start_pos;
vector start_pos;
+
 
rotation start_rot;
 
rotation start_rot;
 
update_loc()
 
{
 
    last_pos=llGetPos();
 
    last_rot=llGetRot();
 
}
 
  
 
default
 
default
Line 24: Line 16:
 
     state_entry()
 
     state_entry()
 
     {
 
     {
         llSay(0, "Welcome to the KeyFrame Setter v1.0 by Jasper Flossberg");
+
         llSay(0, "Welcome to the KeyFrame Setter v2.0 by Jasper Flossberg and others\nTouch to start");
         llListen(0,"",NULL_KEY,"");
+
         llListen(0, "", llGetOwner(), "");      // Listen on channel 0 for 'set' commands from owner only
 +
        channel = (integer) llFrand(4000000);
 +
        llListen(channel, "", llGetOwner(), "");
 +
 
 +
        // Must use 'prim equivalency' for KFM
 +
        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]); 
 +
        llSetKeyframedMotion([],[]);
 +
        last_pos = start_pos = llGetPos();
 +
        last_rot = start_rot = llGetRot();
 +
    }
 +
    on_rez(integer p)
 +
    {
 +
        llResetScript();
 
     }
 
     }
 
 
     touch_start(integer total_number)
 
     touch_start(integer total_number)
 
     {
 
     {
         channel=(integer)llFrand(4000000);
+
         if (llDetectedKey(0) != llGetOwner() )
         llDialog(llDetectedKey(0),"Please choose option",["Init","Run","Export"],channel);
+
            return;
        llListen(channel,"",NULL_KEY,"");
+
         llDialog(llDetectedKey(0), "Please choose option",["Init","Run","Export"],channel);
 
     }
 
     }
 
     listen(integer channel, string name, key id, string message)
 
     listen(integer channel, string name, key id, string message)
 
     {
 
     {
         if(message=="Init")
+
         if(message == "Init")
 
         {
 
         {
             llSay(0,"Intializing KeyFrame Setter");
+
             llSay(0, "Re-Intializing KeyFrame Setter");
             llSetKeyframedMotion([],[]);
+
             llSleep(1);
             keys=[];
+
             llResetScript();
            update_loc();
+
            start_pos=llGetPos();
+
            start_rot=llGetRot();
+
            MODE=1;
+
 
+
 
         }
 
         }
         if(llGetSubString(message,0,2)=="set")
+
         if(llToLower(llGetSubString(message,0,2) ) == "set")
 
         {
 
         {
             if(MODE==1)
+
             string time = llList2String(llParseString2List(message, [" "], []), 1);
            {
+
            llSay(0, "Setting new KeyFrame with " + time);
                string time=llList2String(llParseString2List(message,[" "],[]),1);
+
            keys += [llGetPos() - last_pos, llGetRot() / last_rot, (integer) time];
                llSay(0,"Setting new KeyFrame with "+time);
+
            last_pos = llGetPos();
                keys+=[llGetPos()-last_pos,llGetRot()/last_rot,(integer)time];
+
             last_rot = llGetRot();
                update_loc();
+
             }
+
             
+
 
         }
 
         }
         if(message=="Run")
+
         if(message == "Run")
 
         {
 
         {
            MODE=2;
+
             llSetPrimitiveParams([PRIM_POSITION, start_pos, PRIM_ROTATION, start_rot]);
             llSetPrimitiveParams([PRIM_POSITION,start_pos,PRIM_ROTATION,start_rot]);
+
 
             llSetKeyframedMotion(keys,[KFM_MODE,KFM_LOOP]);
 
             llSetKeyframedMotion(keys,[KFM_MODE,KFM_LOOP]);
 
         }
 
         }
         if(message=="Export")
+
         if(message == "Export")
 
         {
 
         {
             llSay(0,(string)keys);
+
             llSay(0, llList2CSV(keys) );
 
         }
 
         }
        if(channel!=0)
 
        llListenRemove(channel);
 
 
     }
 
     }
 
}
 
}
</lsl>
+
</source>

Latest revision as of 22:17, 24 January 2015

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

integer  channel;
list     keys=[];
vector   last_pos;
rotation last_rot;
vector   start_pos;
rotation start_rot;
 
default
{
    state_entry()
    {
        llSay(0, "Welcome to the KeyFrame Setter v2.0 by Jasper Flossberg and others\nTouch to start");
        llListen(0, "", llGetOwner(), "");      // Listen on channel 0 for 'set' commands from owner only
        channel = (integer) llFrand(4000000);
        llListen(channel, "", llGetOwner(), "");
 
        // Must use 'prim equivalency' for KFM
        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);  
        llSetKeyframedMotion([],[]);
        last_pos = start_pos = llGetPos();
        last_rot = start_rot = llGetRot();
    }
    on_rez(integer p)
    {
        llResetScript();
    }
    touch_start(integer total_number)
    {
        if (llDetectedKey(0)  != llGetOwner() )
            return;
        llDialog(llDetectedKey(0), "Please choose option",["Init","Run","Export"],channel);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message == "Init")
        {
            llSay(0, "Re-Intializing KeyFrame Setter");
            llSleep(1);
            llResetScript();
        }
        if(llToLower(llGetSubString(message,0,2) ) == "set")
        {
            string time = llList2String(llParseString2List(message, [" "], []), 1);
            llSay(0, "Setting new KeyFrame with " + time);
            keys += [llGetPos() - last_pos, llGetRot() / last_rot, (integer) time];
            last_pos = llGetPos();
            last_rot = llGetRot();
        }
        if(message == "Run")
        {
            llSetPrimitiveParams([PRIM_POSITION, start_pos, PRIM_ROTATION, start_rot]);
            llSetKeyframedMotion(keys,[KFM_MODE,KFM_LOOP]);
        }
        if(message == "Export")
        {
            llSay(0, llList2CSV(keys) );
        }
    }
}