From d6c58b5dc9c6f5828abeb9753da053819975c1c3 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 06:57:18 -0700 Subject: [PATCH] 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 --- tools/editor/editor_ui.cpp | 16 ++++++++++++++++ tools/editor/terrain_editor.cpp | 20 ++++++++++++++++++++ tools/editor/terrain_editor.hpp | 3 +++ 3 files changed, 39 insertions(+) diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index 52330aa0..0a94587f 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -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); diff --git a/tools/editor/terrain_editor.cpp b/tools/editor/terrain_editor.cpp index 3ec9efc8..a2f39e8d 100644 --- a/tools/editor/terrain_editor.cpp +++ b/tools/editor/terrain_editor.cpp @@ -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); diff --git a/tools/editor/terrain_editor.hpp b/tools/editor/terrain_editor.hpp index fe1a761b..5cb47f16 100644 --- a/tools/editor/terrain_editor.hpp +++ b/tools/editor/terrain_editor.hpp @@ -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);