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

refactor: streamline namespaces of xmodel dumping and loading

This commit is contained in:
Jan Laupetin
2025-08-03 17:47:21 +02:00
parent 0546572ecf
commit 250556ab61
16 changed files with 39 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
#include "XModelCommon.h" #include "XModelCommon.h"
#include <cmath> #include <cmath>
#include <format>
#include <limits> #include <limits>
#include <tuple> #include <tuple>
@@ -99,3 +100,11 @@ bool operator<(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
return false; return false;
} }
namespace xmodel
{
std::string GetJsonFileNameForAssetName(const std::string& assetName)
{
return std::format("xmodel/{}.json", assetName);
}
} // namespace xmodel

View File

@@ -127,3 +127,8 @@ struct VertexMergerPos
}; };
typedef DistinctMapper<VertexMergerPos> VertexMerger; typedef DistinctMapper<VertexMergerPos> VertexMerger;
namespace xmodel
{
std::string GetJsonFileNameForAssetName(const std::string& assetName);
}

View File

@@ -3,6 +3,7 @@
#include "Asset/GlobalAssetPoolsLoader.h" #include "Asset/GlobalAssetPoolsLoader.h"
#include "Game/IW3/GameIW3.h" #include "Game/IW3/GameIW3.h"
#include "Game/IW3/IW3.h" #include "Game/IW3/IW3.h"
#include "Game/IW3/XModel/LoaderXModelIW3.h"
#include "Image/AssetLoaderImageIW3.h" #include "Image/AssetLoaderImageIW3.h"
#include "Localize/AssetLoaderLocalizeIW3.h" #include "Localize/AssetLoaderLocalizeIW3.h"
#include "Material/LoaderMaterialIW3.h" #include "Material/LoaderMaterialIW3.h"
@@ -90,7 +91,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
collection.AddAssetCreator(CreateImageLoader(memory, searchPath)); collection.AddAssetCreator(CreateImageLoader(memory, searchPath));

View File

@@ -124,7 +124,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
collection.AddAssetCreator(CreatePixelShaderLoader(memory, searchPath)); collection.AddAssetCreator(CreatePixelShaderLoader(memory, searchPath));
collection.AddAssetCreator(CreateVertexShaderLoader(memory, searchPath)); collection.AddAssetCreator(CreateVertexShaderLoader(memory, searchPath));

View File

@@ -125,7 +125,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderPixelShader>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderPixelShader>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderVertexShader>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderVertexShader>(memory));

View File

@@ -104,7 +104,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysConstraints>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderPhysConstraints>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImage>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderImage>(memory));

View File

@@ -399,7 +399,7 @@ namespace T6
collection.AddAssetCreator(CreateGdtPhysConstraintsLoader(memory, searchPath, gdt, zone)); collection.AddAssetCreator(CreateGdtPhysConstraintsLoader(memory, searchPath, gdt, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
collection.AddAssetCreator(CreateImageLoader(memory, searchPath)); collection.AddAssetCreator(CreateImageLoader(memory, searchPath));

View File

@@ -1082,7 +1082,7 @@ namespace
}; };
} // namespace } // namespace
namespace GAME namespace GAME::xmodel
{ {
std::unique_ptr<AssetCreator<AssetXModel>> CreateXModelLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) std::unique_ptr<AssetCreator<AssetXModel>> CreateXModelLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{ {

View File

@@ -13,7 +13,7 @@
#include <memory> #include <memory>
namespace GAME namespace GAME::xmodel
{ {
std::unique_ptr<AssetCreator<AssetXModel>> CreateXModelLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); std::unique_ptr<AssetCreator<AssetXModel>> CreateXModelLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace GAME } // namespace GAME

View File

@@ -26,7 +26,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET) // DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
// DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) // DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)

View File

@@ -42,7 +42,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
DUMP_ASSET_POOL(phys_preset::InfoStringDumper, m_phys_preset, ASSET_TYPE_PHYSPRESET) DUMP_ASSET_POOL(phys_preset::InfoStringDumper, m_phys_preset, ASSET_TYPE_PHYSPRESET)
DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP) DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
#ifdef EXPERIMENTAL_MATERIAL_COMPILATION #ifdef EXPERIMENTAL_MATERIAL_COMPILATION
DUMP_ASSET_POOL(material::DecompilingGdtDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::DecompilingGdtDumper, m_material, ASSET_TYPE_MATERIAL)

View File

@@ -33,7 +33,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP) // DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
// DUMP_ASSET_POOL(AssetDumperXModelSurfs, m_xmodel_surfs, ASSET_TYPE_XMODEL_SURFS) // DUMP_ASSET_POOL(AssetDumperXModelSurfs, m_xmodel_surfs, ASSET_TYPE_XMODEL_SURFS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
// DUMP_ASSET_POOL(AssetDumperMaterialPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER) // DUMP_ASSET_POOL(AssetDumperMaterialPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER)
// DUMP_ASSET_POOL(AssetDumperMaterialVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER) // DUMP_ASSET_POOL(AssetDumperMaterialVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER)

View File

@@ -26,7 +26,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS) // DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)
// DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF) // DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
// DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) // DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)

View File

@@ -50,7 +50,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
DUMP_ASSET_POOL(phys_constraints::InfoStringDumper, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS) DUMP_ASSET_POOL(phys_constraints::InfoStringDumper, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)
// DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF) // DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)

View File

@@ -47,6 +47,7 @@
#include <format> #include <format>
using namespace GAME; using namespace GAME;
using namespace ::xmodel;
namespace namespace
{ {
@@ -830,7 +831,7 @@ namespace
void DumpXModelJson(AssetDumpingContext& context, XAssetInfo<XModel>* asset) void DumpXModelJson(AssetDumpingContext& context, XAssetInfo<XModel>* asset)
{ {
const auto assetFile = context.OpenAssetFile(std::format("xmodel/{}.json", asset->m_name)); const auto assetFile = context.OpenAssetFile(GetJsonFileNameForAssetName(asset->m_name));
if (!assetFile) if (!assetFile)
return; return;
@@ -839,13 +840,16 @@ namespace
} }
} // namespace } // namespace
bool AssetDumperXModel::ShouldDump(XAssetInfo<XModel>* asset) namespace GAME::xmodel
{ {
bool Dumper::ShouldDump(XAssetInfo<XModel>* asset)
{
return !asset->m_name.empty() && asset->m_name[0] != ','; return !asset->m_name.empty() && asset->m_name[0] != ',';
} }
void AssetDumperXModel::DumpAsset(AssetDumpingContext& context, XAssetInfo<XModel>* asset) void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<XModel>* asset)
{ {
DumpXModelJson(context, asset); DumpXModelJson(context, asset);
DumpXModelSurfs(context, asset); DumpXModelSurfs(context, asset);
}
} }

View File

@@ -13,9 +13,9 @@
#include "Dumping/AbstractAssetDumper.h" #include "Dumping/AbstractAssetDumper.h"
#include GAME_HEADER #include GAME_HEADER
namespace GAME namespace GAME::xmodel
{ {
class AssetDumperXModel final : public AbstractAssetDumper<XModel> class Dumper final : public AbstractAssetDumper<XModel>
{ {
protected: protected:
bool ShouldDump(XAssetInfo<XModel>* asset) override; bool ShouldDump(XAssetInfo<XModel>* asset) override;