From 88416bbb1d6b7f5d138428fa7f6cef595198f05c Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 06:55:04 -0700 Subject: [PATCH] fix(editor): NPC markers always on top, mesa generator, terrain tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NPC markers now render with NO depth test (via gizmo pipeline) so they're always visible even on sloped/rough terrain - Mesa/Plateau generator: creates raised flat areas with steep cliff edges — configurable radius, height, and edge steepness - NPC markers drawn after gizmo in the render pipeline to guarantee they appear on top of everything - Fixes NPC visibility on non-flat terrain --- tools/editor/editor_ui.cpp | 13 ++++++++++++ tools/editor/editor_viewport.cpp | 28 ++++++++++++------------- tools/editor/terrain_editor.cpp | 35 ++++++++++++++++++++++++++++++++ tools/editor/terrain_editor.hpp | 3 +++ 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index d517c4fe..52330aa0 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -551,6 +551,19 @@ void EditorUI::renderBrushPanel(EditorApp& app) { ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied"); } + 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); + ImGui::SliderFloat("Height##mesa", &mesaHeight, 5.0f, 100.0f); + ImGui::SliderFloat("Edge Steepness##mesa", &mesaSteep, 0.05f, 1.0f); + auto& brush6 = app.getTerrainEditor().brush(); + if (ImGui::Button("Create Mesa at Cursor", ImVec2(-1, 0)) && brush6.isActive()) { + app.getTerrainEditor().createMesa(brush6.getPosition(), mesaRadius, mesaHeight, mesaSteep); + app.showToast("Mesa created"); + } + ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "Raised flat area with cliff edges"); + } + if (ImGui::CollapsingHeader("Crater Generator")) { static float craterRadius = 30.0f, craterDepth = 10.0f, craterRim = 3.0f; ImGui::SliderFloat("Radius##crater", &craterRadius, 5.0f, 100.0f); diff --git a/tools/editor/editor_viewport.cpp b/tools/editor/editor_viewport.cpp index 88b28dc0..2440d42f 100644 --- a/tools/editor/editor_viewport.cpp +++ b/tools/editor/editor_viewport.cpp @@ -442,21 +442,7 @@ void EditorViewport::render(VkCommandBuffer cmd) { waterRenderer_.render(cmd, perFrameSet); - // NPC position markers (always visible) - if (npcMarkerVB_ && npcMarkerVertCount_ > 0) { - auto* wp = waterRenderer_.getPipeline(); - auto* wl = waterRenderer_.getPipelineLayout(); - static bool loggedOnce = false; - if (!loggedOnce) { loggedOnce = true; LOG_INFO("NPC render: vb=", (wp?"ok":"null"), " layout=", (wl?"ok":"null"), " verts=", npcMarkerVertCount_); } - if (wp && wl) { - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, wp); - vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, wl, - 0, 1, &perFrameSet, 0, nullptr); - VkDeviceSize off = 0; - vkCmdBindVertexBuffers(cmd, 0, 1, &npcMarkerVB_, &off); - vkCmdDraw(cmd, npcMarkerVertCount_, 1, 0, 0); - } - } + // NPC position markers — render AFTER gizmo (no depth test = always on top) // Brush indicator circle if (brushVisible_ && brushVB_ && brushVertCount_ > 0) { @@ -480,6 +466,18 @@ void EditorViewport::render(VkCommandBuffer cmd) { } gizmo_.render(cmd, perFrameSet); + + // NPC markers rendered last with no depth test (always on top via gizmo pipeline) + if (npcMarkerVB_ && npcMarkerVertCount_ > 0) { + // Gizmo pipeline has depthTestEnable=VK_FALSE — markers always visible + auto& gizmoPL = gizmo_; + // Re-bind gizmo pipeline (same vertex format, no depth test) + // gizmo_.render already set it up, just draw our buffer + VkDeviceSize off = 0; + vkCmdBindVertexBuffers(cmd, 0, 1, &npcMarkerVB_, &off); + vkCmdDraw(cmd, npcMarkerVertCount_, 1, 0, 0); + (void)gizmoPL; + } } void EditorViewport::setWireframe(bool enabled) { diff --git a/tools/editor/terrain_editor.cpp b/tools/editor/terrain_editor.cpp index 2ce193d3..3ec9efc8 100644 --- a/tools/editor/terrain_editor.cpp +++ b/tools/editor/terrain_editor.cpp @@ -805,6 +805,41 @@ void TerrainEditor::createCrater(const glm::vec3& center, float radius, float de dirty_ = true; } +void TerrainEditor::createMesa(const glm::vec3& center, float radius, float height, float edgeSteepness) { + 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 * 1.5f) continue; + + float t = dist / radius; + float blend; + if (t < 0.7f) { + blend = 1.0f; // flat top + } else if (t < 1.0f) { + float edgeT = (t - 0.7f) / 0.3f; + blend = 1.0f - std::pow(edgeT, 1.0f / std::max(0.1f, edgeSteepness)); + } else { + blend = 0.0f; + } + + 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 76de52f5..fe1a761b 100644 --- a/tools/editor/terrain_editor.hpp +++ b/tools/editor/terrain_editor.hpp @@ -84,6 +84,9 @@ public: // Create a crater at a position (bowl shape with raised rim) void createCrater(const glm::vec3& center, float radius, float depth, float rimHeight); + // Create a mesa/plateau (raised flat area with steep cliff edges) + void createMesa(const glm::vec3& center, float radius, float height, float edgeSteepness); + // Import/export heightmap (raw 16-bit grayscale, 129x129) bool importHeightmap(const std::string& path, float heightScale); bool exportHeightmap(const std::string& path, float heightScale);