gpu_particles_3d.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**************************************************************************/
  2. /* gpu_particles_3d.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_3D_H
  31. #define GPU_PARTICLES_3D_H
  32. #include "scene/3d/visual_instance_3d.h"
  33. #include "scene/resources/skin.h"
  34. class GPUParticles3D : public GeometryInstance3D {
  35. private:
  36. GDCLASS(GPUParticles3D, GeometryInstance3D);
  37. public:
  38. enum DrawOrder {
  39. DRAW_ORDER_INDEX,
  40. DRAW_ORDER_LIFETIME,
  41. DRAW_ORDER_REVERSE_LIFETIME,
  42. DRAW_ORDER_VIEW_DEPTH,
  43. };
  44. enum TransformAlign {
  45. TRANSFORM_ALIGN_DISABLED,
  46. TRANSFORM_ALIGN_Z_BILLBOARD,
  47. TRANSFORM_ALIGN_Y_TO_VELOCITY,
  48. TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY
  49. };
  50. enum {
  51. MAX_DRAW_PASSES = 4
  52. };
  53. private:
  54. RID particles;
  55. bool emitting = false;
  56. bool active = false;
  57. bool signal_canceled = false;
  58. bool one_shot = false;
  59. int amount = 0;
  60. float amount_ratio = 1.0;
  61. double lifetime = 0.0;
  62. double pre_process_time = 0.0;
  63. real_t explosiveness_ratio = 0.0;
  64. real_t randomness_ratio = 0.0;
  65. double speed_scale = 0.0;
  66. AABB visibility_aabb;
  67. bool local_coords = false;
  68. int fixed_fps = 0;
  69. bool fractional_delta = false;
  70. bool interpolate = true;
  71. NodePath sub_emitter;
  72. real_t collision_base_size = 0.01;
  73. bool trail_enabled = false;
  74. double trail_lifetime = 0.3;
  75. TransformAlign transform_align = TRANSFORM_ALIGN_DISABLED;
  76. Ref<Material> process_material;
  77. DrawOrder draw_order = DRAW_ORDER_INDEX;
  78. Vector<Ref<Mesh>> draw_passes;
  79. Ref<Skin> skin;
  80. double time = 0.0;
  81. double emission_time = 0.0;
  82. double active_time = 0.0;
  83. float interp_to_end_factor = 0;
  84. Vector3 previous_velocity;
  85. Vector3 previous_position;
  86. void _attach_sub_emitter();
  87. void _skinning_changed();
  88. protected:
  89. static void _bind_methods();
  90. void _notification(int p_what);
  91. void _validate_property(PropertyInfo &p_property) const;
  92. public:
  93. AABB get_aabb() const override;
  94. void set_emitting(bool p_emitting);
  95. void set_amount(int p_amount);
  96. void set_lifetime(double p_lifetime);
  97. void set_one_shot(bool p_one_shot);
  98. void set_pre_process_time(double p_time);
  99. void set_explosiveness_ratio(real_t p_ratio);
  100. void set_randomness_ratio(real_t p_ratio);
  101. void set_visibility_aabb(const AABB &p_aabb);
  102. void set_use_local_coordinates(bool p_enable);
  103. void set_process_material(const Ref<Material> &p_material);
  104. void set_speed_scale(double p_scale);
  105. void set_collision_base_size(real_t p_ratio);
  106. void set_trail_enabled(bool p_enabled);
  107. void set_trail_lifetime(double p_seconds);
  108. void set_interp_to_end(float p_interp);
  109. bool is_emitting() const;
  110. int get_amount() const;
  111. double get_lifetime() const;
  112. bool get_one_shot() const;
  113. double get_pre_process_time() const;
  114. real_t get_explosiveness_ratio() const;
  115. real_t get_randomness_ratio() const;
  116. AABB get_visibility_aabb() const;
  117. bool get_use_local_coordinates() const;
  118. Ref<Material> get_process_material() const;
  119. double get_speed_scale() const;
  120. real_t get_collision_base_size() const;
  121. bool is_trail_enabled() const;
  122. double get_trail_lifetime() const;
  123. float get_interp_to_end() const;
  124. void set_amount_ratio(float p_ratio);
  125. float get_amount_ratio() const;
  126. void set_fixed_fps(int p_count);
  127. int get_fixed_fps() const;
  128. void set_fractional_delta(bool p_enable);
  129. bool get_fractional_delta() const;
  130. void set_interpolate(bool p_enable);
  131. bool get_interpolate() const;
  132. void set_draw_order(DrawOrder p_order);
  133. DrawOrder get_draw_order() const;
  134. void set_draw_passes(int p_count);
  135. int get_draw_passes() const;
  136. void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
  137. Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
  138. PackedStringArray get_configuration_warnings() const override;
  139. void set_sub_emitter(const NodePath &p_path);
  140. NodePath get_sub_emitter() const;
  141. void set_skin(const Ref<Skin> &p_skin);
  142. Ref<Skin> get_skin() const;
  143. void set_transform_align(TransformAlign p_align);
  144. TransformAlign get_transform_align() const;
  145. void restart();
  146. enum EmitFlags {
  147. EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
  148. EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
  149. EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
  150. EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
  151. EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
  152. };
  153. void emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  154. AABB capture_aabb() const;
  155. void convert_from_particles(Node *p_particles);
  156. GPUParticles3D();
  157. ~GPUParticles3D();
  158. };
  159. VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder)
  160. VARIANT_ENUM_CAST(GPUParticles3D::TransformAlign)
  161. VARIANT_ENUM_CAST(GPUParticles3D::EmitFlags)
  162. #endif // GPU_PARTICLES_3D_H