diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index 231c9773..012c5f33 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -603,6 +603,18 @@ void EditorUI::renderBrushPanel(EditorApp& app) { ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied"); } + if (ImGui::CollapsingHeader("Island Generator")) { + static float islandHeight = 30.0f, islandDrop = 20.0f; + ImGui::SliderFloat("Center Height##island", &islandHeight, 5.0f, 100.0f); + ImGui::SliderFloat("Edge Drop##island", &islandDrop, 5.0f, 50.0f); + if (ImGui::Button("Create Island Shape", ImVec2(-1, 0))) { + app.getTerrainEditor().createIsland(islandHeight, islandDrop); + app.showToast("Island created"); + } + ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), + "Raised center dropping to edges. Add water around for ocean."); + } + if (ImGui::CollapsingHeader("Ridge / Mountain Range")) { static glm::vec3 ridgeStart{0}, ridgeEnd{0}; static float ridgeWidth = 20.0f, ridgeHeight = 30.0f; diff --git a/tools/editor/terrain_editor.cpp b/tools/editor/terrain_editor.cpp index ac994ea5..4f0f40c2 100644 --- a/tools/editor/terrain_editor.cpp +++ b/tools/editor/terrain_editor.cpp @@ -860,6 +860,49 @@ void TerrainEditor::createHill(const glm::vec3& center, float radius, float heig dirty_ = true; } +void TerrainEditor::createIsland(float centerHeight, float edgeDropoff) { + if (!terrain_) return; + + // Island shape: distance from tile center determines height + // Center is high, edges drop below base height (underwater) + float tileCenterX = 0, tileCenterY = 0; + // Compute tile center from first chunk + { + float tileNW_X = (32.0f - static_cast(terrain_->coord.y)) * TILE_SIZE; + float tileNW_Y = (32.0f - static_cast(terrain_->coord.x)) * TILE_SIZE; + tileCenterX = tileNW_X - TILE_SIZE * 0.5f; + tileCenterY = tileNW_Y - TILE_SIZE * 0.5f; + } + float maxDist = TILE_SIZE * 0.45f; // island radius slightly smaller than tile + + for (int ci = 0; ci < 256; ci++) { + auto& chunk = terrain_->chunks[ci]; + if (!chunk.hasHeightMap()) continue; + for (int v = 0; v < 145; v++) { + glm::vec3 pos = chunkVertexWorldPos(ci, v); + float dist = glm::length(glm::vec2(pos.x - tileCenterX, pos.y - tileCenterY)); + float t = std::clamp(dist / maxDist, 0.0f, 1.0f); + + // Smooth island falloff: high center, gradual drop, steep beach + float islandH; + if (t < 0.6f) { + islandH = centerHeight; // flat interior + } else if (t < 0.85f) { + float beachT = (t - 0.6f) / 0.25f; + islandH = centerHeight * (1.0f - beachT * beachT); + } else { + float dropT = (t - 0.85f) / 0.15f; + islandH = centerHeight * (1.0f - 0.85f * 0.85f) * (1.0f - dropT) - edgeDropoff * dropT; + } + + chunk.heightMap.heights[v] = islandH + chunk.heightMap.heights[v] * 0.3f; + } + dirtyChunks_.push_back(ci); + } + for (int ci = 0; ci < 256; ci++) stitchEdges(ci); + dirty_ = true; +} + void TerrainEditor::createRidge(const glm::vec3& start, const glm::vec3& end, float width, float height) { if (!terrain_) return; diff --git a/tools/editor/terrain_editor.hpp b/tools/editor/terrain_editor.hpp index 9e91a732..3f8a22f9 100644 --- a/tools/editor/terrain_editor.hpp +++ b/tools/editor/terrain_editor.hpp @@ -93,6 +93,9 @@ public: // Create a ridge/mountain range between two points void createRidge(const glm::vec3& start, const glm::vec3& end, float width, float height); + // Create an island shape (raised center, dropping to base at edges) + void createIsland(float centerHeight, float edgeDropoff); + // Import/export heightmap (raw 16-bit grayscale, 129x129) bool importHeightmap(const std::string& path, float heightScale); bool exportHeightmap(const std::string& path, float heightScale);