particleEditor.ed.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Open the particle editor to spawn a test emitter in front of the player.
  23. // Edit the sliders, check boxes, and text fields and see the results in
  24. // realtime. Switch between emitters and particles with the buttons in the
  25. // top left corner. When in particle mode, the only particles available will
  26. // be those assigned to the current emitter to avoid confusion. In the top
  27. // right corner, there is a button marked "Drop Emitter", which will spawn the
  28. // test emitter in front of the player again, and a button marked "Restart
  29. // Emitter", which will play the particle animation again.
  30. //=============================================================================================
  31. // ParticleEditor.
  32. //=============================================================================================
  33. //---------------------------------------------------------------------------------------------
  34. function ParticleEditor::initEditor( %this )
  35. {
  36. echo( "Initializing ParticleEmitterData and ParticleData DataBlocks..." );
  37. datablock ParticleEmitterData(PE_EmitterEditor_NotDirtyEmitter)
  38. {
  39. particles = "DefaultParticle";
  40. };
  41. datablock ParticleData(PE_ParticleEditor_NotDirtyParticle)
  42. {
  43. textureName = "art/particles/defaultParticle";
  44. };
  45. PE_UnlistedEmitters.add( PE_EmitterEditor_NotDirtyEmitter );
  46. PE_UnlistedEmitters.add( PE_ParticleEditor_NotDirtyParticle );
  47. PEE_EmitterSelector.clear();
  48. PEE_EmitterParticleSelector1.clear();
  49. PEE_EmitterParticleSelector2.clear();
  50. PEE_EmitterParticleSelector3.clear();
  51. PEE_EmitterParticleSelector4.clear();
  52. PEP_ParticleSelector.clear();
  53. ParticleEditor.createParticleList();
  54. PEE_EmitterParticleSelector2.add( "None", 0 );
  55. PEE_EmitterParticleSelector3.add( "None", 0 );
  56. PEE_EmitterParticleSelector4.add( "None", 0 );
  57. PEE_EmitterParticleSelector1.sort();
  58. PEE_EmitterParticleSelector2.sort();
  59. PEE_EmitterParticleSelector3.sort();
  60. PEE_EmitterParticleSelector4.sort();
  61. PE_EmitterEditor-->PEE_blendType.clear();
  62. PE_EmitterEditor-->PEE_blendType.add( "NORMAL", 0 );
  63. PE_EmitterEditor-->PEE_blendType.add( "ADDITIVE", 1 );
  64. PE_EmitterEditor-->PEE_blendType.add( "SUBTRACTIVE", 2 );
  65. PE_EmitterEditor-->PEE_blendType.add( "PREMULTALPHA", 3 );
  66. PEE_EmitterSelector.setFirstSelected();
  67. PE_Window-->EditorTabBook.selectPage( 0 );
  68. }
  69. function ParticleEditor::createParticleList( %this )
  70. {
  71. // This function creates the list of all particles and particle emitters
  72. %emitterCount = 0;
  73. %particleCount = 0;
  74. foreach( %obj in DatablockGroup )
  75. {
  76. if( %obj.isMemberOfClass( "ParticleEmitterData" ) )
  77. {
  78. // Filter out emitters on the PE_UnlistedEmitters list.
  79. %unlistedFound = false;
  80. foreach( %unlisted in PE_UnlistedEmitters )
  81. if( %unlisted.getId() == %obj.getId() )
  82. {
  83. %unlistedFound = true;
  84. break;
  85. }
  86. if( %unlistedFound )
  87. continue;
  88. // To prevent our default emitters from getting changed,
  89. // prevent them from populating the list. Default emitters
  90. // should only be used as a template for creating new ones.
  91. if ( %obj.getName() $= "DefaultEmitter")
  92. continue;
  93. PEE_EmitterSelector.add( %obj.getName(), %obj.getId() );
  94. %emitterCount ++;
  95. }
  96. else if( %obj.isMemberOfClass( "ParticleData" ) )
  97. {
  98. %unlistedFound = false;
  99. foreach( %unlisted in PE_UnlistedParticles )
  100. if( %unlisted.getId() == %obj.getId() )
  101. {
  102. %unlistedFound = true;
  103. break;
  104. }
  105. if( %unlistedFound )
  106. continue;
  107. %name = %obj.getName();
  108. %id = %obj.getId();
  109. if ( %name $= "DefaultParticle")
  110. continue;
  111. // Add to particle dropdown selectors.
  112. PEE_EmitterParticleSelector1.add( %name, %id );
  113. PEE_EmitterParticleSelector2.add( %name, %id );
  114. PEE_EmitterParticleSelector3.add( %name, %id );
  115. PEE_EmitterParticleSelector4.add( %name, %id );
  116. %particleCount ++;
  117. }
  118. }
  119. PEE_EmitterSelector.sort();
  120. PEE_EmitterParticleSelector1.sort();
  121. PEE_EmitterParticleSelector2.sort();
  122. PEE_EmitterParticleSelector3.sort();
  123. PEE_EmitterParticleSelector4.sort();
  124. echo( "Found" SPC %emitterCount SPC "emitters and" SPC %particleCount SPC "particles." );
  125. }
  126. //---------------------------------------------------------------------------------------------
  127. function ParticleEditor::openEmitterPane( %this )
  128. {
  129. PE_Window.text = "Particle Editor - Emitters";
  130. PE_EmitterEditor.guiSync();
  131. ParticleEditor.activeEditor = PE_EmitterEditor;
  132. if( !PE_EmitterEditor.dirty )
  133. PE_EmitterEditor.setEmitterNotDirty();
  134. }
  135. //---------------------------------------------------------------------------------------------
  136. function ParticleEditor::openParticlePane( %this )
  137. {
  138. PE_Window.text = "Particle Editor - Particles";
  139. PE_ParticleEditor.guiSync();
  140. ParticleEditor.activeEditor = PE_ParticleEditor;
  141. if( !PE_ParticleEditor.dirty )
  142. PE_ParticleEditor.setParticleNotDirty();
  143. }
  144. //---------------------------------------------------------------------------------------------
  145. function ParticleEditor::resetEmitterNode( %this )
  146. {
  147. %tform = ServerConnection.getControlObject().getEyeTransform();
  148. %vec = VectorNormalize( ServerConnection.getControlObject().getForwardVector() );
  149. %vec = VectorScale( %vec, 4 );
  150. %tform = setWord( %tform, 0, getWord( %tform, 0 ) + getWord( %vec, 0 ) );
  151. %tform = setWord( %tform, 1, getWord( %tform, 1 ) + getWord( %vec, 1 ) );
  152. %tform = setWord( %tform, 2, getWord( %tform, 2 ) + getWord( %vec, 2 ) );
  153. if( !isObject( $ParticleEditor::emitterNode ) )
  154. {
  155. if( !isObject( TestEmitterNodeData ) )
  156. {
  157. datablock ParticleEmitterNodeData( TestEmitterNodeData )
  158. {
  159. timeMultiple = 1;
  160. };
  161. }
  162. $ParticleEditor::emitterNode = new ParticleEmitterNode()
  163. {
  164. emitter = PEE_EmitterSelector.getText();
  165. velocity = 1;
  166. position = getWords( %tform, 0, 2 );
  167. rotation = getWords( %tform, 3, 6 );
  168. datablock = TestEmitterNodeData;
  169. parentGroup = MissionCleanup;
  170. };
  171. }
  172. else
  173. {
  174. $ParticleEditor::emitterNode.setTransform( %tform );
  175. %clientObject = $ParticleEditor::emitterNode.getClientObject();
  176. if( isObject( %clientObject ) )
  177. %clientObject.setTransform( %tform );
  178. ParticleEditor.updateEmitterNode();
  179. }
  180. }
  181. //---------------------------------------------------------------------------------------------
  182. function ParticleEditor::updateEmitterNode( %this )
  183. {
  184. if( isObject( $ParticleEditor::emitterNode ) )
  185. {
  186. %id = PEE_EmitterSelector_Control-->PopUpMenu.getSelected();
  187. %clientObject = $ParticleEditor::emitterNode.getClientObject();
  188. if( isObject( %clientObject ) )
  189. %clientObject.setEmitterDataBlock( %id );
  190. }
  191. else
  192. %this.resetEmitterNode();
  193. }
  194. //=============================================================================================
  195. // PE_TabBook.
  196. //=============================================================================================
  197. //---------------------------------------------------------------------------------------------
  198. function PE_TabBook::onTabSelected( %this, %text, %idx )
  199. {
  200. if( %idx == 0 )
  201. ParticleEditor.openEmitterPane();
  202. else
  203. ParticleEditor.openParticlePane();
  204. }