Created
September 2, 2016 17:38
-
-
Save FelixWolf/c8067a35e3ffe58e27e51d574723727c to your computer and use it in GitHub Desktop.
Quick and easy method for multi-prim alpha animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Format for single animation: | |
ANIM_ON, integer Prim, float Speed, integer Face_count, | |
integer Face_Order[Face_Count] | |
Format for single looped: | |
LOOP, integer count, integer mode, integer Prim, float Speed, integer Face_count, | |
integer Face_Order[Face_Count] | |
Single animation will loop over to next animation unless EOF | |
Looped animations will repeat until received "STOP" from linkset. | |
*/ | |
list anims = [ | |
ANIM_ON, 4, 0.5, 7, | |
1, 2, 3, 4, 5, 7, 6, | |
LOOP, 3, 0, PING_PONG, 0.05, 7, | |
1, 2, 3, 4, 5, 6, 7, | |
ANIM_ON, 4, 0.1, 7, | |
6, 5, 4, 3, 2, 1, | |
EOF | |
]; | |
//Everything else is controlled by the system. | |
//Static(set once) | |
list animationIndex = []; | |
integer animations = 0; | |
//Dynamic | |
integer frame = 0; //Frame number | |
list frames = []; | |
integer framec = 0; | |
integer animationSet = 0; //Animation number | |
integer animationPos = 0; //Offset in the list | |
integer animationCount = 0; //Number of animations | |
integer type = 0; //ANIM_ON, LOOP, or EOF | |
integer prim = 0; //Current prim | |
integer face = 0; //Last face | |
float frameRate = 1; | |
integer loopMode = 0; | |
integer loopCount = 0; | |
vector getColor(integer prim, integer face){ | |
return llList2Vector(llGetLinkPrimitiveParams(prim,[PRIM_COLOR, face]),0); | |
} | |
list uListReverse(list vLstSrc){ | |
integer vIntCnt = (vLstSrc != []); | |
while (vIntCnt){ | |
vLstSrc += llList2List( vLstSrc, (vIntCnt = ~-vIntCnt), vIntCnt ); | |
vLstSrc = llDeleteSubList( vLstSrc, vIntCnt, vIntCnt ); | |
} | |
return vLstSrc; | |
} | |
loadAnimation(){ | |
animationPos = llList2Integer(animationIndex, animationSet); | |
frame = 0; | |
type = llList2Integer(anims, animationPos); | |
prim = llList2Integer(anims, animationPos+1); | |
if(type == ANIM_ON){ | |
frameRate = llList2Float(anims, animationPos+2); | |
framec = llList2Integer(anims, animationPos+3); | |
frames = llList2List(anims, animationPos+4, animationPos+3+framec); | |
}else if(type == LOOP){ | |
loopCount = llList2Integer(anims, animationPos+2); | |
loopMode = llList2Integer(anims, animationPos+3); | |
frameRate = llList2Float(anims, animationPos+4); | |
framec = llList2Integer(anims, animationPos+5); | |
frames = llList2List(anims, animationPos+6, animationPos+5+framec); | |
if(loopMode == PING_PONG){ | |
frames = frames + llList2List(uListReverse(frames),1,-2); | |
framec = llGetListLength(frames); | |
}else if(loopMode == REVERSE) | |
frames = uListReverse(frames); | |
}else if(type == 0){ | |
if(animationSet >= animationCount) | |
animationSet = 0; | |
else | |
animationSet++; | |
return; | |
} | |
} | |
float doAnimation(integer seek){ | |
list commands = [ | |
PRIM_LINK_TARGET, prim, | |
PRIM_COLOR, face, getColor(prim, face), 0 | |
]; | |
if(seek == -1){ | |
if((--animationSet)<0) | |
animationSet = animations; | |
}else if(seek == 1){ | |
if((++animationSet)>=animations) | |
animationSet = 0; | |
} | |
if(seek!=0){ | |
loadAnimation(); | |
if(type==0) | |
return 0; | |
} | |
if(type == LOOP){ | |
if(loopMode==TRUE&&loopCount--<=0) | |
return 0; | |
} | |
llSetLinkPrimitiveParamsFast(0,commands + [ | |
PRIM_LINK_TARGET, prim, | |
PRIM_COLOR, face = llList2Integer(frames,frame), getColor(prim, face), 1 | |
]); | |
if(++frame > framec){ | |
if(type==LOOP){ | |
frame = 0; | |
}else{ | |
if((++animationSet)>=animations) | |
animationSet = 0; | |
loadAnimation(); | |
} | |
} | |
return frameRate; | |
} | |
indexAnimations(){ | |
integer offset = 0; | |
integer length = llGetListLength(anims); | |
while(offset<length){ | |
integer type = llList2Integer(anims, offset); | |
animationCount = animationCount + 1; | |
if(type == 0){ | |
animationIndex = animationIndex + [offset]; | |
offset = offset + 1; | |
}else if(type == ANIM_ON){ | |
animationIndex = animationIndex + [offset]; | |
integer len = llList2Integer(anims, offset+3); | |
offset = offset + 4 + len; | |
}else if(type == LOOP){ | |
animationIndex = animationIndex + [offset]; | |
integer len = llList2Integer(anims, offset+5); | |
offset = offset + 6 + len; | |
}else{ | |
llShout(DEBUG_CHANNEL, "Unexpected OPCode "+(string)type+" at "+(string)offset+"!"); | |
return; | |
} | |
} | |
} | |
init(){ | |
indexAnimations(); | |
animations = llGetListLength(animationIndex); | |
prim = llList2Integer(anims, 1); | |
loadAnimation(); | |
llSetTimerEvent(doAnimation(0)); | |
} | |
default{ | |
state_entry(){ | |
init(); | |
} | |
timer(){ | |
//llOwnerSay((string)doAnimation(0)); | |
llSetTimerEvent(doAnimation(0)); | |
} | |
link_message(integer link, integer i, string m, key k){ | |
if(m=="SEEK"){ | |
llSetTimerEvent(doAnimation(i)); | |
}else if(m=="STOP"){ | |
llSetTimerEvent(0); | |
}else if(m=="PLAY"){ | |
llSetTimerEvent(doAnimation(0)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment