ParticleEmitterResource.h 3.3 KB

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