Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltClothSheetComponent.h
1#pragma once
2
3#include <Core/World/ComponentManager.h>
4#include <GameEngine/Physics/ClothSheetSimulator.h>
5#include <JoltPlugin/JoltPluginDLL.h>
6#include <RendererCore/Components/RenderComponent.h>
7#include <RendererCore/Meshes/MeshBufferResource.h>
8#include <RendererCore/Pipeline/RenderData.h>
9#include <RendererCore/Pipeline/Renderer.h>
10
13
15
16class PL_JOLTPLUGIN_DLL plJoltClothSheetComponentManager : public plComponentManager<class plJoltClothSheetComponent, plBlockStorageType::FreeList>
17{
18public:
21
22 virtual void Initialize() override;
23
24private:
25 void Update(const plWorldModule::UpdateContext& context);
26 void UpdateBounds(const plWorldModule::UpdateContext& context);
27};
28
30
31class PL_JOLTPLUGIN_DLL plJoltClothSheetRenderData final : public plRenderData
32{
33 PL_ADD_DYNAMIC_REFLECTION(plJoltClothSheetRenderData, plRenderData);
34
35public:
36 plUInt32 m_uiUniqueID = 0;
37 plVec2 m_vTextureScale = plVec2(1.0f);
38 plArrayPtr<plVec3> m_Positions;
39 plArrayPtr<plUInt16> m_Indices;
40 plUInt16 m_uiVerticesX;
41 plUInt16 m_uiVerticesY;
42 plColor m_Color = plColor::White;
43
44 plMaterialResourceHandle m_hMaterial;
45};
46
47class PL_JOLTPLUGIN_DLL plJoltClothSheetRenderer : public plRenderer
48{
49 PL_ADD_DYNAMIC_REFLECTION(plJoltClothSheetRenderer, plRenderer);
50 PL_DISALLOW_COPY_AND_ASSIGN(plJoltClothSheetRenderer);
51
52public:
55
56 virtual void GetSupportedRenderDataCategories(plHybridArray<plRenderData::Category, 8>& ref_categories) const override;
57 virtual void GetSupportedRenderDataTypes(plHybridArray<const plRTTI*, 8>& ref_types) const override;
58 virtual void RenderBatch(const plRenderViewContext& renderContext, const plRenderPipelinePass* pPass, const plRenderDataBatch& batch) const override;
59
60
61protected:
62 void CreateVertexBuffer();
63
64 plDynamicMeshBufferResourceHandle m_hDynamicMeshBuffer;
65};
66
68struct PL_JOLTPLUGIN_DLL plJoltClothSheetFlags
69{
70 using StorageType = plUInt16;
71
72 enum Enum
73 {
74 FixedCornerTopLeft = PL_BIT(0),
75 FixedCornerTopRight = PL_BIT(1),
76 FixedCornerBottomRight = PL_BIT(2),
77 FixedCornerBottomLeft = PL_BIT(3),
78 FixedEdgeTop = PL_BIT(4),
79 FixedEdgeRight = PL_BIT(5),
80 FixedEdgeBottom = PL_BIT(6),
81 FixedEdgeLeft = PL_BIT(7),
82
83 Default = FixedEdgeTop
84 };
85
86 struct Bits
87 {
88 StorageType FixedCornerTopLeft : 1;
89 StorageType FixedCornerTopRight : 1;
90 StorageType FixedCornerBottomRight : 1;
91 StorageType FixedCornerBottomLeft : 1;
92 StorageType FixedEdgeTop : 1;
93 StorageType FixedEdgeRight : 1;
94 StorageType FixedEdgeBottom : 1;
95 StorageType FixedEdgeLeft : 1;
96 };
97};
98
99PL_DECLARE_REFLECTABLE_TYPE(PL_JOLTPLUGIN_DLL, plJoltClothSheetFlags);
100
107class PL_JOLTPLUGIN_DLL plJoltClothSheetComponent : public plRenderComponent
108{
110
112 // plComponent
113
114public:
115 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
116 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
117
118protected:
119 virtual void OnActivated() override;
120 virtual void OnSimulationStarted() override;
121 virtual void OnDeactivated() override;
122
124 // plRenderComponent
125
126public:
127 virtual plResult GetLocalBounds(plBoundingBoxSphere& ref_bounds, bool& ref_bAlwaysVisible, plMsgUpdateLocalBounds& ref_msg) override;
128
129private:
130 void OnMsgExtractRenderData(plMsgExtractRenderData& msg) const;
131
133 // plJoltClothSheetComponent
134
135public:
138
140 void SetSize(plVec2 vVal); // [ property ]
141 plVec2 GetSize() const { return m_vSize; } // [ property ]
142
149 void SetSegments(plVec2U32 vVal); // [ property ]
150 plVec2U32 GetSegments() const { return m_vSegments; } // [ property ]
151
153 plUInt8 m_uiCollisionLayer = 0; // [ property ]
154
156 float m_fGravityFactor = 1.0f; // [ property ]
157
159 float m_fWindInfluence = 0.3f; // [ property ]
160
162 float m_fDamping = 0.5f; // [ property ]
163
165 float m_fThickness = 0.05f; // [ property ]
166
168 plColor m_Color = plColor::White; // [ property ]
169
171 void SetFlags(plBitflags<plJoltClothSheetFlags> flags); // [ property ]
172 plBitflags<plJoltClothSheetFlags> GetFlags() const { return m_Flags; } // [ property ]
173
174 void SetMaterialFile(const char* szFile); // [ property ]
175 const char* GetMaterialFile() const; // [ property ]
176
177 plMaterialResourceHandle m_hMaterial; // [ property ]
178
179private:
180 void Update();
181
182 void ApplyWind();
183
184 void SetupCloth();
185 void RemoveBody();
186 void UpdateBodyBounds();
187
188 plVec2 m_vSize = plVec2(1.0f, 1.0f);
189 plVec2 m_vTextureScale = plVec2(1.0f);
190 plVec2U32 m_vSegments = plVec2U32(16, 16);
192 mutable plRenderData::Category m_RenderDataCategory;
193 plUInt8 m_uiSleepCounter = 0;
194
195 plUInt32 m_uiJoltBodyID = plInvalidIndex;
196 plBoundingSphere m_BSphere;
197};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
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
Simulates a rectangular piece of cloth.
Definition JoltClothSheetComponent.h:108
Definition JoltClothSheetComponent.h:17
Definition JoltClothSheetComponent.h:32
Definition JoltClothSheetComponent.h:48
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 JoltClothSheetComponent.h:87
Flags for how a piece of cloth should be simulated.
Definition JoltClothSheetComponent.h:69
Enum
Definition JoltClothSheetComponent.h:73
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
Definition RenderData.h:19
Definition Declarations.h:51
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33