fix(editor): ADT doodad/WMO coordinate conversion, auto-find tile on map select

- ADT doodad/WMO positions now converted from ADT space to render coords
  via core::coords::adtToWorld() — fixes objects appearing at wrong positions
  when loading existing WoW maps
- Selecting a map in the Load dialog now auto-finds the first valid tile
  (no more clicking "Find Tile" manually — it's automatic)
- Better error messages with toast for failed terrain loads
- Validates mesh has valid chunks before attempting GPU upload
This commit is contained in:
Kelsi 2026-05-05 08:55:09 -07:00
parent 9c0bc5fbd1
commit 61f0f39611
2 changed files with 31 additions and 4 deletions

View file

@ -1,6 +1,7 @@
#include "editor_app.hpp"
#include "adt_writer.hpp"
#include "zone_manifest.hpp"
#include "core/coordinates.hpp"
#include "rendering/vk_context.hpp"
#include "pipeline/adt_loader.hpp"
#include "pipeline/terrain_mesh.hpp"
@ -562,9 +563,15 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) {
objectPlacer_.setTerrain(&terrain_);
auto mesh = pipeline::TerrainMeshGenerator::generate(terrain_);
if (mesh.validChunkCount == 0) {
LOG_ERROR("ADT has no valid terrain chunks");
showToast("Error: no valid terrain data in this tile");
return;
}
viewport_.clearTerrain();
if (!viewport_.loadTerrain(mesh, terrain_.textures, tileX, tileY)) {
LOG_ERROR("Failed to upload terrain to GPU");
LOG_ERROR("Failed to upload terrain to GPU (", mesh.validChunkCount, " chunks)");
showToast("Error: terrain upload failed");
return;
}
@ -578,12 +585,13 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) {
camera_.setYawPitch(0.0f, -45.0f);
// Import doodad/WMO placements from the ADT itself
// ADT positions are in ADT coordinate space — convert to render coords
for (const auto& dp : terrain_.doodadPlacements) {
if (dp.nameId < terrain_.doodadNames.size()) {
PlacedObject obj;
obj.type = PlaceableType::M2;
obj.path = terrain_.doodadNames[dp.nameId];
obj.position = glm::vec3(dp.position[0], dp.position[1], dp.position[2]);
obj.position = core::coords::adtToWorld(dp.position[0], dp.position[1], dp.position[2]);
obj.rotation = glm::vec3(dp.rotation[0], dp.rotation[1], dp.rotation[2]);
obj.scale = static_cast<float>(dp.scale) / 1024.0f;
obj.uniqueId = dp.uniqueId;
@ -595,7 +603,7 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) {
PlacedObject obj;
obj.type = PlaceableType::WMO;
obj.path = terrain_.wmoNames[wp.nameId];
obj.position = glm::vec3(wp.position[0], wp.position[1], wp.position[2]);
obj.position = core::coords::adtToWorld(wp.position[0], wp.position[1], wp.position[2]);
obj.rotation = glm::vec3(wp.rotation[0], wp.rotation[1], wp.rotation[2]);
obj.scale = 1.0f;
obj.uniqueId = wp.uniqueId;

View file

@ -383,8 +383,27 @@ void EditorUI::renderLoadDialog(EditorApp& app) {
for (const auto& m : maps) {
if (!filter.empty() && m.find(filter) == std::string::npos) continue;
bool selected = (m == std::string(loadMapNameBuf_));
if (ImGui::Selectable(m.c_str(), selected))
if (ImGui::Selectable(m.c_str(), selected)) {
std::strncpy(loadMapNameBuf_, m.c_str(), sizeof(loadMapNameBuf_) - 1);
// Auto-find first valid tile for this map
std::string ml = m;
bool found = false;
for (int x = 25; x < 45 && !found; x++)
for (int y = 25; y < 45 && !found; y++) {
std::string tp = "world\\maps\\" + ml + "\\" + ml + "_" +
std::to_string(x) + "_" + std::to_string(y) + ".adt";
if (app.getAssetManager()->getManifest().hasEntry(tp))
{ loadTileX_ = x; loadTileY_ = y; found = true; }
}
if (!found)
for (int x = 0; x < 64 && !found; x++)
for (int y = 0; y < 64 && !found; y++) {
std::string tp = "world\\maps\\" + ml + "\\" + ml + "_" +
std::to_string(x) + "_" + std::to_string(y) + ".adt";
if (app.getAssetManager()->getManifest().hasEntry(tp))
{ loadTileX_ = x; loadTileY_ = y; found = true; }
}
}
}
ImGui::EndChild();