afxParticleEmitter.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #ifndef _AFX_EMITTER_PARTICLE_H_
  25. #define _AFX_EMITTER_PARTICLE_H_
  26. #include "T3D/fx/particleEmitter.h"
  27. class afxPathData;
  28. class afxPath3D;
  29. class afxParticleEmitterData : public ParticleEmitterData
  30. {
  31. typedef ParticleEmitterData Parent;
  32. public:
  33. // The afx enhanced particle emitter allows fading
  34. // of particle color, size, velocity, and/or offset.
  35. // Fading is controlled by a common value which is
  36. // set externally using setFadeAmount().
  37. //
  38. bool fade_velocity;
  39. bool fade_offset;
  40. Point3F pe_vector;
  41. // new -- consider vector in world space?
  42. bool pe_vector_is_world;
  43. // new -- transform paths?
  44. StringTableEntry tpaths_string; //
  45. Vector<afxPathData*> tPathDataBlocks; // datablocks for paths
  46. Vector<U32> tPathDataBlockIds; // datablock IDs which correspond to the pathDataBlocks
  47. public:
  48. /*C*/ afxParticleEmitterData();
  49. /*C*/ afxParticleEmitterData(const afxParticleEmitterData&, bool = false);
  50. void packData(BitStream* stream) override;
  51. void unpackData(BitStream* stream) override;
  52. bool onAdd() override;
  53. bool preload(bool server, String &errorStr) override;
  54. bool allowSubstitutions() const override { return true; }
  55. static void initPersistFields();
  56. DECLARE_CONOBJECT(afxParticleEmitterData);
  57. };
  58. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  59. // VECTOR
  60. class afxParticleEmitterVectorData : public afxParticleEmitterData
  61. {
  62. typedef afxParticleEmitterData Parent;
  63. public:
  64. /*C*/ afxParticleEmitterVectorData();
  65. /*C*/ afxParticleEmitterVectorData(const afxParticleEmitterVectorData&, bool = false);
  66. void packData(BitStream* stream) override;
  67. void unpackData(BitStream* stream) override;
  68. bool onAdd() override;
  69. bool preload(bool server, String &errorStr) override;
  70. bool allowSubstitutions() const override { return true; }
  71. static void initPersistFields();
  72. DECLARE_CONOBJECT(afxParticleEmitterVectorData);
  73. };
  74. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  75. // CONE
  76. class afxParticleEmitterConeData : public afxParticleEmitterData
  77. {
  78. typedef afxParticleEmitterData Parent;
  79. public:
  80. F32 spread_min;
  81. F32 spread_max;
  82. public:
  83. /*C*/ afxParticleEmitterConeData();
  84. /*C*/ afxParticleEmitterConeData(const afxParticleEmitterConeData&, bool = false);
  85. void packData(BitStream* stream) override;
  86. void unpackData(BitStream* stream) override;
  87. bool onAdd() override;
  88. bool preload(bool server, String &errorStr) override;
  89. bool allowSubstitutions() const override { return true; }
  90. static void initPersistFields();
  91. DECLARE_CONOBJECT(afxParticleEmitterConeData);
  92. };
  93. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  94. // PATH
  95. class afxParticleEmitterPathData : public afxParticleEmitterData
  96. {
  97. typedef afxParticleEmitterData Parent;
  98. public:
  99. enum PathOriginType
  100. {
  101. PATHEMIT_ORIGIN,
  102. PATHEMIT_POINT,
  103. PATHEMIT_VECTOR,
  104. PATHEMIT_TANGENT
  105. };
  106. StringTableEntry epaths_string; //
  107. Vector<afxPathData*> epathDataBlocks; // datablocks for paths
  108. Vector<U32> epathDataBlockIds; // datablock IDs which correspond to the pathDataBlocks
  109. U32 path_origin_type;
  110. bool ground_conform;
  111. bool ground_conform_terrain;
  112. bool ground_conform_interiors;
  113. F32 ground_conform_height;
  114. public:
  115. /*C*/ afxParticleEmitterPathData();
  116. /*C*/ afxParticleEmitterPathData(const afxParticleEmitterPathData&, bool = false);
  117. void packData(BitStream* stream) override;
  118. void unpackData(BitStream* stream) override;
  119. bool onAdd() override;
  120. bool preload(bool server, String &errorStr) override;
  121. void onPerformSubstitutions() override;
  122. bool allowSubstitutions() const override { return true; }
  123. static void initPersistFields();
  124. DECLARE_CONOBJECT(afxParticleEmitterPathData);
  125. };
  126. typedef afxParticleEmitterPathData::PathOriginType afxParticleEmitterPath_OriginType;
  127. DefineEnumType( afxParticleEmitterPath_OriginType );
  128. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  129. // DISC
  130. class afxParticleEmitterDiscData : public afxParticleEmitterData
  131. {
  132. typedef afxParticleEmitterData Parent;
  133. public:
  134. F32 pe_radius_min;
  135. F32 pe_radius_max;
  136. public:
  137. /*C*/ afxParticleEmitterDiscData();
  138. /*C*/ afxParticleEmitterDiscData(const afxParticleEmitterDiscData&, bool = false);
  139. void packData(BitStream* stream) override;
  140. void unpackData(BitStream* stream) override;
  141. bool onAdd() override;
  142. bool preload(bool server, String &errorStr) override;
  143. bool allowSubstitutions() const override { return true; }
  144. static void initPersistFields();
  145. DECLARE_CONOBJECT(afxParticleEmitterDiscData);
  146. };
  147. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  148. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  149. class afxParticleEmitter : public ParticleEmitter
  150. {
  151. typedef ParticleEmitter Parent;
  152. private:
  153. afxParticleEmitterData* mDataBlock;
  154. protected:
  155. Point3F pe_vector, pe_vector_norm;
  156. // these go with the "pathsTransform" field
  157. Vector<afxPath3D*> tpaths;
  158. Vector<F32> tpath_mults;
  159. U32 n_tpath_points;
  160. Point3F** tpath_points;
  161. const SimObject* afx_owner;
  162. void init_paths();
  163. void cleanup_paths();
  164. Particle* alloc_particle();
  165. ParticleData* pick_particle_type();
  166. void afx_emitParticles(const Point3F& point, const bool useLastPosition, const Point3F& velocity, const U32 numMilliseconds);
  167. void afx_emitParticles(const Point3F& start, const Point3F& end, const Point3F& velocity, const U32 numMilliseconds);
  168. void preCompute(const MatrixF& mat);
  169. void sub_particleUpdate(Particle*) override;
  170. virtual void sub_preCompute(const MatrixF& mat)=0;
  171. virtual void sub_addParticle(const Point3F& pos, const Point3F& vel, const U32 age_offset, S32 part_idx)=0;
  172. public:
  173. /*C*/ afxParticleEmitter();
  174. /*D*/ ~afxParticleEmitter();
  175. void emitParticlesExt(const MatrixF& xfm, const Point3F& point, const Point3F& velocity, const U32 numMilliseconds) override;
  176. afxParticleEmitterData* getDataBlock(){ return mDataBlock; }
  177. void setAFXOwner(const SimObject* owner) { afx_owner = owner; }
  178. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  179. bool onAdd() override;
  180. void onRemove() override;
  181. };
  182. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  183. // VECTOR
  184. class afxParticleEmitterVector : public afxParticleEmitter
  185. {
  186. typedef afxParticleEmitter Parent;
  187. private:
  188. afxParticleEmitterVectorData* mDataBlock;
  189. public:
  190. /*C*/ afxParticleEmitterVector();
  191. /*D*/ ~afxParticleEmitterVector();
  192. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  193. protected:
  194. void sub_preCompute(const MatrixF& mat) override;
  195. void sub_addParticle(const Point3F& pos, const Point3F& vel, const U32 age_offse, S32 part_idxt) override;
  196. };
  197. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  198. // CONE
  199. class afxParticleEmitterCone : public afxParticleEmitter
  200. {
  201. typedef afxParticleEmitter Parent;
  202. private:
  203. afxParticleEmitterData* mDataBlock;
  204. Point3F cone_v, cone_s0, cone_s1;
  205. public:
  206. /*C*/ afxParticleEmitterCone();
  207. /*D*/ ~afxParticleEmitterCone();
  208. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  209. protected:
  210. void sub_preCompute(const MatrixF& mat) override;
  211. void sub_addParticle(const Point3F& pos, const Point3F& vel, const U32 age_offset, S32 part_idx) override;
  212. };
  213. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  214. // PATH
  215. class afxParticleEmitterPath : public afxParticleEmitter
  216. {
  217. typedef afxParticleEmitter Parent;
  218. private:
  219. afxParticleEmitterPathData* mDataBlock;
  220. Vector<afxPath3D*> epaths;
  221. Vector<F32> epath_mults;
  222. U32 n_epath_points;
  223. Point3F** epath_points;
  224. void init_paths();
  225. void cleanup_paths();
  226. void groundConformPoint(Point3F& point, const MatrixF& mat);
  227. public:
  228. /*C*/ afxParticleEmitterPath();
  229. /*D*/ ~afxParticleEmitterPath();
  230. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  231. protected:
  232. bool onAdd() override;
  233. void onRemove() override;
  234. void sub_preCompute(const MatrixF& mat) override;
  235. void sub_addParticle(const Point3F& pos, const Point3F& vel, const U32 age_offset, S32 part_idx) override;
  236. };
  237. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  238. // DISC
  239. class afxParticleEmitterDisc : public afxParticleEmitter
  240. {
  241. typedef afxParticleEmitter Parent;
  242. private:
  243. afxParticleEmitterDiscData* mDataBlock;
  244. Point3F disc_v, disc_r;
  245. public:
  246. /*C*/ afxParticleEmitterDisc();
  247. /*D*/ ~afxParticleEmitterDisc();
  248. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  249. protected:
  250. void sub_preCompute(const MatrixF& mat) override;
  251. void sub_addParticle(const Point3F& pos, const Point3F& vel, const U32 age_offset, S32 part_idx) override;
  252. };
  253. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  254. #endif // _AFX_EMITTER_PARTICLE_H_