particle_starburst.lsl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // :SHOW:1
  2. // :CATEGORY:Light
  3. // :NAME:Rene Free Lighting System
  4. // :AUTHOR:Rene10957 Resident
  5. // :KEYWORDS: light,lamp,lighting light
  6. // :CREATED:2015-06-11 14:42:06
  7. // :EDITED:2016-03-30 20:29:28
  8. // :ID:1079
  9. // :NUM:1798
  10. // :REV:1.4
  11. // :WORLD:Opensim
  12. // :DESCRIPTION:
  13. // Particle Plugin "Starburst"
  14. // :CODE:
  15. // :LICENSE: CC0 (Public Domain)
  16. // Rene's Free Lighting System - Particle Plugin "Starburst"
  17. //
  18. // Author: Rene10957 Resident
  19. // Date: 21-03-2014
  20. ////////////////////////////////////////////////////////////////////////////////
  21. // HOW TO USE: drop this script into the same prim where the LIGHT is located //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. string title = "Particle Plugin"; // title
  24. string name = "Starburst"; // name
  25. string version = "1.4"; // version
  26. integer silent = TRUE; // silent startup
  27. // Constants
  28. // Note: the official upper limit for particles is 4.0 meters but for more delicate particle effects
  29. // it can be useful to set maxScale to a lower value, in order to achieve more fine-grained control.
  30. integer particleChannel = -75901; // particle channel
  31. integer feedbackChannel = -57910; // feedback channel
  32. float minScale = 0.03125; // min. startScale or endScale
  33. float maxScale = 4.0; // max. startScale or endScale
  34. // Particle parameters
  35. // Note: startScale and endScale are not actual sizes, but more like aspect ratios.
  36. // The real size is determined by particleSize in the notecard, a percentage of maxScale.
  37. float age = 1.0; // particle lifetime
  38. float rate = 0.1; // particle burst rate
  39. integer count = 5; // particle count
  40. vector startScale = <0.1, 1.0, 0.0>; // particle start size
  41. vector endScale = <0.1, 1.0, 0.0>; // particle end size
  42. float minSpeed = 0.1; // particle min. burst speed
  43. float maxSpeed = 0.1; // particle max. burst speed
  44. float burstRadius = 0.0; // particle burst radius
  45. vector partAccel = <0.0, 0.0, 0.0>; // particle accelleration
  46. // Variables
  47. float particleSize; // particle size (percentage)
  48. float defParticleSize; // default particle size (percentage)
  49. float minParticleSize; // minimum particle size (percentage)
  50. // Functions
  51. startParticles(vector color, vector start, vector end, float min, float max, float radius, vector push, string txtr)
  52. {
  53. llParticleSystem([
  54. PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
  55. PSYS_PART_START_COLOR, color,
  56. PSYS_PART_END_COLOR, color,
  57. PSYS_PART_START_ALPHA, 0.5,
  58. PSYS_PART_END_ALPHA, 0.0,
  59. PSYS_PART_START_SCALE, start,
  60. PSYS_PART_END_SCALE, end,
  61. PSYS_PART_MAX_AGE, age,
  62. PSYS_SRC_BURST_RATE, rate,
  63. PSYS_SRC_BURST_PART_COUNT, count,
  64. PSYS_SRC_BURST_SPEED_MIN, min,
  65. PSYS_SRC_BURST_SPEED_MAX, max,
  66. PSYS_SRC_BURST_RADIUS, radius,
  67. PSYS_SRC_ACCEL, push,
  68. PSYS_SRC_TEXTURE, txtr,
  69. PSYS_PART_FLAGS,
  70. 0 |
  71. PSYS_PART_EMISSIVE_MASK |
  72. PSYS_PART_FOLLOW_SRC_MASK |
  73. PSYS_PART_FOLLOW_VELOCITY_MASK |
  74. PSYS_PART_INTERP_COLOR_MASK |
  75. PSYS_PART_INTERP_SCALE_MASK ]);
  76. }
  77. /////////////////////////////////////////////////////////////////
  78. // From this point onwards, every particle script is identical //
  79. /////////////////////////////////////////////////////////////////
  80. // Particle size = largest dimension across both scale vectors
  81. float getParticleSize (vector start, vector end)
  82. {
  83. float max = 0.0;
  84. if (start.x > max) max = start.x;
  85. if (start.y > max) max = start.y;
  86. if (end.x > max) max = end.x;
  87. if (end.y > max) max = end.y;
  88. return max / (maxScale / 100.0);
  89. }
  90. // Particle size is too small if both start.x and end.x < minScale (0.03125), or...
  91. // both start.y and end.y < minScale (0.03125)
  92. float getMinSize (vector start, vector end, float size)
  93. {
  94. float maxX = 0.0;
  95. float maxY = 0.0;
  96. float minXY = 0.0;
  97. if (start.x < minScale && end.x < minScale) {
  98. if (start.x > end.x) maxX = start.x;
  99. else maxX = end.x;
  100. }
  101. if (start.y < minScale && end.y < minScale) {
  102. if (start.y > end.y) maxY = start.y;
  103. else maxY = end.y;
  104. }
  105. if (maxX == 0.0 && maxY == 0.0) return size;
  106. if (maxX == 0.0) minXY = maxY;
  107. else if (maxY == 0.0) minXY = maxX;
  108. else if (maxX < maxY) minXY = maxX;
  109. else minXY = maxY;
  110. return (float)llCeil((minScale / minXY) * size);
  111. }
  112. unpackMessage(string msg)
  113. {
  114. list msgList = llCSV2List(msg);
  115. integer on = (integer)llList2String(msgList, 0); // particles on/off
  116. vector color = (vector)llList2String(msgList, 1); // particle color
  117. float size = (float)llList2String(msgList, 2); // particle size (%) from notecard
  118. float inc = (float)llList2String(msgList, 3); // particle increase/decrease (%) from menu
  119. string texture = llList2String(msgList, 4); // particle texture from notecard
  120. if (inc == 999) particleSize = size; // reset particle size
  121. else particleSize += inc; // increase/decrease particle size
  122. if (particleSize < 1) particleSize = 1; // correct if size < 1%
  123. else if (particleSize > 100) particleSize = 100; // correct if size > 100%
  124. if (particleSize < minParticleSize) particleSize = minParticleSize; // correct undersized particles
  125. if (on) {
  126. vector start = startScale / defParticleSize * particleSize; // start scale
  127. vector end = endScale / defParticleSize * particleSize; // end scale
  128. float min = minSpeed / defParticleSize * particleSize; // equally resize min. burst speed
  129. float max = maxSpeed / defParticleSize * particleSize; // equally resize max. burst speed
  130. float radius = burstRadius / defParticleSize * particleSize; // equally resize burst radius
  131. vector push = partAccel / defParticleSize * particleSize; // equally resize accelleration
  132. startParticles(color, start, end, min, max, radius, push, texture);
  133. }
  134. else {
  135. llParticleSystem([]);
  136. }
  137. }
  138. default
  139. {
  140. state_entry()
  141. {
  142. defParticleSize = getParticleSize(startScale, endScale); // default particle size (percentage)
  143. vector start = startScale / defParticleSize; // start scale = 1%
  144. vector end = endScale / defParticleSize; // end scale = 1%
  145. minParticleSize = getMinSize(start, end, 1.0); // minimum particle size (percentage)
  146. if (!silent) llWhisper(0, title + " \"" + name + "\" " + version + " ready");
  147. llMessageLinked(LINK_THIS, feedbackChannel, "READY", ""); // request particle info from light script
  148. }
  149. on_rez(integer start_param)
  150. {
  151. llResetScript();
  152. }
  153. link_message(integer sender_number, integer number, string msg, key id)
  154. {
  155. if (number == particleChannel) unpackMessage(msg);
  156. }
  157. }