mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-05 16:43:52 +00:00
feat(editor): thermal erosion simulation for natural terrain aging
- Thermal Erosion: physically-based material transfer where steep slopes shed material to neighbors based on angle of repose - Configurable iterations (1-50) and talus angle (10-80 degrees) - Lower talus angle = more aggressive erosion (sandy terrain) - Higher angle = less erosion (rocky terrain holds steep slopes) - Creates natural talus fans at cliff bases and rounded hilltops - Workflow: sculpt/generate → thermal erosion → smooth → auto-paint
This commit is contained in:
parent
9be32a6634
commit
2d5692d5ad
3 changed files with 52 additions and 0 deletions
|
|
@ -603,6 +603,19 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
|
|||
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Thermal Erosion")) {
|
||||
static int erosionIters = 10;
|
||||
static float talusAngle = 40.0f;
|
||||
ImGui::SliderInt("Iterations##therm", &erosionIters, 1, 50);
|
||||
ImGui::SliderFloat("Talus Angle##therm", &talusAngle, 10.0f, 80.0f, "%.0f deg");
|
||||
if (ImGui::Button("Apply Thermal Erosion", ImVec2(-1, 0))) {
|
||||
app.getTerrainEditor().thermalErosion(erosionIters, talusAngle);
|
||||
app.showToast("Thermal erosion applied");
|
||||
}
|
||||
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1),
|
||||
"Material slides downhill. Lower angle = more erosion.");
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Terrace / Steps")) {
|
||||
static int terraceSteps = 6;
|
||||
ImGui::SliderInt("Steps##terrace", &terraceSteps, 2, 20);
|
||||
|
|
|
|||
|
|
@ -860,6 +860,42 @@ void TerrainEditor::createHill(const glm::vec3& center, float radius, float heig
|
|||
dirty_ = true;
|
||||
}
|
||||
|
||||
void TerrainEditor::thermalErosion(int iterations, float talusAngle) {
|
||||
if (!terrain_) return;
|
||||
float unitSize = CHUNK_SIZE / 8.0f;
|
||||
float maxDelta = std::tan(talusAngle * 3.14159f / 180.0f) * unitSize;
|
||||
|
||||
for (int iter = 0; iter < iterations; iter++) {
|
||||
for (int ci = 0; ci < 256; ci++) {
|
||||
auto& chunk = terrain_->chunks[ci];
|
||||
if (!chunk.hasHeightMap()) continue;
|
||||
for (int v = 0; v < 145; v++) {
|
||||
int row = v / 17, col = v % 17;
|
||||
if (col > 8) continue;
|
||||
float h = chunk.heightMap.heights[v];
|
||||
int neighbors[] = {v - 17, v + 17, v - 1, v + 1};
|
||||
for (int n : neighbors) {
|
||||
if (n < 0 || n >= 145) continue;
|
||||
int nRow = n / 17, nCol = n % 17;
|
||||
if (nCol > 8 || std::abs(nRow - row) > 1 || std::abs(nCol - col) > 1) continue;
|
||||
float nh = chunk.heightMap.heights[n];
|
||||
float delta = h - nh;
|
||||
if (delta > maxDelta) {
|
||||
float transfer = (delta - maxDelta) * 0.25f;
|
||||
chunk.heightMap.heights[v] -= transfer;
|
||||
chunk.heightMap.heights[n] += transfer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int ci = 0; ci < 256; ci++) {
|
||||
stitchEdges(ci);
|
||||
dirtyChunks_.push_back(ci);
|
||||
}
|
||||
dirty_ = true;
|
||||
}
|
||||
|
||||
void TerrainEditor::terraceHeights(int steps) {
|
||||
if (!terrain_ || steps < 2) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,9 @@ public:
|
|||
// Terrace/quantize heights into N steps
|
||||
void terraceHeights(int steps);
|
||||
|
||||
// Thermal erosion: material falls downhill based on angle of repose
|
||||
void thermalErosion(int iterations, float talusAngle);
|
||||
|
||||
// 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