mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-02 15:07:26 +00:00
refactor: restructure image dumper
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "AssetDumperGfxImage.h"
|
||||
#include "ImageDumperIW5.h"
|
||||
|
||||
#include "Image/DdsWriter.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/ImageCommon.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiWriter8.h"
|
||||
#include "ObjWriting.h"
|
||||
@@ -10,7 +11,9 @@
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
|
||||
using namespace IW5;
|
||||
using namespace ::image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -56,48 +59,43 @@ namespace
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AssetDumperGfxImage::AssetDumperGfxImage()
|
||||
namespace IW5::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<iwi8::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<iwi8::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 IW5::image
|
@@ -6,19 +6,18 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW5
|
||||
namespace IW5::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 IW5
|
||||
} // namespace IW5::image
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
||||
#include "Image/AssetDumperGfxImage.h"
|
||||
#include "Image/ImageDumperIW5.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
||||
#include "Localize/AssetDumperLocalizeEntry.h"
|
||||
#include "Maps/AssetDumperAddonMapEnts.h"
|
||||
@@ -39,7 +39,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
// DUMP_ASSET_POOL(AssetDumperMaterialVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER)
|
||||
// DUMP_ASSET_POOL(AssetDumperMaterialVertexDeclaration, m_material_vertex_decl, ASSET_TYPE_VERTEXDECL)
|
||||
// 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)
|
||||
|
Reference in New Issue
Block a user