mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
chore: move xmodel dumping and loading code into generic files
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include "AssetLoaderXModel.h"
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Game/T6/XModel/JsonXModelLoader.h"
|
||||
#include "Game/T6/XModel/XModelLoaderT6.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
@ -33,7 +33,7 @@ bool AssetLoaderXModel::LoadFromRaw(
|
||||
xmodel->name = memory->Dup(assetName.c_str());
|
||||
|
||||
std::vector<XAssetInfoGeneric*> dependencies;
|
||||
if (LoadXModelAsJson(*file.m_stream, *xmodel, memory, manager, dependencies))
|
||||
if (LoadXModel(*file.m_stream, *xmodel, memory, manager, dependencies))
|
||||
manager->AddAsset<AssetXModel>(assetName, xmodel, std::move(dependencies));
|
||||
else
|
||||
std::cerr << std::format("Failed to load xmodel \"{}\"\n", assetName);
|
||||
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <istream>
|
||||
|
||||
namespace T6
|
||||
{
|
||||
bool LoadXModelAsJson(
|
||||
std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies);
|
||||
} // namespace T6
|
51
src/ObjLoading/Game/T6/XModel/XModelLoaderT6.cpp
Normal file
51
src/ObjLoading/Game/T6/XModel/XModelLoaderT6.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "XModelLoaderT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/Json/JsonXModel.h"
|
||||
|
||||
#define GAME_NAMESPACE T6
|
||||
|
||||
namespace T6
|
||||
{
|
||||
const char* HITLOC_NAMES[]{
|
||||
// clang-format off
|
||||
"none",
|
||||
"helmet",
|
||||
"head",
|
||||
"neck",
|
||||
"torso_upper",
|
||||
"torso_middle",
|
||||
"torso_lower",
|
||||
"right_arm_upper",
|
||||
"left_arm_upper",
|
||||
"right_arm_lower",
|
||||
"left_arm_lower",
|
||||
"right_hand",
|
||||
"left_hand",
|
||||
"right_leg_upper",
|
||||
"left_leg_upper",
|
||||
"right_leg_lower",
|
||||
"left_leg_lower",
|
||||
"right_foot",
|
||||
"left_foot",
|
||||
"gun",
|
||||
"shield",
|
||||
// clang-format on
|
||||
};
|
||||
static_assert(std::extent_v<decltype(HITLOC_NAMES)> == HITLOC_COUNT);
|
||||
} // namespace T6
|
||||
|
||||
#include "XModel/GenericXModelLoader.inc.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
bool LoadXModel(std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
{
|
||||
std::set<XAssetInfoGeneric*> dependenciesSet;
|
||||
XModelLoader loader(stream, *memory, *manager, dependenciesSet);
|
||||
|
||||
dependencies.assign(dependenciesSet.cbegin(), dependenciesSet.cend());
|
||||
|
||||
return loader.Load(xmodel);
|
||||
}
|
||||
} // namespace T6
|
13
src/ObjLoading/Game/T6/XModel/XModelLoaderT6.h
Normal file
13
src/ObjLoading/Game/T6/XModel/XModelLoaderT6.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
namespace T6
|
||||
{
|
||||
bool LoadXModel(std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies);
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include "JsonXModelLoader.h"
|
||||
#pragma once
|
||||
|
||||
#ifndef GAME_NAMESPACE
|
||||
#error Must define GAME_NAMESPACE
|
||||
#endif
|
||||
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/Json/JsonXModel.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "Utils/QuatInt16.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
@ -13,6 +14,7 @@
|
||||
|
||||
#pragma warning(push, 0)
|
||||
#include <Eigen>
|
||||
#include <nlohmann/json.hpp>
|
||||
#pragma warning(pop)
|
||||
|
||||
#include "XModel/PartClassificationState.h"
|
||||
@ -23,48 +25,15 @@
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace T6;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
namespace GAME_NAMESPACE
|
||||
{
|
||||
const char* HITLOC_NAMES[]{
|
||||
// clang-format off
|
||||
"none",
|
||||
"helmet",
|
||||
"head",
|
||||
"neck",
|
||||
"torso_upper",
|
||||
"torso_middle",
|
||||
"torso_lower",
|
||||
"right_arm_upper",
|
||||
"left_arm_upper",
|
||||
"right_arm_lower",
|
||||
"left_arm_lower",
|
||||
"right_hand",
|
||||
"left_hand",
|
||||
"right_leg_upper",
|
||||
"left_leg_upper",
|
||||
"right_leg_lower",
|
||||
"left_leg_lower",
|
||||
"right_foot",
|
||||
"left_foot",
|
||||
"gun",
|
||||
"shield",
|
||||
// clang-format on
|
||||
};
|
||||
static_assert(std::extent_v<decltype(HITLOC_NAMES)> == HITLOC_COUNT);
|
||||
|
||||
class JsonLoader
|
||||
class XModelLoader
|
||||
{
|
||||
public:
|
||||
JsonLoader(std::istream& stream, MemoryManager& memory, IAssetLoadingManager& manager, std::set<XAssetInfoGeneric*>& dependencies)
|
||||
XModelLoader(std::istream& stream, MemoryManager& memory, IAssetLoadingManager& manager, std::set<XAssetInfoGeneric*>& dependencies)
|
||||
: m_stream(stream),
|
||||
m_memory(memory),
|
||||
m_script_strings(manager.GetAssetLoadingContext()->m_zone->m_script_strings),
|
||||
@ -77,7 +46,7 @@ namespace
|
||||
|
||||
bool Load(XModel& xmodel)
|
||||
{
|
||||
const auto jRoot = json::parse(m_stream);
|
||||
const auto jRoot = nlohmann::json::parse(m_stream);
|
||||
std::string type;
|
||||
unsigned version;
|
||||
|
||||
@ -95,7 +64,7 @@ namespace
|
||||
const auto jXModel = jRoot.get<JsonXModel>();
|
||||
return CreateXModelFromJson(jXModel, xmodel);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
catch (const nlohmann::json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of xmodel: {}\n", e.what());
|
||||
}
|
||||
@ -616,7 +585,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
auto extension = fs::path(jLod.file).extension().string();
|
||||
auto extension = std::filesystem::path(jLod.file).extension().string();
|
||||
utils::MakeStringLowerCase(extension);
|
||||
|
||||
const auto common = LoadModelByExtension(*file.m_stream, extension);
|
||||
@ -822,18 +791,4 @@ namespace
|
||||
PartClassificationState& m_part_classification_state;
|
||||
std::set<XAssetInfoGeneric*>& m_dependencies;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace T6
|
||||
{
|
||||
bool LoadXModelAsJson(
|
||||
std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
{
|
||||
std::set<XAssetInfoGeneric*> dependenciesSet;
|
||||
JsonLoader loader(stream, *memory, *manager, dependenciesSet);
|
||||
|
||||
dependencies.assign(dependenciesSet.cbegin(), dependenciesSet.cend());
|
||||
|
||||
return loader.Load(xmodel);
|
||||
}
|
||||
} // namespace T6
|
||||
} // namespace GAME_NAMESPACE
|
Reference in New Issue
Block a user