From 9322d37b810ee718285b2e2476758c1212a9d965 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 05:55:05 -0700 Subject: [PATCH] feat(editor): height scale tool for terrain relief control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Scale Heights: multiply all terrain heights by a factor (0.1x - 5.0x) - >1.0 exaggerates relief (deeper valleys, taller peaks) - <1.0 flattens terrain toward base height - Re-stitches all chunk edges after scaling for seamless results - Workflow: noise → smooth → scale → clamp for precise control --- tools/editor/editor_ui.cpp | 9 ++++++++- tools/editor/terrain_editor.cpp | 14 ++++++++++++++ tools/editor/terrain_editor.hpp | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index 98b93443..49b18823 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -404,8 +404,15 @@ void EditorUI::renderBrushPanel(EditorApp& app) { app.getTerrainEditor().clampHeights(clampMin, clampMax); app.showToast("Heights clamped"); } + ImGui::Separator(); + static float hScale = 1.5f; + ImGui::SliderFloat("Height Scale", &hScale, 0.1f, 5.0f, "%.2f"); + if (ImGui::Button("Scale Heights", ImVec2(-1, 0))) { + app.getTerrainEditor().scaleHeights(hScale); + app.showToast("Heights scaled"); + } ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), - "Generate, smooth, then clamp for controlled range"); + "Exaggerate (>1) or flatten (<1) terrain relief"); } ImGui::Separator(); diff --git a/tools/editor/terrain_editor.cpp b/tools/editor/terrain_editor.cpp index 06aaf134..c7e4c374 100644 --- a/tools/editor/terrain_editor.cpp +++ b/tools/editor/terrain_editor.cpp @@ -652,6 +652,20 @@ void TerrainEditor::smoothEntireTile(int iterations) { dirty_ = true; } +void TerrainEditor::scaleHeights(float factor) { + if (!terrain_) return; + for (int ci = 0; ci < 256; ci++) { + auto& chunk = terrain_->chunks[ci]; + if (!chunk.hasHeightMap()) continue; + for (int v = 0; v < 145; v++) + chunk.heightMap.heights[v] *= factor; + dirtyChunks_.push_back(ci); + } + // Re-stitch all edges after scaling + for (int ci = 0; ci < 256; ci++) stitchEdges(ci); + dirty_ = true; +} + void TerrainEditor::clampHeights(float minH, float maxH) { if (!terrain_) return; for (int ci = 0; ci < 256; ci++) { diff --git a/tools/editor/terrain_editor.hpp b/tools/editor/terrain_editor.hpp index ed80bee8..8bb1d5a5 100644 --- a/tools/editor/terrain_editor.hpp +++ b/tools/editor/terrain_editor.hpp @@ -60,6 +60,9 @@ public: // Clamp all heights to a min/max range void clampHeights(float minH, float maxH); + // Scale all heights by a factor (useful for exaggerating or flattening) + void scaleHeights(float factor); + // Import/export heightmap (raw 16-bit grayscale, 129x129) bool importHeightmap(const std::string& path, float heightScale); bool exportHeightmap(const std::string& path, float heightScale);