ParticleEmitterResource.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Resource/ResourceObject.h>
  7. #include <AnKi/Resource/RenderingKey.h>
  8. #include <AnKi/Resource/MaterialResource.h>
  9. #include <AnKi/Math.h>
  10. #include <AnKi/Gr.h>
  11. namespace anki {
  12. class XmlElement;
  13. /// @addtogroup resource
  14. /// @{
  15. /// The particle emitter properties. Different class from ParticleEmitterResource so it can be inherited
  16. class ParticleEmitterProperties
  17. {
  18. public:
  19. /// @name Particle specific properties
  20. /// @{
  21. class
  22. {
  23. public:
  24. Second m_minLife = 10.0;
  25. Second m_maxLife = 10.0;
  26. F32 m_minMass = 1.0f;
  27. F32 m_maxMass = 1.0f;
  28. F32 m_minInitialSize = 1.0f;
  29. F32 m_maxInitialSize = 1.0f;
  30. F32 m_minFinalSize = 1.0f;
  31. F32 m_maxFinalSize = 1.0f;
  32. F32 m_minInitialAlpha = 1.0f;
  33. F32 m_maxInitialAlpha = 1.0f;
  34. F32 m_minFinalAlpha = 1.0f;
  35. F32 m_maxFinalAlpha = 1.0f;
  36. Vec3 m_minForceDirection = Vec3(0.0f, 1.0f, 0.0f);
  37. Vec3 m_maxForceDirection = Vec3(0.0f, 1.0f, 0.0f);
  38. F32 m_minForceMagnitude = 0.0f;
  39. F32 m_maxForceMagnitude = 0.0f;
  40. /// If not set then it uses the world's default
  41. Vec3 m_minGravity = Vec3(MAX_F32);
  42. Vec3 m_maxGravity = Vec3(MAX_F32);
  43. /// This position is relevant to the particle emitter pos
  44. Vec3 m_minStartingPosition = Vec3(0.0);
  45. Vec3 m_maxStartingPosition = Vec3(0.0);
  46. } m_particle;
  47. /// @}
  48. /// @name Emitter specific properties
  49. /// @{
  50. U32 m_maxNumOfParticles = 16; ///< The size of the particles vector. Required
  51. F32 m_emissionPeriod = 1.0; ///< How often the emitter emits new particles. In secs. Required
  52. U32 m_particlesPerEmission = 1; ///< How many particles are emitted every emission. Required
  53. Bool m_usePhysicsEngine = false; ///< Use bullet for the simulation
  54. Vec3 m_emitterBoundingVolumeMin = Vec3(0.0f); ///< Limit the size of the emitter. Mainly for visibility tests.
  55. Vec3 m_emitterBoundingVolumeMax = Vec3(0.0f); ///< Limit the size of the emitter. Mainly for visibility tests.
  56. /// @}
  57. ParticleEmitterProperties()
  58. {
  59. }
  60. ParticleEmitterProperties(const ParticleEmitterProperties& b)
  61. {
  62. *this = b;
  63. }
  64. ParticleEmitterProperties& operator=(const ParticleEmitterProperties& b)
  65. {
  66. memcpy(this, &b, sizeof(*this));
  67. return *this;
  68. }
  69. Bool forceEnabled() const
  70. {
  71. return m_particle.m_maxForceMagnitude > 0.0f;
  72. }
  73. Bool wordGravityEnabled() const
  74. {
  75. return m_particle.m_maxGravity.x() < MAX_F32;
  76. }
  77. };
  78. /// This is the properties of the particle emitter resource
  79. class ParticleEmitterResource : public ResourceObject, private ParticleEmitterProperties
  80. {
  81. public:
  82. ParticleEmitterResource(ResourceManager* manager);
  83. ~ParticleEmitterResource();
  84. const ParticleEmitterProperties& getProperties() const
  85. {
  86. return *this;
  87. }
  88. const MaterialResourcePtr& getMaterial() const
  89. {
  90. return m_material;
  91. }
  92. /// Get program for rendering.
  93. void getRenderingInfo(const RenderingKey& key, ShaderProgramPtr& prog) const;
  94. /// Load it
  95. ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
  96. private:
  97. MaterialResourcePtr m_material;
  98. U8 m_lodCount = 1; ///< Cache the value from the material
  99. void loadInternal(const XmlElement& el);
  100. template<typename T>
  101. ANKI_USE_RESULT Error readVar(const XmlElement& rootEl, CString varName, T& minVal, T& maxVal, const T* defaultVal);
  102. };
  103. /// @}
  104. } // end namespace anki