Prim_Animation_Compiler_1984.lsl 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Script Name: Prim_Animation_Compiler.lsl
  2. // Author: Ferd Frederix
  3. // This prim animator compiler is a very useful and easy to use script for Second Life and OpenSim. Setup is very simple. Just drop the two script into the object, click the object, and give your animation a name. Move all the prims around, and click Record. When done, click the Compile button. It writes fast, optimized code for you.
  4. // Downloaded from : http://www.outworldz.com/cgi/freescripts.plx?ID=1691
  5. // This program is free software; you can redistribute it and/or modify it.
  6. // Additional Licenes may apply that prevent you from selling this code
  7. // and these licenses may require you to publish any changes you make on request.
  8. //
  9. // There are literally thousands of hours of work in these scripts. Please respect
  10. // the creators wishes and Copyright law and follow their license requirements.
  11. //
  12. // License information included herein must be included in any script you give out or use.
  13. // Licenses may also be included in the script or comments by the original author, in which case
  14. // the authors license must be followed, and their licenses override any licenses outlined in this header.
  15. //
  16. // You cannot attach a license to any of these scripts to make any license more or less restrictive.
  17. //
  18. // All scripts by avatar Ferd Frederix, unless stated otherwise in the script, are licensed as Creative Commons By Attribution and Non-Commercial.
  19. // Commercial use is NOT allowed - no resale of my scripts in any form.
  20. // This means you cannot sell my scripts but you can give them away if they are FREE.
  21. // Scripts by Ferd Frederix may be sold when included in a new object that actually uses these scripts. Putting my script in a prim and selling it on marketplace does not constitute a build.
  22. // For any reuse or distribution, you must make clear to others the license terms of my works. This is done by leaving headers intact.
  23. // See http://creativecommons.org/licenses/by-nc/3.0/ for more details and the actual license agreement.
  24. // You must leave any author credits and any headers intact in any script you use or publish.
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////
  26. // If you don't like these restrictions and licenses, then don't use these scripts.
  27. //////////////////////// ORIGINAL AUTHORS CODE BEGINS ////////////////////////////////////////////
  28. // This script produces optimized LSL code that can be triggered by link messages.
  29. // fred@mitsi.com
  30. // 3-7-2012
  31. // Rev B, added a missing } at the end of multiple recordings.
  32. // Script Name: Super_Prim_Animator_Motion_Compiler.lsl
  33. // Author: Ferd Frederix
  34. // Based on an excellent script by Allen Firethorn
  35. // This is free software, it is not for sale at any price
  36. // Tunable stuff:
  37. integer OpenSim = FALSE; // Set to FALSE for Second Life to save memory
  38. string fast="Fast"; // Set this to an empty string if you don't want to use the fast animation
  39. integer debug = FALSE; // set to TRUE to see stuff inside as it runs
  40. // CODE below - no need to change anything after this.
  41. list animations; // holds a list of all animation names
  42. list receivedData; // the data from the main program
  43. integer STRIDE = 5; // size of the data packets in receivedData
  44. integer currentLine; // the line we are processing
  45. // Link messages
  46. integer CLEAR = -234756;
  47. integer DATA = -234757;
  48. integer COMPILE = -234758;
  49. integer DIE = -234759;
  50. DEBUG(string msg)
  51. {
  52. if (debug) llOwnerSay("// " + msg);
  53. }
  54. // speak without the name of the prim in the way
  55. SayCode (string story){
  56. llOwnerSay (story);
  57. llSleep(0.1);
  58. }
  59. default {
  60. link_message(integer sender_num,integer num, string msg, key id) {
  61. if (num == DIE && msg =="die") // clear
  62. {
  63. llOwnerSay("Compiler has been removed");
  64. if (! debug) {
  65. llRemoveInventory(llGetScriptName());
  66. }
  67. }
  68. if (num == CLEAR) // clear
  69. {
  70. animations = [];
  71. receivedData = [];
  72. currentLine = 0;
  73. llOwnerSay("Compiler Ready");
  74. }
  75. else if (num == DATA) // data
  76. {
  77. // data formatted like this:
  78. // name|primnum|vector Pos|rotation rot|vector size
  79. // test1|2|<0.026306,-0.150208,0.191069>|<-0.000008,0.956309,-0.292356,0.000000>|<0.074010,0.074010,0.074010>
  80. list primList = llParseString2List(msg,["|"],[]);
  81. string name = llList2String(primList,0);
  82. receivedData += name;
  83. receivedData += (float) llList2String(primList,1); // prim Number or ms to sleep
  84. receivedData += (vector) llList2String(primList,2); // pos
  85. receivedData += (rotation) llList2String(primList,3); // rot
  86. receivedData += (vector) llList2String(primList,4); // size
  87. // Store the name of the animation if it is not already stored
  88. integer i = llListFindList(animations, [name]);
  89. if( i < 0 ){
  90. DEBUG("Adding Animation named " + name);
  91. animations += name;
  92. }
  93. currentLine++;
  94. }
  95. else if (num == COMPILE) // finish, compile it
  96. {
  97. //DEBUG("Animations:" + llDumpList2String(animations,":"));
  98. //DEBUG("Length:" + ((string) llGetListLength(animations)));
  99. //DEBUG("history:" + llDumpList2String(receivedData,":"));
  100. //DEBUG("Length:" + ((string) llGetListLength(receivedData)));
  101. string code;
  102. integer i;
  103. llOwnerSay("Compiler processing " + (string)currentLine + " prim movements and " + (string) llGetListLength(animations) + " animations");
  104. llOwnerSay("Copy everything below this line and paste it into a new script\n");
  105. string oldname = llGetObjectName ();
  106. llSetObjectName ("Compiler");
  107. vector scale = llGetScale();
  108. SayCode("// Prim animation compiler //\n"
  109. + "// Ferd Frederix - http://www.outworldz.com\n"
  110. + "integer playbackchannel = 1; // The default llMessageLinked number\n"
  111. + "rotation calcChildRot(rotation rdeltaRot){\n"
  112. + "\tif (llGetAttached())\n"
  113. + "\t\treturn rdeltaRot/llGetLocalRot();\n"
  114. + "\telse\n"
  115. + "\t\treturn rdeltaRot/llGetRootRotation();\n"
  116. + "}\n"
  117. + "vector originalScale = "
  118. + (string) scale
  119. + ";"
  120. );
  121. // Go through each animation and create a function for each one
  122. for(i = 0; i < llGetListLength(animations); i++){
  123. integer j;
  124. string animationName = llList2String(animations, i);
  125. //DEBUG("Processing " + animationName);
  126. SayCode(animationName
  127. + "(){\n"
  128. + "\tvector currentSize = llGetScale();\n"
  129. + "\tfloat scaleby = currentSize.x/originalScale.x;\n"
  130. );
  131. //Read through the list and print out the instructions for this animation
  132. integer count = llGetListLength(receivedData);
  133. for(j=0; j < count; j += STRIDE)
  134. {
  135. string name = llList2String(receivedData,j);
  136. float primNum = (float) llList2String(receivedData,j+1);
  137. //DEBUG("name: " + name + " Prim Num: " + primNum);
  138. if( name == animationName){
  139. if(primNum > 1){ // not a root prim or sleep
  140. SayCode( "\tllSetLinkPrimitiveParams"
  141. + fast
  142. + "("
  143. + (string) ((integer)primNum)
  144. + ", [PRIM_POSITION, "
  145. + (string) llList2Vector(receivedData,j+2)
  146. + "*scaleby, "
  147. + "PRIM_ROTATION,calcChildRot("
  148. + (string) llList2Rot(receivedData,j+3)
  149. + "), "
  150. + "PRIM_SIZE, "
  151. + (string) llList2Vector(receivedData,j+4)
  152. + "*scaleby]);"
  153. );
  154. } else {
  155. SayCode("\tllSleep("
  156. +(string)(primNum*-1) // negative numbers are sleep times
  157. +");"
  158. );
  159. }
  160. } // if name
  161. } // for j
  162. SayCode ("\n}");
  163. } // for animations
  164. SayCode (
  165. "\n\n"
  166. + "default{\n"
  167. );
  168. if (!OpenSim)
  169. SayCode("\tstate_entry(){\n"
  170. +"\t\tllSetMemoryLimit(llGetUsedMemory() + 512);\n"
  171. + "\t\t}");
  172. code = "\n\tlink_message(integer sender_num, integer num, string message, key id){\n"+
  173. "\t\tif(num == playbackchannel){\n";
  174. for(i=0; i<llGetListLength(animations);i++){
  175. code+="\t\t\tif(message == \""+llList2String(animations,i)+"\"){\n"+
  176. "\t\t\t\t"+llList2String(animations,i)+"();\n"+
  177. "\t\t\t}\n";
  178. }
  179. code += "\t\t}\n"+
  180. "\t}\n}";
  181. SayCode(code);
  182. SayCode("// Done! Copy everything above to a new script, and Search/Replace the time stamp and Compiler: on the left to be blank");
  183. llSetObjectName (oldname);
  184. }
  185. }
  186. }