feat(editor): BLP→PNG texture export for open format zones

- TextureExporter: converts Blizzard BLP textures to standard PNG
  for fully open redistribution of custom zones
- collectUsedTextures(): finds all texture paths referenced by terrain
- exportTexturesAsPng(): loads BLP via asset manager, writes RGBA PNG
  using stb_image_write to output/MapName/textures/
- Zone export now automatically converts all used textures to PNG
- Client's PNG override system already loads these automatically
  (checks for .png alongside .blp before loading)

Format replacement progress:
- DONE: ADT→WOT/WHM (terrain)
- DONE: WDT→zone.json (map definition)
- DONE: BLP→PNG (textures — auto-exported on zone save)
- TODO: DBC→JSON, M2→open model, WMO→open building
This commit is contained in:
Kelsi 2026-05-05 10:17:03 -07:00
parent 5adb6cb364
commit cb3de59b5c
4 changed files with 100 additions and 0 deletions

View file

@ -1299,6 +1299,7 @@ add_executable(wowee_editor
tools/editor/content_pack.cpp
tools/editor/wowee_terrain.cpp
tools/editor/editor_project.cpp
tools/editor/texture_exporter.cpp
tools/editor/asset_browser.cpp
tools/editor/editor_water.cpp
tools/editor/editor_markers.cpp

View file

@ -3,6 +3,7 @@
#include "zone_manifest.hpp"
#include "content_pack.hpp"
#include "wowee_terrain.hpp"
#include "texture_exporter.hpp"
#include "core/coordinates.hpp"
#include "rendering/vk_context.hpp"
#include "pipeline/adt_loader.hpp"
@ -731,6 +732,14 @@ void EditorApp::exportZone(const std::string& outputDir) {
objectPlacer_.saveToFile(objPath);
}
// Export used textures as PNG (open format replacement for BLP)
auto usedTextures = TextureExporter::collectUsedTextures(terrain_);
if (!usedTextures.empty()) {
int exported = TextureExporter::exportTexturesAsPng(
assetManager_.get(), usedTextures, base + "/textures");
LOG_INFO("Exported ", exported, " textures as PNG");
}
// Export open terrain format alongside ADT
std::string openBase = base + "/" + loadedMap_ + "_" +
std::to_string(loadedTileX_) + "_" + std::to_string(loadedTileY_);

View file

@ -0,0 +1,64 @@
#include "texture_exporter.hpp"
#include "pipeline/asset_manager.hpp"
#include "pipeline/blp_loader.hpp"
#include "core/logger.hpp"
#include <filesystem>
#include <algorithm>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
namespace wowee {
namespace editor {
std::vector<std::string> TextureExporter::collectUsedTextures(const pipeline::ADTTerrain& terrain) {
std::unordered_set<std::string> unique;
for (const auto& tex : terrain.textures)
unique.insert(tex);
std::vector<std::string> result(unique.begin(), unique.end());
std::sort(result.begin(), result.end());
return result;
}
int TextureExporter::exportTexturesAsPng(pipeline::AssetManager* am,
const std::vector<std::string>& texturePaths,
const std::string& outputDir) {
namespace fs = std::filesystem;
int exported = 0;
for (const auto& texPath : texturePaths) {
auto blpImage = am->loadTexture(texPath);
if (!blpImage.isValid()) {
LOG_WARNING("Texture not found or invalid: ", texPath);
continue;
}
// Build output path: replace backslashes, change .blp to .png
std::string outPath = texPath;
std::replace(outPath.begin(), outPath.end(), '\\', '/');
// Lowercase
std::transform(outPath.begin(), outPath.end(), outPath.begin(),
[](unsigned char c) { return std::tolower(c); });
// Change extension
auto dotPos = outPath.rfind('.');
if (dotPos != std::string::npos)
outPath = outPath.substr(0, dotPos) + ".png";
std::string fullPath = outputDir + "/" + outPath;
fs::create_directories(fs::path(fullPath).parent_path());
// Write RGBA data as PNG
if (stbi_write_png(fullPath.c_str(), blpImage.width, blpImage.height, 4,
blpImage.data.data(), blpImage.width * 4)) {
exported++;
} else {
LOG_WARNING("Failed to write PNG: ", fullPath);
}
}
LOG_INFO("Exported ", exported, "/", texturePaths.size(), " textures as PNG to ", outputDir);
return exported;
}
} // namespace editor
} // namespace wowee

View file

@ -0,0 +1,26 @@
#pragma once
#include "pipeline/adt_loader.hpp"
#include <string>
#include <vector>
#include <unordered_set>
namespace wowee {
namespace pipeline { class AssetManager; }
namespace editor {
class TextureExporter {
public:
// Collect all texture paths referenced by the terrain
static std::vector<std::string> collectUsedTextures(const pipeline::ADTTerrain& terrain);
// Export all used textures as PNG to an output directory
// Returns count of successfully exported textures
static int exportTexturesAsPng(pipeline::AssetManager* am,
const std::vector<std::string>& texturePaths,
const std::string& outputDir);
};
} // namespace editor
} // namespace wowee