feat(editor): hill/valley generator with smooth bell curve shape

- Hill Generator: creates smooth bell-curve hills at cursor position
  with configurable radius and height
- Valley mode: same shape inverted, creates natural depressions
- Uses (1-t^2)^2 falloff for very smooth natural-looking slopes
- Two buttons: "Create Hill" and "Create Valley" for quick terrain
  shaping without switching brush modes
This commit is contained in:
Kelsi 2026-05-05 06:57:18 -07:00
parent 88416bbb1d
commit d6c58b5dc9
3 changed files with 39 additions and 0 deletions

View file

@ -551,6 +551,22 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
}
if (ImGui::CollapsingHeader("Hill Generator")) {
static float hillRadius = 40.0f, hillHeight = 25.0f;
ImGui::SliderFloat("Radius##hill", &hillRadius, 10.0f, 150.0f);
ImGui::SliderFloat("Height##hill", &hillHeight, 5.0f, 100.0f);
auto& brushH = app.getTerrainEditor().brush();
if (ImGui::Button("Create Hill", ImVec2(120, 0)) && brushH.isActive()) {
app.getTerrainEditor().createHill(brushH.getPosition(), hillRadius, hillHeight);
app.showToast("Hill created");
}
ImGui::SameLine();
if (ImGui::Button("Create Valley", ImVec2(120, 0)) && brushH.isActive()) {
app.getTerrainEditor().createHill(brushH.getPosition(), hillRadius, -hillHeight);
app.showToast("Valley created");
}
}
if (ImGui::CollapsingHeader("Mesa / Plateau")) {
static float mesaRadius = 40.0f, mesaHeight = 20.0f, mesaSteep = 0.3f;
ImGui::SliderFloat("Radius##mesa", &mesaRadius, 10.0f, 150.0f);

View file

@ -840,6 +840,26 @@ void TerrainEditor::createMesa(const glm::vec3& center, float radius, float heig
dirty_ = true;
}
void TerrainEditor::createHill(const glm::vec3& center, float radius, float height) {
if (!terrain_) return;
for (int ci = 0; ci < 256; ci++) {
auto& chunk = terrain_->chunks[ci];
if (!chunk.hasHeightMap()) continue;
bool modified = false;
for (int v = 0; v < 145; v++) {
glm::vec3 pos = chunkVertexWorldPos(ci, v);
float dist = glm::length(glm::vec2(pos.x - center.x, pos.y - center.y));
if (dist >= radius) continue;
float t = dist / radius;
float blend = (1.0f - t * t) * (1.0f - t * t); // smooth bell curve
chunk.heightMap.heights[v] += height * blend;
modified = true;
}
if (modified) { stitchEdges(ci); dirtyChunks_.push_back(ci); }
}
dirty_ = true;
}
void TerrainEditor::flattenRoad(const glm::vec3& start, const glm::vec3& end, float width) {
if (!terrain_) return;
glm::vec2 lineStart(start.x, start.y);

View file

@ -87,6 +87,9 @@ public:
// Create a mesa/plateau (raised flat area with steep cliff edges)
void createMesa(const glm::vec3& center, float radius, float height, float edgeSteepness);
// Create a smooth hill/mountain
void createHill(const glm::vec3& center, float radius, float height);
// Import/export heightmap (raw 16-bit grayscale, 129x129)
bool importHeightmap(const std::string& path, float heightScale);
bool exportHeightmap(const std::string& path, float heightScale);