1 /** 2 GPU-based 2D particle emitter. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.particles2d; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.node2d; 25 import godot.canvasitem; 26 import godot.node; 27 import godot.texture; 28 import godot.material; 29 /** 30 GPU-based 2D particle emitter. 31 32 2D particle node used to create a variety of particle systems and effects. $(D Particles2D) features an emitter that generates some number of particles at a given rate. 33 Use the `process_material` property to add a $(D ParticlesMaterial) to configure particle appearance and behavior. Alternatively, you can add a $(D ShaderMaterial) which will be applied to all particles. 34 $(B Note:) $(D Particles2D) only work when using the GLES3 renderer. If using the GLES2 renderer, use $(D CPUParticles2D) instead. You can convert $(D Particles2D) to $(D CPUParticles2D) by selecting the node, clicking the $(B Particles) menu at the top of the 2D editor viewport then choosing $(B Convert to CPUParticles2D). 35 $(B Note:) After working on a Particles node, remember to update its $(D visibilityRect) by selecting it, clicking the $(B Particles) menu at the top of the 2D editor viewport then choose $(B Generate Visibility Rect). Otherwise, particles may suddenly disappear depending on the camera position and angle. 36 $(B Note:) Unlike $(D CPUParticles2D), $(D Particles2D) currently ignore the texture region defined in $(D AtlasTexture)s. 37 */ 38 @GodotBaseClass struct Particles2D 39 { 40 package(godot) enum string _GODOT_internal_name = "Particles2D"; 41 public: 42 @nogc nothrow: 43 union { /** */ godot_object _godot_object; /** */ Node2D _GODOT_base; } 44 alias _GODOT_base this; 45 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 46 package(godot) __gshared bool _classBindingInitialized = false; 47 package(godot) static struct GDNativeClassBinding 48 { 49 __gshared: 50 @GodotName("capture_rect") GodotMethod!(Rect2) captureRect; 51 @GodotName("get_amount") GodotMethod!(long) getAmount; 52 @GodotName("get_draw_order") GodotMethod!(Particles2D.DrawOrder) getDrawOrder; 53 @GodotName("get_explosiveness_ratio") GodotMethod!(double) getExplosivenessRatio; 54 @GodotName("get_fixed_fps") GodotMethod!(long) getFixedFps; 55 @GodotName("get_fractional_delta") GodotMethod!(bool) getFractionalDelta; 56 @GodotName("get_lifetime") GodotMethod!(double) getLifetime; 57 @GodotName("get_normal_map") GodotMethod!(Texture) getNormalMap; 58 @GodotName("get_one_shot") GodotMethod!(bool) getOneShot; 59 @GodotName("get_pre_process_time") GodotMethod!(double) getPreProcessTime; 60 @GodotName("get_process_material") GodotMethod!(Material) getProcessMaterial; 61 @GodotName("get_randomness_ratio") GodotMethod!(double) getRandomnessRatio; 62 @GodotName("get_speed_scale") GodotMethod!(double) getSpeedScale; 63 @GodotName("get_texture") GodotMethod!(Texture) getTexture; 64 @GodotName("get_use_local_coordinates") GodotMethod!(bool) getUseLocalCoordinates; 65 @GodotName("get_visibility_rect") GodotMethod!(Rect2) getVisibilityRect; 66 @GodotName("is_emitting") GodotMethod!(bool) isEmitting; 67 @GodotName("restart") GodotMethod!(void) restart; 68 @GodotName("set_amount") GodotMethod!(void, long) setAmount; 69 @GodotName("set_draw_order") GodotMethod!(void, long) setDrawOrder; 70 @GodotName("set_emitting") GodotMethod!(void, bool) setEmitting; 71 @GodotName("set_explosiveness_ratio") GodotMethod!(void, double) setExplosivenessRatio; 72 @GodotName("set_fixed_fps") GodotMethod!(void, long) setFixedFps; 73 @GodotName("set_fractional_delta") GodotMethod!(void, bool) setFractionalDelta; 74 @GodotName("set_lifetime") GodotMethod!(void, double) setLifetime; 75 @GodotName("set_normal_map") GodotMethod!(void, Texture) setNormalMap; 76 @GodotName("set_one_shot") GodotMethod!(void, bool) setOneShot; 77 @GodotName("set_pre_process_time") GodotMethod!(void, double) setPreProcessTime; 78 @GodotName("set_process_material") GodotMethod!(void, Material) setProcessMaterial; 79 @GodotName("set_randomness_ratio") GodotMethod!(void, double) setRandomnessRatio; 80 @GodotName("set_speed_scale") GodotMethod!(void, double) setSpeedScale; 81 @GodotName("set_texture") GodotMethod!(void, Texture) setTexture; 82 @GodotName("set_use_local_coordinates") GodotMethod!(void, bool) setUseLocalCoordinates; 83 @GodotName("set_visibility_rect") GodotMethod!(void, Rect2) setVisibilityRect; 84 } 85 /// 86 pragma(inline, true) bool opEquals(in Particles2D other) const 87 { return _godot_object.ptr is other._godot_object.ptr; } 88 /// 89 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 90 { _godot_object.ptr = n; return null; } 91 /// 92 pragma(inline, true) bool opEquals(typeof(null) n) const 93 { return _godot_object.ptr is n; } 94 /// 95 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 96 mixin baseCasts; 97 /// Construct a new instance of Particles2D. 98 /// Note: use `memnew!Particles2D` instead. 99 static Particles2D _new() 100 { 101 static godot_class_constructor constructor; 102 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Particles2D"); 103 if(constructor is null) return typeof(this).init; 104 return cast(Particles2D)(constructor()); 105 } 106 @disable new(size_t s); 107 /// 108 enum DrawOrder : int 109 { 110 /** 111 Particles are drawn in the order emitted. 112 */ 113 drawOrderIndex = 0, 114 /** 115 Particles are drawn in order of remaining lifetime. 116 */ 117 drawOrderLifetime = 1, 118 } 119 /// 120 enum Constants : int 121 { 122 drawOrderIndex = 0, 123 drawOrderLifetime = 1, 124 } 125 /** 126 Returns a rectangle containing the positions of all existing particles. 127 */ 128 Rect2 captureRect() const 129 { 130 checkClassBinding!(typeof(this))(); 131 return ptrcall!(Rect2)(GDNativeClassBinding.captureRect, _godot_object); 132 } 133 /** 134 135 */ 136 long getAmount() const 137 { 138 checkClassBinding!(typeof(this))(); 139 return ptrcall!(long)(GDNativeClassBinding.getAmount, _godot_object); 140 } 141 /** 142 143 */ 144 Particles2D.DrawOrder getDrawOrder() const 145 { 146 checkClassBinding!(typeof(this))(); 147 return ptrcall!(Particles2D.DrawOrder)(GDNativeClassBinding.getDrawOrder, _godot_object); 148 } 149 /** 150 151 */ 152 double getExplosivenessRatio() const 153 { 154 checkClassBinding!(typeof(this))(); 155 return ptrcall!(double)(GDNativeClassBinding.getExplosivenessRatio, _godot_object); 156 } 157 /** 158 159 */ 160 long getFixedFps() const 161 { 162 checkClassBinding!(typeof(this))(); 163 return ptrcall!(long)(GDNativeClassBinding.getFixedFps, _godot_object); 164 } 165 /** 166 167 */ 168 bool getFractionalDelta() const 169 { 170 checkClassBinding!(typeof(this))(); 171 return ptrcall!(bool)(GDNativeClassBinding.getFractionalDelta, _godot_object); 172 } 173 /** 174 175 */ 176 double getLifetime() const 177 { 178 checkClassBinding!(typeof(this))(); 179 return ptrcall!(double)(GDNativeClassBinding.getLifetime, _godot_object); 180 } 181 /** 182 183 */ 184 Ref!Texture getNormalMap() const 185 { 186 checkClassBinding!(typeof(this))(); 187 return ptrcall!(Texture)(GDNativeClassBinding.getNormalMap, _godot_object); 188 } 189 /** 190 191 */ 192 bool getOneShot() const 193 { 194 checkClassBinding!(typeof(this))(); 195 return ptrcall!(bool)(GDNativeClassBinding.getOneShot, _godot_object); 196 } 197 /** 198 199 */ 200 double getPreProcessTime() const 201 { 202 checkClassBinding!(typeof(this))(); 203 return ptrcall!(double)(GDNativeClassBinding.getPreProcessTime, _godot_object); 204 } 205 /** 206 207 */ 208 Ref!Material getProcessMaterial() const 209 { 210 checkClassBinding!(typeof(this))(); 211 return ptrcall!(Material)(GDNativeClassBinding.getProcessMaterial, _godot_object); 212 } 213 /** 214 215 */ 216 double getRandomnessRatio() const 217 { 218 checkClassBinding!(typeof(this))(); 219 return ptrcall!(double)(GDNativeClassBinding.getRandomnessRatio, _godot_object); 220 } 221 /** 222 223 */ 224 double getSpeedScale() const 225 { 226 checkClassBinding!(typeof(this))(); 227 return ptrcall!(double)(GDNativeClassBinding.getSpeedScale, _godot_object); 228 } 229 /** 230 231 */ 232 Ref!Texture getTexture() const 233 { 234 checkClassBinding!(typeof(this))(); 235 return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object); 236 } 237 /** 238 239 */ 240 bool getUseLocalCoordinates() const 241 { 242 checkClassBinding!(typeof(this))(); 243 return ptrcall!(bool)(GDNativeClassBinding.getUseLocalCoordinates, _godot_object); 244 } 245 /** 246 247 */ 248 Rect2 getVisibilityRect() const 249 { 250 checkClassBinding!(typeof(this))(); 251 return ptrcall!(Rect2)(GDNativeClassBinding.getVisibilityRect, _godot_object); 252 } 253 /** 254 255 */ 256 bool isEmitting() const 257 { 258 checkClassBinding!(typeof(this))(); 259 return ptrcall!(bool)(GDNativeClassBinding.isEmitting, _godot_object); 260 } 261 /** 262 Restarts all the existing particles. 263 */ 264 void restart() 265 { 266 checkClassBinding!(typeof(this))(); 267 ptrcall!(void)(GDNativeClassBinding.restart, _godot_object); 268 } 269 /** 270 271 */ 272 void setAmount(in long amount) 273 { 274 checkClassBinding!(typeof(this))(); 275 ptrcall!(void)(GDNativeClassBinding.setAmount, _godot_object, amount); 276 } 277 /** 278 279 */ 280 void setDrawOrder(in long order) 281 { 282 checkClassBinding!(typeof(this))(); 283 ptrcall!(void)(GDNativeClassBinding.setDrawOrder, _godot_object, order); 284 } 285 /** 286 287 */ 288 void setEmitting(in bool emitting) 289 { 290 checkClassBinding!(typeof(this))(); 291 ptrcall!(void)(GDNativeClassBinding.setEmitting, _godot_object, emitting); 292 } 293 /** 294 295 */ 296 void setExplosivenessRatio(in double ratio) 297 { 298 checkClassBinding!(typeof(this))(); 299 ptrcall!(void)(GDNativeClassBinding.setExplosivenessRatio, _godot_object, ratio); 300 } 301 /** 302 303 */ 304 void setFixedFps(in long fps) 305 { 306 checkClassBinding!(typeof(this))(); 307 ptrcall!(void)(GDNativeClassBinding.setFixedFps, _godot_object, fps); 308 } 309 /** 310 311 */ 312 void setFractionalDelta(in bool enable) 313 { 314 checkClassBinding!(typeof(this))(); 315 ptrcall!(void)(GDNativeClassBinding.setFractionalDelta, _godot_object, enable); 316 } 317 /** 318 319 */ 320 void setLifetime(in double secs) 321 { 322 checkClassBinding!(typeof(this))(); 323 ptrcall!(void)(GDNativeClassBinding.setLifetime, _godot_object, secs); 324 } 325 /** 326 327 */ 328 void setNormalMap(Texture texture) 329 { 330 checkClassBinding!(typeof(this))(); 331 ptrcall!(void)(GDNativeClassBinding.setNormalMap, _godot_object, texture); 332 } 333 /** 334 335 */ 336 void setOneShot(in bool secs) 337 { 338 checkClassBinding!(typeof(this))(); 339 ptrcall!(void)(GDNativeClassBinding.setOneShot, _godot_object, secs); 340 } 341 /** 342 343 */ 344 void setPreProcessTime(in double secs) 345 { 346 checkClassBinding!(typeof(this))(); 347 ptrcall!(void)(GDNativeClassBinding.setPreProcessTime, _godot_object, secs); 348 } 349 /** 350 351 */ 352 void setProcessMaterial(Material material) 353 { 354 checkClassBinding!(typeof(this))(); 355 ptrcall!(void)(GDNativeClassBinding.setProcessMaterial, _godot_object, material); 356 } 357 /** 358 359 */ 360 void setRandomnessRatio(in double ratio) 361 { 362 checkClassBinding!(typeof(this))(); 363 ptrcall!(void)(GDNativeClassBinding.setRandomnessRatio, _godot_object, ratio); 364 } 365 /** 366 367 */ 368 void setSpeedScale(in double scale) 369 { 370 checkClassBinding!(typeof(this))(); 371 ptrcall!(void)(GDNativeClassBinding.setSpeedScale, _godot_object, scale); 372 } 373 /** 374 375 */ 376 void setTexture(Texture texture) 377 { 378 checkClassBinding!(typeof(this))(); 379 ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture); 380 } 381 /** 382 383 */ 384 void setUseLocalCoordinates(in bool enable) 385 { 386 checkClassBinding!(typeof(this))(); 387 ptrcall!(void)(GDNativeClassBinding.setUseLocalCoordinates, _godot_object, enable); 388 } 389 /** 390 391 */ 392 void setVisibilityRect(in Rect2 visibility_rect) 393 { 394 checkClassBinding!(typeof(this))(); 395 ptrcall!(void)(GDNativeClassBinding.setVisibilityRect, _godot_object, visibility_rect); 396 } 397 /** 398 The number of particles emitted in one emission cycle (corresponding to the $(D lifetime)). 399 $(B Note:) Changing $(D amount) will reset the particle emission, therefore removing all particles that were already emitted before changing $(D amount). 400 */ 401 @property long amount() 402 { 403 return getAmount(); 404 } 405 /// ditto 406 @property void amount(long v) 407 { 408 setAmount(v); 409 } 410 /** 411 Particle draw order. Uses $(D draworder) values. 412 */ 413 @property Particles2D.DrawOrder drawOrder() 414 { 415 return getDrawOrder(); 416 } 417 /// ditto 418 @property void drawOrder(long v) 419 { 420 setDrawOrder(v); 421 } 422 /** 423 If `true`, particles are being emitted. 424 */ 425 @property bool emitting() 426 { 427 return isEmitting(); 428 } 429 /// ditto 430 @property void emitting(bool v) 431 { 432 setEmitting(v); 433 } 434 /** 435 How rapidly particles in an emission cycle are emitted. If greater than `0`, there will be a gap in emissions before the next cycle begins. 436 */ 437 @property double explosiveness() 438 { 439 return getExplosivenessRatio(); 440 } 441 /// ditto 442 @property void explosiveness(double v) 443 { 444 setExplosivenessRatio(v); 445 } 446 /** 447 The particle system's frame rate is fixed to a value. For instance, changing the value to 2 will make the particles render at 2 frames per second. Note this does not slow down the simulation of the particle system itself. 448 */ 449 @property long fixedFps() 450 { 451 return getFixedFps(); 452 } 453 /// ditto 454 @property void fixedFps(long v) 455 { 456 setFixedFps(v); 457 } 458 /** 459 If `true`, results in fractional delta calculation which has a smoother particles display effect. 460 */ 461 @property bool fractDelta() 462 { 463 return getFractionalDelta(); 464 } 465 /// ditto 466 @property void fractDelta(bool v) 467 { 468 setFractionalDelta(v); 469 } 470 /** 471 The amount of time each particle will exist (in seconds). 472 */ 473 @property double lifetime() 474 { 475 return getLifetime(); 476 } 477 /// ditto 478 @property void lifetime(double v) 479 { 480 setLifetime(v); 481 } 482 /** 483 If `true`, particles use the parent node's coordinate space. If `false`, they use global coordinates. 484 */ 485 @property bool localCoords() 486 { 487 return getUseLocalCoordinates(); 488 } 489 /// ditto 490 @property void localCoords(bool v) 491 { 492 setUseLocalCoordinates(v); 493 } 494 /** 495 Normal map to be used for the $(D texture) property. 496 $(B Note:) Godot expects the normal map to use X+, Y-, and Z+ coordinates. See $(D url=http://wiki.polycount.com/wiki/Normal_Map_Technical_Details#Common_Swizzle_Coordinates)this page$(D /url) for a comparison of normal map coordinates expected by popular engines. 497 */ 498 @property Texture normalMap() 499 { 500 return getNormalMap(); 501 } 502 /// ditto 503 @property void normalMap(Texture v) 504 { 505 setNormalMap(v); 506 } 507 /** 508 If `true`, only one emission cycle occurs. If set `true` during a cycle, emission will stop at the cycle's end. 509 */ 510 @property bool oneShot() 511 { 512 return getOneShot(); 513 } 514 /// ditto 515 @property void oneShot(bool v) 516 { 517 setOneShot(v); 518 } 519 /** 520 Particle system starts as if it had already run for this many seconds. 521 */ 522 @property double preprocess() 523 { 524 return getPreProcessTime(); 525 } 526 /// ditto 527 @property void preprocess(double v) 528 { 529 setPreProcessTime(v); 530 } 531 /** 532 Emission lifetime randomness ratio. 533 */ 534 @property double randomness() 535 { 536 return getRandomnessRatio(); 537 } 538 /// ditto 539 @property void randomness(double v) 540 { 541 setRandomnessRatio(v); 542 } 543 /** 544 Particle system's running speed scaling ratio. A value of `0` can be used to pause the particles. 545 */ 546 @property double speedScale() 547 { 548 return getSpeedScale(); 549 } 550 /// ditto 551 @property void speedScale(double v) 552 { 553 setSpeedScale(v); 554 } 555 /** 556 Particle texture. If `null`, particles will be squares. 557 */ 558 @property Texture texture() 559 { 560 return getTexture(); 561 } 562 /// ditto 563 @property void texture(Texture v) 564 { 565 setTexture(v); 566 } 567 /** 568 The $(D Rect2) that determines the node's region which needs to be visible on screen for the particle system to be active. 569 Grow the rect if particles suddenly appear/disappear when the node enters/exits the screen. The $(D Rect2) can be grown via code or with the $(B Particles → Generate Visibility Rect) editor tool. 570 */ 571 @property Rect2 visibilityRect() 572 { 573 return getVisibilityRect(); 574 } 575 /// ditto 576 @property void visibilityRect(Rect2 v) 577 { 578 setVisibilityRect(v); 579 } 580 }