feat(editor): crater generator for lakes, arenas, impact sites

- Crater Generator in Sculpt panel: creates a bowl-shaped depression
  with configurable radius, depth, and raised rim height
- Parabolic bowl interior with sinusoidal rim and smooth outer falloff
- Perfect for creating lakes (fill with Water mode), arenas, or
  impact craters for volcanic zones
- One click at cursor position, uses brush position for center
This commit is contained in:
Kelsi 2026-05-05 06:50:24 -07:00
parent 496f97f9db
commit 1502c2ed85
3 changed files with 57 additions and 0 deletions

View file

@ -764,6 +764,47 @@ void TerrainEditor::carveRiver(const glm::vec3& start, const glm::vec3& end,
dirty_ = true;
}
void TerrainEditor::createCrater(const glm::vec3& center, float radius, float depth, float rimHeight) {
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++) {
glm::vec3 pos = chunkVertexWorldPos(ci, v);
float dist = glm::length(glm::vec2(pos.x - center.x, pos.y - center.y));
if (dist > radius * 1.3f) continue;
float t = dist / radius;
float delta = 0.0f;
if (t < 0.8f) {
// Bowl interior: parabolic depression
float bowlT = t / 0.8f;
delta = -depth * (1.0f - bowlT * bowlT);
} else if (t < 1.0f) {
// Rim: raised edge
float rimT = (t - 0.8f) / 0.2f;
delta = rimHeight * std::sin(rimT * 3.14159f);
} else if (t < 1.3f) {
// Outer falloff
float fallT = (t - 1.0f) / 0.3f;
delta = rimHeight * (1.0f - fallT) * 0.3f;
}
chunk.heightMap.heights[v] += delta;
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);