Plasma Engine  2.0
Loading...
Searching...
No Matches
InstancedMeshComponent.h
1#pragma once
2
3#include <Foundation/Containers/DynamicArray.h>
4#include <RendererCore/Meshes/MeshComponentBase.h>
5
6struct plPerInstanceData;
10class plStreamWriter;
11class plStreamReader;
12
13struct PL_RENDERERCORE_DLL plMeshInstanceData
14{
15 void SetLocalPosition(plVec3 vPosition);
16 plVec3 GetLocalPosition() const;
17
18 void SetLocalRotation(plQuat qRotation);
19 plQuat GetLocalRotation() const;
20
21 void SetLocalScaling(plVec3 vScaling);
22 plVec3 GetLocalScaling() const;
23
24 plResult Serialize(plStreamWriter& ref_writer) const;
25 plResult Deserialize(plStreamReader& ref_reader);
26
27 plTransform m_transform;
28
29 plColor m_color;
30};
31
32PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plMeshInstanceData);
33
35
36class PL_RENDERERCORE_DLL plInstancedMeshRenderData : public plMeshRenderData
37{
38 PL_ADD_DYNAMIC_REFLECTION(plInstancedMeshRenderData, plMeshRenderData);
39
40public:
41 virtual void FillBatchIdAndSortingKey() override;
42
43 plInstanceData* m_pExplicitInstanceData = nullptr;
44 plUInt32 m_uiExplicitInstanceCount = 0;
45};
46
48
49class PL_RENDERERCORE_DLL plInstancedMeshComponentManager : public plComponentManager<class plInstancedMeshComponent, plBlockStorageType::Compact>
50{
51public:
53
55
56 void EnqueueUpdate(const plInstancedMeshComponent* pComponent) const;
57
58private:
59 struct ComponentToUpdate
60 {
61 plComponentHandle m_hComponent;
62 plArrayPtr<plPerInstanceData> m_InstanceData;
63 };
64
65 mutable plMutex m_Mutex;
66 mutable plDeque<ComponentToUpdate> m_RequireUpdate;
67
68protected:
69 void OnRenderEvent(const plRenderWorldRenderEvent& e);
70
71 virtual void Initialize() override;
72 virtual void Deinitialize() override;
73};
74
85class PL_RENDERERCORE_DLL plInstancedMeshComponent : public plMeshComponentBase
86{
88
90 // plComponent
91
92public:
93 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
94 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
95
96protected:
97 virtual void OnActivated() override;
98 virtual void OnDeactivated() override;
99
100
102 // plRenderComponent
103
104public:
105 virtual plResult GetLocalBounds(plBoundingBoxSphere& ref_bounds, bool& ref_bAlwaysVisible, plMsgUpdateLocalBounds& ref_msg) override;
106
108 // plMeshComponentBase
109
110protected:
111 virtual plMeshRenderData* CreateRenderData() const override;
112
114 // plInstancedMeshComponent
115
116public:
119
121 void OnMsgExtractGeometry(plMsgExtractGeometry& ref_msg); // [ msg handler ]
122
123protected:
124 void OnMsgExtractRenderData(plMsgExtractRenderData& msg) const;
125
126 plUInt32 Instances_GetCount() const; // [ property ]
127 plMeshInstanceData Instances_GetValue(plUInt32 uiIndex) const; // [ property ]
128 void Instances_SetValue(plUInt32 uiIndex, plMeshInstanceData value); // [ property ]
129 void Instances_Insert(plUInt32 uiIndex, plMeshInstanceData value); // [ property ]
130 void Instances_Remove(plUInt32 uiIndex); // [ property ]
131
132 plArrayPtr<plPerInstanceData> GetInstanceData() const;
133
134 // Unpacked, reflected instance data for editing and ease of access
135 plDynamicArray<plMeshInstanceData> m_RawInstancedData;
136
137 plInstanceData* m_pExplicitInstanceData = nullptr;
138
139 mutable plUInt64 m_uiEnqueuedFrame = plUInt64(-1);
140};
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
Definition ComponentManager.h:88
Definition Deque.h:270
Definition DynamicArray.h:81
Renders multiple instances of the same mesh.
Definition InstancedMeshComponent.h:86
Definition InstancedMeshComponent.h:50
Definition InstancedMeshComponent.h:37
Base class for components that render static or animated meshes.
Definition MeshComponentBase.h:67
Definition MeshComponentBase.h:13
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
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
A handle to a component.
Definition Declarations.h:138
Definition InstanceDataProvider.h:12
Definition InstancedMeshComponent.h:14
Sent by plWorldGeoExtractionUtil to gather geometry information about objects in a world.
Definition WorldGeoExtractionUtil.h:56
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
Definition RenderWorld.h:24
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54