mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-15 09:17:57 -05:00
Add dumper and reader for IW4 GfxLightDef
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include "AssetLoaderGfxLightDef.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "ObjLoading.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
@ -8,6 +10,15 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
std::string AssetLoaderGfxLightDef::GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "lights/" << assetName;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* lightDef = memory->Create<GfxLightDef>();
|
||||
@ -15,3 +26,46 @@ void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, Mem
|
||||
lightDef->name = memory->Dup(assetName.c_str());
|
||||
return lightDef;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxLightDef::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxLightDef::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto filename = GetAssetFilename(assetName);
|
||||
const auto file = searchPath->Open(filename);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char);
|
||||
if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE)
|
||||
return false;
|
||||
|
||||
std::string imageName(static_cast<size_t>(imageNameSize), '\0');
|
||||
|
||||
int8_t samplerState;
|
||||
int8_t lmapLookupStart;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&samplerState), sizeof(int8_t));
|
||||
file.m_stream->read(&imageName[0], static_cast<size_t>(imageNameSize));
|
||||
file.m_stream->read(reinterpret_cast<char*>(&lmapLookupStart), sizeof(int8_t));
|
||||
|
||||
auto* imageDependency = reinterpret_cast<XAssetInfo<GfxImage>*>(manager->LoadDependency(ASSET_TYPE_IMAGE, imageName));
|
||||
|
||||
if(!imageDependency)
|
||||
{
|
||||
std::cerr << "Could not load GfxLightDef \"" << assetName << "\" due to missing image \"" << imageName << "\"\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* lightDef = memory->Create<GfxLightDef>();
|
||||
lightDef->name = memory->Dup(assetName.c_str());
|
||||
lightDef->attenuation.samplerState = samplerState;
|
||||
lightDef->attenuation.image = imageDependency->Asset();
|
||||
lightDef->lmapLookupStart = static_cast<int>(static_cast<uint8_t>(lmapLookupStart));
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LIGHT_DEF, assetName, lightDef);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user