mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-05 16:43:52 +00:00
feat(editor): ridge/mountain range generator between two points
- Ridge Generator: creates mountain ranges by setting start and end points, with configurable width and height - Cross-section uses quadratic falloff, along-axis uses sqrt taper for natural mountain range silhouette (wider at center, tapering at both ends) - Same start/end workflow as river/road tools
This commit is contained in:
parent
d6c58b5dc9
commit
1c58911da0
3 changed files with 61 additions and 0 deletions
|
|
@ -551,6 +551,29 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
|
|||
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Ridge / Mountain Range")) {
|
||||
static glm::vec3 ridgeStart{0}, ridgeEnd{0};
|
||||
static float ridgeWidth = 20.0f, ridgeHeight = 30.0f;
|
||||
static bool ridgeStartSet = false;
|
||||
ImGui::SliderFloat("Width##ridge", &ridgeWidth, 5.0f, 80.0f);
|
||||
ImGui::SliderFloat("Height##ridge", &ridgeHeight, 5.0f, 100.0f);
|
||||
auto& brushR = app.getTerrainEditor().brush();
|
||||
if (ImGui::Button("Set Start##ridge", ImVec2(120, 0)) && brushR.isActive()) {
|
||||
ridgeStart = brushR.getPosition();
|
||||
ridgeStartSet = true;
|
||||
app.showToast("Ridge start set");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Set End + Create##ridge", ImVec2(140, 0)) && brushR.isActive() && ridgeStartSet) {
|
||||
ridgeEnd = brushR.getPosition();
|
||||
app.getTerrainEditor().createRidge(ridgeStart, ridgeEnd, ridgeWidth, ridgeHeight);
|
||||
app.showToast("Ridge created");
|
||||
ridgeStartSet = false;
|
||||
}
|
||||
if (ridgeStartSet)
|
||||
ImGui::TextColored(ImVec4(0.5f, 0.9f, 0.5f, 1), "Start set");
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Hill Generator")) {
|
||||
static float hillRadius = 40.0f, hillHeight = 25.0f;
|
||||
ImGui::SliderFloat("Radius##hill", &hillRadius, 10.0f, 150.0f);
|
||||
|
|
|
|||
|
|
@ -860,6 +860,41 @@ void TerrainEditor::createHill(const glm::vec3& center, float radius, float heig
|
|||
dirty_ = true;
|
||||
}
|
||||
|
||||
void TerrainEditor::createRidge(const glm::vec3& start, const glm::vec3& end,
|
||||
float width, float height) {
|
||||
if (!terrain_) return;
|
||||
glm::vec2 lineStart(start.x, start.y);
|
||||
glm::vec2 lineEnd(end.x, end.y);
|
||||
glm::vec2 lineDir = glm::normalize(lineEnd - lineStart);
|
||||
float lineLen = glm::length(lineEnd - lineStart);
|
||||
|
||||
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);
|
||||
glm::vec2 p(pos.x, pos.y);
|
||||
glm::vec2 toP = p - lineStart;
|
||||
float along = glm::dot(toP, lineDir);
|
||||
along = std::clamp(along, 0.0f, lineLen);
|
||||
glm::vec2 closest = lineStart + lineDir * along;
|
||||
float dist = glm::length(p - closest);
|
||||
if (dist >= width) continue;
|
||||
|
||||
float crossFalloff = 1.0f - (dist / width);
|
||||
crossFalloff = crossFalloff * crossFalloff;
|
||||
float alongFalloff = 1.0f - 2.0f * std::abs(along / lineLen - 0.5f);
|
||||
alongFalloff = std::max(0.0f, alongFalloff);
|
||||
float h = height * crossFalloff * std::sqrt(alongFalloff);
|
||||
chunk.heightMap.heights[v] += h;
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ public:
|
|||
// Create a smooth hill/mountain
|
||||
void createHill(const glm::vec3& center, float radius, float height);
|
||||
|
||||
// Create a ridge/mountain range between two points
|
||||
void createRidge(const glm::vec3& start, const glm::vec3& end, float width, 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue