// // ParticleSystemRenderer.h // cocos2d_libs // // Created by 徐俊杰 on 2020/4/24. // #ifndef ParticleSystemRenderer_h #define ParticleSystemRenderer_h #include "2d/CCComponent.h" //#include "cocos2d.h" #include "rparticle/Macros/RParticleMacros.h" #include "rparticle/RParticleSystem.h" #include "rparticle/Modules/UVModule.h" #define COMPONENT_PS_RENDERER "component_ps_renderer_un" NS_RRP_BEGIN class Mesh; //struct MinMaxAABB; //struct ParticleSystemVertex; typedef cocos2d::V3F_C4B_T2F_Quad ParticleSystemVertex; struct ParticleSystemRendererData { // Must match the one in RendererModuleUI.cs enum { kMaxNumParticleMeshes = 4 }; bool orthographic; float scale; int renderMode; ///< enum { Billboard = 0, Stretched = 1, Horizontal Billboard = 2, Vertical Billboard = 3, Mesh = 4 } int sortMode; ///< enum { None = 0, By Distance = 1, Youngest First = 2, Oldest First = 3 } float maxParticleSize; ///< How large is a particle allowed to be on screen at most? 1 is entire viewport. 0.5 is half viewport. float cameraVelocityScale; ///< How much the camera motion is factored in when determining particle stretching. float velocityScale; ///< When Stretch Particles is enabled, defines the length of the particle compared to its velocity. float lengthScale; ///< When Stretch Particles is enabled, defines the length of the particle compared to its width. float sortingFudge; ///< Lower the number, most likely that these particles will appear in front of other transparent objects, including other particles. 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. Mesh* cachedMesh[kMaxNumParticleMeshes]; /// Node hooked into the mesh user list of cached meshes so we get notified /// when a mesh goes away. /// /// NOTE: Must be initialized properly after construction to point to the /// ParticleSystemRenderer. //ListNode cachedMeshUserNode[kMaxNumParticleMeshes]; std::vector cachedVertexInfos; }; //struct ParticleSystemParticles; //struct ParticleSystemParticlesTempData; //class ParticleSystem; struct ParticleSystemGeomConstInputData; class CC_DLL ParticleSystemRenderer { public: DECLARE_MODULE (ParticleSystemRenderer) // static ParticleSystemRenderer* create(); virtual ~ParticleSystemRenderer(); // int GetRenderMode(){return 1;}; ParticleSystemRenderer (/*MemLabelId label, ObjectCreationMode mode*/); virtual void Render (RParticleSystem* system, ParticleSystemVertex* vbPtr/*int materialIndex, const ChannelAssigns& channels*/, const Matrix4x4f &transform); static void RenderMultiple (/*const BatchInstanceData* instances, size_t count, const ChannelAssigns& channels*/); //virtual void GetLocalAABB (AABB& result); //virtual void GetWorldAABB (AABB& result); virtual float GetSortingFudge () const; template void Transfer (TransferFunction& transfer); //virtual void CheckConsistency (); virtual void Reset (); //virtual void AwakeFromLoad (AwakeFromLoadMode awakeMode); //void Update (const AABB& aabb); //void UpdateLocalAABB(); void SetDirty () {} virtual void RendererBecameVisible(); virtual void RendererBecameInvisible(); static void SetUsesAxisOfRotationRec(RParticleSystem& system, bool first); //static void CombineBoundsRec(RParticleSystem& shuriken, MinMaxAABB& aabb, bool first); GET_SET_DIRTY (bool, Orthographic, m_Data.orthographic); GET_SET_DIRTY (float, Scale, m_Data.scale); GET_SET_DIRTY (int, RenderMode, m_Data.renderMode); GET_SET_DIRTY (int, SortMode, m_Data.sortMode) ; GET_SET_DIRTY (float, MaxParticleSize, m_Data.maxParticleSize) ; GET_SET_DIRTY (float, CameraVelocityScale, m_Data.cameraVelocityScale) ; GET_SET_DIRTY (float, VelocityScale, m_Data.velocityScale) ; GET_SET_DIRTY (float, LengthScale, m_Data.lengthScale) ; GET_SET_DIRTY (float, NormalDirection, m_Data.normalDirection) ; void SetSortingFudge(float value) { m_Data.sortingFudge = value; } std::vector& GetCachedVertexInfos() { return m_Data.cachedVertexInfos; } //void SetMesh (PPtr mesh){ // m_Mesh[0] = mesh; // SetDirty(); // UpdateCachedMesh (); //} //PPtr GetMesh () const { // return m_Mesh[0]; //} // //const PPtr* GetMeshes () const { // return m_Mesh; //} const ParticleSystemRendererData& GetData() const { return m_Data; } #if UNITY_EDITOR bool GetEditorEnabled() const { return m_EditorEnabled; } void SetEditorEnabled(bool value) { m_EditorEnabled = value; } #endif // For mesh we use world space rotation, else screen space bool GetScreenSpaceRotation() const { return m_Data.renderMode != kSRMMesh; }; private: // bool init(); // from Renderer //virtual void UpdateRenderer (); void UpdateCachedMesh (); //void OnDidDeleteMesh (Mesh* mesh); static void CalculateTotalParticleCount(UInt32& totalNumberOfParticles, RParticleSystem& shuriken, bool first); static void CombineParticleBuffersRec(int& offset, ParticleSystemParticles& particles, ParticleSystemParticlesTempData& psTemp, RParticleSystem& shuriken, bool first, bool needsAxisOfRotation); //static void RenderBatch (const BatchInstanceData* instances, size_t count, size_t numParticles, const ChannelAssigns& channels); static void RenderInternal (RParticleSystem& system, const ParticleSystemRenderer& renderer, ParticleSystemVertex* vbPtr, UInt32 particleCountTotal, const Matrix4x4f &transform); ParticleSystemRendererData m_Data; //dynamic_array m_CachedIndexBuffer[ParticleSystemRendererData::kMaxNumParticleMeshes]; //PPtr m_Mesh[ParticleSystemRendererData::kMaxNumParticleMeshes]; MinMaxAABB m_LocalSpaceAABB; #if UNITY_EDITOR bool m_EditorEnabled; #endif }; NS_RRP_END #endif /* ParticleSystemRenderer_h */