2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-01 22:47:26 +00:00

refactor: restructure image dumper

This commit is contained in:
Jan Laupetin
2025-07-28 23:15:45 +01:00
parent 9a6f0c8919
commit 22dbf57269
17 changed files with 245 additions and 240 deletions

View File

@@ -1,7 +1,8 @@
#include "AssetDumperGfxImage.h"
#include "ImageDumperIW3.h"
#include "Image/DdsWriter.h"
#include "Image/Dx9TextureLoader.h"
#include "Image/ImageCommon.h"
#include "Image/IwiLoader.h"
#include "Image/IwiTypes.h"
#include "Image/IwiWriter6.h"
@@ -13,7 +14,9 @@
#include <cassert>
#include <format>
using namespace IW3;
using namespace ::image;
namespace
{
@@ -58,48 +61,43 @@ namespace
}
} // namespace
AssetDumperGfxImage::AssetDumperGfxImage()
namespace IW3::image
{
switch (ObjWriting::Configuration.ImageOutputFormat)
Dumper::Dumper()
{
case ObjWriting::Configuration_t::ImageOutputFormat_e::DDS:
m_writer = std::make_unique<DdsWriter>();
break;
case ObjWriting::Configuration_t::ImageOutputFormat_e::IWI:
m_writer = std::make_unique<iwi6::IwiWriter>();
break;
default:
assert(false);
m_writer = nullptr;
break;
switch (ObjWriting::Configuration.ImageOutputFormat)
{
case ObjWriting::Configuration_t::ImageOutputFormat_e::DDS:
m_writer = std::make_unique<DdsWriter>();
break;
case ObjWriting::Configuration_t::ImageOutputFormat_e::IWI:
m_writer = std::make_unique<iwi6::IwiWriter>();
break;
default:
assert(false);
m_writer = nullptr;
break;
}
}
}
bool AssetDumperGfxImage::ShouldDump(XAssetInfo<GfxImage>* asset)
{
return true;
}
bool Dumper::ShouldDump(XAssetInfo<GfxImage>* asset)
{
return true;
}
std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& asset) const
{
auto cleanAssetName = asset.m_name;
std::ranges::replace(cleanAssetName, '*', '_');
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;
return std::format("images/{}{}", cleanAssetName, m_writer->GetFileExtension());
}
const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset->m_name, m_writer->GetFileExtension()));
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;
if (!assetFile)
return;
const auto assetFile = context.OpenAssetFile(GetAssetFileName(*asset));
if (!assetFile)
return;
auto& stream = *assetFile;
m_writer->DumpImage(stream, texture.get());
}
auto& stream = *assetFile;
m_writer->DumpImage(stream, texture.get());
}
} // namespace IW3::image

View File

@@ -6,19 +6,18 @@
#include <memory>
namespace IW3
namespace IW3::image
{
class AssetDumperGfxImage final : public AbstractAssetDumper<GfxImage>
class Dumper final : public AbstractAssetDumper<GfxImage>
{
std::unique_ptr<IImageWriter> m_writer;
[[nodiscard]] std::string GetAssetFileName(const XAssetInfo<GfxImage>& asset) const;
public:
Dumper();
protected:
bool ShouldDump(XAssetInfo<GfxImage>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset) override;
public:
AssetDumperGfxImage();
private:
std::unique_ptr<IImageWriter> m_writer;
};
} // namespace IW3
} // namespace IW3::image

View File

@@ -2,7 +2,7 @@
#include "Game/IW3/GameAssetPoolIW3.h"
#include "Game/IW3/XModel/XModelDumperIW3.h"
#include "Image/AssetDumperGfxImage.h"
#include "Image/ImageDumperIW3.h"
#include "Localize/AssetDumperLocalizeEntry.h"
#include "Maps/AssetDumperMapEnts.h"
#include "Material/DumperMaterialIW3.h"
@@ -30,7 +30,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(AssetDumperMaterial, m_material, ASSET_TYPE_MATERIAL)
// DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(AssetDumperGfxImage, m_image, ASSET_TYPE_IMAGE)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)
// DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND)
// DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
DUMP_ASSET_POOL(AssetDumperLoadedSound, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)