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

@ -551,6 +551,19 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
}
if (ImGui::CollapsingHeader("Crater Generator")) {
static float craterRadius = 30.0f, craterDepth = 10.0f, craterRim = 3.0f;
ImGui::SliderFloat("Radius##crater", &craterRadius, 5.0f, 100.0f);
ImGui::SliderFloat("Depth##crater", &craterDepth, 2.0f, 50.0f);
ImGui::SliderFloat("Rim Height##crater", &craterRim, 0.0f, 15.0f);
auto& brush5 = app.getTerrainEditor().brush();
if (ImGui::Button("Create Crater at Cursor", ImVec2(-1, 0)) && brush5.isActive()) {
app.getTerrainEditor().createCrater(brush5.getPosition(), craterRadius, craterDepth, craterRim);
app.showToast("Crater created");
}
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "Bowl with raised rim. Fill with water for a lake.");
}
if (ImGui::CollapsingHeader("Flatten Platform")) {
auto& brush3 = app.getTerrainEditor().brush();
if (ImGui::Button("Create Flat Platform at Cursor", ImVec2(-1, 0)) && brush3.isActive()) {

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);

View file

@ -81,6 +81,9 @@ public:
// Flatten a road between two points (smooths to average height along path)
void flattenRoad(const glm::vec3& start, const glm::vec3& end, float width);
// Create a crater at a position (bowl shape with raised rim)
void createCrater(const glm::vec3& center, float radius, float depth, float rimHeight);
// Import/export heightmap (raw 16-bit grayscale, 129x129)
bool importHeightmap(const std::string& path, float heightScale);
bool exportHeightmap(const std::string& path, float heightScale);