Plasma Engine  2.0
Loading...
Searching...
No Matches
HeightfieldComponent.h
1#pragma once
2
3#include <Core/ResourceManager/ResourceHandle.h>
4#include <Core/World/Component.h>
5#include <Core/World/World.h>
6#include <Foundation/Math/Vec2.h>
7#include <GameComponentsPlugin/GameComponentsDLL.h>
8#include <RendererCore/Components/RenderComponent.h>
9#include <RendererCore/Pipeline/RenderData.h>
10
11class plGeometry;
17
21
22class PL_GAMECOMPONENTS_DLL plHeightfieldComponentManager : public plComponentManager<plHeightfieldComponent, plBlockStorageType::Compact>
23{
24public:
27
28 virtual void Initialize() override;
29
30 void Update(const plWorldModule::UpdateContext& context);
31 void AddToUpdateList(plHeightfieldComponent* pComponent);
32
33private:
34 void ResourceEventHandler(const plResourceEvent& e);
35
36 plDeque<plComponentHandle> m_ComponentsToUpdate;
37};
38
45class PL_GAMECOMPONENTS_DLL plHeightfieldComponent : public plRenderComponent
46{
48
50 // plComponent
51
52 virtual void SerializeComponent(plWorldWriter& stream) const override;
53 virtual void DeserializeComponent(plWorldReader& stream) override;
54
55 virtual void OnActivated() override;
56
58 // plRenderComponent
59protected:
60 virtual plResult GetLocalBounds(plBoundingBoxSphere& bounds, bool& bAlwaysVisible, plMsgUpdateLocalBounds& msg) override;
61 void OnMsgExtractRenderData(plMsgExtractRenderData& msg) const;
62
64 // plHeightfieldComponent
65
66public:
69
70 plVec2 GetHalfExtents() const { return m_vHalfExtents; } // [ property ]
71 void SetHalfExtents(plVec2 value); // [ property ]
72
73 float GetHeight() const { return m_fHeight; } // [ property ]
74 void SetHeight(float value); // [ property ]
75
76 plVec2 GetTexCoordOffset() const { return m_vTexCoordOffset; } // [ property ]
77 void SetTexCoordOffset(plVec2 value); // [ property ]
78
79 plVec2 GetTexCoordScale() const { return m_vTexCoordScale; } // [ property ]
80 void SetTexCoordScale(plVec2 value); // [ property ]
81
82 void SetMaterialFile(const char* szFile); // [ property ]
83 const char* GetMaterialFile() const; // [ property ]
84
85 void SetMaterial(const plMaterialResourceHandle& hMaterial) { m_hMaterial = hMaterial; }
86 plMaterialResourceHandle GetMaterial() const { return m_hMaterial; }
87
88 void SetHeightfieldFile(const char* szFile); // [ property ]
89 const char* GetHeightfieldFile() const; // [ property ]
90
91 void SetHeightfield(const plImageDataResourceHandle& hResource);
92 plImageDataResourceHandle GetHeightfield() const { return m_hHeightfield; }
93
94 plVec2U32 GetTesselation() const { return m_vTesselation; } // [ property ]
95 void SetTesselation(plVec2U32 value); // [ property ]
96
97 void SetGenerateCollision(bool b); // [ property ]
98 bool GetGenerateCollision() const { return m_bGenerateCollision; } // [ property ]
99
100 plVec2U32 GetColMeshTesselation() const { return m_vColMeshTesselation; } // [ property ]
101 void SetColMeshTesselation(plVec2U32 value); // [ property ]
102
103 void SetIncludeInNavmesh(bool b); // [ property ]
104 bool GetIncludeInNavmesh() const { return m_bIncludeInNavmesh; } // [ property ]
105
106protected:
107 void OnBuildStaticMesh(plMsgBuildStaticMesh& msg) const; // [ msg handler ]
108 void OnMsgExtractGeometry(plMsgExtractGeometry& msg) const; // [ msg handler ]
109
110 void InvalidateMesh();
111 void BuildGeometry(plGeometry& geom) const;
112 plResult BuildMeshDescriptor(plMeshResourceDescriptor& desc) const;
113
114 template <typename ResourceType>
115 plTypedResourceHandle<ResourceType> GenerateMesh() const;
116
117 plUInt32 m_uiHeightfieldChangeCounter = 0;
118 plImageDataResourceHandle m_hHeightfield;
119 plMaterialResourceHandle m_hMaterial;
120
121 plVec2 m_vHalfExtents = plVec2(100.0f);
122 float m_fHeight = 50.0f;
123
124 plVec2 m_vTexCoordOffset = plVec2::MakeZero();
125 plVec2 m_vTexCoordScale = plVec2(1);
126
127 plVec2U32 m_vTesselation = plVec2U32(128);
128 plVec2U32 m_vColMeshTesselation = plVec2U32(64);
129
130 bool m_bGenerateCollision = true;
131 bool m_bIncludeInNavmesh = true;
132
133 plMeshResourceHandle m_hMesh;
134};
Definition ComponentManager.h:88
Definition Deque.h:270
Provides functions to generate standard geometric shapes, such as boxes, spheres, cylinders,...
Definition Geometry.h:17
This component utilizes a greyscale image to generate an elevation mesh, which is typically used for ...
Definition HeightfieldComponent.h:46
Definition HeightfieldComponent.h:23
Definition MeshResourceDescriptor.h:9
Base class for objects that should be rendered.
Definition RenderComponent.h:9
static constexpr plVec2Template< float > MakeZero()
Definition Vec2.h:49
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
Definition PhysicsWorldModule.h:263
Sent by plWorldGeoExtractionUtil to gather geometry information about objects in a world.
Definition WorldGeoExtractionUtil.h:56
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
These events may be sent by a specific plResource or by the plResourceManager.
Definition Declarations.h:22
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33