03-11-2005 13:13
I was bored, so I wrote a generalized alpha-animation script. You know, faking animation by making prims in a link-set turn visible/invisible in sequence, all that good stuff. :)

Controller Script (this runs the animation):
CODE
// Alpha-animation Controller Script
//
// User speficies the total number of frames in the animation and
// the frame rate in frames per second. Try to keep this reasonably low...


integer NUMBER_OF_FRAMES = 4 ; // Total number of frames in this animation

float FRAMES_PER_SECOND = 5 ; // I doubt it could handle 10fps :)

integer running = TRUE ;

animcycle()
{
integer i ;

for( i = 0; i < NUMBER_OF_FRAMES; i++ )
{
llMessageLinked( LINK_SET, (integer)llPow( 2.0, (float)i ), "", "" ) ;
llSleep( 1.0 / FRAMES_PER_SECOND ) ;
}
}


default
{
state_entry()
{
llSetTimerEvent( (float)NUMBER_OF_FRAMES / FRAMES_PER_SECOND ) ;
}

timer()
{
animcycle() ;
}

touch_start( integer num )
{
running = !running ;

if( running ) llSetTimerEvent( (float)NUMBER_OF_FRAMES / FRAMES_PER_SECOND ) ;

else llSetTimerEvent( 0 ) ;
}
}

Individual frame script (goes on every prim to be animated):
CODE
// Framescript
//
// Place this script in every prim that should be changing between frames
//
// For the FRAME_NUMBERS integer, OR together ( | ) the FRAMEs on which this prim should be visible
// Ie. if it should be visible on the 0th and 3rd frames, FRAME_NUMBERS = FRAME0 | FRAME3 ;
//
// Frames are numbered starting at zero!

integer FRAME0 = 1 ;
integer FRAME1 = 2 ;
integer FRAME2 = 4 ;
integer FRAME3 = 8 ;
integer FRAME4 = 16 ;
integer FRAME5 = 32 ;
integer FRAME6 = 64 ;
integer FRAME7 = 128 ;
integer FRAME8 = 256 ;
integer FRAME9 = 512 ;
integer FRAME10 = 1024 ;

integer FRAME_NUMBERS ;

integer is_visible = FALSE ;

default
{
state_entry()
{
FRAME_NUMBERS = FRAME0 ; // OR together all the frames this prim should be -visible- on
}

link_message( integer sender, integer num, string message, key id )
{
if( FRAME_NUMBERS & num )
{
if( !is_visible )
{
is_visible = TRUE ;
llSetAlpha( 1.0, ALL_SIDES ) ;
}
}

else
{
is_visible = FALSE ;
llSetAlpha( 0.0, ALL_SIDES ) ;
}
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"