mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-30 16:27:47 +00:00
refactor: move iw3,iw4,iw5,t5 dumpers into seperate folders
This commit is contained in:
105
src/ObjWriting/Game/IW3/Image/AssetDumperGfxImage.cpp
Normal file
105
src/ObjWriting/Game/IW3/Image/AssetDumperGfxImage.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "AssetDumperGfxImage.h"
|
||||
|
||||
#include "Image/DdsWriter.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "Image/IwiWriter6.h"
|
||||
#include "Image/Texture.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
|
||||
{
|
||||
Dx9TextureLoader textureLoader;
|
||||
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
textureLoader.Width(loadDef.dimensions[0]).Height(loadDef.dimensions[1]).Depth(loadDef.dimensions[2]);
|
||||
|
||||
if (loadDef.flags & iwi6::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef.flags & iwi6::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi6::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
|
||||
{
|
||||
const auto imageFileName = std::format("images/{}.iwi", image.name);
|
||||
const auto filePathImage = searchPath.Open(imageFileName);
|
||||
if (!filePathImage.IsOpen())
|
||||
{
|
||||
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
{
|
||||
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
|
||||
return LoadImageFromLoadDef(image);
|
||||
|
||||
return LoadImageFromIwi(image, searchPath);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AssetDumperGfxImage::AssetDumperGfxImage()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& asset) const
|
||||
{
|
||||
auto cleanAssetName = asset.m_name;
|
||||
std::ranges::replace(cleanAssetName, '*', '_');
|
||||
|
||||
return std::format("images/{}{}", cleanAssetName, 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;
|
||||
|
||||
const auto assetFile = context.OpenAssetFile(GetAssetFileName(*asset));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
m_writer->DumpImage(stream, texture.get());
|
||||
}
|
||||
24
src/ObjWriting/Game/IW3/Image/AssetDumperGfxImage.h
Normal file
24
src/ObjWriting/Game/IW3/Image/AssetDumperGfxImage.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetDumperGfxImage final : public AbstractAssetDumper<GfxImage>
|
||||
{
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
|
||||
[[nodiscard]] std::string GetAssetFileName(const XAssetInfo<GfxImage>& asset) const;
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<GfxImage>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset) override;
|
||||
|
||||
public:
|
||||
AssetDumperGfxImage();
|
||||
};
|
||||
} // namespace IW3
|
||||
Reference in New Issue
Block a user