Debian Codegraph @

scene/3d/cpu_particles_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* cpu_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
31 #pragma once
32
33 #include "scene/3d/visual_instance_3d.h"
34 #include "scene/resources/gradient.h"
35
36 class RandomNumberGenerator;
37
38 class CPUParticles3D : public GeometryInstance3D {
39 private:
40 GDCLASS(CPUParticles3D, GeometryInstance3D);
41
42 public:
43 enum DrawOrder {
44 DRAW_ORDER_INDEX,
45 DRAW_ORDER_LIFETIME,
46 DRAW_ORDER_VIEW_DEPTH,
47 DRAW_ORDER_MAX
48 };
49
50 enum Parameter {
51 PARAM_INITIAL_LINEAR_VELOCITY,
52 PARAM_ANGULAR_VELOCITY,
53 PARAM_ORBIT_VELOCITY,
54 PARAM_LINEAR_ACCEL,
55 PARAM_RADIAL_ACCEL,
56 PARAM_TANGENTIAL_ACCEL,
57 PARAM_DAMPING,
58 PARAM_ANGLE,
59 PARAM_SCALE,
60 PARAM_HUE_VARIATION,
61 PARAM_ANIM_SPEED,
62 PARAM_ANIM_OFFSET,
63 PARAM_MAX
64 };
65
66 enum ParticleFlags {
67 PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY,
68 PARTICLE_FLAG_ROTATE_Y,
69 PARTICLE_FLAG_DISABLE_Z,
70 PARTICLE_FLAG_MAX
71 };
72
73 enum EmissionShape {
74 EMISSION_SHAPE_POINT,
75 EMISSION_SHAPE_SPHERE,
76 EMISSION_SHAPE_SPHERE_SURFACE,
77 EMISSION_SHAPE_BOX,
78 EMISSION_SHAPE_POINTS,
79 EMISSION_SHAPE_DIRECTED_POINTS,
80 EMISSION_SHAPE_RING,
81 EMISSION_SHAPE_MAX
82 };
83
84 private:
85 bool emitting = false;
86 bool active = false;
87
88 struct Particle {
89 Transform3D transform;
90 Color color;
91 real_t custom[4] = {};
92 Vector3 velocity;
93 bool active = false;
94 real_t angle_rand = 0.0;
95 real_t scale_rand = 0.0;
96 real_t hue_rot_rand = 0.0;
97 real_t anim_offset_rand = 0.0;
98 Color start_color_rand;
99 double time = 0.0;
100 double lifetime = 0.0;
101 Color base_color;
102
103 uint32_t seed = 0;
104 };
105
106 double time = 0.0;
107 double frame_remainder = 0.0;
108 int cycle = 0;
109 bool redraw = false;
110
111 RID multimesh;
112
113 Vector<Particle> particles;
114 Vector<float> particle_data;
115 Vector<int> particle_order;
116
117 struct SortLifetime {
118 const Particle *particles = nullptr;
119
120 bool operator()(int p_a, int p_b) const {
121 return particles[p_a].time > particles[p_b].time;
122 }
123 };
124
125 struct SortAxis {
126 const Particle *particles = nullptr;
127 Vector3 axis;
128 bool operator()(int p_a, int p_b) const {
129 return axis.dot(particles[p_a].transform.origin) < axis.dot(particles[p_b].transform.origin);
130 }
131 };
132
133 //
134
135 bool one_shot = false;
136
137 double lifetime = 1.0;
138 double pre_process_time = 0.0;
139 double _requested_process_time = 0.0;
140 real_t explosiveness_ratio = 0.0;
141 real_t randomness_ratio = 0.0;
142 double lifetime_randomness = 0.0;
143 double speed_scale = 1.0;
144 AABB visibility_aabb;
145 bool local_coords = false;
146 int fixed_fps = 0;
147 bool fractional_delta = true;
148 uint32_t seed = 0;
149 bool use_fixed_seed = false;
150
151 Transform3D inv_emission_transform;
152
153 SafeFlag can_update;
154
155 DrawOrder draw_order = DRAW_ORDER_INDEX;
156
157 Ref<Mesh> mesh;
158
159 ////////
160
161 Vector3 direction = Vector3(1, 0, 0);
162 real_t spread = 45.0;
163 real_t flatness = 0.0;
164
165 real_t parameters_min[PARAM_MAX] = {};
166 real_t parameters_max[PARAM_MAX] = {};
167
168 Ref<Curve> curve_parameters[PARAM_MAX];
169 Color color = Color(1, 1, 1, 1);
170 Ref<Gradient> color_ramp;
171 Ref<Gradient> color_initial_ramp;
172
173 bool particle_flags[PARTICLE_FLAG_MAX] = {};
174
175 EmissionShape emission_shape = EMISSION_SHAPE_POINT;
176 real_t emission_sphere_radius = 1.0;
177 Vector3 emission_box_extents = Vector3(1, 1, 1);
178 Vector<Vector3> emission_points;
179 Vector<Vector3> emission_normals;
180 Vector<Color> emission_colors;
181 Vector3 emission_ring_axis;
182 real_t emission_ring_height = 0.0;
183 real_t emission_ring_radius = 0.0;
184 real_t emission_ring_inner_radius = 0.0;
185 real_t emission_ring_cone_angle = 0.0;
186
187 Ref<Curve> scale_curve_x;
188 Ref<Curve> scale_curve_y;
189 Ref<Curve> scale_curve_z;
190 bool split_scale = false;
191
192 Vector3 gravity = Vector3(0, -9.8, 0);
193
194 Ref<RandomNumberGenerator> rng;
195
196 void _update_internal();
197 void _particles_process(double p_delta);
198 void _update_particle_data_buffer();
199 void _set_emitting();
200
201 Mutex update_mutex;
202
203 void _update_render_thread();
204
205 void _set_redraw(bool p_redraw);
206
207 protected:
208 static void _bind_methods();
209 void _notification(int p_what);
210 void _validate_property(PropertyInfo &p_property) const;
211
212 #ifndef DISABLE_DEPRECATED
213 void _restart_bind_compat_92089();
214 static void _bind_compatibility_methods();
215 #endif
216
217 public:
218 AABB get_aabb() const override;
219
220 void set_emitting(bool p_emitting);
221 void set_amount(int p_amount);
222 void set_lifetime(double p_lifetime);
223 void set_one_shot(bool p_one_shot);
224 void set_pre_process_time(double p_time);
225 void set_explosiveness_ratio(real_t p_ratio);
226 void set_randomness_ratio(real_t p_ratio);
227 void set_visibility_aabb(const AABB &p_aabb);
228 void set_lifetime_randomness(double p_random);
229 void set_use_local_coordinates(bool p_enable);
230 void set_speed_scale(double p_scale);
231
232 bool is_emitting() const;
233 int get_amount() const;
234 double get_lifetime() const;
235 bool get_one_shot() const;
236 double get_pre_process_time() const;
237 real_t get_explosiveness_ratio() const;
238 real_t get_randomness_ratio() const;
239 AABB get_visibility_aabb() const;
240 double get_lifetime_randomness() const;
241 bool get_use_local_coordinates() const;
242 double get_speed_scale() const;
243
244 void set_fixed_fps(int p_count);
245 int get_fixed_fps() const;
246
247 void set_fractional_delta(bool p_enable);
248 bool get_fractional_delta() const;
249
250 void set_draw_order(DrawOrder p_order);
251 DrawOrder get_draw_order() const;
252
253 void set_mesh(const Ref<Mesh> &p_mesh);
254 Ref<Mesh> get_mesh() const;
255
256 void set_use_fixed_seed(bool p_use_fixed_seed = false);
257 bool get_use_fixed_seed() const;
258
259 void set_seed(uint32_t p_seed);
260 uint32_t get_seed() const;
261
262 void request_particles_process(real_t p_requested_process_time);
263
264 ///////////////////
265
266 void set_direction(Vector3 p_direction);
267 Vector3 get_direction() const;
268
269 void set_spread(real_t p_spread);
270 real_t get_spread() const;
271
272 void set_flatness(real_t p_flatness);
273 real_t get_flatness() const;
274
275 void set_param_min(Parameter p_param, real_t p_value);
276 real_t get_param_min(Parameter p_param) const;
277
278 void set_param_max(Parameter p_param, real_t p_value);
279 real_t get_param_max(Parameter p_param) const;
280
281 void set_param_curve(Parameter p_param, const Ref<Curve> &p_curve);
282 Ref<Curve> get_param_curve(Parameter p_param) const;
283
284 void set_color(const Color &p_color);
285 Color get_color() const;
286
287 void set_color_ramp(const Ref<Gradient> &p_ramp);
288 Ref<Gradient> get_color_ramp() const;
289
290 void set_color_initial_ramp(const Ref<Gradient> &p_ramp);
291 Ref<Gradient> get_color_initial_ramp() const;
292
293 void set_particle_flag(ParticleFlags p_particle_flag, bool p_enable);
294 bool get_particle_flag(ParticleFlags p_particle_flag) const;
295
296 void set_emission_shape(EmissionShape p_shape);
297 void set_emission_sphere_radius(real_t p_radius);
298 void set_emission_box_extents(Vector3 p_extents);
299 void set_emission_points(const Vector<Vector3> &p_points);
300 void set_emission_normals(const Vector<Vector3> &p_normals);
301 void set_emission_colors(const Vector<Color> &p_colors);
302 void set_emission_ring_axis(Vector3 p_axis);
303 void set_emission_ring_height(real_t p_height);
304 void set_emission_ring_radius(real_t p_radius);
305 void set_emission_ring_inner_radius(real_t p_radius);
306 void set_emission_ring_cone_angle(real_t p_angle);
307 void set_scale_curve_x(Ref<Curve> p_scale_curve);
308 void set_scale_curve_y(Ref<Curve> p_scale_curve);
309 void set_scale_curve_z(Ref<Curve> p_scale_curve);
310 void set_split_scale(bool p_split_scale);
311
312 EmissionShape get_emission_shape() const;
313 real_t get_emission_sphere_radius() const;
314 Vector3 get_emission_box_extents() const;
315 Vector<Vector3> get_emission_points() const;
316 Vector<Vector3> get_emission_normals() const;
317 Vector<Color> get_emission_colors() const;
318 Vector3 get_emission_ring_axis() const;
319 real_t get_emission_ring_height() const;
320 real_t get_emission_ring_radius() const;
321 real_t get_emission_ring_inner_radius() const;
322 real_t get_emission_ring_cone_angle() const;
323 Ref<Curve> get_scale_curve_x() const;
324 Ref<Curve> get_scale_curve_y() const;
325 Ref<Curve> get_scale_curve_z() const;
326 bool get_split_scale();
327
328 void set_gravity(const Vector3 &p_gravity);
329 Vector3 get_gravity() const;
330
331 PackedStringArray get_configuration_warnings() const override;
332
333 void restart(bool p_keep_seed = false);
334
335 void convert_from_particles(Node *p_particles);
336
337 AABB capture_aabb() const;
338
339 CPUParticles3D();
340 ~CPUParticles3D();
341 };
342
343 VARIANT_ENUM_CAST(CPUParticles3D::DrawOrder)
344 VARIANT_ENUM_CAST(CPUParticles3D::Parameter)
345 VARIANT_ENUM_CAST(CPUParticles3D::ParticleFlags)
346 VARIANT_ENUM_CAST(CPUParticles3D::EmissionShape)