mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-06 00:53:52 +00:00
feat(editor): island terrain generator with beach falloff
- Island Generator: creates raised center terrain dropping to edges with configurable center height and edge drop depth - Flat interior plateau → gradual beach slope → steep underwater drop - Preserves existing noise detail at 30% blend for natural variation - Add water around the island for instant ocean environment - Workflow: New Terrain → Island → Noise → Smooth → Auto-paint
This commit is contained in:
parent
f15fbf508f
commit
7971fd7989
3 changed files with 58 additions and 0 deletions
|
|
@ -603,6 +603,18 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
|
||||||
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
|
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")) {
|
if (ImGui::CollapsingHeader("Ridge / Mountain Range")) {
|
||||||
static glm::vec3 ridgeStart{0}, ridgeEnd{0};
|
static glm::vec3 ridgeStart{0}, ridgeEnd{0};
|
||||||
static float ridgeWidth = 20.0f, ridgeHeight = 30.0f;
|
static float ridgeWidth = 20.0f, ridgeHeight = 30.0f;
|
||||||
|
|
|
||||||
|
|
@ -860,6 +860,49 @@ void TerrainEditor::createHill(const glm::vec3& center, float radius, float heig
|
||||||
dirty_ = true;
|
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<float>(terrain_->coord.y)) * TILE_SIZE;
|
||||||
|
float tileNW_Y = (32.0f - static_cast<float>(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,
|
void TerrainEditor::createRidge(const glm::vec3& start, const glm::vec3& end,
|
||||||
float width, float height) {
|
float width, float height) {
|
||||||
if (!terrain_) return;
|
if (!terrain_) return;
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,9 @@ public:
|
||||||
// Create a ridge/mountain range between two points
|
// Create a ridge/mountain range between two points
|
||||||
void createRidge(const glm::vec3& start, const glm::vec3& end, float width, float height);
|
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)
|
// Import/export heightmap (raw 16-bit grayscale, 129x129)
|
||||||
bool importHeightmap(const std::string& path, float heightScale);
|
bool importHeightmap(const std::string& path, float heightScale);
|
||||||
bool exportHeightmap(const std::string& path, float heightScale);
|
bool exportHeightmap(const std::string& path, float heightScale);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue