| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
|
| 35 |
class GPUParticles2D : public Node2D { |
| 36 |
private: |
| 37 |
GDCLASS(GPUParticles2D, Node2D); |
| 38 |
|
| 39 |
public: |
| 40 |
enum DrawOrder { |
| 41 |
DRAW_ORDER_INDEX, |
| 42 |
DRAW_ORDER_LIFETIME, |
| 43 |
DRAW_ORDER_REVERSE_LIFETIME, |
| 44 |
}; |
| 45 |
|
| 46 |
private: |
| 47 |
RID particles; |
| 48 |
|
| 49 |
bool emitting = false; |
| 50 |
bool active = false; |
| 51 |
bool signal_canceled = false; |
| 52 |
bool one_shot = false; |
| 53 |
int amount = 0; |
| 54 |
float amount_ratio = 1.0; |
| 55 |
double lifetime = 0.0; |
| 56 |
double pre_process_time = 0.0; |
| 57 |
real_t explosiveness_ratio = 0.0; |
| 58 |
real_t randomness_ratio = 0.0; |
| 59 |
double speed_scale = 0.0; |
| 60 |
Rect2 visibility_rect; |
| 61 |
bool local_coords = false; |
| 62 |
int fixed_fps = 0; |
| 63 |
bool fractional_delta = false; |
| 64 |
bool interpolate = true; |
| 65 |
float interp_to_end_factor = 0; |
| 66 |
Vector3 previous_velocity; |
| 67 |
Vector2 previous_position; |
| 68 |
uint32_t seed = 0; |
| 69 |
bool use_fixed_seed = false; |
| 70 |
#ifdef TOOLS_ENABLED |
| 71 |
bool show_gizmos = false; |
| 72 |
#endif |
| 73 |
Ref<Material> process_material; |
| 74 |
|
| 75 |
DrawOrder draw_order = DRAW_ORDER_LIFETIME; |
| 76 |
|
| 77 |
Ref<Texture2D> texture; |
| 78 |
|
| 79 |
void _update_particle_emission_transform(); |
| 80 |
|
| 81 |
NodePath sub_emitter; |
| 82 |
real_t collision_base_size = 1.0; |
| 83 |
|
| 84 |
bool trail_enabled = false; |
| 85 |
double trail_lifetime = 0.3; |
| 86 |
int trail_sections = 8; |
| 87 |
int trail_section_subdivisions = 4; |
| 88 |
|
| 89 |
double time = 0.0; |
| 90 |
double emission_time = 0.0; |
| 91 |
double active_time = 0.0; |
| 92 |
|
| 93 |
RID mesh; |
| 94 |
|
| 95 |
void _attach_sub_emitter(); |
| 96 |
|
| 97 |
void _texture_changed(); |
| 98 |
|
| 99 |
protected: |
| 100 |
static void _bind_methods(); |
| 101 |
void _validate_property(PropertyInfo &p_property) const; |
| 102 |
void _notification(int p_what); |
| 103 |
#ifdef TOOLS_ENABLED |
| 104 |
void _draw_emission_gizmo(); |
| 105 |
#endif |
| 106 |
void _update_collision_size(); |
| 107 |
|
| 108 |
#ifndef DISABLE_DEPRECATED |
| 109 |
void _restart_bind_compat_92089(); |
| 110 |
static void _bind_compatibility_methods(); |
| 111 |
#endif |
| 112 |
|
| 113 |
public: |
| 114 |
void set_emitting(bool p_emitting); |
| 115 |
void set_amount(int p_amount); |
| 116 |
void set_lifetime(double p_lifetime); |
| 117 |
void set_one_shot(bool p_enable); |
| 118 |
void set_pre_process_time(double p_time); |
| 119 |
void set_explosiveness_ratio(real_t p_ratio); |
| 120 |
void set_randomness_ratio(real_t p_ratio); |
| 121 |
void set_visibility_rect(const Rect2 &p_visibility_rect); |
| 122 |
void set_use_local_coordinates(bool p_enable); |
| 123 |
void set_process_material(const Ref<Material> &p_material); |
| 124 |
void set_speed_scale(double p_scale); |
| 125 |
void set_collision_base_size(real_t p_ratio); |
| 126 |
void set_trail_enabled(bool p_enabled); |
| 127 |
void set_trail_lifetime(double p_seconds); |
| 128 |
void set_trail_sections(int p_sections); |
| 129 |
void set_trail_section_subdivisions(int p_subdivisions); |
| 130 |
void set_interp_to_end(float p_interp); |
| 131 |
void request_particles_process(real_t p_requested_process_time); |
| 132 |
|
| 133 |
#ifdef TOOLS_ENABLED |
| 134 |
void set_show_gizmos(bool p_show_gizmos); |
| 135 |
#endif |
| 136 |
|
| 137 |
bool is_emitting() const; |
| 138 |
int get_amount() const; |
| 139 |
double get_lifetime() const; |
| 140 |
bool get_one_shot() const; |
| 141 |
double get_pre_process_time() const; |
| 142 |
real_t get_explosiveness_ratio() const; |
| 143 |
real_t get_randomness_ratio() const; |
| 144 |
Rect2 get_visibility_rect() const; |
| 145 |
bool get_use_local_coordinates() const; |
| 146 |
Ref<Material> get_process_material() const; |
| 147 |
double get_speed_scale() const; |
| 148 |
|
| 149 |
real_t get_collision_base_size() const; |
| 150 |
bool is_trail_enabled() const; |
| 151 |
double get_trail_lifetime() const; |
| 152 |
int get_trail_sections() const; |
| 153 |
int get_trail_section_subdivisions() const; |
| 154 |
float get_interp_to_end() const; |
| 155 |
|
| 156 |
void set_fixed_fps(int p_count); |
| 157 |
int get_fixed_fps() const; |
| 158 |
|
| 159 |
void set_fractional_delta(bool p_enable); |
| 160 |
bool get_fractional_delta() const; |
| 161 |
|
| 162 |
void set_interpolate(bool p_enable); |
| 163 |
bool get_interpolate() const; |
| 164 |
|
| 165 |
void set_draw_order(DrawOrder p_order); |
| 166 |
DrawOrder get_draw_order() const; |
| 167 |
|
| 168 |
void set_texture(const Ref<Texture2D> &p_texture); |
| 169 |
Ref<Texture2D> get_texture() const; |
| 170 |
|
| 171 |
void set_amount_ratio(float p_ratio); |
| 172 |
float get_amount_ratio() const; |
| 173 |
|
| 174 |
PackedStringArray get_configuration_warnings() const override; |
| 175 |
|
| 176 |
void set_sub_emitter(const NodePath &p_path); |
| 177 |
NodePath get_sub_emitter() const; |
| 178 |
|
| 179 |
void set_use_fixed_seed(bool p_use_fixed_seed); |
| 180 |
bool get_use_fixed_seed() const; |
| 181 |
|
| 182 |
void set_seed(uint32_t p_seed); |
| 183 |
uint32_t get_seed() const; |
| 184 |
|
| 185 |
enum EmitFlags { |
| 186 |
EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION, |
| 187 |
EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE, |
| 188 |
EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY, |
| 189 |
EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR, |
| 190 |
EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM |
| 191 |
}; |
| 192 |
|
| 193 |
void emit_particle(const Transform2D &p_transform, const Vector2 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags); |
| 194 |
|
| 195 |
void restart(bool p_keep_seed = false); |
| 196 |
Rect2 capture_rect() const; |
| 197 |
void convert_from_particles(Node *p_particles); |
| 198 |
|
| 199 |
GPUParticles2D(); |
| 200 |
~GPUParticles2D(); |
| 201 |
}; |
| 202 |
|
| 203 |
VARIANT_ENUM_CAST(GPUParticles2D::DrawOrder) |
| 204 |
VARIANT_ENUM_CAST(GPUParticles2D::EmitFlags) |