feat(editor): road flattener tool alongside river carver

- River/Road Carver section now has two modes:
  - River: carves a channel below terrain (existing)
  - Road: flattens terrain to interpolated height between start/end
- Road mode smoothly transitions height along the path with quadratic
  falloff at edges for natural embankment shape
- Set Start → Set End + Apply workflow works for both modes
- Roads follow terrain slope by interpolating between start/end heights
- Pair with Paint mode to add cobblestone/dirt texture on the road
This commit is contained in:
Kelsi 2026-05-05 06:37:54 -07:00
parent d253aed635
commit 3ac40d27ad
3 changed files with 71 additions and 17 deletions

View file

@ -752,6 +752,50 @@ void TerrainEditor::carveRiver(const glm::vec3& start, const glm::vec3& end,
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);
glm::vec2 lineEnd(end.x, end.y);
glm::vec2 lineDir = glm::normalize(lineEnd - lineStart);
float lineLen = glm::length(lineEnd - lineStart);
// Interpolate height along the path
auto heightAtT = [&](float t) -> float {
return start.z + (end.z - start.z) * (t / lineLen);
};
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 t = glm::dot(toP, lineDir);
t = std::clamp(t, 0.0f, lineLen);
glm::vec2 closest = lineStart + lineDir * t;
float dist = glm::length(p - closest);
if (dist < width) {
float targetH = heightAtT(t);
float relTarget = targetH - chunk.position[2];
float falloff = 1.0f - (dist / width);
falloff = falloff * falloff;
float h = chunk.heightMap.heights[v];
chunk.heightMap.heights[v] = h + (relTarget - h) * falloff;
modified = true;
}
}
if (modified) {
stitchEdges(ci);
dirtyChunks_.push_back(ci);
}
}
dirty_ = true;
}
void TerrainEditor::copyStamp(const glm::vec3& center, float radius) {
if (!terrain_) return;
stampData_.clear();