@@ -301,6 +301,36 @@ void GPUParticles3D::_validate_property(PropertyInfo &property) const {
301
301
}
302
302
}
303
303
304
+ void GPUParticles3D::emit_particle (const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) {
305
+ RS::get_singleton ()->particles_emit (particles, p_transform, p_velocity, p_color, p_custom, p_emit_flags);
306
+ }
307
+
308
+ void GPUParticles3D::_attach_sub_emitter () {
309
+ Node *n = get_node_or_null (sub_emitter);
310
+ if (n) {
311
+ GPUParticles3D *sen = Object::cast_to<GPUParticles3D>(n);
312
+ if (sen && sen != this ) {
313
+ RS::get_singleton ()->particles_set_subemitter (particles, sen->particles );
314
+ }
315
+ }
316
+ }
317
+
318
+ void GPUParticles3D::set_sub_emitter (const NodePath &p_path) {
319
+ if (is_inside_tree ()) {
320
+ RS::get_singleton ()->particles_set_subemitter (particles, RID ());
321
+ }
322
+
323
+ sub_emitter = p_path;
324
+
325
+ if (is_inside_tree () && sub_emitter != NodePath ()) {
326
+ _attach_sub_emitter ();
327
+ }
328
+ }
329
+
330
+ NodePath GPUParticles3D::get_sub_emitter () const {
331
+ return sub_emitter;
332
+ }
333
+
304
334
void GPUParticles3D::_notification (int p_what) {
305
335
if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
306
336
if (can_process ()) {
@@ -319,6 +349,16 @@ void GPUParticles3D::_notification(int p_what) {
319
349
}
320
350
}
321
351
352
+ if (p_what == NOTIFICATION_ENTER_TREE) {
353
+ if (sub_emitter != NodePath ()) {
354
+ _attach_sub_emitter ();
355
+ }
356
+ }
357
+
358
+ if (p_what == NOTIFICATION_EXIT_TREE) {
359
+ RS::get_singleton ()->particles_set_subemitter (particles, RID ());
360
+ }
361
+
322
362
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
323
363
// make sure particles are updated before rendering occurs if they were active before
324
364
if (is_visible_in_tree () && !RS::get_singleton ()->particles_is_inactive (particles)) {
@@ -369,8 +409,14 @@ void GPUParticles3D::_bind_methods() {
369
409
ClassDB::bind_method (D_METHOD (" restart" ), &GPUParticles3D::restart);
370
410
ClassDB::bind_method (D_METHOD (" capture_aabb" ), &GPUParticles3D::capture_aabb);
371
411
412
+ ClassDB::bind_method (D_METHOD (" set_sub_emitter" , " path" ), &GPUParticles3D::set_sub_emitter);
413
+ ClassDB::bind_method (D_METHOD (" get_sub_emitter" ), &GPUParticles3D::get_sub_emitter);
414
+
415
+ ClassDB::bind_method (D_METHOD (" emit_particle" , " xform" , " velocity" , " color" , " custom" , " flags" ), &GPUParticles3D::emit_particle);
416
+
372
417
ADD_PROPERTY (PropertyInfo (Variant::BOOL, " emitting" ), " set_emitting" , " is_emitting" );
373
418
ADD_PROPERTY (PropertyInfo (Variant::INT, " amount" , PROPERTY_HINT_EXP_RANGE, " 1,1000000,1" ), " set_amount" , " get_amount" );
419
+ ADD_PROPERTY (PropertyInfo (Variant::NODE_PATH, " sub_emitter" , PROPERTY_HINT_NODE_PATH_VALID_TYPES, " GPUParticles3D" ), " set_sub_emitter" , " get_sub_emitter" );
374
420
ADD_GROUP (" Time" , " " );
375
421
ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " lifetime" , PROPERTY_HINT_EXP_RANGE, " 0.01,600.0,0.01,or_greater" ), " set_lifetime" , " get_lifetime" );
376
422
ADD_PROPERTY (PropertyInfo (Variant::BOOL, " one_shot" ), " set_one_shot" , " get_one_shot" );
@@ -396,6 +442,12 @@ void GPUParticles3D::_bind_methods() {
396
442
BIND_ENUM_CONSTANT (DRAW_ORDER_LIFETIME);
397
443
BIND_ENUM_CONSTANT (DRAW_ORDER_VIEW_DEPTH);
398
444
445
+ BIND_ENUM_CONSTANT (EMIT_FLAG_POSITION);
446
+ BIND_ENUM_CONSTANT (EMIT_FLAG_ROTATION_SCALE);
447
+ BIND_ENUM_CONSTANT (EMIT_FLAG_VELOCITY);
448
+ BIND_ENUM_CONSTANT (EMIT_FLAG_COLOR);
449
+ BIND_ENUM_CONSTANT (EMIT_FLAG_CUSTOM);
450
+
399
451
BIND_CONSTANT (MAX_DRAW_PASSES);
400
452
}
401
453
0 commit comments