mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-08 18:13:52 +00:00
feat(editor): in-editor "Snap All Spawns to Ground" menu
Adds EditorApp::snapAllSpawnsToGround() and a menu item under Generate, mirroring the --snap-zone-to-ground CLI for users who want the action without context-switching to a terminal. Walks every NPC + object, casts a downward ray from baseZ+500y, and writes the hit Z into spawn.position.z. Patrol waypoints on each NPC are snapped too. Marks the project dirty + auto-save pending so the change persists without a manual Ctrl+S. Existing per-selection "Snap Ground" button on the right panel is unchanged; this is the bulk version for "I just edited terrain under a populated area."
This commit is contained in:
parent
f589fa20ce
commit
f870a516dd
3 changed files with 50 additions and 0 deletions
|
|
@ -1792,6 +1792,44 @@ void EditorApp::randomPopulateZone(int creatureCount, int objectCount,
|
|||
" creatures + " + std::to_string(placedObjects) + " objects");
|
||||
}
|
||||
|
||||
void EditorApp::snapAllSpawnsToGround() {
|
||||
if (!terrain_.isLoaded()) {
|
||||
showToast("Load a tile first");
|
||||
return;
|
||||
}
|
||||
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 terrainEditor_.raycastTerrain(ray, hit);
|
||||
};
|
||||
int snappedC = 0, snappedO = 0;
|
||||
for (auto& s : npcSpawner_.getSpawns()) {
|
||||
glm::vec3 hit;
|
||||
if (castDown(s.position, hit)) {
|
||||
s.position.z = hit.z;
|
||||
snappedC++;
|
||||
}
|
||||
for (auto& wp : s.patrolPath) {
|
||||
if (castDown(wp.position, hit)) wp.position.z = hit.z;
|
||||
}
|
||||
}
|
||||
for (auto& o : objectPlacer_.getObjects()) {
|
||||
glm::vec3 hit;
|
||||
if (castDown(o.position, hit)) {
|
||||
o.position.z = hit.z;
|
||||
snappedO++;
|
||||
}
|
||||
}
|
||||
if (snappedC > 0 || snappedO > 0) {
|
||||
objectsDirty_ = true;
|
||||
autoSavePendingChanges_ = true;
|
||||
viewport_.updateNpcMarkers(npcSpawner_.getSpawns());
|
||||
}
|
||||
showToast("Snapped " + std::to_string(snappedC) + " creature(s) + " +
|
||||
std::to_string(snappedO) + " object(s) to ground");
|
||||
}
|
||||
|
||||
void EditorApp::clearAllObjects() {
|
||||
vkDeviceWaitIdle(window_->getVkContext()->getDevice());
|
||||
objectPlacer_.clearAll();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue