feat(editor): in-editor "Audit Spawns Against Terrain" menu

EditorApp::auditSpawnsAgainstTerrain(threshold) counts every
creature + object whose Z is more than `threshold` yards off the
sampled terrain. Returns the issue count; non-mutating.

Generate menu gets a new "Audit Spawns Against Terrain" item that
runs the audit at the default 5y threshold and shows a toast: a
clean count if everything's fine, or the issue count + a hint to
run "Snap All" if not. Surfaces placement bugs without dropping
to the CLI.

Pairs with the existing "Snap All Spawns to Ground" so the
workflow stays inside the editor: audit → see count → snap →
audit again.
This commit is contained in:
Kelsi 2026-05-07 15:47:26 -07:00
parent 6c84a8da6c
commit 6a7ea6dcfc
3 changed files with 42 additions and 0 deletions

View file

@ -1830,6 +1830,30 @@ void EditorApp::snapAllSpawnsToGround() {
std::to_string(snappedO) + " object(s) to ground");
}
int EditorApp::auditSpawnsAgainstTerrain(float threshold) const {
if (!terrain_.isLoaded()) return 0;
auto castDown = [&](const glm::vec3& pos, glm::vec3& hit) {
rendering::Ray ray;
ray.origin = pos + glm::vec3(0, 0, 500);
ray.direction = glm::vec3(0, 0, -1);
return const_cast<TerrainEditor&>(terrainEditor_).raycastTerrain(ray, hit);
};
int issues = 0;
for (const auto& s : npcSpawner_.getSpawns()) {
glm::vec3 hit;
if (castDown(s.position, hit)) {
if (std::fabs(s.position.z - hit.z) > threshold) issues++;
}
}
for (const auto& o : objectPlacer_.getObjects()) {
glm::vec3 hit;
if (castDown(o.position, hit)) {
if (std::fabs(o.position.z - hit.z) > threshold) issues++;
}
}
return issues;
}
void EditorApp::clearAllObjects() {
vkDeviceWaitIdle(window_->getVkContext()->getDevice());
objectPlacer_.clearAll();