| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsCorePrerequisites.h" |
| 6 | #include "Particles/BsParticleModule.h" |
| 7 | #include "BsParticleDistribution.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | class Random; |
| 12 | class ParticleSet; |
| 13 | |
| 14 | /** @addtogroup Particles |
| 15 | * @{ |
| 16 | */ |
| 17 | |
| 18 | /** Properties that describe a specific type of ParticleEvolver. */ |
| 19 | struct ParticleEvolverProperties |
| 20 | { |
| 21 | ParticleEvolverProperties(bool analytical, INT32 priority) |
| 22 | : analytical(analytical), priority(priority) |
| 23 | { } |
| 24 | |
| 25 | /** |
| 26 | * True if the evolver can be evaluated analytically. This means the exact particle state can be retrieved based on |
| 27 | * just the time value. Non-analytical (numerical) evolvers require the previous state of the particle and will |
| 28 | * incrementally update the particle state. |
| 29 | */ |
| 30 | bool analytical; |
| 31 | |
| 32 | /** |
| 33 | * Determines the order in which this evolver will be evaluated relative to other active evolvers. Higher values |
| 34 | * means that the evolver will be executed sooner. Negative values mean the evolver will be executed after |
| 35 | * position/velocity is integrated. |
| 36 | */ |
| 37 | INT32 priority; |
| 38 | }; |
| 39 | |
| 40 | /** Updates properties of all active particles in a particle system in some way. */ |
| 41 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleEvolver : public ParticleModule |
| 42 | { |
| 43 | public: |
| 44 | ParticleEvolver() = default; |
| 45 | virtual ~ParticleEvolver() = default; |
| 46 | |
| 47 | /** Returns a set of properties that describe this evolver type. */ |
| 48 | virtual const ParticleEvolverProperties& getProperties() const = 0; |
| 49 | protected: |
| 50 | friend class ParticleSystem; |
| 51 | |
| 52 | /** |
| 53 | * Updates properties of particles in the provided range according to the ruleset of the evolver. |
| 54 | * |
| 55 | * @param[in] random Utility class for generating random numbers. |
| 56 | * @param[in] state Particle system state for this frame. |
| 57 | * @param[in] set Set containing the particles to update. |
| 58 | * @param[in] startIdx Index of the first particle in @p set to update. |
| 59 | * @param[in] count Number of particles to update, starting from @p startIdx. |
| 60 | * @param[in] spacing When false all particles will use the same time-step as provided by @p state. If |
| 61 | * true the time-step will be divided by @p count so particles are uniformly |
| 62 | * distributed over the time-step. |
| 63 | * @param[in] spacingOffset Extra offset that controls the starting position of the first particle when |
| 64 | * calculating spacing. Should be in range [0, 1). 0 = beginning of the current |
| 65 | * time step, 1 = start of next particle. |
| 66 | */ |
| 67 | virtual void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 68 | UINT32 count, bool spacing, float spacingOffset) const = 0; |
| 69 | }; |
| 70 | |
| 71 | /** Structure used for initializing a ParticleTextureAnimation object. */ |
| 72 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleTextureAnimationOptions) PARTICLE_TEXTURE_ANIMATION_DESC |
| 73 | { |
| 74 | /** |
| 75 | * Randomly pick a row to use for animation when the particle is first spawned. This implies that only a single row |
| 76 | * of the grid will be used for individual particle's animation. |
| 77 | */ |
| 78 | bool randomizeRow = false; |
| 79 | |
| 80 | /** Number of cycles to loop the animation during particle's lifetime. */ |
| 81 | UINT32 numCycles = 1; |
| 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * Provides functionality for particle texture animation. Uses the sprite texture assigned to the particle's material |
| 86 | * to determine animation properties. |
| 87 | */ |
| 88 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleTextureAnimation : public ParticleEvolver |
| 89 | { |
| 90 | public: |
| 91 | ParticleTextureAnimation() = default; |
| 92 | ParticleTextureAnimation(const PARTICLE_TEXTURE_ANIMATION_DESC& desc); |
| 93 | |
| 94 | /** Options describing the evolver. */ |
| 95 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 96 | void setOptions(const PARTICLE_TEXTURE_ANIMATION_DESC& options) { mDesc = options; } |
| 97 | |
| 98 | /** @copydoc setOptions */ |
| 99 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 100 | const PARTICLE_TEXTURE_ANIMATION_DESC& getOptions() const { return mDesc; } |
| 101 | |
| 102 | /** @copydoc ParticleEvolver::getProperties */ |
| 103 | const ParticleEvolverProperties& getProperties() const override |
| 104 | { |
| 105 | static const ParticleEvolverProperties sProperties(true, 0); |
| 106 | return sProperties; |
| 107 | } |
| 108 | |
| 109 | /** Creates a new particle texture animation evolver. */ |
| 110 | BS_SCRIPT_EXPORT(ec:T) |
| 111 | static SPtr<ParticleTextureAnimation> create(const PARTICLE_TEXTURE_ANIMATION_DESC& desc); |
| 112 | |
| 113 | /** Creates a new particle texture animation evolver. */ |
| 114 | BS_SCRIPT_EXPORT(ec:T) |
| 115 | static SPtr<ParticleTextureAnimation> create(); |
| 116 | private: |
| 117 | /** @copydoc ParticleEvolver::evolve */ |
| 118 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 119 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 120 | |
| 121 | PARTICLE_TEXTURE_ANIMATION_DESC mDesc; |
| 122 | |
| 123 | /************************************************************************/ |
| 124 | /* RTTI */ |
| 125 | /************************************************************************/ |
| 126 | public: |
| 127 | friend class ParticleTextureAnimationRTTI; |
| 128 | static RTTITypeBase* getRTTIStatic(); |
| 129 | RTTITypeBase* getRTTI() const override; |
| 130 | }; |
| 131 | |
| 132 | /** Structure used for initializing a ParticleOrbit object. */ |
| 133 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleOrbitOptions) PARTICLE_ORBIT_DESC |
| 134 | { |
| 135 | /** Position of the center around which to orbit. Evaluated over particle system lifetime. */ |
| 136 | Vector3Distribution center = Vector3(0.0f, 0.0f, 0.0f); |
| 137 | |
| 138 | /** |
| 139 | * Determines the speed of rotation around each axis. The speed is specified in "turns" where 0 = no rotation, |
| 140 | * 0.5 = 180 degree rotation and 1 = 360 degree rotation. Evaluated over particle lifetime. |
| 141 | */ |
| 142 | Vector3Distribution velocity = Vector3(0.0f, 1.0f, 0.0f); |
| 143 | |
| 144 | /** Speed at which to push or pull the particles towards/away from the center. Evaluated over particle lifetime. */ |
| 145 | FloatDistribution radial = 0.0f; |
| 146 | |
| 147 | /** True if the properties provided are in world space, false if in local space. */ |
| 148 | bool worldSpace = false; |
| 149 | }; |
| 150 | |
| 151 | /** Moves particles so that their sprites orbit their center according to the provided offset and rotation values. */ |
| 152 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleOrbit : public ParticleEvolver |
| 153 | { |
| 154 | public: |
| 155 | ParticleOrbit() = default; |
| 156 | ParticleOrbit(const PARTICLE_ORBIT_DESC& desc); |
| 157 | |
| 158 | /** Options describing the evolver. */ |
| 159 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 160 | void setOptions(const PARTICLE_ORBIT_DESC& options) { mDesc = options; } |
| 161 | |
| 162 | /** @copydoc setOptions */ |
| 163 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 164 | const PARTICLE_ORBIT_DESC& getOptions() const { return mDesc; } |
| 165 | |
| 166 | /** @copydoc ParticleEvolver::getProperties */ |
| 167 | const ParticleEvolverProperties& getProperties() const override |
| 168 | { |
| 169 | static const ParticleEvolverProperties sProperties(true, 0); |
| 170 | return sProperties; |
| 171 | } |
| 172 | |
| 173 | /** Creates a new particle orbit evolver. */ |
| 174 | BS_SCRIPT_EXPORT(ec:T) |
| 175 | static SPtr<ParticleOrbit> create(const PARTICLE_ORBIT_DESC& desc); |
| 176 | |
| 177 | /** Creates a new particle orbit evolver. */ |
| 178 | BS_SCRIPT_EXPORT(ec:T) |
| 179 | static SPtr<ParticleOrbit> create(); |
| 180 | private: |
| 181 | /** @copydoc ParticleEvolver::evolve */ |
| 182 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 183 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 184 | |
| 185 | PARTICLE_ORBIT_DESC mDesc; |
| 186 | |
| 187 | /************************************************************************/ |
| 188 | /* RTTI */ |
| 189 | /************************************************************************/ |
| 190 | public: |
| 191 | friend class ParticleOrbitRTTI; |
| 192 | static RTTITypeBase* getRTTIStatic(); |
| 193 | RTTITypeBase* getRTTI() const override; |
| 194 | }; |
| 195 | |
| 196 | /** Structure used for initializing a ParticleVelocity object. */ |
| 197 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleVelocityOptions) PARTICLE_VELOCITY_DESC |
| 198 | { |
| 199 | /** Determines the velocity of the particles evaluated over particle lifetime. */ |
| 200 | Vector3Distribution velocity = Vector3(0.0f, 1.0f, 0.0f); |
| 201 | |
| 202 | /** True if the velocity is provided in world space, false if in local space. */ |
| 203 | bool worldSpace = false; |
| 204 | }; |
| 205 | |
| 206 | /** Applies linear velocity to the particles. */ |
| 207 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleVelocity : public ParticleEvolver |
| 208 | { |
| 209 | public: |
| 210 | ParticleVelocity() = default; |
| 211 | ParticleVelocity(const PARTICLE_VELOCITY_DESC& desc); |
| 212 | |
| 213 | /** Options describing the evolver. */ |
| 214 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 215 | void setOptions(const PARTICLE_VELOCITY_DESC& options) { mDesc = options; } |
| 216 | |
| 217 | /** @copydoc setOptions */ |
| 218 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 219 | const PARTICLE_VELOCITY_DESC& getOptions() const { return mDesc; } |
| 220 | |
| 221 | /** @copydoc ParticleEvolver::getProperties */ |
| 222 | const ParticleEvolverProperties& getProperties() const override |
| 223 | { |
| 224 | static const ParticleEvolverProperties sProperties(true, 0); |
| 225 | return sProperties; |
| 226 | } |
| 227 | |
| 228 | /** Creates a new particle velocity evolver. */ |
| 229 | BS_SCRIPT_EXPORT(ec:T) |
| 230 | static SPtr<ParticleVelocity> create(const PARTICLE_VELOCITY_DESC& desc); |
| 231 | |
| 232 | /** Creates a new particle velocity evolver. */ |
| 233 | BS_SCRIPT_EXPORT(ec:T) |
| 234 | static SPtr<ParticleVelocity> create(); |
| 235 | private: |
| 236 | /** @copydoc ParticleEvolver::evolve */ |
| 237 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 238 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 239 | |
| 240 | PARTICLE_VELOCITY_DESC mDesc; |
| 241 | |
| 242 | /************************************************************************/ |
| 243 | /* RTTI */ |
| 244 | /************************************************************************/ |
| 245 | public: |
| 246 | friend class ParticleVelocityRTTI; |
| 247 | static RTTITypeBase* getRTTIStatic(); |
| 248 | RTTITypeBase* getRTTI() const override; |
| 249 | }; |
| 250 | |
| 251 | /** Structure used for initializing a ParticleForce object. */ |
| 252 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleForceOptions) PARTICLE_FORCE_DESC |
| 253 | { |
| 254 | /** Determines the force of the particles evaluated over particle lifetime. */ |
| 255 | Vector3Distribution force = Vector3(0.0f, 0.0f, 0.0f); |
| 256 | |
| 257 | /** True if the force is provided in world space, false if in local space. */ |
| 258 | bool worldSpace = false; |
| 259 | }; |
| 260 | |
| 261 | /** Applies an arbitrary force to the particles. */ |
| 262 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleForce : public ParticleEvolver |
| 263 | { |
| 264 | public: |
| 265 | ParticleForce() = default; |
| 266 | ParticleForce(const PARTICLE_FORCE_DESC&desc); |
| 267 | |
| 268 | /** Options describing the evolver. */ |
| 269 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 270 | void setOptions(const PARTICLE_FORCE_DESC& options) { mDesc = options; } |
| 271 | |
| 272 | /** @copydoc setOptions */ |
| 273 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 274 | const PARTICLE_FORCE_DESC& getOptions() const { return mDesc; } |
| 275 | |
| 276 | /** @copydoc ParticleEvolver::getProperties */ |
| 277 | const ParticleEvolverProperties& getProperties() const override |
| 278 | { |
| 279 | static const ParticleEvolverProperties sProperties(true, 0); |
| 280 | return sProperties; |
| 281 | } |
| 282 | |
| 283 | /** Creates a new particle force evolver. */ |
| 284 | BS_SCRIPT_EXPORT(ec:T) |
| 285 | static SPtr<ParticleForce> create(const PARTICLE_FORCE_DESC& desc); |
| 286 | |
| 287 | /** Creates a new particle force evolver. */ |
| 288 | BS_SCRIPT_EXPORT(ec:T) |
| 289 | static SPtr<ParticleForce> create(); |
| 290 | private: |
| 291 | /** @copydoc ParticleEvolver::evolve */ |
| 292 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 293 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 294 | |
| 295 | PARTICLE_FORCE_DESC mDesc; |
| 296 | |
| 297 | /************************************************************************/ |
| 298 | /* RTTI */ |
| 299 | /************************************************************************/ |
| 300 | public: |
| 301 | friend class ParticleForceRTTI; |
| 302 | static RTTITypeBase* getRTTIStatic(); |
| 303 | RTTITypeBase* getRTTI() const override; |
| 304 | }; |
| 305 | |
| 306 | /** Structure used for initializing a ParticleGravity object. */ |
| 307 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleGravityOptions) PARTICLE_GRAVITY_DESC |
| 308 | { |
| 309 | /** Scale which to apply to the gravity value retrieved from the physics sub-system. */ |
| 310 | float scale = 1.0f; |
| 311 | }; |
| 312 | |
| 313 | /** Applies gravity to the particles. */ |
| 314 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleGravity : public ParticleEvolver |
| 315 | { |
| 316 | public: |
| 317 | ParticleGravity() = default; |
| 318 | ParticleGravity(const PARTICLE_GRAVITY_DESC& desc); |
| 319 | |
| 320 | /** Options describing the evolver. */ |
| 321 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 322 | void setOptions(const PARTICLE_GRAVITY_DESC& options) { mDesc = options; } |
| 323 | |
| 324 | /** @copydoc setOptions */ |
| 325 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 326 | const PARTICLE_GRAVITY_DESC& getOptions() const { return mDesc; } |
| 327 | |
| 328 | /** @copydoc ParticleEvolver::getProperties */ |
| 329 | const ParticleEvolverProperties& getProperties() const override |
| 330 | { |
| 331 | static const ParticleEvolverProperties sProperties(true, 0); |
| 332 | return sProperties; |
| 333 | } |
| 334 | |
| 335 | /** Creates a new particle gravity evolver. */ |
| 336 | BS_SCRIPT_EXPORT(ec:T) |
| 337 | static SPtr<ParticleGravity> create(const PARTICLE_GRAVITY_DESC& desc); |
| 338 | |
| 339 | /** Creates a new particle gravity evolver. */ |
| 340 | BS_SCRIPT_EXPORT(ec:T) |
| 341 | static SPtr<ParticleGravity> create(); |
| 342 | private: |
| 343 | /** @copydoc ParticleEvolver::evolve */ |
| 344 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 345 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 346 | |
| 347 | PARTICLE_GRAVITY_DESC mDesc; |
| 348 | |
| 349 | /************************************************************************/ |
| 350 | /* RTTI */ |
| 351 | /************************************************************************/ |
| 352 | public: |
| 353 | friend class ParticleGravityRTTI; |
| 354 | static RTTITypeBase* getRTTIStatic(); |
| 355 | RTTITypeBase* getRTTI() const override; |
| 356 | }; |
| 357 | |
| 358 | /** Structure used for initializing a ParticleColor object. */ |
| 359 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleColorOptions) PARTICLE_COLOR_DESC |
| 360 | { |
| 361 | /** Determines the color of the particles evaluated over particle lifetime. */ |
| 362 | ColorDistribution color = Color::White; |
| 363 | }; |
| 364 | |
| 365 | /** Changes the color of the particles over the particle lifetime. */ |
| 366 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleColor : public ParticleEvolver |
| 367 | { |
| 368 | public: |
| 369 | ParticleColor() = default; // RTTI only |
| 370 | ParticleColor(const PARTICLE_COLOR_DESC& desc); |
| 371 | |
| 372 | /** Options describing the evolver. */ |
| 373 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 374 | void setOptions(const PARTICLE_COLOR_DESC& options) { mDesc = options; } |
| 375 | |
| 376 | /** @copydoc setOptions */ |
| 377 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 378 | const PARTICLE_COLOR_DESC& getOptions() const { return mDesc; } |
| 379 | |
| 380 | /** @copydoc ParticleEvolver::getProperties */ |
| 381 | const ParticleEvolverProperties& getProperties() const override |
| 382 | { |
| 383 | static const ParticleEvolverProperties sProperties(true, 0); |
| 384 | return sProperties; |
| 385 | } |
| 386 | |
| 387 | /** Creates a new particle color evolver. */ |
| 388 | BS_SCRIPT_EXPORT(ec:T) |
| 389 | static SPtr<ParticleColor> create(const PARTICLE_COLOR_DESC& desc); |
| 390 | |
| 391 | /** Creates a new particle color evolver. */ |
| 392 | BS_SCRIPT_EXPORT(ec:T) |
| 393 | static SPtr<ParticleColor> create(); |
| 394 | private: |
| 395 | /** @copydoc ParticleEvolver::evolve */ |
| 396 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 397 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 398 | |
| 399 | PARTICLE_COLOR_DESC mDesc; |
| 400 | |
| 401 | /************************************************************************/ |
| 402 | /* RTTI */ |
| 403 | /************************************************************************/ |
| 404 | public: |
| 405 | friend class ParticleColorRTTI; |
| 406 | static RTTITypeBase* getRTTIStatic(); |
| 407 | RTTITypeBase* getRTTI() const override; |
| 408 | }; |
| 409 | |
| 410 | /** Structure used for initializing a ParticleSize object. */ |
| 411 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleSizeOptions) PARTICLE_SIZE_DESC |
| 412 | { |
| 413 | /** |
| 414 | * Determines the uniform size of the particles evaluated over particle lifetime. Only used if 3D size is disabled. |
| 415 | */ |
| 416 | FloatDistribution size = 1.0f; |
| 417 | |
| 418 | /** |
| 419 | * Determines the non-uniform size of the particles evaluated over particle lifetime. Only used if 3D size is |
| 420 | * enabled. |
| 421 | */ |
| 422 | Vector3Distribution size3D = Vector3::ONE; |
| 423 | |
| 424 | /** |
| 425 | * Determines should the size be evaluated uniformly for all dimensions, or evaluate each dimension with its own |
| 426 | * distribution. |
| 427 | */ |
| 428 | bool use3DSize = false; |
| 429 | }; |
| 430 | |
| 431 | /** Changes the size of the particles over the particle lifetime. */ |
| 432 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleSize : public ParticleEvolver |
| 433 | { |
| 434 | public: |
| 435 | ParticleSize() = default; |
| 436 | ParticleSize(const PARTICLE_SIZE_DESC& desc); |
| 437 | |
| 438 | /** Options describing the evolver. */ |
| 439 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 440 | void setOptions(const PARTICLE_SIZE_DESC& options) { mDesc = options; } |
| 441 | |
| 442 | /** @copydoc setOptions */ |
| 443 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 444 | const PARTICLE_SIZE_DESC& getOptions() const { return mDesc; } |
| 445 | |
| 446 | /** @copydoc ParticleEvolver::getProperties */ |
| 447 | const ParticleEvolverProperties& getProperties() const override |
| 448 | { |
| 449 | static const ParticleEvolverProperties sProperties(true, 0); |
| 450 | return sProperties; |
| 451 | } |
| 452 | |
| 453 | /** Creates a new particle size evolver. */ |
| 454 | BS_SCRIPT_EXPORT(ec:T) |
| 455 | static SPtr<ParticleSize> create(const PARTICLE_SIZE_DESC& desc); |
| 456 | |
| 457 | /** Creates a new particle size evolver. */ |
| 458 | BS_SCRIPT_EXPORT(ec:T) |
| 459 | static SPtr<ParticleSize> create(); |
| 460 | private: |
| 461 | /** @copydoc ParticleEvolver::evolve */ |
| 462 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 463 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 464 | |
| 465 | PARTICLE_SIZE_DESC mDesc; |
| 466 | |
| 467 | /************************************************************************/ |
| 468 | /* RTTI */ |
| 469 | /************************************************************************/ |
| 470 | public: |
| 471 | friend class ParticleSizeRTTI; |
| 472 | static RTTITypeBase* getRTTIStatic(); |
| 473 | RTTITypeBase* getRTTI() const override; |
| 474 | }; |
| 475 | |
| 476 | /** Structure used for initializing a ParticleRotation object. */ |
| 477 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleRotationOptions) PARTICLE_ROTATION_DESC |
| 478 | { |
| 479 | /** |
| 480 | * Determines the rotation of the particles in degrees, applied around the particle's local Z axis. Only used if |
| 481 | * 3D rotation is disabled. |
| 482 | */ |
| 483 | FloatDistribution rotation = 0.0f; |
| 484 | |
| 485 | /** Determines the rotation of the particles in degrees as Euler angles. Only used if 3D rotation is enabled. */ |
| 486 | Vector3Distribution rotation3D = Vector3::ZERO; |
| 487 | |
| 488 | /** |
| 489 | * Determines should the particle rotation be a single angle applied around a Z axis (if disabled), or a |
| 490 | * set of Euler angles that allow you to rotate around every axis (if enabled). |
| 491 | */ |
| 492 | bool use3DRotation = false; |
| 493 | }; |
| 494 | |
| 495 | /** Rotates the particles over the particle lifetime. */ |
| 496 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleRotation : public ParticleEvolver |
| 497 | { |
| 498 | public: |
| 499 | ParticleRotation() = default; |
| 500 | ParticleRotation(const PARTICLE_ROTATION_DESC& desc); |
| 501 | |
| 502 | /** Options describing the evolver. */ |
| 503 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 504 | void setOptions(const PARTICLE_ROTATION_DESC& options) { mDesc = options; } |
| 505 | |
| 506 | /** @copydoc setOptions */ |
| 507 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 508 | const PARTICLE_ROTATION_DESC& getOptions() const { return mDesc; } |
| 509 | |
| 510 | /** @copydoc ParticleEvolver::getProperties */ |
| 511 | const ParticleEvolverProperties& getProperties() const override |
| 512 | { |
| 513 | static const ParticleEvolverProperties sProperties(true, 0); |
| 514 | return sProperties; |
| 515 | } |
| 516 | |
| 517 | /** Creates a new particle rotation evolver. */ |
| 518 | BS_SCRIPT_EXPORT(ec:T) |
| 519 | static SPtr<ParticleRotation> create(const PARTICLE_ROTATION_DESC& desc); |
| 520 | |
| 521 | /** Creates a new particle rotation evolver. */ |
| 522 | BS_SCRIPT_EXPORT(ec:T) |
| 523 | static SPtr<ParticleRotation> create(); |
| 524 | private: |
| 525 | /** @copydoc ParticleEvolver::evolve */ |
| 526 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 527 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 528 | |
| 529 | PARTICLE_ROTATION_DESC mDesc; |
| 530 | |
| 531 | /************************************************************************/ |
| 532 | /* RTTI */ |
| 533 | /************************************************************************/ |
| 534 | public: |
| 535 | friend class ParticleRotationRTTI; |
| 536 | static RTTITypeBase* getRTTIStatic(); |
| 537 | RTTITypeBase* getRTTI() const override; |
| 538 | }; |
| 539 | |
| 540 | /** Types of collision modes that ParticleCollisions evolver can operate in. */ |
| 541 | enum class BS_SCRIPT_EXPORT(m:Particles) ParticleCollisionMode |
| 542 | { |
| 543 | /** Particles will collide with a user-provided set of planes. */ |
| 544 | Plane, |
| 545 | |
| 546 | /** Particles will collide with physics colliders in the scene. */ |
| 547 | World, |
| 548 | }; |
| 549 | |
| 550 | /** Structure used for initializing a ParticleCollisions object. */ |
| 551 | struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:ParticleCollisionsOptions) PARTICLE_COLLISIONS_DESC |
| 552 | { |
| 553 | /** Collision mode determining with which geometry the particles will interact with. */ |
| 554 | ParticleCollisionMode mode = ParticleCollisionMode::Plane; |
| 555 | |
| 556 | /** |
| 557 | * Determines the elasticity (bounciness) of the particle collision. Lower values make the collision less bouncy |
| 558 | * and higher values more. |
| 559 | */ |
| 560 | float restitution = 1.0f; |
| 561 | |
| 562 | /** |
| 563 | * Determines how much velocity should a particle lose after a collision, in percent of its current velocity. In |
| 564 | * range [0, 1]. |
| 565 | */ |
| 566 | float dampening = 0.5f; |
| 567 | |
| 568 | /** |
| 569 | * Determines how much should the particle lifetime be reduced after a collision, in percent of its original |
| 570 | * lifetime. In range [0, 1]. |
| 571 | */ |
| 572 | float lifetimeLoss = 0.0f; |
| 573 | |
| 574 | /** Radius of every individual particle used for collisions, in meters. */ |
| 575 | float radius = 0.01f; |
| 576 | |
| 577 | /** |
| 578 | * Physics layers that determine which objects will particle collide with. Only relevant when using the World |
| 579 | * collision mode. |
| 580 | */ |
| 581 | UINT64 layer = 0xFFFFFFFFFFFFFFFF; |
| 582 | }; |
| 583 | |
| 584 | /** Particle evolver that allows particles to collide with the world. */ |
| 585 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) ParticleCollisions : public ParticleEvolver |
| 586 | { |
| 587 | public: |
| 588 | ParticleCollisions() = default; |
| 589 | ParticleCollisions(const PARTICLE_COLLISIONS_DESC& desc); |
| 590 | |
| 591 | /** |
| 592 | * Determines a set of planes to use when using the Plane collision mode. Planes are expected to be in world |
| 593 | * space. |
| 594 | */ |
| 595 | BS_SCRIPT_EXPORT(pr:setter,n:Planes) |
| 596 | void setPlanes(Vector<Plane> planes) { mCollisionPlanes = std::move(planes); } |
| 597 | |
| 598 | /** @copydoc setPlanes */ |
| 599 | BS_SCRIPT_EXPORT(pr:getter,n:Planes) |
| 600 | const Vector<Plane>& getPlanes() const { return mCollisionPlanes; } |
| 601 | |
| 602 | /** |
| 603 | * Determines a set of objects whose transforms to derive the collision planes from. Objects can move in the world |
| 604 | * and collision planes will be updated automatically. Object's negative Z axis is considered to be plane normal. |
| 605 | */ |
| 606 | BS_SCRIPT_EXPORT(pr:setter,n:PlaneObjects) |
| 607 | void setPlaneObjects(Vector<HSceneObject> objects) { mCollisionPlaneObjects = std::move(objects); } |
| 608 | |
| 609 | /** @copydoc setPlaneObjects */ |
| 610 | BS_SCRIPT_EXPORT(pr:getter,n:PlaneObjects) |
| 611 | const Vector<HSceneObject>& getPlaneObjects() const { return mCollisionPlaneObjects; } |
| 612 | |
| 613 | /** Options describing the evolver. */ |
| 614 | BS_SCRIPT_EXPORT(pr:setter,n:Options) |
| 615 | void setOptions(const PARTICLE_COLLISIONS_DESC& options) { mDesc = options; } |
| 616 | |
| 617 | /** @copydoc setOptions */ |
| 618 | BS_SCRIPT_EXPORT(pr:getter,n:Options) |
| 619 | const PARTICLE_COLLISIONS_DESC& getOptions() const { return mDesc; } |
| 620 | |
| 621 | /** @copydoc ParticleEvolver::getProperties */ |
| 622 | const ParticleEvolverProperties& getProperties() const override |
| 623 | { |
| 624 | static const ParticleEvolverProperties sProperties(false, -10000); |
| 625 | return sProperties; |
| 626 | } |
| 627 | |
| 628 | /** Creates a new particle collision evolver. */ |
| 629 | BS_SCRIPT_EXPORT(ec:T) |
| 630 | static SPtr<ParticleCollisions> create(const PARTICLE_COLLISIONS_DESC& desc); |
| 631 | |
| 632 | /** Creates a new particle collision evolver. */ |
| 633 | BS_SCRIPT_EXPORT(ec:T) |
| 634 | static SPtr<ParticleCollisions> create(); |
| 635 | private: |
| 636 | /** @copydoc ParticleEvolver::evolve */ |
| 637 | void evolve(Random& random, const ParticleSystemState& state, ParticleSet& set, UINT32 startIdx, |
| 638 | UINT32 count, bool spacing, float spacingOffset) const override; |
| 639 | |
| 640 | PARTICLE_COLLISIONS_DESC mDesc; |
| 641 | |
| 642 | Vector<Plane> mCollisionPlanes; |
| 643 | Vector<HSceneObject> mCollisionPlaneObjects; |
| 644 | |
| 645 | /************************************************************************/ |
| 646 | /* RTTI */ |
| 647 | /************************************************************************/ |
| 648 | public: |
| 649 | friend class ParticleCollisionsRTTI; |
| 650 | static RTTITypeBase* getRTTIStatic(); |
| 651 | RTTITypeBase* getRTTI() const override; |
| 652 | }; |
| 653 | |
| 654 | /** @} */ |
| 655 | } |
| 656 | |