mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 00:08:26 -05:00
chore: implement base loading and writing of xmodel json
This commit is contained in:
44
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.cpp
Normal file
44
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "AssetLoaderXModel.h"
|
||||
|
||||
#include "Game/T6/XModel/JsonXModelLoader.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
void* AssetLoaderXModel::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* xmodel = memory->Create<XModel>();
|
||||
memset(xmodel, 0, sizeof(XModel));
|
||||
xmodel->name = memory->Dup(assetName.c_str());
|
||||
|
||||
return xmodel;
|
||||
}
|
||||
|
||||
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 (LoadXModelAsJson(*file.m_stream, *xmodel, memory, manager, dependencies))
|
||||
manager->AddAsset<AssetXModel>(assetName, xmodel, std::move(dependencies));
|
||||
else
|
||||
std::cerr << "Failed to load xmodel \"" << assetName << "\"\n";
|
||||
|
||||
return true;
|
||||
}
|
19
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.h
Normal file
19
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class AssetLoaderXModel final : public BasicAssetLoader<ASSET_TYPE_XMODEL, XModel>
|
||||
{
|
||||
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 T6
|
Reference in New Issue
Block a user