ParticleSystemRenderer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // ParticleSystemRenderer.h
  3. // cocos2d_libs
  4. //
  5. // Created by 徐俊杰 on 2020/4/24.
  6. //
  7. #ifndef ParticleSystemRenderer_h
  8. #define ParticleSystemRenderer_h
  9. #include "2d/CCComponent.h"
  10. //#include "cocos2d.h"
  11. #include "rparticle/Macros/RParticleMacros.h"
  12. #include "rparticle/RParticleSystem.h"
  13. #include "rparticle/Modules/UVModule.h"
  14. #define COMPONENT_PS_RENDERER "component_ps_renderer_un"
  15. NS_RRP_BEGIN
  16. class Mesh;
  17. //struct MinMaxAABB;
  18. //struct ParticleSystemVertex;
  19. typedef cocos2d::V3F_C4B_T2F_Quad ParticleSystemVertex;
  20. struct ParticleSystemRendererData
  21. {
  22. // Must match the one in RendererModuleUI.cs
  23. enum { kMaxNumParticleMeshes = 4 };
  24. bool orthographic;
  25. float scale;
  26. int renderMode; ///< enum { Billboard = 0, Stretched = 1, Horizontal Billboard = 2, Vertical Billboard = 3, Mesh = 4 }
  27. int sortMode; ///< enum { None = 0, By Distance = 1, Youngest First = 2, Oldest First = 3 }
  28. float maxParticleSize; ///< How large is a particle allowed to be on screen at most? 1 is entire viewport. 0.5 is half viewport.
  29. float cameraVelocityScale; ///< How much the camera motion is factored in when determining particle stretching.
  30. float velocityScale; ///< When Stretch Particles is enabled, defines the length of the particle compared to its velocity.
  31. float lengthScale; ///< When Stretch Particles is enabled, defines the length of the particle compared to its width.
  32. float sortingFudge; ///< Lower the number, most likely that these particles will appear in front of other transparent objects, including other particles.
  33. float normalDirection; ///< Value between 0.0 and 1.0. If 1.0 is used, normals will point towards camera. If 0.0 is used, normals will point out in the corner direction of the particle.
  34. Mesh* cachedMesh[kMaxNumParticleMeshes];
  35. /// Node hooked into the mesh user list of cached meshes so we get notified
  36. /// when a mesh goes away.
  37. ///
  38. /// NOTE: Must be initialized properly after construction to point to the
  39. /// ParticleSystemRenderer.
  40. //ListNode<Object> cachedMeshUserNode[kMaxNumParticleMeshes];
  41. std::vector<RRP_PARTICLEQUAD_VERTEX_INFO> cachedVertexInfos;
  42. };
  43. //struct ParticleSystemParticles;
  44. //struct ParticleSystemParticlesTempData;
  45. //class ParticleSystem;
  46. struct ParticleSystemGeomConstInputData;
  47. class CC_DLL ParticleSystemRenderer
  48. {
  49. public:
  50. DECLARE_MODULE (ParticleSystemRenderer)
  51. // static ParticleSystemRenderer* create();
  52. virtual ~ParticleSystemRenderer();
  53. // int GetRenderMode(){return 1;};
  54. ParticleSystemRenderer (/*MemLabelId label, ObjectCreationMode mode*/);
  55. virtual void Render (RParticleSystem* system, ParticleSystemVertex* vbPtr/*int materialIndex, const ChannelAssigns& channels*/, const Matrix4x4f &transform);
  56. static void RenderMultiple (/*const BatchInstanceData* instances, size_t count, const ChannelAssigns& channels*/);
  57. //virtual void GetLocalAABB (AABB& result);
  58. //virtual void GetWorldAABB (AABB& result);
  59. virtual float GetSortingFudge () const;
  60. template<class TransferFunction>
  61. void Transfer (TransferFunction& transfer);
  62. //virtual void CheckConsistency ();
  63. virtual void Reset ();
  64. //virtual void AwakeFromLoad (AwakeFromLoadMode awakeMode);
  65. //void Update (const AABB& aabb);
  66. //void UpdateLocalAABB();
  67. void SetDirty () {}
  68. virtual void RendererBecameVisible();
  69. virtual void RendererBecameInvisible();
  70. static void SetUsesAxisOfRotationRec(RParticleSystem& system, bool first);
  71. //static void CombineBoundsRec(RParticleSystem& shuriken, MinMaxAABB& aabb, bool first);
  72. GET_SET_DIRTY (bool, Orthographic, m_Data.orthographic);
  73. GET_SET_DIRTY (float, Scale, m_Data.scale);
  74. GET_SET_DIRTY (int, RenderMode, m_Data.renderMode);
  75. GET_SET_DIRTY (int, SortMode, m_Data.sortMode) ;
  76. GET_SET_DIRTY (float, MaxParticleSize, m_Data.maxParticleSize) ;
  77. GET_SET_DIRTY (float, CameraVelocityScale, m_Data.cameraVelocityScale) ;
  78. GET_SET_DIRTY (float, VelocityScale, m_Data.velocityScale) ;
  79. GET_SET_DIRTY (float, LengthScale, m_Data.lengthScale) ;
  80. GET_SET_DIRTY (float, NormalDirection, m_Data.normalDirection) ;
  81. void SetSortingFudge(float value) { m_Data.sortingFudge = value; }
  82. std::vector<RRP_PARTICLEQUAD_VERTEX_INFO>& GetCachedVertexInfos() { return m_Data.cachedVertexInfos; }
  83. //void SetMesh (PPtr<Mesh> mesh){
  84. // m_Mesh[0] = mesh;
  85. // SetDirty();
  86. // UpdateCachedMesh ();
  87. //}
  88. //PPtr<Mesh> GetMesh () const {
  89. // return m_Mesh[0];
  90. //}
  91. //
  92. //const PPtr<Mesh>* GetMeshes () const {
  93. // return m_Mesh;
  94. //}
  95. const ParticleSystemRendererData& GetData() const {
  96. return m_Data;
  97. }
  98. #if UNITY_EDITOR
  99. bool GetEditorEnabled() const { return m_EditorEnabled; }
  100. void SetEditorEnabled(bool value) { m_EditorEnabled = value; }
  101. #endif
  102. // For mesh we use world space rotation, else screen space
  103. bool GetScreenSpaceRotation() const { return m_Data.renderMode != kSRMMesh; };
  104. private:
  105. // bool init();
  106. // from Renderer
  107. //virtual void UpdateRenderer ();
  108. void UpdateCachedMesh ();
  109. //void OnDidDeleteMesh (Mesh* mesh);
  110. static void CalculateTotalParticleCount(UInt32& totalNumberOfParticles, RParticleSystem& shuriken, bool first);
  111. static void CombineParticleBuffersRec(int& offset, ParticleSystemParticles& particles, ParticleSystemParticlesTempData& psTemp, RParticleSystem& shuriken, bool first, bool needsAxisOfRotation);
  112. //static void RenderBatch (const BatchInstanceData* instances, size_t count, size_t numParticles, const ChannelAssigns& channels);
  113. static void RenderInternal (RParticleSystem& system, const ParticleSystemRenderer& renderer, ParticleSystemVertex* vbPtr, UInt32 particleCountTotal, const Matrix4x4f &transform);
  114. ParticleSystemRendererData m_Data;
  115. //dynamic_array<UInt16> m_CachedIndexBuffer[ParticleSystemRendererData::kMaxNumParticleMeshes];
  116. //PPtr<Mesh> m_Mesh[ParticleSystemRendererData::kMaxNumParticleMeshes];
  117. MinMaxAABB m_LocalSpaceAABB;
  118. #if UNITY_EDITOR
  119. bool m_EditorEnabled;
  120. #endif
  121. };
  122. NS_RRP_END
  123. #endif /* ParticleSystemRenderer_h */