particle.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _PARTICLE_H_
  27. #define _PARTICLE_H_
  28. #ifndef _GAMEBASE_H_
  29. #include "T3D/gameBase/gameBase.h"
  30. #endif
  31. #ifndef _GFXTEXTUREHANDLE_H_
  32. #include "gfx/gfxTextureHandle.h"
  33. #endif
  34. #include "T3D/assets/ImageAsset.h"
  35. #define MaxParticleSize 50.0
  36. struct Particle;
  37. //*****************************************************************************
  38. // Particle Data
  39. //*****************************************************************************
  40. class ParticleData : public SimDataBlock
  41. {
  42. typedef SimDataBlock Parent;
  43. public:
  44. enum PDConst
  45. {
  46. // This increase the keyframes from 4 to 8. Especially useful for premult-alpha blended particles
  47. // for which 4 keyframes is often not enough.
  48. PDC_NUM_KEYS = 8,
  49. };
  50. F32 dragCoefficient;
  51. F32 windCoefficient;
  52. F32 gravityCoefficient;
  53. F32 inheritedVelFactor;
  54. F32 constantAcceleration;
  55. S32 lifetimeMS;
  56. S32 lifetimeVarianceMS;
  57. F32 spinSpeed; // degrees per second
  58. F32 spinRandomMin;
  59. F32 spinRandomMax;
  60. bool useInvAlpha;
  61. bool animateTexture;
  62. U32 numFrames;
  63. U32 framesPerSec;
  64. LinearColorF colors[ PDC_NUM_KEYS ];
  65. F32 sizes[ PDC_NUM_KEYS ];
  66. F32 times[ PDC_NUM_KEYS ];
  67. Point2F* animTexUVs;
  68. Point2F texCoords[4]; // default: {{0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0}}
  69. Point2I animTexTiling;
  70. StringTableEntry animTexFramesString;
  71. Vector<U8> animTexFrames;
  72. DECLARE_IMAGEASSET(ParticleData, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
  73. DECLARE_ASSET_SETGET(ParticleData, Texture);
  74. static bool protectedSetSizes(void* object, const char* index, const char* data);
  75. static bool protectedSetTimes(void* object, const char* index, const char* data);
  76. void onImageChanged() {}
  77. public:
  78. ParticleData();
  79. ~ParticleData();
  80. // move this procedure to Particle
  81. void initializeParticle(Particle*, const Point3F&);
  82. void packData(BitStream* stream);
  83. void unpackData(BitStream* stream);
  84. bool onAdd();
  85. bool preload(bool server, String &errorStr);
  86. DECLARE_CONOBJECT(ParticleData);
  87. static void initPersistFields();
  88. bool reload(char errorBuffer[256]);
  89. public:
  90. /*C*/ ParticleData(const ParticleData&, bool = false);
  91. virtual void onPerformSubstitutions();
  92. virtual bool allowSubstitutions() const { return true; }
  93. protected:
  94. F32 spinBias;
  95. bool randomizeSpinDir;
  96. public:
  97. DECLARE_IMAGEASSET(ParticleData, TextureExt, onImageChanged, GFXStaticTextureSRGBProfile);
  98. DECLARE_ASSET_SETGET(ParticleData, TextureExt);
  99. bool constrain_pos;
  100. F32 start_angle;
  101. F32 angle_variance;
  102. F32 sizeBias;
  103. public:
  104. bool loadParameters();
  105. bool reload(String &errorStr);
  106. };
  107. //*****************************************************************************
  108. // Particle
  109. //
  110. // This structure should be as small as possible.
  111. //*****************************************************************************
  112. struct Particle
  113. {
  114. Point3F pos; // current instantaneous position
  115. Point3F vel; // " " velocity
  116. Point3F acc; // Constant acceleration
  117. Point3F orientDir; // direction particle should go if using oriented particles
  118. U32 totalLifetime; // Total ms that this instance should be "live"
  119. ParticleData* dataBlock; // datablock that contains global parameters for
  120. // this instance
  121. U32 currentAge;
  122. // are these necessary to store here? - they are interpolated in real time
  123. LinearColorF color;
  124. F32 size;
  125. F32 spinSpeed;
  126. Particle * next;
  127. Point3F pos_local;
  128. F32 t_last;
  129. Point3F radial_v; // radial vector for concentric effects
  130. // note -- for non-oriented particles, we use orientDir.x to store the billboard start angle.
  131. };
  132. #endif // _PARTICLE_H_