Polyphase Game Engine
Loading...
Searching...
No Matches
TerrainSculptManager.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "Maths.h"
6#include "AssetRef.h"
7#include <vector>
8#include <set>
9#include <cstdint>
10
11class Terrain3D;
12class Node;
13
14enum class TerrainSculptMode : uint8_t
15{
16 Raise = 0,
17 Lower,
18 Flatten,
19 Smooth,
20 PaintMaterial,
21 Count
22};
23
24struct TerrainHeightChange
25{
26 int32_t x, z;
27 float oldHeight;
28 float newHeight;
29 uint32_t oldSplat;
30 uint32_t newSplat;
31};
32
33struct TerrainSculptOptions
34{
35 TerrainSculptMode mMode = TerrainSculptMode::Raise;
36 float mBrushRadius = 5.0f; // world-space radius
37 float mBrushStrength = 0.5f; // 0-1
38 float mBrushFalloff = 0.5f; // 0=hard edge, 1=soft
39 float mFlattenHeight = 0.0f; // target for flatten mode
40 int32_t mPaintSlot = 0; // material slot for paint mode
41
42 // Brush mask: grayscale texture for custom brush shape/hardness
43 // White=full effect, black=no effect. nullptr = circular falloff
44 TextureRef mBrushMask;
45};
46
47class TerrainSculptManager
48{
49public:
50 TerrainSculptManager();
51 ~TerrainSculptManager();
52
53 void Update();
54 void HandleNodeDestroy(Node* node);
55
56 TerrainSculptOptions mOptions;
57
58 // Hover state (read by UI panel)
59 bool mHoverValid = false;
60 glm::vec3 mHoverWorldPos = {};
61 int32_t mHoverGridX = 0;
62 int32_t mHoverGridZ = 0;
63
64private:
65 void UpdateHover();
66 void UpdateStroke();
67 void CommitStroke();
68 void DrawCursor();
69 void ApplyBrush(Terrain3D* terrain, glm::vec3 worldCenter);
70 float ComputeFalloff(float distance, float radius) const;
71 float SampleBrushMask(float dx, float dz, float radius) const;
72
73 static uint64_t GridKey(int32_t x, int32_t z);
74
75 // Stroke state
76 bool mStrokeActive = false;
77 Terrain3D* mPendingTarget = nullptr;
78 std::vector<TerrainHeightChange> mPendingChanges;
79 std::set<uint64_t> mModifiedSet;
80};
81
82#endif
bool Update()
Definition Engine.cpp:710
Definition AssetRef.h:18
Definition Node.h:67
Definition Terrain3d.h:13