Nebula
Loading...
Searching...
No Matches
terrainsession.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
25//------------------------------------------------------------------------------
26#if WITH_NEBULA_EDITOR
27#include "core/refcounted.h"
28#include "game/entity.h"
31#include "math/line.h"
32#include "math/rectangle.h"
33#include "math/vec3.h"
34#include "util/fixedarray.h"
35#include "util/guid.h"
36#include "util/string.h"
37#include "ids/id.h"
40#include "flat/render/terrainresource.h"
41
42namespace Editor
43{
44class Scene;
45}
46
47namespace GraphicsFeature
48{
49
51struct TerrainBrush
52{
53 enum Tool
54 {
55 Raise,
56 Lower,
57 Flatten,
58 Smooth,
59 Paint,
60 Erase,
61 NumTools
62 };
63 enum Shape
64 {
65 Circle,
66 Square,
67 };
68 int tool = Raise;
69 int shape = Circle;
71 float radius = 16.0f;
73 float hardness = 0.5f;
76 float strength = 0.5f;
78 float rate = 8.0f;
79};
80
81class TerrainSession : public Core::RefCounted
82{
83 __DeclareClass(TerrainSession)
84public:
86 enum class Map
87 {
88 Height,
89 Biome,
90 Plant
91 };
92
93 TerrainSession();
94 virtual ~TerrainSession();
95
98 bool Open(Editor::Scene* scene, Game::Entity entity);
101 void Close(bool restore = true);
103 bool IsOpen() const;
104
107 bool Update();
108
110 Editor::Scene* GetScene() const;
111 Game::Entity GetEntity() const;
112 const Util::Guid& GetEntityGuid() const;
114 Graphics::GraphicsEntityId GetGraphicsEntity() const;
115
117 const Util::String& GetFile() const;
119 Util::String SuggestFile() const;
120
122 Render::TerrainResourceT& GetResource();
125 void ApplyStructure();
127 void ApplyBiome(IndexT biome);
128 void ApplyPlant(IndexT plant);
130 void AddBiome();
131 void RemoveBiome(IndexT biome);
132 void AddPlant();
133 void RemovePlant(IndexT plant);
134
136 CoreGraphics::TextureId GetMapTexture(Map map, IndexT index) const;
138 int GetMapWidth() const;
139 int GetMapHeight() const;
140
142 bool HeightAt(float x, float z, float& outHeight) const;
144 bool Raycast(const Math::line& ray, Math::vec3& outHit) const;
145
147 void BeginStroke(Map map, IndexT index);
149 void Stroke(const TerrainBrush& brush, const Math::vec3& center, float seconds);
151 void EndStroke();
153 bool IsStroking() const;
154
156 void WriteRegion(Map map, IndexT index, const Math::rectangle<int>& region, const Util::FixedArray<float>& texels);
157
159 bool IsDirty() const;
161 void MarkDirty();
164 bool Save(const Util::String& file, Util::String& outError);
165
166private:
167 struct EditMap
168 {
169 Util::FixedArray<float> texels;
170 CoreGraphics::TextureId texture = CoreGraphics::InvalidTextureId;
171 Math::rectangle<int> dirty;
172 bool hasDirty = false;
173 };
174
176 EditMap* GetMap(Map map, IndexT index);
177 const EditMap* GetMap(Map map, IndexT index) const;
179 void CreateMapTexture(EditMap& map, bool height, const char* name);
181 static void DestroyMapTexture(EditMap& map);
183 void LoadMap(EditMap& map, const Util::String& texture, float fallback, bool height, const char* name);
185 void Resize(int width, int height);
187 static void Touch(EditMap& map, const Math::rectangle<int>& region);
189 static void Upload(EditMap& map, bool height);
191 void Rebuild();
194 void AttachMaps();
196 bool SaveMap(const EditMap& map, bool height, const Util::String& folder, const Util::String& name, Util::String& outUrn, Util::String& outError);
197
198 Editor::Scene* scene;
199 Game::Entity entity;
200 Util::Guid entityGuid;
201 Graphics::GraphicsEntityId graphicsEntity;
202 Util::String file;
203 Render::TerrainResourceT resource;
204
205 int width, height;
206 EditMap heights;
207 Util::Array<EditMap> biomes;
208 Util::Array<EditMap> plants;
209
210 struct StrokeState
211 {
212 bool active = false;
213 Map map = Map::Height;
214 IndexT index = 0;
215 Util::FixedArray<float> before;
216 Math::rectangle<int> region;
217 bool touched = false;
218 float flattenTarget = 0.0f;
219 bool hasFlattenTarget = false;
220 } stroke;
221
222 bool open;
223 bool dirty;
224 bool terrainChanged;
225};
226
227} // namespace GraphicsFeature
228#endif // WITH_NEBULA_EDITOR
229//------------------------------------------------------------------------------
Util::Pair< Memory::RangeAllocation, CoreGraphics::BufferId > Upload(const TYPE &data, const SizeT alignment=1)
Upload single item to GPU source buffer.
Definition graphicsdevice.h:429
Definition graphicsfeatureunit.cc:66
bool Raycast(Navigation::NavMeshId navMesh, const Math::point &start, const Math::point &end, Math::point &outHit, const QueryFilter *filter)
walk along the surface from start towards end. Returns true and the point where it is blocked if an e...
Definition navquery.cc:231
Physics::Scene & GetScene(IndexT idx)
Definition physicsinterface.cc:210
@ Update
Definition resourceloader.h:53
#define __DeclareClass(type)
int IndexT
Definition types.h:49