gpu_particles_2d.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**************************************************************************/
  2. /* gpu_particles_2d.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 GPU_PARTICLES_2D_H
  31. #define GPU_PARTICLES_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class GPUParticles2D : public Node2D {
  34. private:
  35. GDCLASS(GPUParticles2D, Node2D);
  36. public:
  37. enum DrawOrder {
  38. DRAW_ORDER_INDEX,
  39. DRAW_ORDER_LIFETIME,
  40. DRAW_ORDER_REVERSE_LIFETIME,
  41. };
  42. private:
  43. RID particles;
  44. bool emitting = false;
  45. bool active = false;
  46. bool signal_canceled = false;
  47. bool one_shot = false;
  48. int amount = 0;
  49. float amount_ratio = 1.0;
  50. double lifetime = 0.0;
  51. double pre_process_time = 0.0;
  52. real_t explosiveness_ratio = 0.0;
  53. real_t randomness_ratio = 0.0;
  54. double speed_scale = 0.0;
  55. Rect2 visibility_rect;
  56. bool local_coords = false;
  57. int fixed_fps = 0;
  58. bool fractional_delta = false;
  59. bool interpolate = true;
  60. float interp_to_end_factor = 0;
  61. Vector3 previous_velocity;
  62. Vector2 previous_position;
  63. #ifdef TOOLS_ENABLED
  64. bool show_visibility_rect = false;
  65. #endif
  66. Ref<Material> process_material;
  67. DrawOrder draw_order = DRAW_ORDER_LIFETIME;
  68. Ref<Texture2D> texture;
  69. void _update_particle_emission_transform();
  70. NodePath sub_emitter;
  71. real_t collision_base_size = 1.0;
  72. bool trail_enabled = false;
  73. double trail_lifetime = 0.3;
  74. int trail_sections = 8;
  75. int trail_section_subdivisions = 4;
  76. double time = 0.0;
  77. double emission_time = 0.0;
  78. double active_time = 0.0;
  79. RID mesh;
  80. void _attach_sub_emitter();
  81. void _texture_changed();
  82. protected:
  83. static void _bind_methods();
  84. void _validate_property(PropertyInfo &p_property) const;
  85. void _notification(int p_what);
  86. void _update_collision_size();
  87. public:
  88. void set_emitting(bool p_emitting);
  89. void set_amount(int p_amount);
  90. void set_lifetime(double p_lifetime);
  91. void set_one_shot(bool p_enable);
  92. void set_pre_process_time(double p_time);
  93. void set_explosiveness_ratio(real_t p_ratio);
  94. void set_randomness_ratio(real_t p_ratio);
  95. void set_visibility_rect(const Rect2 &p_visibility_rect);
  96. void set_use_local_coordinates(bool p_enable);
  97. void set_process_material(const Ref<Material> &p_material);
  98. void set_speed_scale(double p_scale);
  99. void set_collision_base_size(real_t p_ratio);
  100. void set_trail_enabled(bool p_enabled);
  101. void set_trail_lifetime(double p_seconds);
  102. void set_trail_sections(int p_sections);
  103. void set_trail_section_subdivisions(int p_subdivisions);
  104. void set_interp_to_end(float p_interp);
  105. #ifdef TOOLS_ENABLED
  106. void set_show_visibility_rect(bool p_show_visibility_rect);
  107. #endif
  108. bool is_emitting() const;
  109. int get_amount() const;
  110. double get_lifetime() const;
  111. bool get_one_shot() const;
  112. double get_pre_process_time() const;
  113. real_t get_explosiveness_ratio() const;
  114. real_t get_randomness_ratio() const;
  115. Rect2 get_visibility_rect() const;
  116. bool get_use_local_coordinates() const;
  117. Ref<Material> get_process_material() const;
  118. double get_speed_scale() const;
  119. real_t get_collision_base_size() const;
  120. bool is_trail_enabled() const;
  121. double get_trail_lifetime() const;
  122. int get_trail_sections() const;
  123. int get_trail_section_subdivisions() const;
  124. float get_interp_to_end() const;
  125. void set_fixed_fps(int p_count);
  126. int get_fixed_fps() const;
  127. void set_fractional_delta(bool p_enable);
  128. bool get_fractional_delta() const;
  129. void set_interpolate(bool p_enable);
  130. bool get_interpolate() const;
  131. void set_draw_order(DrawOrder p_order);
  132. DrawOrder get_draw_order() const;
  133. void set_texture(const Ref<Texture2D> &p_texture);
  134. Ref<Texture2D> get_texture() const;
  135. void set_amount_ratio(float p_ratio);
  136. float get_amount_ratio() const;
  137. PackedStringArray get_configuration_warnings() const override;
  138. void set_sub_emitter(const NodePath &p_path);
  139. NodePath get_sub_emitter() const;
  140. enum EmitFlags {
  141. EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
  142. EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
  143. EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
  144. EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
  145. EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
  146. };
  147. void emit_particle(const Transform2D &p_transform, const Vector2 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  148. void restart();
  149. Rect2 capture_rect() const;
  150. void convert_from_particles(Node *p_particles);
  151. GPUParticles2D();
  152. ~GPUParticles2D();
  153. };
  154. VARIANT_ENUM_CAST(GPUParticles2D::DrawOrder)
  155. VARIANT_ENUM_CAST(GPUParticles2D::EmitFlags)
  156. #endif // GPU_PARTICLES_2D_H