Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/3d/cpu_particles_3d.cpp
9898 views
1
/**************************************************************************/
2
/* cpu_particles_3d.cpp */
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
#include "cpu_particles_3d.h"
32
#include "cpu_particles_3d.compat.inc"
33
34
#include "core/math/random_number_generator.h"
35
#include "scene/3d/camera_3d.h"
36
#include "scene/3d/gpu_particles_3d.h"
37
#include "scene/main/viewport.h"
38
#include "scene/resources/curve_texture.h"
39
#include "scene/resources/gradient_texture.h"
40
#include "scene/resources/particle_process_material.h"
41
42
AABB CPUParticles3D::get_aabb() const {
43
return AABB();
44
}
45
46
void CPUParticles3D::set_emitting(bool p_emitting) {
47
if (emitting == p_emitting) {
48
return;
49
}
50
51
if (p_emitting && !use_fixed_seed && one_shot) {
52
set_seed(Math::rand());
53
}
54
55
emitting = p_emitting;
56
if (emitting) {
57
_set_emitting();
58
}
59
}
60
61
void CPUParticles3D::_set_emitting() {
62
active = true;
63
set_process_internal(true);
64
// first update before rendering to avoid one frame delay after emitting starts
65
if (time == 0) {
66
_update_internal();
67
}
68
}
69
70
void CPUParticles3D::set_amount(int p_amount) {
71
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0.");
72
73
particles.resize(p_amount);
74
{
75
Particle *w = particles.ptrw();
76
77
for (int i = 0; i < p_amount; i++) {
78
w[i].active = false;
79
w[i].custom[3] = 1.0; // Make sure w component isn't garbage data and doesn't break shaders with CUSTOM.y/Custom.w
80
}
81
}
82
83
particle_data.resize((12 + 4 + 4) * p_amount);
84
RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
85
RS::get_singleton()->multimesh_allocate_data(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_3D, true, true);
86
87
particle_order.resize(p_amount);
88
}
89
90
void CPUParticles3D::set_lifetime(double p_lifetime) {
91
ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
92
lifetime = p_lifetime;
93
}
94
95
void CPUParticles3D::set_one_shot(bool p_one_shot) {
96
one_shot = p_one_shot;
97
}
98
99
void CPUParticles3D::set_pre_process_time(double p_time) {
100
pre_process_time = p_time;
101
}
102
103
void CPUParticles3D::set_explosiveness_ratio(real_t p_ratio) {
104
explosiveness_ratio = p_ratio;
105
}
106
107
void CPUParticles3D::set_randomness_ratio(real_t p_ratio) {
108
randomness_ratio = p_ratio;
109
}
110
111
void CPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
112
RS::get_singleton()->multimesh_set_custom_aabb(multimesh, p_aabb);
113
visibility_aabb = p_aabb;
114
update_gizmos();
115
}
116
117
void CPUParticles3D::set_lifetime_randomness(double p_random) {
118
lifetime_randomness = p_random;
119
}
120
121
void CPUParticles3D::set_use_local_coordinates(bool p_enable) {
122
local_coords = p_enable;
123
}
124
125
void CPUParticles3D::set_speed_scale(double p_scale) {
126
speed_scale = p_scale;
127
}
128
129
bool CPUParticles3D::is_emitting() const {
130
return emitting;
131
}
132
133
int CPUParticles3D::get_amount() const {
134
return particles.size();
135
}
136
137
double CPUParticles3D::get_lifetime() const {
138
return lifetime;
139
}
140
141
bool CPUParticles3D::get_one_shot() const {
142
return one_shot;
143
}
144
145
double CPUParticles3D::get_pre_process_time() const {
146
return pre_process_time;
147
}
148
149
real_t CPUParticles3D::get_explosiveness_ratio() const {
150
return explosiveness_ratio;
151
}
152
153
real_t CPUParticles3D::get_randomness_ratio() const {
154
return randomness_ratio;
155
}
156
157
AABB CPUParticles3D::get_visibility_aabb() const {
158
return visibility_aabb;
159
}
160
161
double CPUParticles3D::get_lifetime_randomness() const {
162
return lifetime_randomness;
163
}
164
165
bool CPUParticles3D::get_use_local_coordinates() const {
166
return local_coords;
167
}
168
169
double CPUParticles3D::get_speed_scale() const {
170
return speed_scale;
171
}
172
173
void CPUParticles3D::set_draw_order(DrawOrder p_order) {
174
ERR_FAIL_INDEX(p_order, DRAW_ORDER_MAX);
175
draw_order = p_order;
176
}
177
178
CPUParticles3D::DrawOrder CPUParticles3D::get_draw_order() const {
179
return draw_order;
180
}
181
182
void CPUParticles3D::set_mesh(const Ref<Mesh> &p_mesh) {
183
mesh = p_mesh;
184
if (mesh.is_valid()) {
185
RS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid());
186
} else {
187
RS::get_singleton()->multimesh_set_mesh(multimesh, RID());
188
}
189
190
update_configuration_warnings();
191
}
192
193
Ref<Mesh> CPUParticles3D::get_mesh() const {
194
return mesh;
195
}
196
197
void CPUParticles3D::set_fixed_fps(int p_count) {
198
fixed_fps = p_count;
199
}
200
201
int CPUParticles3D::get_fixed_fps() const {
202
return fixed_fps;
203
}
204
205
void CPUParticles3D::set_fractional_delta(bool p_enable) {
206
fractional_delta = p_enable;
207
}
208
209
bool CPUParticles3D::get_fractional_delta() const {
210
return fractional_delta;
211
}
212
213
PackedStringArray CPUParticles3D::get_configuration_warnings() const {
214
PackedStringArray warnings = GeometryInstance3D::get_configuration_warnings();
215
216
bool mesh_found = false;
217
bool anim_material_found = false;
218
219
if (get_mesh().is_valid()) {
220
mesh_found = true;
221
for (int j = 0; j < get_mesh()->get_surface_count(); j++) {
222
anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != nullptr;
223
StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_mesh()->surface_get_material(j).ptr());
224
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
225
}
226
}
227
228
anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr;
229
StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr());
230
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
231
232
if (!mesh_found) {
233
warnings.push_back(RTR("Nothing is visible because no mesh has been assigned."));
234
}
235
236
if (!anim_material_found && (get_param_max(PARAM_ANIM_SPEED) != 0.0 || get_param_max(PARAM_ANIM_OFFSET) != 0.0 || get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) {
237
warnings.push_back(RTR("CPUParticles3D animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."));
238
}
239
240
return warnings;
241
}
242
243
void CPUParticles3D::restart(bool p_keep_seed) {
244
time = 0;
245
frame_remainder = 0;
246
cycle = 0;
247
emitting = false;
248
249
{
250
int pc = particles.size();
251
Particle *w = particles.ptrw();
252
253
for (int i = 0; i < pc; i++) {
254
w[i].active = false;
255
}
256
}
257
if (!p_keep_seed && !use_fixed_seed) {
258
seed = Math::rand();
259
}
260
261
emitting = true;
262
_set_emitting();
263
}
264
265
void CPUParticles3D::set_direction(Vector3 p_direction) {
266
direction = p_direction;
267
}
268
269
Vector3 CPUParticles3D::get_direction() const {
270
return direction;
271
}
272
273
void CPUParticles3D::set_spread(real_t p_spread) {
274
spread = p_spread;
275
}
276
277
real_t CPUParticles3D::get_spread() const {
278
return spread;
279
}
280
281
void CPUParticles3D::set_flatness(real_t p_flatness) {
282
flatness = p_flatness;
283
}
284
285
real_t CPUParticles3D::get_flatness() const {
286
return flatness;
287
}
288
289
void CPUParticles3D::set_param_min(Parameter p_param, real_t p_value) {
290
ERR_FAIL_INDEX(p_param, PARAM_MAX);
291
292
parameters_min[p_param] = p_value;
293
if (parameters_min[p_param] > parameters_max[p_param]) {
294
set_param_max(p_param, p_value);
295
}
296
297
update_configuration_warnings();
298
}
299
300
real_t CPUParticles3D::get_param_min(Parameter p_param) const {
301
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
302
303
return parameters_min[p_param];
304
}
305
306
void CPUParticles3D::set_param_max(Parameter p_param, real_t p_value) {
307
ERR_FAIL_INDEX(p_param, PARAM_MAX);
308
309
parameters_max[p_param] = p_value;
310
if (parameters_min[p_param] > parameters_max[p_param]) {
311
set_param_min(p_param, p_value);
312
}
313
314
update_configuration_warnings();
315
}
316
317
real_t CPUParticles3D::get_param_max(Parameter p_param) const {
318
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
319
320
return parameters_max[p_param];
321
}
322
323
static void _adjust_curve_range(const Ref<Curve> &p_curve, real_t p_min, real_t p_max) {
324
Ref<Curve> curve = p_curve;
325
if (curve.is_null()) {
326
return;
327
}
328
329
curve->ensure_default_setup(p_min, p_max);
330
}
331
332
void CPUParticles3D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) {
333
ERR_FAIL_INDEX(p_param, PARAM_MAX);
334
335
curve_parameters[p_param] = p_curve;
336
337
switch (p_param) {
338
case PARAM_INITIAL_LINEAR_VELOCITY: {
339
//do none for this one
340
} break;
341
case PARAM_ANGULAR_VELOCITY: {
342
_adjust_curve_range(p_curve, -360, 360);
343
} break;
344
case PARAM_ORBIT_VELOCITY: {
345
_adjust_curve_range(p_curve, -500, 500);
346
} break;
347
case PARAM_LINEAR_ACCEL: {
348
_adjust_curve_range(p_curve, -200, 200);
349
} break;
350
case PARAM_RADIAL_ACCEL: {
351
_adjust_curve_range(p_curve, -200, 200);
352
} break;
353
case PARAM_TANGENTIAL_ACCEL: {
354
_adjust_curve_range(p_curve, -200, 200);
355
} break;
356
case PARAM_DAMPING: {
357
_adjust_curve_range(p_curve, 0, 100);
358
} break;
359
case PARAM_ANGLE: {
360
_adjust_curve_range(p_curve, -360, 360);
361
} break;
362
case PARAM_SCALE: {
363
} break;
364
case PARAM_HUE_VARIATION: {
365
_adjust_curve_range(p_curve, -1, 1);
366
} break;
367
case PARAM_ANIM_SPEED: {
368
_adjust_curve_range(p_curve, 0, 200);
369
} break;
370
case PARAM_ANIM_OFFSET: {
371
} break;
372
default: {
373
}
374
}
375
376
update_configuration_warnings();
377
}
378
379
Ref<Curve> CPUParticles3D::get_param_curve(Parameter p_param) const {
380
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>());
381
382
return curve_parameters[p_param];
383
}
384
385
void CPUParticles3D::set_color(const Color &p_color) {
386
color = p_color;
387
}
388
389
Color CPUParticles3D::get_color() const {
390
return color;
391
}
392
393
void CPUParticles3D::set_color_ramp(const Ref<Gradient> &p_ramp) {
394
color_ramp = p_ramp;
395
}
396
397
Ref<Gradient> CPUParticles3D::get_color_ramp() const {
398
return color_ramp;
399
}
400
401
void CPUParticles3D::set_color_initial_ramp(const Ref<Gradient> &p_ramp) {
402
color_initial_ramp = p_ramp;
403
}
404
405
Ref<Gradient> CPUParticles3D::get_color_initial_ramp() const {
406
return color_initial_ramp;
407
}
408
409
void CPUParticles3D::set_particle_flag(ParticleFlags p_particle_flag, bool p_enable) {
410
ERR_FAIL_INDEX(p_particle_flag, PARTICLE_FLAG_MAX);
411
particle_flags[p_particle_flag] = p_enable;
412
if (p_particle_flag == PARTICLE_FLAG_DISABLE_Z) {
413
notify_property_list_changed();
414
}
415
}
416
417
bool CPUParticles3D::get_particle_flag(ParticleFlags p_particle_flag) const {
418
ERR_FAIL_INDEX_V(p_particle_flag, PARTICLE_FLAG_MAX, false);
419
return particle_flags[p_particle_flag];
420
}
421
422
void CPUParticles3D::set_emission_shape(EmissionShape p_shape) {
423
ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
424
emission_shape = p_shape;
425
update_gizmos();
426
}
427
428
void CPUParticles3D::set_emission_sphere_radius(real_t p_radius) {
429
emission_sphere_radius = p_radius;
430
update_gizmos();
431
}
432
433
void CPUParticles3D::set_emission_box_extents(Vector3 p_extents) {
434
emission_box_extents = p_extents;
435
update_gizmos();
436
}
437
438
void CPUParticles3D::set_emission_points(const Vector<Vector3> &p_points) {
439
emission_points = p_points;
440
}
441
442
void CPUParticles3D::set_emission_normals(const Vector<Vector3> &p_normals) {
443
emission_normals = p_normals;
444
}
445
446
void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) {
447
emission_colors = p_colors;
448
}
449
450
void CPUParticles3D::set_emission_ring_axis(Vector3 p_axis) {
451
emission_ring_axis = p_axis;
452
update_gizmos();
453
}
454
455
void CPUParticles3D::set_emission_ring_height(real_t p_height) {
456
emission_ring_height = p_height;
457
update_gizmos();
458
}
459
460
void CPUParticles3D::set_emission_ring_radius(real_t p_radius) {
461
emission_ring_radius = p_radius;
462
update_gizmos();
463
}
464
465
void CPUParticles3D::set_emission_ring_inner_radius(real_t p_radius) {
466
emission_ring_inner_radius = p_radius;
467
update_gizmos();
468
}
469
470
void CPUParticles3D::set_emission_ring_cone_angle(real_t p_angle) {
471
emission_ring_cone_angle = p_angle;
472
update_gizmos();
473
}
474
475
void CPUParticles3D::set_scale_curve_x(Ref<Curve> p_scale_curve) {
476
scale_curve_x = p_scale_curve;
477
}
478
479
void CPUParticles3D::set_scale_curve_y(Ref<Curve> p_scale_curve) {
480
scale_curve_y = p_scale_curve;
481
}
482
483
void CPUParticles3D::set_scale_curve_z(Ref<Curve> p_scale_curve) {
484
scale_curve_z = p_scale_curve;
485
}
486
487
void CPUParticles3D::set_split_scale(bool p_split_scale) {
488
split_scale = p_split_scale;
489
notify_property_list_changed();
490
}
491
492
real_t CPUParticles3D::get_emission_sphere_radius() const {
493
return emission_sphere_radius;
494
}
495
496
Vector3 CPUParticles3D::get_emission_box_extents() const {
497
return emission_box_extents;
498
}
499
500
Vector<Vector3> CPUParticles3D::get_emission_points() const {
501
return emission_points;
502
}
503
504
Vector<Vector3> CPUParticles3D::get_emission_normals() const {
505
return emission_normals;
506
}
507
508
Vector<Color> CPUParticles3D::get_emission_colors() const {
509
return emission_colors;
510
}
511
512
Vector3 CPUParticles3D::get_emission_ring_axis() const {
513
return emission_ring_axis;
514
}
515
516
real_t CPUParticles3D::get_emission_ring_height() const {
517
return emission_ring_height;
518
}
519
520
real_t CPUParticles3D::get_emission_ring_radius() const {
521
return emission_ring_radius;
522
}
523
524
real_t CPUParticles3D::get_emission_ring_inner_radius() const {
525
return emission_ring_inner_radius;
526
}
527
528
real_t CPUParticles3D::get_emission_ring_cone_angle() const {
529
return emission_ring_cone_angle;
530
}
531
532
CPUParticles3D::EmissionShape CPUParticles3D::get_emission_shape() const {
533
return emission_shape;
534
}
535
536
void CPUParticles3D::set_gravity(const Vector3 &p_gravity) {
537
gravity = p_gravity;
538
}
539
540
Vector3 CPUParticles3D::get_gravity() const {
541
return gravity;
542
}
543
544
Ref<Curve> CPUParticles3D::get_scale_curve_x() const {
545
return scale_curve_x;
546
}
547
548
Ref<Curve> CPUParticles3D::get_scale_curve_y() const {
549
return scale_curve_y;
550
}
551
552
Ref<Curve> CPUParticles3D::get_scale_curve_z() const {
553
return scale_curve_z;
554
}
555
556
bool CPUParticles3D::get_split_scale() {
557
return split_scale;
558
}
559
560
AABB CPUParticles3D::capture_aabb() const {
561
RS::get_singleton()->multimesh_set_custom_aabb(multimesh, AABB());
562
return RS::get_singleton()->multimesh_get_aabb(multimesh);
563
}
564
565
void CPUParticles3D::set_use_fixed_seed(bool p_use_fixed_seed) {
566
if (p_use_fixed_seed == use_fixed_seed) {
567
return;
568
}
569
use_fixed_seed = p_use_fixed_seed;
570
notify_property_list_changed();
571
}
572
573
bool CPUParticles3D::get_use_fixed_seed() const {
574
return use_fixed_seed;
575
}
576
577
void CPUParticles3D::set_seed(uint32_t p_seed) {
578
seed = p_seed;
579
}
580
581
uint32_t CPUParticles3D::get_seed() const {
582
return seed;
583
}
584
585
void CPUParticles3D::request_particles_process(real_t p_requested_process_time) {
586
_requested_process_time = p_requested_process_time;
587
}
588
589
void CPUParticles3D::_validate_property(PropertyInfo &p_property) const {
590
if (Engine::get_singleton()->is_editor_hint() && p_property.name == "emitting") {
591
p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE;
592
}
593
594
if (p_property.name == "emission_sphere_radius" && (emission_shape != EMISSION_SHAPE_SPHERE && emission_shape != EMISSION_SHAPE_SPHERE_SURFACE)) {
595
p_property.usage = PROPERTY_USAGE_NONE;
596
}
597
598
if (p_property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) {
599
p_property.usage = PROPERTY_USAGE_NONE;
600
}
601
602
if ((p_property.name == "emission_point_texture" || p_property.name == "emission_color_texture" || p_property.name == "emission_points") && (emission_shape != EMISSION_SHAPE_POINTS && (emission_shape != EMISSION_SHAPE_DIRECTED_POINTS))) {
603
p_property.usage = PROPERTY_USAGE_NONE;
604
}
605
606
if (p_property.name == "emission_normals" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
607
p_property.usage = PROPERTY_USAGE_NONE;
608
}
609
610
if (p_property.name.begins_with("emission_ring_") && emission_shape != EMISSION_SHAPE_RING) {
611
p_property.usage = PROPERTY_USAGE_NONE;
612
}
613
614
if (p_property.name.begins_with("orbit_") && !particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
615
p_property.usage = PROPERTY_USAGE_NONE;
616
}
617
618
if (p_property.name.begins_with("scale_curve_") && !split_scale) {
619
p_property.usage = PROPERTY_USAGE_NONE;
620
}
621
622
if (p_property.name == "seed" && !use_fixed_seed) {
623
p_property.usage = PROPERTY_USAGE_NONE;
624
}
625
}
626
627
static uint32_t idhash(uint32_t x) {
628
x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
629
x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
630
x = (x >> uint32_t(16)) ^ x;
631
return x;
632
}
633
634
static real_t rand_from_seed(uint32_t &seed) {
635
int k;
636
int s = int(seed);
637
if (s == 0) {
638
s = 305420679;
639
}
640
k = s / 127773;
641
s = 16807 * (s - k * 127773) - 2836 * k;
642
if (s < 0) {
643
s += 2147483647;
644
}
645
seed = uint32_t(s);
646
return (seed % uint32_t(65536)) / 65535.0;
647
}
648
649
void CPUParticles3D::_update_internal() {
650
if (particles.is_empty() || !is_visible_in_tree()) {
651
_set_redraw(false);
652
return;
653
}
654
655
double delta = get_process_delta_time();
656
if (!active && !emitting) {
657
set_process_internal(false);
658
_set_redraw(false);
659
660
//reset variables
661
time = 0;
662
frame_remainder = 0;
663
cycle = 0;
664
return;
665
}
666
_set_redraw(true);
667
668
bool processed = false;
669
670
double frame_time;
671
if (fixed_fps > 0) {
672
frame_time = 1.0 / fixed_fps;
673
} else {
674
frame_time = 1.0 / 30.0;
675
}
676
double todo = _requested_process_time;
677
_requested_process_time = 0.;
678
if (time == 0 && pre_process_time > 0.0) {
679
todo += pre_process_time;
680
}
681
real_t tmp_speed = speed_scale;
682
speed_scale = 1.0;
683
while (todo > 0) {
684
_particles_process(frame_time);
685
todo -= frame_time;
686
}
687
speed_scale = tmp_speed;
688
todo = 0.0;
689
690
if (fixed_fps > 0) {
691
double decr = frame_time;
692
693
double ldelta = delta;
694
if (ldelta > 0.1) { //avoid recursive stalls if fps goes below 10
695
ldelta = 0.1;
696
} else if (ldelta <= 0.0) { //unlikely but..
697
ldelta = 0.001;
698
}
699
todo = frame_remainder + ldelta;
700
701
while (todo >= frame_time) {
702
_particles_process(frame_time);
703
processed = true;
704
todo -= decr;
705
}
706
707
frame_remainder = todo;
708
709
} else {
710
_particles_process(delta);
711
processed = true;
712
}
713
714
if (processed) {
715
_update_particle_data_buffer();
716
}
717
}
718
719
void CPUParticles3D::_particles_process(double p_delta) {
720
p_delta *= speed_scale;
721
722
int pcount = particles.size();
723
Particle *w = particles.ptrw();
724
725
Particle *parray = w;
726
727
double prev_time = time;
728
time += p_delta;
729
if (time > lifetime) {
730
time = Math::fmod(time, lifetime);
731
cycle++;
732
if (one_shot && cycle > 0) {
733
set_emitting(false);
734
notify_property_list_changed();
735
}
736
}
737
738
Transform3D emission_xform;
739
Basis velocity_xform;
740
if (!local_coords) {
741
emission_xform = get_global_transform_interpolated();
742
velocity_xform = emission_xform.basis;
743
}
744
745
double system_phase = time / lifetime;
746
747
bool should_be_active = false;
748
for (int i = 0; i < pcount; i++) {
749
Particle &p = parray[i];
750
751
if (!emitting && !p.active) {
752
continue;
753
}
754
755
double local_delta = p_delta;
756
757
// The phase is a ratio between 0 (birth) and 1 (end of life) for each particle.
758
// While we use time in tests later on, for randomness we use the phase as done in the
759
// original shader code, and we later multiply by lifetime to get the time.
760
double restart_phase = double(i) / double(pcount);
761
762
if (randomness_ratio > 0.0) {
763
uint32_t _seed = cycle;
764
if (restart_phase >= system_phase) {
765
_seed -= uint32_t(1);
766
}
767
_seed *= uint32_t(pcount);
768
_seed += uint32_t(i);
769
double random = double(idhash(_seed) % uint32_t(65536)) / 65536.0;
770
restart_phase += randomness_ratio * random * 1.0 / double(pcount);
771
}
772
773
restart_phase *= (1.0 - explosiveness_ratio);
774
double restart_time = restart_phase * lifetime;
775
bool restart = false;
776
777
if (time > prev_time) {
778
// restart_time >= prev_time is used so particles emit in the first frame they are processed
779
780
if (restart_time >= prev_time && restart_time < time) {
781
restart = true;
782
if (fractional_delta) {
783
local_delta = time - restart_time;
784
}
785
}
786
787
} else if (local_delta > 0.0) {
788
if (restart_time >= prev_time) {
789
restart = true;
790
if (fractional_delta) {
791
local_delta = lifetime - restart_time + time;
792
}
793
794
} else if (restart_time < time) {
795
restart = true;
796
if (fractional_delta) {
797
local_delta = time - restart_time;
798
}
799
}
800
}
801
802
if (p.time * (1.0 - explosiveness_ratio) > p.lifetime) {
803
restart = true;
804
}
805
806
float tv = 0.0;
807
808
if (restart) {
809
if (!emitting) {
810
p.active = false;
811
continue;
812
}
813
p.active = true;
814
815
/*real_t tex_linear_velocity = 0;
816
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
817
tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->sample(0);
818
}*/
819
820
real_t tex_angle = 1.0;
821
if (curve_parameters[PARAM_ANGLE].is_valid()) {
822
tex_angle = curve_parameters[PARAM_ANGLE]->sample(tv);
823
}
824
825
real_t tex_anim_offset = 1.0;
826
if (curve_parameters[PARAM_ANGLE].is_valid()) {
827
tex_anim_offset = curve_parameters[PARAM_ANGLE]->sample(tv);
828
}
829
830
p.seed = seed + uint32_t(1) + i + cycle;
831
rng->set_seed(p.seed);
832
p.angle_rand = rng->randf();
833
p.scale_rand = rng->randf();
834
p.hue_rot_rand = rng->randf();
835
p.anim_offset_rand = rng->randf();
836
837
if (color_initial_ramp.is_valid()) {
838
p.start_color_rand = color_initial_ramp->get_color_at_offset(rng->randf());
839
} else {
840
p.start_color_rand = Color(1, 1, 1, 1);
841
}
842
843
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
844
real_t angle1_rad = Math::atan2(direction.y, direction.x) + Math::deg_to_rad((rng->randf() * 2.0 - 1.0) * spread);
845
Vector3 rot = Vector3(Math::cos(angle1_rad), Math::sin(angle1_rad), 0.0);
846
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rng->randf());
847
} else {
848
//initiate velocity spread in 3D
849
real_t angle1_rad = Math::deg_to_rad((rng->randf() * (real_t)2.0 - (real_t)1.0) * spread);
850
real_t angle2_rad = Math::deg_to_rad((rng->randf() * (real_t)2.0 - (real_t)1.0) * ((real_t)1.0 - flatness) * spread);
851
852
Vector3 direction_xz = Vector3(Math::sin(angle1_rad), 0, Math::cos(angle1_rad));
853
Vector3 direction_yz = Vector3(0, Math::sin(angle2_rad), Math::cos(angle2_rad));
854
Vector3 spread_direction = Vector3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);
855
Vector3 direction_nrm = direction;
856
if (direction_nrm.length_squared() > 0) {
857
direction_nrm.normalize();
858
} else {
859
direction_nrm = Vector3(0, 0, 1);
860
}
861
// rotate spread to direction
862
Vector3 binormal = Vector3(0.0, 1.0, 0.0).cross(direction_nrm);
863
if (binormal.length_squared() < 0.00000001) {
864
// direction is parallel to Y. Choose Z as the binormal.
865
binormal = Vector3(0.0, 0.0, 1.0);
866
}
867
binormal.normalize();
868
Vector3 normal = binormal.cross(direction_nrm);
869
spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;
870
p.velocity = spread_direction * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rng->randf());
871
}
872
873
real_t base_angle = tex_angle * Math::lerp(parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand);
874
p.custom[0] = Math::deg_to_rad(base_angle); //angle
875
p.custom[1] = 0.0; //phase
876
p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand); //animation offset (0-1)
877
p.custom[3] = (1.0 - rng->randf() * lifetime_randomness);
878
p.transform = Transform3D();
879
p.time = 0;
880
p.lifetime = lifetime * p.custom[3];
881
p.base_color = Color(1, 1, 1, 1);
882
883
switch (emission_shape) {
884
case EMISSION_SHAPE_POINT: {
885
//do none
886
} break;
887
case EMISSION_SHAPE_SPHERE: {
888
real_t s = 2.0 * rng->randf() - 1.0;
889
real_t t = Math::TAU * rng->randf();
890
real_t x = rng->randf();
891
real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
892
p.transform.origin = Vector3(0, 0, 0).lerp(Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s), x);
893
} break;
894
case EMISSION_SHAPE_SPHERE_SURFACE: {
895
real_t s = 2.0 * rng->randf() - 1.0;
896
real_t t = Math::TAU * rng->randf();
897
real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
898
p.transform.origin = Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s);
899
} break;
900
case EMISSION_SHAPE_BOX: {
901
p.transform.origin = Vector3(rng->randf() * 2.0 - 1.0, rng->randf() * 2.0 - 1.0, rng->randf() * 2.0 - 1.0) * emission_box_extents;
902
} break;
903
case EMISSION_SHAPE_POINTS:
904
case EMISSION_SHAPE_DIRECTED_POINTS: {
905
int pc = emission_points.size();
906
if (pc == 0) {
907
break;
908
}
909
910
int random_idx = Math::rand() % pc;
911
912
p.transform.origin = emission_points.get(random_idx);
913
914
if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS && emission_normals.size() == pc) {
915
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
916
Vector3 normal = emission_normals.get(random_idx);
917
Vector2 normal_2d(normal.x, normal.y);
918
Transform2D m2;
919
m2.columns[0] = normal_2d;
920
m2.columns[1] = normal_2d.orthogonal();
921
Vector2 velocity_2d(p.velocity.x, p.velocity.y);
922
velocity_2d = m2.basis_xform(velocity_2d);
923
p.velocity.x = velocity_2d.x;
924
p.velocity.y = velocity_2d.y;
925
} else {
926
Vector3 normal = emission_normals.get(random_idx);
927
Vector3 v0 = Math::abs(normal.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(0, 1.0, 0.0);
928
Vector3 tangent = v0.cross(normal).normalized();
929
Vector3 bitangent = tangent.cross(normal).normalized();
930
Basis m3;
931
m3.set_column(0, tangent);
932
m3.set_column(1, bitangent);
933
m3.set_column(2, normal);
934
p.velocity = m3.xform(p.velocity);
935
}
936
}
937
938
if (emission_colors.size() == pc) {
939
p.base_color = emission_colors.get(random_idx);
940
}
941
} break;
942
case EMISSION_SHAPE_RING: {
943
real_t radius_clamped = MAX(0.001, emission_ring_radius);
944
real_t top_radius = MAX(radius_clamped - Math::tan(Math::deg_to_rad(90.0 - emission_ring_cone_angle)) * emission_ring_height, 0.0);
945
real_t y_pos = rng->randf();
946
real_t skew = MAX(MIN(radius_clamped, top_radius) / MAX(radius_clamped, top_radius), 0.5);
947
y_pos = radius_clamped < top_radius ? Math::pow(y_pos, skew) : 1.0 - Math::pow(y_pos, skew);
948
real_t ring_random_angle = rng->randf() * Math::TAU;
949
real_t ring_random_radius = Math::sqrt(rng->randf() * (radius_clamped * radius_clamped - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);
950
ring_random_radius = Math::lerp(ring_random_radius, ring_random_radius * (top_radius / radius_clamped), y_pos);
951
Vector3 axis = emission_ring_axis == Vector3(0.0, 0.0, 0.0) ? Vector3(0.0, 0.0, 1.0) : emission_ring_axis.normalized();
952
Vector3 ortho_axis;
953
if (axis.abs() == Vector3(1.0, 0.0, 0.0)) {
954
ortho_axis = Vector3(0.0, 1.0, 0.0).cross(axis);
955
} else {
956
ortho_axis = Vector3(1.0, 0.0, 0.0).cross(axis);
957
}
958
ortho_axis = ortho_axis.normalized();
959
ortho_axis.rotate(axis, ring_random_angle);
960
ortho_axis = ortho_axis.normalized();
961
p.transform.origin = ortho_axis * ring_random_radius + (y_pos * emission_ring_height - emission_ring_height / 2.0) * axis;
962
} break;
963
case EMISSION_SHAPE_MAX: { // Max value for validity check.
964
break;
965
}
966
}
967
968
if (!local_coords) {
969
p.velocity = velocity_xform.xform(p.velocity);
970
p.transform = emission_xform * p.transform;
971
}
972
973
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
974
p.velocity.z = 0.0;
975
p.transform.origin.z = 0.0;
976
}
977
978
} else if (!p.active) {
979
continue;
980
} else if (p.time > p.lifetime) {
981
p.active = false;
982
tv = 1.0;
983
} else {
984
uint32_t alt_seed = p.seed;
985
986
p.time += local_delta;
987
p.custom[1] = p.time / lifetime;
988
tv = p.time / p.lifetime;
989
990
real_t tex_linear_velocity = 1.0;
991
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
992
tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->sample(tv);
993
}
994
995
real_t tex_orbit_velocity = 1.0;
996
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
997
if (curve_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
998
tex_orbit_velocity = curve_parameters[PARAM_ORBIT_VELOCITY]->sample(tv);
999
}
1000
}
1001
1002
real_t tex_angular_velocity = 1.0;
1003
if (curve_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
1004
tex_angular_velocity = curve_parameters[PARAM_ANGULAR_VELOCITY]->sample(tv);
1005
}
1006
1007
real_t tex_linear_accel = 1.0;
1008
if (curve_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
1009
tex_linear_accel = curve_parameters[PARAM_LINEAR_ACCEL]->sample(tv);
1010
}
1011
1012
real_t tex_tangential_accel = 1.0;
1013
if (curve_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
1014
tex_tangential_accel = curve_parameters[PARAM_TANGENTIAL_ACCEL]->sample(tv);
1015
}
1016
1017
real_t tex_radial_accel = 1.0;
1018
if (curve_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
1019
tex_radial_accel = curve_parameters[PARAM_RADIAL_ACCEL]->sample(tv);
1020
}
1021
1022
real_t tex_damping = 1.0;
1023
if (curve_parameters[PARAM_DAMPING].is_valid()) {
1024
tex_damping = curve_parameters[PARAM_DAMPING]->sample(tv);
1025
}
1026
1027
real_t tex_angle = 1.0;
1028
if (curve_parameters[PARAM_ANGLE].is_valid()) {
1029
tex_angle = curve_parameters[PARAM_ANGLE]->sample(tv);
1030
}
1031
real_t tex_anim_speed = 1.0;
1032
if (curve_parameters[PARAM_ANIM_SPEED].is_valid()) {
1033
tex_anim_speed = curve_parameters[PARAM_ANIM_SPEED]->sample(tv);
1034
}
1035
1036
real_t tex_anim_offset = 1.0;
1037
if (curve_parameters[PARAM_ANIM_OFFSET].is_valid()) {
1038
tex_anim_offset = curve_parameters[PARAM_ANIM_OFFSET]->sample(tv);
1039
}
1040
1041
Vector3 force = gravity;
1042
Vector3 position = p.transform.origin;
1043
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
1044
position.z = 0.0;
1045
}
1046
//apply linear acceleration
1047
force += p.velocity.length() > 0.0 ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(alt_seed)) : Vector3();
1048
//apply radial acceleration
1049
Vector3 org = emission_xform.origin;
1050
Vector3 diff = position - org;
1051
force += diff.length() > 0.0 ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(alt_seed)) : Vector3();
1052
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
1053
Vector2 yx = Vector2(diff.y, diff.x);
1054
Vector2 yx2 = (yx * Vector2(-1.0, 1.0)).normalized();
1055
force += yx.length() > 0.0 ? Vector3(yx2.x, yx2.y, 0.0) * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
1056
1057
} else {
1058
Vector3 crossDiff = diff.normalized().cross(gravity.normalized());
1059
force += crossDiff.length() > 0.0 ? crossDiff.normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
1060
}
1061
//apply attractor forces
1062
p.velocity += force * local_delta;
1063
//orbit velocity
1064
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
1065
real_t orbit_amount = tex_orbit_velocity * Math::lerp(parameters_min[PARAM_ORBIT_VELOCITY], parameters_max[PARAM_ORBIT_VELOCITY], rand_from_seed(alt_seed));
1066
if (orbit_amount != 0.0) {
1067
real_t ang = orbit_amount * local_delta * Math::TAU;
1068
// Not sure why the ParticleProcessMaterial code uses a clockwise rotation matrix,
1069
// but we use -ang here to reproduce its behavior.
1070
Transform2D rot = Transform2D(-ang, Vector2());
1071
Vector2 rotv = rot.basis_xform(Vector2(diff.x, diff.y));
1072
p.transform.origin -= Vector3(diff.x, diff.y, 0);
1073
p.transform.origin += Vector3(rotv.x, rotv.y, 0);
1074
}
1075
}
1076
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
1077
p.velocity = p.velocity.normalized() * tex_linear_velocity;
1078
}
1079
1080
if (parameters_max[PARAM_DAMPING] + tex_damping > 0.0) {
1081
real_t v = p.velocity.length();
1082
real_t damp = tex_damping * Math::lerp(parameters_min[PARAM_DAMPING], parameters_max[PARAM_DAMPING], rand_from_seed(alt_seed));
1083
v -= damp * local_delta;
1084
if (v < 0.0) {
1085
p.velocity = Vector3();
1086
} else {
1087
p.velocity = p.velocity.normalized() * v;
1088
}
1089
}
1090
real_t base_angle = (tex_angle)*Math::lerp(parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand);
1091
base_angle += p.custom[1] * lifetime * tex_angular_velocity * Math::lerp(parameters_min[PARAM_ANGULAR_VELOCITY], parameters_max[PARAM_ANGULAR_VELOCITY], rand_from_seed(alt_seed));
1092
p.custom[0] = Math::deg_to_rad(base_angle); //angle
1093
p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand) + tv * tex_anim_speed * Math::lerp(parameters_min[PARAM_ANIM_SPEED], parameters_max[PARAM_ANIM_SPEED], rand_from_seed(alt_seed)); //angle
1094
}
1095
//apply color
1096
//apply hue rotation
1097
1098
Vector3 tex_scale = Vector3(1.0, 1.0, 1.0);
1099
if (split_scale) {
1100
if (scale_curve_x.is_valid()) {
1101
tex_scale.x = scale_curve_x->sample(tv);
1102
} else {
1103
tex_scale.x = 1.0;
1104
}
1105
if (scale_curve_y.is_valid()) {
1106
tex_scale.y = scale_curve_y->sample(tv);
1107
} else {
1108
tex_scale.y = 1.0;
1109
}
1110
if (scale_curve_z.is_valid()) {
1111
tex_scale.z = scale_curve_z->sample(tv);
1112
} else {
1113
tex_scale.z = 1.0;
1114
}
1115
} else {
1116
if (curve_parameters[PARAM_SCALE].is_valid()) {
1117
float tmp_scale = curve_parameters[PARAM_SCALE]->sample(tv);
1118
tex_scale.x = tmp_scale;
1119
tex_scale.y = tmp_scale;
1120
tex_scale.z = tmp_scale;
1121
}
1122
}
1123
1124
real_t tex_hue_variation = 0.0;
1125
if (curve_parameters[PARAM_HUE_VARIATION].is_valid()) {
1126
tex_hue_variation = curve_parameters[PARAM_HUE_VARIATION]->sample(tv);
1127
}
1128
1129
real_t hue_rot_angle = (tex_hue_variation)*Math::TAU * Math::lerp(parameters_min[PARAM_HUE_VARIATION], parameters_max[PARAM_HUE_VARIATION], p.hue_rot_rand);
1130
real_t hue_rot_c = Math::cos(hue_rot_angle);
1131
real_t hue_rot_s = Math::sin(hue_rot_angle);
1132
1133
Basis hue_rot_mat;
1134
{
1135
Basis mat1(0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587, 0.114);
1136
Basis mat2(0.701, -0.587, -0.114, -0.299, 0.413, -0.114, -0.300, -0.588, 0.886);
1137
Basis mat3(0.168, 0.330, -0.497, -0.328, 0.035, 0.292, 1.250, -1.050, -0.203);
1138
1139
for (int j = 0; j < 3; j++) {
1140
hue_rot_mat[j] = mat1[j] + mat2[j] * hue_rot_c + mat3[j] * hue_rot_s;
1141
}
1142
}
1143
1144
if (color_ramp.is_valid()) {
1145
p.color = color_ramp->get_color_at_offset(tv) * color;
1146
} else {
1147
p.color = color;
1148
}
1149
1150
Vector3 color_rgb = hue_rot_mat.xform_inv(Vector3(p.color.r, p.color.g, p.color.b));
1151
p.color.r = color_rgb.x;
1152
p.color.g = color_rgb.y;
1153
p.color.b = color_rgb.z;
1154
1155
p.color *= p.base_color * p.start_color_rand;
1156
1157
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
1158
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
1159
if (p.velocity.length() > 0.0) {
1160
p.transform.basis.set_column(1, p.velocity.normalized());
1161
} else {
1162
p.transform.basis.set_column(1, p.transform.basis.get_column(1));
1163
}
1164
p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
1165
p.transform.basis.set_column(2, Vector3(0, 0, 1));
1166
1167
} else {
1168
p.transform.basis.set_column(0, Vector3(Math::cos(p.custom[0]), -Math::sin(p.custom[0]), 0.0));
1169
p.transform.basis.set_column(1, Vector3(Math::sin(p.custom[0]), Math::cos(p.custom[0]), 0.0));
1170
p.transform.basis.set_column(2, Vector3(0, 0, 1));
1171
}
1172
1173
} else {
1174
//orient particle Y towards velocity
1175
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
1176
if (p.velocity.length() > 0.0) {
1177
p.transform.basis.set_column(1, p.velocity.normalized());
1178
} else {
1179
p.transform.basis.set_column(1, p.transform.basis.get_column(1).normalized());
1180
}
1181
if (p.transform.basis.get_column(1) == p.transform.basis.get_column(0)) {
1182
p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
1183
p.transform.basis.set_column(2, p.transform.basis.get_column(0).cross(p.transform.basis.get_column(1)).normalized());
1184
} else {
1185
p.transform.basis.set_column(2, p.transform.basis.get_column(0).cross(p.transform.basis.get_column(1)).normalized());
1186
p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
1187
}
1188
} else {
1189
p.transform.basis.orthonormalize();
1190
}
1191
1192
//turn particle by rotation in Y
1193
if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
1194
Basis rot_y(Vector3(0, 1, 0), p.custom[0]);
1195
p.transform.basis = rot_y;
1196
}
1197
}
1198
1199
p.transform.basis = p.transform.basis.orthonormalized();
1200
//scale by scale
1201
1202
Vector3 base_scale = tex_scale * Math::lerp(parameters_min[PARAM_SCALE], parameters_max[PARAM_SCALE], p.scale_rand);
1203
if (base_scale.x < CMP_EPSILON) {
1204
base_scale.x = CMP_EPSILON;
1205
}
1206
if (base_scale.y < CMP_EPSILON) {
1207
base_scale.y = CMP_EPSILON;
1208
}
1209
if (base_scale.z < CMP_EPSILON) {
1210
base_scale.z = CMP_EPSILON;
1211
}
1212
1213
p.transform.basis.scale(base_scale);
1214
1215
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
1216
p.velocity.z = 0.0;
1217
p.transform.origin.z = 0.0;
1218
}
1219
1220
p.transform.origin += p.velocity * local_delta;
1221
1222
should_be_active = true;
1223
}
1224
if (!Math::is_equal_approx(time, 0.0) && active && !should_be_active) {
1225
active = false;
1226
emit_signal(SceneStringName(finished));
1227
}
1228
}
1229
1230
void CPUParticles3D::_update_particle_data_buffer() {
1231
MutexLock lock(update_mutex);
1232
1233
int pc = particles.size();
1234
1235
int *ow;
1236
int *order = nullptr;
1237
1238
float *w = particle_data.ptrw();
1239
const Particle *r = particles.ptr();
1240
float *ptr = w;
1241
1242
if (draw_order != DRAW_ORDER_INDEX) {
1243
ow = particle_order.ptrw();
1244
order = ow;
1245
1246
for (int i = 0; i < pc; i++) {
1247
order[i] = i;
1248
}
1249
if (draw_order == DRAW_ORDER_LIFETIME) {
1250
SortArray<int, SortLifetime> sorter;
1251
sorter.compare.particles = r;
1252
sorter.sort(order, pc);
1253
} else if (draw_order == DRAW_ORDER_VIEW_DEPTH) {
1254
ERR_FAIL_NULL(get_viewport());
1255
Camera3D *c = get_viewport()->get_camera_3d();
1256
if (c) {
1257
Vector3 dir = c->get_global_transform().basis.get_column(2); //far away to close
1258
1259
if (local_coords) {
1260
// will look different from Particles in editor as this is based on the camera in the scenetree
1261
// and not the editor camera
1262
dir = inv_emission_transform.xform(dir).normalized();
1263
} else {
1264
dir = dir.normalized();
1265
}
1266
1267
SortArray<int, SortAxis> sorter;
1268
sorter.compare.particles = r;
1269
sorter.compare.axis = dir;
1270
sorter.sort(order, pc);
1271
}
1272
}
1273
}
1274
1275
for (int i = 0; i < pc; i++) {
1276
int idx = order ? order[i] : i;
1277
1278
Transform3D t = r[idx].transform;
1279
1280
if (!local_coords) {
1281
t = inv_emission_transform * t;
1282
}
1283
1284
if (r[idx].active) {
1285
ptr[0] = t.basis.rows[0][0];
1286
ptr[1] = t.basis.rows[0][1];
1287
ptr[2] = t.basis.rows[0][2];
1288
ptr[3] = t.origin.x;
1289
ptr[4] = t.basis.rows[1][0];
1290
ptr[5] = t.basis.rows[1][1];
1291
ptr[6] = t.basis.rows[1][2];
1292
ptr[7] = t.origin.y;
1293
ptr[8] = t.basis.rows[2][0];
1294
ptr[9] = t.basis.rows[2][1];
1295
ptr[10] = t.basis.rows[2][2];
1296
ptr[11] = t.origin.z;
1297
} else {
1298
memset(ptr, 0, sizeof(float) * 12);
1299
}
1300
1301
Color c = r[idx].color;
1302
1303
ptr[12] = c.r;
1304
ptr[13] = c.g;
1305
ptr[14] = c.b;
1306
ptr[15] = c.a;
1307
1308
ptr[16] = r[idx].custom[0];
1309
ptr[17] = r[idx].custom[1];
1310
ptr[18] = r[idx].custom[2];
1311
ptr[19] = r[idx].custom[3];
1312
1313
ptr += 20;
1314
}
1315
1316
can_update.set();
1317
}
1318
1319
void CPUParticles3D::_set_redraw(bool p_redraw) {
1320
if (redraw == p_redraw) {
1321
return;
1322
}
1323
redraw = p_redraw;
1324
1325
{
1326
MutexLock lock(update_mutex);
1327
1328
if (redraw) {
1329
RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread));
1330
RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true);
1331
RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
1332
} else {
1333
if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread))) {
1334
RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread));
1335
}
1336
RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false);
1337
RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
1338
}
1339
}
1340
}
1341
1342
void CPUParticles3D::_update_render_thread() {
1343
MutexLock lock(update_mutex);
1344
1345
if (can_update.is_set()) {
1346
RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data);
1347
can_update.clear(); //wait for next time
1348
}
1349
}
1350
1351
void CPUParticles3D::_notification(int p_what) {
1352
switch (p_what) {
1353
case NOTIFICATION_ENTER_TREE: {
1354
set_process_internal(emitting);
1355
1356
// first update before rendering to avoid one frame delay after emitting starts
1357
if (emitting && (time == 0)) {
1358
_update_internal();
1359
}
1360
} break;
1361
1362
case NOTIFICATION_EXIT_TREE: {
1363
_set_redraw(false);
1364
} break;
1365
1366
case NOTIFICATION_VISIBILITY_CHANGED: {
1367
// first update before rendering to avoid one frame delay after emitting starts
1368
if (emitting && (time == 0)) {
1369
_update_internal();
1370
}
1371
} break;
1372
1373
case NOTIFICATION_INTERNAL_PROCESS: {
1374
_update_internal();
1375
} break;
1376
1377
case NOTIFICATION_TRANSFORM_CHANGED: {
1378
inv_emission_transform = get_global_transform().affine_inverse();
1379
1380
if (!local_coords) {
1381
int pc = particles.size();
1382
1383
float *w = particle_data.ptrw();
1384
const Particle *r = particles.ptr();
1385
float *ptr = w;
1386
1387
for (int i = 0; i < pc; i++) {
1388
Transform3D t = inv_emission_transform * r[i].transform;
1389
1390
if (r[i].active) {
1391
ptr[0] = t.basis.rows[0][0];
1392
ptr[1] = t.basis.rows[0][1];
1393
ptr[2] = t.basis.rows[0][2];
1394
ptr[3] = t.origin.x;
1395
ptr[4] = t.basis.rows[1][0];
1396
ptr[5] = t.basis.rows[1][1];
1397
ptr[6] = t.basis.rows[1][2];
1398
ptr[7] = t.origin.y;
1399
ptr[8] = t.basis.rows[2][0];
1400
ptr[9] = t.basis.rows[2][1];
1401
ptr[10] = t.basis.rows[2][2];
1402
ptr[11] = t.origin.z;
1403
} else {
1404
memset(ptr, 0, sizeof(float) * 12);
1405
}
1406
1407
ptr += 20;
1408
}
1409
1410
can_update.set();
1411
}
1412
} break;
1413
}
1414
}
1415
1416
void CPUParticles3D::convert_from_particles(Node *p_particles) {
1417
GPUParticles3D *gpu_particles = Object::cast_to<GPUParticles3D>(p_particles);
1418
ERR_FAIL_NULL_MSG(gpu_particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D.");
1419
1420
set_emitting(gpu_particles->is_emitting());
1421
set_amount(gpu_particles->get_amount());
1422
set_lifetime(gpu_particles->get_lifetime());
1423
set_one_shot(gpu_particles->get_one_shot());
1424
set_pre_process_time(gpu_particles->get_pre_process_time());
1425
set_explosiveness_ratio(gpu_particles->get_explosiveness_ratio());
1426
set_randomness_ratio(gpu_particles->get_randomness_ratio());
1427
set_visibility_aabb(gpu_particles->get_visibility_aabb());
1428
set_use_local_coordinates(gpu_particles->get_use_local_coordinates());
1429
set_fixed_fps(gpu_particles->get_fixed_fps());
1430
set_fractional_delta(gpu_particles->get_fractional_delta());
1431
set_speed_scale(gpu_particles->get_speed_scale());
1432
set_draw_order(DrawOrder(gpu_particles->get_draw_order()));
1433
set_mesh(gpu_particles->get_draw_pass_mesh(0));
1434
1435
Ref<ParticleProcessMaterial> material = gpu_particles->get_process_material();
1436
if (material.is_null()) {
1437
return;
1438
}
1439
1440
set_direction(material->get_direction());
1441
set_spread(material->get_spread());
1442
set_flatness(material->get_flatness());
1443
1444
set_color(material->get_color());
1445
1446
Ref<GradientTexture1D> gt = material->get_color_ramp();
1447
if (gt.is_valid()) {
1448
set_color_ramp(gt->get_gradient());
1449
}
1450
1451
Ref<GradientTexture1D> gti = material->get_color_initial_ramp();
1452
if (gti.is_valid()) {
1453
set_color_initial_ramp(gti->get_gradient());
1454
}
1455
1456
set_particle_flag(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY));
1457
set_particle_flag(PARTICLE_FLAG_ROTATE_Y, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ROTATE_Y));
1458
set_particle_flag(PARTICLE_FLAG_DISABLE_Z, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_DISABLE_Z));
1459
1460
set_emission_shape(EmissionShape(material->get_emission_shape()));
1461
set_emission_sphere_radius(material->get_emission_sphere_radius());
1462
set_emission_box_extents(material->get_emission_box_extents());
1463
set_emission_ring_height(material->get_emission_ring_height());
1464
set_emission_ring_radius(material->get_emission_ring_radius());
1465
set_emission_ring_inner_radius(material->get_emission_ring_inner_radius());
1466
set_emission_ring_cone_angle(material->get_emission_ring_cone_angle());
1467
1468
Ref<CurveXYZTexture> scale3D = material->get_param_texture(ParticleProcessMaterial::PARAM_SCALE);
1469
if (scale3D.is_valid()) {
1470
split_scale = true;
1471
scale_curve_x = scale3D->get_curve_x();
1472
scale_curve_y = scale3D->get_curve_y();
1473
scale_curve_z = scale3D->get_curve_z();
1474
}
1475
1476
set_gravity(material->get_gravity());
1477
set_lifetime_randomness(material->get_lifetime_randomness());
1478
1479
#define CONVERT_PARAM(m_param) \
1480
set_param_min(m_param, material->get_param_min(ParticleProcessMaterial::m_param)); \
1481
{ \
1482
Ref<CurveTexture> ctex = material->get_param_texture(ParticleProcessMaterial::m_param); \
1483
if (ctex.is_valid()) \
1484
set_param_curve(m_param, ctex->get_curve()); \
1485
} \
1486
set_param_max(m_param, material->get_param_max(ParticleProcessMaterial::m_param));
1487
1488
CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
1489
CONVERT_PARAM(PARAM_ANGULAR_VELOCITY);
1490
CONVERT_PARAM(PARAM_ORBIT_VELOCITY);
1491
CONVERT_PARAM(PARAM_LINEAR_ACCEL);
1492
CONVERT_PARAM(PARAM_RADIAL_ACCEL);
1493
CONVERT_PARAM(PARAM_TANGENTIAL_ACCEL);
1494
CONVERT_PARAM(PARAM_DAMPING);
1495
CONVERT_PARAM(PARAM_ANGLE);
1496
CONVERT_PARAM(PARAM_SCALE);
1497
CONVERT_PARAM(PARAM_HUE_VARIATION);
1498
CONVERT_PARAM(PARAM_ANIM_SPEED);
1499
CONVERT_PARAM(PARAM_ANIM_OFFSET);
1500
1501
#undef CONVERT_PARAM
1502
}
1503
1504
void CPUParticles3D::_bind_methods() {
1505
ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles3D::set_emitting);
1506
ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles3D::set_amount);
1507
ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles3D::set_lifetime);
1508
ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles3D::set_one_shot);
1509
ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles3D::set_pre_process_time);
1510
ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles3D::set_explosiveness_ratio);
1511
ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles3D::set_randomness_ratio);
1512
ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &CPUParticles3D::set_visibility_aabb);
1513
ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles3D::set_lifetime_randomness);
1514
ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles3D::set_use_local_coordinates);
1515
ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles3D::set_fixed_fps);
1516
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles3D::set_fractional_delta);
1517
ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles3D::set_speed_scale);
1518
1519
ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles3D::is_emitting);
1520
ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles3D::get_amount);
1521
ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles3D::get_lifetime);
1522
ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles3D::get_one_shot);
1523
ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles3D::get_pre_process_time);
1524
ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles3D::get_explosiveness_ratio);
1525
ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles3D::get_randomness_ratio);
1526
ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &CPUParticles3D::get_visibility_aabb);
1527
ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles3D::get_lifetime_randomness);
1528
ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles3D::get_use_local_coordinates);
1529
ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles3D::get_fixed_fps);
1530
ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles3D::get_fractional_delta);
1531
ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles3D::get_speed_scale);
1532
1533
ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles3D::set_draw_order);
1534
1535
ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles3D::get_draw_order);
1536
1537
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles3D::set_mesh);
1538
ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles3D::get_mesh);
1539
1540
ClassDB::bind_method(D_METHOD("set_use_fixed_seed", "use_fixed_seed"), &CPUParticles3D::set_use_fixed_seed);
1541
ClassDB::bind_method(D_METHOD("get_use_fixed_seed"), &CPUParticles3D::get_use_fixed_seed);
1542
1543
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &CPUParticles3D::set_seed);
1544
ClassDB::bind_method(D_METHOD("get_seed"), &CPUParticles3D::get_seed);
1545
1546
ClassDB::bind_method(D_METHOD("restart", "keep_seed"), &CPUParticles3D::restart, DEFVAL(false));
1547
ClassDB::bind_method(D_METHOD("request_particles_process", "process_time"), &CPUParticles3D::request_particles_process);
1548
ClassDB::bind_method(D_METHOD("capture_aabb"), &CPUParticles3D::capture_aabb);
1549
1550
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting", PROPERTY_HINT_ONESHOT), "set_emitting", "is_emitting");
1551
ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); // FIXME: Evaluate support for `exp` in integer properties, or remove this.
1552
ADD_GROUP("Time", "");
1553
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime");
1554
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
1555
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,10.0,0.01,or_greater,exp,suffix:s"), "set_pre_process_time", "get_pre_process_time");
1556
1557
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
1558
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
1559
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
1560
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_fixed_seed"), "set_use_fixed_seed", "get_use_fixed_seed");
1561
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed", PROPERTY_HINT_RANGE, "0," + itos(UINT32_MAX) + ",1"), "set_seed", "get_seed");
1562
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
1563
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1,suffix:FPS"), "set_fixed_fps", "get_fixed_fps");
1564
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
1565
ADD_GROUP("Drawing", "");
1566
ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb", PROPERTY_HINT_NONE, "suffix:m"), "set_visibility_aabb", "get_visibility_aabb");
1567
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
1568
ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,View Depth"), "set_draw_order", "get_draw_order");
1569
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
1570
1571
BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
1572
BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
1573
BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH);
1574
1575
ADD_PROPERTY_DEFAULT("seed", 0);
1576
1577
////////////////////////////////
1578
1579
ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles3D::set_direction);
1580
ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles3D::get_direction);
1581
1582
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles3D::set_spread);
1583
ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles3D::get_spread);
1584
1585
ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles3D::set_flatness);
1586
ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles3D::get_flatness);
1587
1588
ClassDB::bind_method(D_METHOD("set_param_min", "param", "value"), &CPUParticles3D::set_param_min);
1589
ClassDB::bind_method(D_METHOD("get_param_min", "param"), &CPUParticles3D::get_param_min);
1590
1591
ClassDB::bind_method(D_METHOD("set_param_max", "param", "value"), &CPUParticles3D::set_param_max);
1592
ClassDB::bind_method(D_METHOD("get_param_max", "param"), &CPUParticles3D::get_param_max);
1593
1594
ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles3D::set_param_curve);
1595
ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles3D::get_param_curve);
1596
1597
ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles3D::set_color);
1598
ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles3D::get_color);
1599
1600
ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles3D::set_color_ramp);
1601
ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles3D::get_color_ramp);
1602
1603
ClassDB::bind_method(D_METHOD("set_color_initial_ramp", "ramp"), &CPUParticles3D::set_color_initial_ramp);
1604
ClassDB::bind_method(D_METHOD("get_color_initial_ramp"), &CPUParticles3D::get_color_initial_ramp);
1605
1606
ClassDB::bind_method(D_METHOD("set_particle_flag", "particle_flag", "enable"), &CPUParticles3D::set_particle_flag);
1607
ClassDB::bind_method(D_METHOD("get_particle_flag", "particle_flag"), &CPUParticles3D::get_particle_flag);
1608
1609
ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles3D::set_emission_shape);
1610
ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles3D::get_emission_shape);
1611
1612
ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles3D::set_emission_sphere_radius);
1613
ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles3D::get_emission_sphere_radius);
1614
1615
ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles3D::set_emission_box_extents);
1616
ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles3D::get_emission_box_extents);
1617
1618
ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles3D::set_emission_points);
1619
ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles3D::get_emission_points);
1620
1621
ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles3D::set_emission_normals);
1622
ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles3D::get_emission_normals);
1623
1624
ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles3D::set_emission_colors);
1625
ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles3D::get_emission_colors);
1626
1627
ClassDB::bind_method(D_METHOD("set_emission_ring_axis", "axis"), &CPUParticles3D::set_emission_ring_axis);
1628
ClassDB::bind_method(D_METHOD("get_emission_ring_axis"), &CPUParticles3D::get_emission_ring_axis);
1629
1630
ClassDB::bind_method(D_METHOD("set_emission_ring_height", "height"), &CPUParticles3D::set_emission_ring_height);
1631
ClassDB::bind_method(D_METHOD("get_emission_ring_height"), &CPUParticles3D::get_emission_ring_height);
1632
1633
ClassDB::bind_method(D_METHOD("set_emission_ring_radius", "radius"), &CPUParticles3D::set_emission_ring_radius);
1634
ClassDB::bind_method(D_METHOD("get_emission_ring_radius"), &CPUParticles3D::get_emission_ring_radius);
1635
1636
ClassDB::bind_method(D_METHOD("set_emission_ring_inner_radius", "inner_radius"), &CPUParticles3D::set_emission_ring_inner_radius);
1637
ClassDB::bind_method(D_METHOD("get_emission_ring_inner_radius"), &CPUParticles3D::get_emission_ring_inner_radius);
1638
1639
ClassDB::bind_method(D_METHOD("set_emission_ring_cone_angle", "cone_angle"), &CPUParticles3D::set_emission_ring_cone_angle);
1640
ClassDB::bind_method(D_METHOD("get_emission_ring_cone_angle"), &CPUParticles3D::get_emission_ring_cone_angle);
1641
1642
ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles3D::get_gravity);
1643
ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles3D::set_gravity);
1644
1645
ClassDB::bind_method(D_METHOD("get_split_scale"), &CPUParticles3D::get_split_scale);
1646
ClassDB::bind_method(D_METHOD("set_split_scale", "split_scale"), &CPUParticles3D::set_split_scale);
1647
1648
ClassDB::bind_method(D_METHOD("get_scale_curve_x"), &CPUParticles3D::get_scale_curve_x);
1649
ClassDB::bind_method(D_METHOD("set_scale_curve_x", "scale_curve"), &CPUParticles3D::set_scale_curve_x);
1650
1651
ClassDB::bind_method(D_METHOD("get_scale_curve_y"), &CPUParticles3D::get_scale_curve_y);
1652
ClassDB::bind_method(D_METHOD("set_scale_curve_y", "scale_curve"), &CPUParticles3D::set_scale_curve_y);
1653
1654
ClassDB::bind_method(D_METHOD("get_scale_curve_z"), &CPUParticles3D::get_scale_curve_z);
1655
ClassDB::bind_method(D_METHOD("set_scale_curve_z", "scale_curve"), &CPUParticles3D::set_scale_curve_z);
1656
1657
ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles);
1658
1659
ADD_SIGNAL(MethodInfo("finished"));
1660
1661
ADD_GROUP("Emission Shape", "emission_");
1662
ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Sphere Surface,Box,Points,Directed Points,Ring", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
1663
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01"), "set_emission_sphere_radius", "get_emission_sphere_radius");
1664
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_box_extents"), "set_emission_box_extents", "get_emission_box_extents");
1665
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_points"), "set_emission_points", "get_emission_points");
1666
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_normals"), "set_emission_normals", "get_emission_normals");
1667
ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "emission_colors"), "set_emission_colors", "get_emission_colors");
1668
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_ring_axis"), "set_emission_ring_axis", "get_emission_ring_axis");
1669
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_height", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_height", "get_emission_ring_height");
1670
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_radius", "get_emission_ring_radius");
1671
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_inner_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_inner_radius", "get_emission_ring_inner_radius");
1672
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_cone_angle", PROPERTY_HINT_RANGE, "0,90,0.01,degrees"), "set_emission_ring_cone_angle", "get_emission_ring_cone_angle");
1673
ADD_GROUP("Particle Flags", "particle_flag_");
1674
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
1675
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_rotate_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ROTATE_Y);
1676
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_disable_z"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_DISABLE_Z);
1677
ADD_GROUP("Direction", "");
1678
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "direction"), "set_direction", "get_direction");
1679
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread");
1680
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "flatness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_flatness", "get_flatness");
1681
ADD_GROUP("Gravity", "");
1682
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity"), "set_gravity", "get_gravity");
1683
ADD_GROUP("Initial Velocity", "initial_");
1684
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity_min", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_min", "get_param_min", PARAM_INITIAL_LINEAR_VELOCITY);
1685
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity_max", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_max", "get_param_max", PARAM_INITIAL_LINEAR_VELOCITY);
1686
ADD_GROUP("Angular Velocity", "angular_");
1687
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity_min", PROPERTY_HINT_RANGE, "-720,720,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ANGULAR_VELOCITY);
1688
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity_max", PROPERTY_HINT_RANGE, "-720,720,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ANGULAR_VELOCITY);
1689
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGULAR_VELOCITY);
1690
ADD_GROUP("Orbit Velocity", "orbit_");
1691
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity_min", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ORBIT_VELOCITY);
1692
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity_max", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ORBIT_VELOCITY);
1693
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "orbit_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ORBIT_VELOCITY);
1694
ADD_GROUP("Linear Accel", "linear_");
1695
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_LINEAR_ACCEL);
1696
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_LINEAR_ACCEL);
1697
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "linear_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_LINEAR_ACCEL);
1698
ADD_GROUP("Radial Accel", "radial_");
1699
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_RADIAL_ACCEL);
1700
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_RADIAL_ACCEL);
1701
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "radial_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_RADIAL_ACCEL);
1702
ADD_GROUP("Tangential Accel", "tangential_");
1703
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_TANGENTIAL_ACCEL);
1704
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_TANGENTIAL_ACCEL);
1705
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "tangential_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_TANGENTIAL_ACCEL);
1706
ADD_GROUP("Damping", "");
1707
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_min", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_param_min", "get_param_min", PARAM_DAMPING);
1708
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_max", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_param_max", "get_param_max", PARAM_DAMPING);
1709
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_DAMPING);
1710
ADD_GROUP("Angle", "");
1711
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_min", PROPERTY_HINT_RANGE, "-720,720,0.1,or_less,or_greater,degrees"), "set_param_min", "get_param_min", PARAM_ANGLE);
1712
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_max", PROPERTY_HINT_RANGE, "-720,720,0.1,or_less,or_greater,degrees"), "set_param_max", "get_param_max", PARAM_ANGLE);
1713
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGLE);
1714
ADD_GROUP("Scale", "");
1715
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount_min", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_min", "get_param_min", PARAM_SCALE);
1716
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount_max", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_max", "get_param_max", PARAM_SCALE);
1717
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "scale_amount_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_SCALE);
1718
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "split_scale"), "set_split_scale", "get_split_scale");
1719
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_x", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_x", "get_scale_curve_x");
1720
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_y", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_y", "get_scale_curve_y");
1721
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_z", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_z", "get_scale_curve_z");
1722
ADD_GROUP("Color", "");
1723
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
1724
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_ramp", "get_color_ramp");
1725
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_initial_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_initial_ramp", "get_color_initial_ramp");
1726
1727
ADD_GROUP("Hue Variation", "hue_");
1728
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_min", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param_min", "get_param_min", PARAM_HUE_VARIATION);
1729
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_max", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param_max", "get_param_max", PARAM_HUE_VARIATION);
1730
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "hue_variation_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_HUE_VARIATION);
1731
ADD_GROUP("Animation", "anim_");
1732
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_min", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,or_less"), "set_param_min", "get_param_min", PARAM_ANIM_SPEED);
1733
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_max", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,or_less"), "set_param_max", "get_param_max", PARAM_ANIM_SPEED);
1734
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_speed_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_SPEED);
1735
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_min", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_min", "get_param_min", PARAM_ANIM_OFFSET);
1736
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_max", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_max", "get_param_max", PARAM_ANIM_OFFSET);
1737
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_OFFSET);
1738
1739
BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
1740
BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
1741
BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
1742
BIND_ENUM_CONSTANT(PARAM_LINEAR_ACCEL);
1743
BIND_ENUM_CONSTANT(PARAM_RADIAL_ACCEL);
1744
BIND_ENUM_CONSTANT(PARAM_TANGENTIAL_ACCEL);
1745
BIND_ENUM_CONSTANT(PARAM_DAMPING);
1746
BIND_ENUM_CONSTANT(PARAM_ANGLE);
1747
BIND_ENUM_CONSTANT(PARAM_SCALE);
1748
BIND_ENUM_CONSTANT(PARAM_HUE_VARIATION);
1749
BIND_ENUM_CONSTANT(PARAM_ANIM_SPEED);
1750
BIND_ENUM_CONSTANT(PARAM_ANIM_OFFSET);
1751
BIND_ENUM_CONSTANT(PARAM_MAX);
1752
1753
BIND_ENUM_CONSTANT(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
1754
BIND_ENUM_CONSTANT(PARTICLE_FLAG_ROTATE_Y);
1755
BIND_ENUM_CONSTANT(PARTICLE_FLAG_DISABLE_Z);
1756
BIND_ENUM_CONSTANT(PARTICLE_FLAG_MAX);
1757
1758
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINT);
1759
BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE);
1760
BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE_SURFACE);
1761
BIND_ENUM_CONSTANT(EMISSION_SHAPE_BOX);
1762
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
1763
BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
1764
BIND_ENUM_CONSTANT(EMISSION_SHAPE_RING);
1765
BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
1766
}
1767
1768
CPUParticles3D::CPUParticles3D() {
1769
set_notify_transform(true);
1770
1771
multimesh = RenderingServer::get_singleton()->multimesh_create();
1772
RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
1773
set_base(multimesh);
1774
1775
set_emitting(true);
1776
set_amount(8);
1777
set_seed(Math::rand());
1778
1779
rng.instantiate();
1780
1781
set_param_min(PARAM_INITIAL_LINEAR_VELOCITY, 0);
1782
set_param_min(PARAM_ANGULAR_VELOCITY, 0);
1783
set_param_min(PARAM_ORBIT_VELOCITY, 0);
1784
set_param_min(PARAM_LINEAR_ACCEL, 0);
1785
set_param_min(PARAM_RADIAL_ACCEL, 0);
1786
set_param_min(PARAM_TANGENTIAL_ACCEL, 0);
1787
set_param_min(PARAM_DAMPING, 0);
1788
set_param_min(PARAM_ANGLE, 0);
1789
set_param_min(PARAM_SCALE, 1);
1790
set_param_min(PARAM_HUE_VARIATION, 0);
1791
set_param_min(PARAM_ANIM_SPEED, 0);
1792
set_param_min(PARAM_ANIM_OFFSET, 0);
1793
set_param_max(PARAM_INITIAL_LINEAR_VELOCITY, 0);
1794
set_param_max(PARAM_ANGULAR_VELOCITY, 0);
1795
set_param_max(PARAM_ORBIT_VELOCITY, 0);
1796
set_param_max(PARAM_LINEAR_ACCEL, 0);
1797
set_param_max(PARAM_RADIAL_ACCEL, 0);
1798
set_param_max(PARAM_TANGENTIAL_ACCEL, 0);
1799
set_param_max(PARAM_DAMPING, 0);
1800
set_param_max(PARAM_ANGLE, 0);
1801
set_param_max(PARAM_SCALE, 1);
1802
set_param_max(PARAM_HUE_VARIATION, 0);
1803
set_param_max(PARAM_ANIM_SPEED, 0);
1804
set_param_max(PARAM_ANIM_OFFSET, 0);
1805
set_emission_shape(EMISSION_SHAPE_POINT);
1806
set_emission_sphere_radius(1);
1807
set_emission_box_extents(Vector3(1, 1, 1));
1808
set_emission_ring_axis(Vector3(0, 0, 1.0));
1809
set_emission_ring_height(1);
1810
set_emission_ring_radius(1);
1811
set_emission_ring_inner_radius(0);
1812
set_emission_ring_cone_angle(90);
1813
1814
set_gravity(Vector3(0, -9.8, 0));
1815
1816
for (int i = 0; i < PARTICLE_FLAG_MAX; i++) {
1817
particle_flags[i] = false;
1818
}
1819
1820
set_color(Color(1, 1, 1, 1));
1821
}
1822
1823
CPUParticles3D::~CPUParticles3D() {
1824
ERR_FAIL_NULL(RenderingServer::get_singleton());
1825
RS::get_singleton()->free(multimesh);
1826
}
1827
1828