mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Load T6 GfxImages from raw when building
This commit is contained in:
parent
abbb697d7c
commit
e16ea9de84
@ -765,10 +765,10 @@ namespace T6
|
|||||||
int platform[2];
|
int platform[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct GfxStreamedPartInfo
|
struct GfxStreamedPartInfo
|
||||||
{
|
{
|
||||||
unsigned int levelCountAndSize;
|
uint32_t levelCount : 4;
|
||||||
|
uint32_t levelSize : 28;
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
|
71
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp
Normal file
71
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "AssetLoaderGfxImage.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include "Game/T6/CommonT6.h"
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
#include "Image/IwiLoader.h"
|
||||||
|
#include "Pool/GlobalAssetPool.h"
|
||||||
|
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
|
void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||||
|
{
|
||||||
|
auto* image = memory->Create<GfxImage>();
|
||||||
|
memset(image, 0, sizeof(GfxImage));
|
||||||
|
image->name = memory->Dup(assetName.c_str());
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderGfxImage::CanLoadFromRaw() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderGfxImage::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||||
|
{
|
||||||
|
const auto fileName = "images/" + assetName + ".iwi";
|
||||||
|
const auto file = searchPath->Open(fileName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto fileSize = static_cast<size_t>(file.m_length);
|
||||||
|
const auto fileData = std::make_unique<char[]>(fileSize);
|
||||||
|
file.m_stream->read(fileData.get(), fileSize);
|
||||||
|
const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(fileData.get()), fileSize));
|
||||||
|
|
||||||
|
MemoryManager tempMemory;
|
||||||
|
IwiLoader iwiLoader(&tempMemory);
|
||||||
|
std::istringstream ss(std::string(fileData.get(), fileSize));
|
||||||
|
const auto texture = iwiLoader.LoadIwi(ss);
|
||||||
|
if (!texture)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to load texture from: " << fileName << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* image = memory->Create<GfxImage>();
|
||||||
|
memset(image, 0, sizeof(GfxImage));
|
||||||
|
|
||||||
|
image->name = memory->Dup(assetName.c_str());
|
||||||
|
image->hash = Common::R_HashString(image->name, 0);
|
||||||
|
image->delayLoadPixels = true;
|
||||||
|
|
||||||
|
image->noPicmip = !texture->HasMipMaps();
|
||||||
|
image->width = static_cast<uint16_t>(texture->GetWidth());
|
||||||
|
image->height = static_cast<uint16_t>(texture->GetHeight());
|
||||||
|
image->depth = static_cast<uint16_t>(texture->GetDepth());
|
||||||
|
|
||||||
|
image->streaming = 1;
|
||||||
|
image->streamedParts[0].levelCount = 1;
|
||||||
|
image->streamedParts[0].levelSize = static_cast<uint32_t>(fileSize);
|
||||||
|
image->streamedParts[0].hash = dataHash & 0x1FFFFFFF;
|
||||||
|
image->streamedPartCount = 1;
|
||||||
|
|
||||||
|
manager->AddAsset(ASSET_TYPE_IMAGE, assetName, image);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
16
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h
Normal file
16
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
#include "AssetLoading/BasicAssetLoader.h"
|
||||||
|
#include "AssetLoading/IAssetLoadingManager.h"
|
||||||
|
#include "SearchPath/ISearchPath.h"
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class AssetLoaderGfxImage final : public BasicAssetLoader<ASSET_TYPE_IMAGE, GfxImage>
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
#include "ObjContainer/IPak/IPak.h"
|
#include "ObjContainer/IPak/IPak.h"
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "AssetLoaders/AssetLoaderFontIcon.h"
|
#include "AssetLoaders/AssetLoaderFontIcon.h"
|
||||||
|
#include "AssetLoaders/AssetLoaderGfxImage.h"
|
||||||
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
||||||
#include "AssetLoaders/AssetLoaderPhysConstraints.h"
|
#include "AssetLoaders/AssetLoaderPhysConstraints.h"
|
||||||
#include "AssetLoaders/AssetLoaderPhysPreset.h"
|
#include "AssetLoaders/AssetLoaderPhysPreset.h"
|
||||||
@ -45,7 +46,7 @@ namespace T6
|
|||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MATERIAL, Material))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MATERIAL, Material))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_IMAGE, GfxImage))
|
REGISTER_ASSET_LOADER(AssetLoaderGfxImage)
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND, SndBank))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND, SndBank))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND_PATCH, SndPatch))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND_PATCH, SndPatch))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_CLIPMAP, clipMap_t))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_CLIPMAP, clipMap_t))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user