mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
feat: dump and load xmodels for IW5 via template
This commit is contained in:
@ -814,8 +814,8 @@ namespace
|
||||
for (auto i = 0u; i < originalGraphKnotCount; i++)
|
||||
{
|
||||
const auto& commonKnot = graph.knots[i];
|
||||
originalGraphKnots[i][0] = static_cast<float>(commonKnot.x);
|
||||
originalGraphKnots[i][1] = static_cast<float>(commonKnot.y);
|
||||
originalGraphKnots[i].x = static_cast<float>(commonKnot.x);
|
||||
originalGraphKnots[i].y = static_cast<float>(commonKnot.y);
|
||||
}
|
||||
|
||||
graphKnots = originalGraphKnots;
|
||||
|
@ -1,17 +1,42 @@
|
||||
#include "AssetLoaderXModel.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "Game/IW5/XModel/XModelLoaderIW5.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
void* AssetLoaderXModel::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* model = memory->Create<XModel>();
|
||||
memset(model, 0, sizeof(XModel));
|
||||
model->name = memory->Dup(assetName.c_str());
|
||||
return model;
|
||||
auto* asset = memory->Alloc<AssetXModel::Type>();
|
||||
asset->name = memory->Dup(assetName.c_str());
|
||||
return asset;
|
||||
}
|
||||
|
||||
bool AssetLoaderXModel::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderXModel::LoadFromRaw(
|
||||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto file = searchPath->Open(std::format("xmodel/{}.json", assetName));
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* xmodel = memory->Alloc<XModel>();
|
||||
xmodel->name = memory->Dup(assetName.c_str());
|
||||
|
||||
std::vector<XAssetInfoGeneric*> 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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
@ -8,7 +8,12 @@ namespace IW5
|
||||
{
|
||||
class AssetLoaderXModel final : public BasicAssetLoader<AssetXModel>
|
||||
{
|
||||
static std::string GetFileNameForAsset(const std::string& assetName);
|
||||
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool
|
||||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
Reference in New Issue
Block a user