particles_editor_plugin.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**************************************************************************/
  2. /* particles_editor_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef PARTICLES_EDITOR_PLUGIN_H
  31. #define PARTICLES_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  33. class CheckBox;
  34. class ConfirmationDialog;
  35. class EditorFileDialog;
  36. class GPUParticles2D;
  37. class HBoxContainer;
  38. class MenuButton;
  39. class OptionButton;
  40. class SceneTreeDialog;
  41. class SpinBox;
  42. class ParticlesEditorPlugin : public EditorPlugin {
  43. GDCLASS(ParticlesEditorPlugin, EditorPlugin);
  44. private:
  45. enum {
  46. MENU_OPTION_CONVERT,
  47. MENU_RESTART
  48. };
  49. HBoxContainer *toolbar = nullptr;
  50. MenuButton *menu = nullptr;
  51. protected:
  52. String handled_type;
  53. String conversion_option_name;
  54. Node *edited_node = nullptr;
  55. void _notification(int p_what);
  56. bool need_show_lifetime_dialog(SpinBox *p_seconds);
  57. virtual void _menu_callback(int p_idx);
  58. virtual void _add_menu_options(PopupMenu *p_menu) {}
  59. virtual Node *_convert_particles() = 0;
  60. public:
  61. virtual void edit(Object *p_object) override;
  62. virtual bool handles(Object *p_object) const override;
  63. virtual void make_visible(bool p_visible) override;
  64. ParticlesEditorPlugin();
  65. };
  66. // 2D /////////////////////////////////////////////
  67. class Particles2DEditorPlugin : public ParticlesEditorPlugin {
  68. GDCLASS(Particles2DEditorPlugin, ParticlesEditorPlugin);
  69. protected:
  70. enum {
  71. MENU_LOAD_EMISSION_MASK = 100,
  72. };
  73. enum EmissionMode {
  74. EMISSION_MODE_SOLID,
  75. EMISSION_MODE_BORDER,
  76. EMISSION_MODE_BORDER_DIRECTED
  77. };
  78. EditorFileDialog *file = nullptr;
  79. ConfirmationDialog *emission_mask = nullptr;
  80. OptionButton *emission_mask_mode = nullptr;
  81. CheckBox *emission_mask_centered = nullptr;
  82. CheckBox *emission_colors = nullptr;
  83. String source_emission_file;
  84. virtual void _menu_callback(int p_idx) override;
  85. virtual void _add_menu_options(PopupMenu *p_menu) override;
  86. void _file_selected(const String &p_file);
  87. void _get_base_emission_mask(PackedVector2Array &r_valid_positions, PackedVector2Array &r_valid_normals, PackedByteArray &r_valid_colors, Vector2i &r_image_size);
  88. virtual void _generate_emission_mask() = 0;
  89. public:
  90. Particles2DEditorPlugin();
  91. };
  92. class GPUParticles2DEditorPlugin : public Particles2DEditorPlugin {
  93. GDCLASS(GPUParticles2DEditorPlugin, Particles2DEditorPlugin);
  94. enum {
  95. MENU_GENERATE_VISIBILITY_RECT = 200,
  96. };
  97. List<GPUParticles2D *> selected_particles;
  98. ConfirmationDialog *generate_visibility_rect = nullptr;
  99. SpinBox *generate_seconds = nullptr;
  100. void _selection_changed();
  101. void _generate_visibility_rect();
  102. protected:
  103. void _notification(int p_what);
  104. void _menu_callback(int p_idx) override;
  105. void _add_menu_options(PopupMenu *p_menu) override;
  106. Node *_convert_particles() override;
  107. void _generate_emission_mask() override;
  108. public:
  109. GPUParticles2DEditorPlugin();
  110. };
  111. class CPUParticles2DEditorPlugin : public Particles2DEditorPlugin {
  112. GDCLASS(CPUParticles2DEditorPlugin, Particles2DEditorPlugin);
  113. protected:
  114. Node *_convert_particles() override;
  115. void _generate_emission_mask() override;
  116. public:
  117. CPUParticles2DEditorPlugin();
  118. };
  119. // 3D /////////////////////////////////////////////
  120. class Particles3DEditorPlugin : public ParticlesEditorPlugin {
  121. GDCLASS(Particles3DEditorPlugin, ParticlesEditorPlugin);
  122. enum {
  123. MENU_OPTION_GENERATE_AABB = 300,
  124. MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE,
  125. };
  126. ConfirmationDialog *generate_aabb = nullptr;
  127. SpinBox *generate_seconds = nullptr;
  128. SceneTreeDialog *emission_tree_dialog = nullptr;
  129. ConfirmationDialog *emission_dialog = nullptr;
  130. SpinBox *emission_amount = nullptr;
  131. OptionButton *emission_fill = nullptr;
  132. void _generate_aabb();
  133. void _node_selected(const NodePath &p_path);
  134. protected:
  135. Vector<Face3> geometry;
  136. virtual void _menu_callback(int p_idx) override;
  137. virtual void _add_menu_options(PopupMenu *p_menu) override;
  138. bool _generate(Vector<Vector3> &r_points, Vector<Vector3> &r_normals);
  139. virtual bool _can_generate_points() const = 0;
  140. virtual void _generate_emission_points() = 0;
  141. public:
  142. Particles3DEditorPlugin();
  143. };
  144. class GPUParticles3DEditorPlugin : public Particles3DEditorPlugin {
  145. GDCLASS(GPUParticles3DEditorPlugin, Particles3DEditorPlugin);
  146. protected:
  147. Node *_convert_particles() override;
  148. bool _can_generate_points() const override;
  149. void _generate_emission_points() override;
  150. public:
  151. GPUParticles3DEditorPlugin();
  152. };
  153. class CPUParticles3DEditorPlugin : public Particles3DEditorPlugin {
  154. GDCLASS(CPUParticles3DEditorPlugin, Particles3DEditorPlugin);
  155. protected:
  156. Node *_convert_particles() override;
  157. bool _can_generate_points() const override { return true; }
  158. void _generate_emission_points() override;
  159. public:
  160. CPUParticles3DEditorPlugin();
  161. };
  162. #endif // PARTICLES_EDITOR_PLUGIN_H