feat(editor): height clamp tool for controlled terrain range

- Clamp Heights: sets min/max height bounds across entire tile
  (DragFloatRange2 slider for min/max, -500 to 2000 range)
- Useful workflow: Generate noise → Smooth → Clamp to desired range
- Prevents terrain from going underground or too high
- All affected chunks marked dirty for mesh regeneration
This commit is contained in:
Kelsi 2026-05-05 05:51:03 -07:00
parent c93a997424
commit d59d69b0c5
3 changed files with 32 additions and 1 deletions

View file

@ -652,6 +652,27 @@ void TerrainEditor::smoothEntireTile(int iterations) {
dirty_ = true;
}
void TerrainEditor::clampHeights(float minH, float maxH) {
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++) {
float absH = chunk.position[2] + chunk.heightMap.heights[v];
if (absH < minH) {
chunk.heightMap.heights[v] = minH - chunk.position[2];
modified = true;
} else if (absH > maxH) {
chunk.heightMap.heights[v] = maxH - chunk.position[2];
modified = true;
}
}
if (modified) dirtyChunks_.push_back(ci);
}
dirty_ = true;
}
void TerrainEditor::applyErode(float dt) {
float factor = std::min(1.0f, brush_.settings().strength * dt * 0.3f);