Plasma Engine  2.0
Loading...
Searching...
No Matches
ClothSheetComponent.h
1#pragma once
2
3#include <Core/World/ComponentManager.h>
4#include <GameEngine/Physics/ClothSheetSimulator.h>
5#include <RendererCore/Components/RenderComponent.h>
6#include <RendererCore/Meshes/MeshBufferResource.h>
7#include <RendererCore/Pipeline/RenderData.h>
8#include <RendererCore/Pipeline/Renderer.h>
9
12
14
15class PL_GAMECOMPONENTS_DLL plClothSheetComponentManager : public plComponentManager<class plClothSheetComponent, plBlockStorageType::FreeList>
16{
17public:
20
21 virtual void Initialize() override;
22
23private:
24 void Update(const plWorldModule::UpdateContext& context);
25 void UpdateBounds(const plWorldModule::UpdateContext& context);
26};
27
29
30class PL_GAMECOMPONENTS_DLL plClothSheetRenderData final : public plRenderData
31{
32 PL_ADD_DYNAMIC_REFLECTION(plClothSheetRenderData, plRenderData);
33
34public:
35 plUInt32 m_uiUniqueID = 0;
36 plArrayPtr<plVec3> m_Positions;
37 plArrayPtr<plUInt16> m_Indices;
38 plUInt16 m_uiVerticesX;
39 plUInt16 m_uiVerticesY;
40 plColor m_Color;
41
42 plMaterialResourceHandle m_hMaterial;
43};
44
45class PL_GAMECOMPONENTS_DLL plClothSheetRenderer : public plRenderer
46{
47 PL_ADD_DYNAMIC_REFLECTION(plClothSheetRenderer, plRenderer);
48 PL_DISALLOW_COPY_AND_ASSIGN(plClothSheetRenderer);
49
50public:
53
54 virtual void GetSupportedRenderDataCategories(plHybridArray<plRenderData::Category, 8>& ref_categories) const override;
55 virtual void GetSupportedRenderDataTypes(plHybridArray<const plRTTI*, 8>& ref_types) const override;
56 virtual void RenderBatch(const plRenderViewContext& renderContext, const plRenderPipelinePass* pPass, const plRenderDataBatch& batch) const override;
57
58
59protected:
60 void CreateVertexBuffer();
61
62 plDynamicMeshBufferResourceHandle m_hDynamicMeshBuffer;
63};
64
66struct PL_GAMECOMPONENTS_DLL plClothSheetFlags
67{
68 using StorageType = plUInt16;
69
70 enum Enum
71 {
72 FixedCornerTopLeft = PL_BIT(0),
73 FixedCornerTopRight = PL_BIT(1),
74 FixedCornerBottomRight = PL_BIT(2),
75 FixedCornerBottomLeft = PL_BIT(3),
76 FixedEdgeTop = PL_BIT(4),
77 FixedEdgeRight = PL_BIT(5),
78 FixedEdgeBottom = PL_BIT(6),
79 FixedEdgeLeft = PL_BIT(7),
80
81 Default = FixedEdgeTop
82 };
83
84 struct Bits
85 {
86 StorageType FixedCornerTopLeft : 1;
87 StorageType FixedCornerTopRight : 1;
88 StorageType FixedCornerBottomRight : 1;
89 StorageType FixedCornerBottomLeft : 1;
90 StorageType FixedEdgeTop : 1;
91 StorageType FixedEdgeRight : 1;
92 StorageType FixedEdgeBottom : 1;
93 StorageType FixedEdgeLeft : 1;
94 };
95};
96
97PL_DECLARE_REFLECTABLE_TYPE(PL_GAMECOMPONENTS_DLL, plClothSheetFlags);
98
105class PL_GAMECOMPONENTS_DLL plClothSheetComponent : public plRenderComponent
106{
108
110 // plComponent
111
112public:
113 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
114 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
115
116protected:
117 virtual void OnActivated() override;
118 virtual void OnSimulationStarted() override;
119 virtual void OnDeactivated() override;
120
122 // plRenderComponent
123
124public:
125 virtual plResult GetLocalBounds(plBoundingBoxSphere& ref_bounds, bool& ref_bAlwaysVisible, plMsgUpdateLocalBounds& ref_msg) override;
126
127private:
128 void OnMsgExtractRenderData(plMsgExtractRenderData& msg) const;
129
131 // plClothSheetComponent
132
133public:
136
138 void SetSize(plVec2 vVal); // [ property ]
139 plVec2 GetSize() const { return m_vSize; } // [ property ]
140
147 void SetSegments(plVec2U32 vVal); // [ property ]
148 plVec2U32 GetSegments() const { return m_vSegments; } // [ property ]
149
151 void SetSlack(plVec2 vVal); // [ property ]
152 plVec2 GetSlack() const { return m_vSlack; } // [ property ]
153
155 float m_fWindInfluence = 0.3f; // [ property ]
156
158 float m_fDamping = 0.5f; // [ property ]
159
161 plColor m_Color = plColor::White; // [ property ]
162
164 void SetFlags(plBitflags<plClothSheetFlags> flags); // [ property ]
165 plBitflags<plClothSheetFlags> GetFlags() const { return m_Flags; } // [ property ]
166
167 void SetMaterialFile(const char* szFile); // [ property ]
168 const char* GetMaterialFile() const; // [ property ]
169
170 plMaterialResourceHandle m_hMaterial; // [ property ]
171
172private:
173 void Update();
174 void SetupCloth();
175
176 plVec2 m_vSize;
177 plVec2 m_vSlack;
178 plVec2U32 m_vSegments;
180
181 plUInt8 m_uiSleepCounter = 0;
182 mutable plUInt8 m_uiVisibleCounter = 0;
183 plUInt8 m_uiCheckEquilibriumCounter = 0;
184 plClothSimulator m_Simulator;
185
186 plBoundingBox m_Bbox;
187};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Simulates a rectangular piece of cloth.
Definition ClothSheetComponent.h:106
Definition ClothSheetComponent.h:16
Definition ClothSheetComponent.h:31
Definition ClothSheetComponent.h:46
A simple simulator for swinging and hanging cloth.
Definition ClothSheetSimulator.h:16
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
static const plColor White
#FFFFFF
Definition Color.h:194
Definition ComponentManager.h:88
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Base class for objects that should be rendered.
Definition RenderComponent.h:9
Definition RenderDataBatch.h:6
Base class for all render data. Render data must contain all information that is needed to render the...
Definition RenderData.h:14
Definition RenderPipelinePass.h:26
This is the base class for types that handle rendering of different object types.
Definition Renderer.h:9
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition ClothSheetComponent.h:85
Flags for how a piece of cloth should be simulated.
Definition ClothSheetComponent.h:67
Enum
Definition ClothSheetComponent.h:71
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
Definition Declarations.h:51
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33