particleEditor.ed.tscript 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. if (EWorldEditor.getSelectionSize()>0)
  181. {
  182. %obj = EWorldEditor.getSelectedObject(0);
  183. if (%obj.isMemberOfClass("ParticleEmitterNode"))
  184. $ParticleEditor::emitterNode.sethidden(true);
  185. }
  186. }
  187. //---------------------------------------------------------------------------------------------
  188. function ParticleEditor::updateEmitterNode( %this )
  189. {
  190. if( isObject( $ParticleEditor::emitterNode ) )
  191. {
  192. %id = PEE_EmitterSelector_Control-->PopUpMenu.getSelected();
  193. %clientObject = $ParticleEditor::emitterNode.getClientObject();
  194. if( isObject( %clientObject ) )
  195. %clientObject.setEmitterDataBlock( %id );
  196. }
  197. else
  198. %this.resetEmitterNode();
  199. }
  200. //=============================================================================================
  201. // PE_TabBook.
  202. //=============================================================================================
  203. //---------------------------------------------------------------------------------------------
  204. function PE_TabBook::onTabSelected( %this, %text, %idx )
  205. {
  206. if( %idx == 0 )
  207. ParticleEditor.openEmitterPane();
  208. else
  209. ParticleEditor.openParticlePane();
  210. }
  211. //------------------------------------------------------------------------------
  212. // PE Window
  213. //------------------------------------------------------------------------------
  214. //------------------------------------------------------------------------------
  215. function ParticleEditor::maxSize(%this, %window)
  216. {
  217. // Resize the windows to the max height
  218. // and force these to the right side if set
  219. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
  220. {
  221. // prevent onResize after a resize
  222. %this.resizing = false;
  223. %offset = -1; // tweak the vertical offset so that it aligns neatly
  224. %top = EditorGuiToolbar.extent.y + %offset;
  225. %bottom = %top + 59;
  226. %maxHeight = Canvas.extent.y - %top - %bottom;
  227. // --- Fixed window (top) ------------------------------------------------
  228. // put it back if it moved
  229. %window.position.x = Canvas.extent.x - %window.extent.x;
  230. %window.position.y = %top;
  231. // don't go beyond the canvas
  232. %window.extent.y = %maxHeight + 42;
  233. %position = %window.position.x SPC %window.position.y;
  234. %extent = %window.extent.x SPC %window.extent.y;
  235. %window.resize(%position.x, %position.y, %extent.x, %extent.y);
  236. // --- AssetBrowser window ----------------------------------------------
  237. if(isObject(AssetBrowserWindow))
  238. {
  239. // Only resize the AssetBrowser if it's docked
  240. if(AssetBrowserWindow.docked == true)
  241. {
  242. // The width is relative to the sidepanel
  243. %browserWidth = Canvas.extent.x - %extent.x;
  244. %browserHeight = AssetBrowserWindow.extent.y;
  245. %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
  246. AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
  247. }
  248. }
  249. // --- Windowed Console --------------------------------------------------
  250. if(isObject(windowConsoleControl))
  251. {
  252. // Only resize the AssetBrowser if it's docked
  253. if(windowConsoleControl.docked == true)
  254. {
  255. // The width is relative to the sidepanel
  256. %consoleWidth = Canvas.extent.x - %extent.x;
  257. %consoleHeight = windowConsoleControl.extent.y;
  258. %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
  259. windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
  260. }
  261. }
  262. }
  263. }
  264. function PE_Window::onMouseDragged(%this)
  265. {
  266. %parent = ParticleEditor;
  267. if(%parent.resizing == false)
  268. {
  269. %parent.resizing = true;
  270. %parent.maxSize(%this);
  271. }
  272. }
  273. function ParticleEditor::onResize(%this, %newPosition, %newExtent)
  274. {
  275. // Window to focus on (mostly the fluid window)
  276. %window = PE_Window;
  277. if(%this.resizing == false)
  278. {
  279. // Only resize once
  280. %this.resizing = true;
  281. %this.maxSize(%window);
  282. }
  283. FieldInfoControl.position = 5 SPC EWInspectorWindow.extent.y - 40;
  284. }
  285. //------------------------------------------------------------------------------