2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-16 23:11:42 +00:00

feat: add t6 gfxlight dumper and loader

This commit is contained in:
njohnson
2026-04-30 19:27:49 -04:00
committed by Jan Laupetin
parent 5b6a725f78
commit 2b3f680d48
7 changed files with 133 additions and 3 deletions
+1 -1
View File
@@ -179,7 +179,7 @@ The following section specify which assets are supported to be dumped to disk (u
| GameWorldMp | ❌ | ❌ | |
| MapEnts | ✅ | ❌ | |
| GfxWorld | ❌ | ❌ | |
| GfxLightDef | | | |
| GfxLightDef | | | |
| Font_s | ❌ | ❌ | |
| FontIcon | ✅ | ✅ | |
| MenuList | ❌ | ❌ | |
@@ -0,0 +1,77 @@
#include "LightDefLoaderT6.h"
#include "Game/T6/T6.h"
#include "LightDef/LightDefCommon.h"
#include "Utils/Logging/Log.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
namespace
{
constexpr auto MAX_IMAGE_NAME_SIZE = 0x800;
class LoaderLightDef final : public AssetCreator<AssetLightDef>
{
public:
LoaderLightDef(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto filename = light_def::GetFileNameForAsset(assetName);
const auto file = m_search_path.Open(filename);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char);
if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE)
return AssetCreationResult::Failure();
auto* lightDef = m_memory.Alloc<GfxLightDef>();
lightDef->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetLightDef> registration(assetName, lightDef);
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 = context.LoadDependency<AssetImage>(imageName);
if (!imageDependency)
{
con::error("Could not load GfxLightDef \"{}\" due to missing image \"{}\"", assetName, imageName);
return AssetCreationResult::Failure();
}
registration.AddDependency(imageDependency);
lightDef->attenuation.samplerState = samplerState;
lightDef->attenuation.image = imageDependency->Asset();
lightDef->lmapLookupStart = static_cast<int>(static_cast<uint8_t>(lmapLookupStart));
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace light_def
{
std::unique_ptr<AssetCreator<AssetLightDef>> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LoaderLightDef>(memory, searchPath);
}
} // namespace light_def
@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace light_def
{
std::unique_ptr<AssetCreator<T6::AssetLightDef>> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath);
} // namespace light_def
+2 -1
View File
@@ -17,6 +17,7 @@
#include "Image/IwiTypes.h"
#include "Image/Texture.h"
#include "Leaderboard/JsonLoaderLeaderboardT6.h"
#include "LightDef/LightDefLoaderT6.h"
#include "Localize/LocalizeLoaderT6.h"
#include "Material/LoaderMaterialT6.h"
#include "ObjContainer/IPak/IPak.h"
@@ -399,7 +400,7 @@ namespace T6
// collection.AddAssetCreator(std::make_unique<AssetLoaderGameWorldMp>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMapEnts>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderGfxWorld>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderLightDef>(memory));
collection.AddAssetCreator(light_def::CreateLoaderT6(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory));
collection.AddAssetCreator(font_icon::CreateCsvLoaderT6(memory, searchPath));
collection.AddAssetCreator(font_icon::CreateJsonLoaderT6(memory, searchPath));
@@ -0,0 +1,25 @@
#include "LightDefDumperT6.h"
#include "LightDef/LightDefCommon.h"
using namespace T6;
namespace light_def
{
void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetLightDef::Type>& asset)
{
const auto* lightDef = asset.Asset();
const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset.m_name));
if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr)
return;
auto& stream = *assetFile;
const auto* imageName = lightDef->attenuation.image->name;
if (imageName[0] == ',')
imageName = &imageName[1];
stream << lightDef->attenuation.samplerState << imageName << static_cast<char>(lightDef->lmapLookupStart);
}
} // namespace light_def
@@ -0,0 +1,13 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace light_def
{
class DumperT6 final : public AbstractAssetDumper<T6::AssetLightDef>
{
protected:
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T6::AssetLightDef::Type>& asset) override;
};
} // namespace light_def
+2 -1
View File
@@ -6,6 +6,7 @@
#include "Game/T6/XModel/XModelDumperT6.h"
#include "Image/ImageDumperT6.h"
#include "Leaderboard/LeaderboardJsonDumperT6.h"
#include "LightDef/LightDefDumperT6.h"
#include "Localize/LocalizeDumperT6.h"
#include "Maps/MapEntsDumperT6.h"
#include "PhysConstraints/PhysConstraintsInfoStringDumperT6.h"
@@ -51,7 +52,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
// REGISTER_DUMPER(AssetDumperGameWorldMp, m_game_world_mp)
RegisterAssetDumper(std::make_unique<map_ents::DumperT6>());
// REGISTER_DUMPER(AssetDumperGfxWorld, m_gfx_world)
// REGISTER_DUMPER(AssetDumperGfxLightDef, m_gfx_light_def)
RegisterAssetDumper(std::make_unique<light_def::DumperT6>());
// REGISTER_DUMPER(AssetDumperFont, m_font)
RegisterAssetDumper(font_icon::CreateDumperT6());
// REGISTER_DUMPER(AssetDumperMenuList, m_menu_list)