2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-06 00:37:26 +00:00

feat: dump and load T5 materials

This commit is contained in:
Jan
2025-07-01 21:09:02 +01:00
committed by Jan Laupetin
parent 65c8cd6198
commit babfe7c884
18 changed files with 952 additions and 35 deletions

View File

@@ -0,0 +1,54 @@
#include "LoaderMaterialT5.h"
#include "Game/T5/Material/JsonMaterialLoaderT5.h"
#include "Game/T5/T5.h"
#include "Material/MaterialCommon.h"
#include <format>
#include <iostream>
using namespace T5;
namespace
{
class MaterialLoader final : public AssetCreator<AssetMaterial>
{
public:
MaterialLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(material::GetFileNameForAssetName(assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* material = m_memory.Alloc<Material>();
material->info.name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetMaterial> registration(assetName, material);
if (!LoadMaterialAsJson(*file.m_stream, *material, m_memory, context, registration))
{
std::cerr << std::format("Failed to load material \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace T5
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MaterialLoader>(memory, searchPath);
}
} // namespace T5

View File

@@ -0,0 +1,12 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T5/T5.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
namespace T5
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace T5

View File

@@ -5,6 +5,7 @@
#include "Game/T5/T5.h"
#include "Game/T5/XModel/LoaderXModelT5.h"
#include "Localize/LoaderLocalizeT5.h"
#include "Material/LoaderMaterialT5.h"
#include "ObjLoading.h"
#include "RawFile/LoaderRawFileT5.h"
#include "StringTable/LoaderStringTableT5.h"
@@ -104,7 +105,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMaterial>(memory));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImage>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundBank>(memory));

View File

@@ -1,4 +1,4 @@
#options GAME (IW3, IW4, IW5, T6)
#options GAME (IW3, IW4, IW5, T5, T6)
#filename "Game/" + GAME + "/Material/JsonMaterialLoader" + GAME + ".cpp"
@@ -14,6 +14,10 @@
#define FEATURE_IW5
#define HAS_WATER
#define GAME_LOWER "iw5"
#elif GAME == "T5"
#define FEATURE_T5
#define HAS_WATER
#define GAME_LOWER "t5"
#elif GAME == "T6"
#define FEATURE_T6
#define GAME_LOWER "t6"
@@ -29,6 +33,7 @@
#ifdef HAS_WATER
#include "Base64.h"
#endif
#set COMMON_HEADER "\"Game/" + GAME + "/Common" + GAME + ".h\""
#include COMMON_HEADER
#set JSON_HEADER "\"Game/" + GAME + "/Material/JsonMaterial" + GAME + ".h\""
@@ -100,7 +105,7 @@ namespace
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5)
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned char& gameFlags)
#elif defined(FEATURE_T6)
#elif defined(FEATURE_T5) || defined(FEATURE_T6)
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned& gameFlags)
#endif
{
@@ -201,7 +206,7 @@ namespace
CreateSamplerStateFromJson(jTexture.samplerState, textureDef.samplerState);
textureDef.semantic = jTexture.semantic;
#ifdef FEATURE_T6
#if defined(FEATURE_T5) || defined(FEATURE_T6)
textureDef.isMatureContent = jTexture.isMatureContent;
#endif
@@ -314,6 +319,12 @@ namespace
structured.alphaTestDisabled = 0;
structured.alphaTest = GFXS_ALPHA_TEST_LT_128;
}
#elif defined(FEATURE_T5)
else if (jStateBitsTableEntry.alphaTest == JsonAlphaTest::GE255)
{
structured.alphaTestDisabled = 0;
structured.alphaTest = GFXS_ALPHA_TEST_GE_255;
}
#endif
else if (jStateBitsTableEntry.alphaTest == JsonAlphaTest::GE128)
{
@@ -424,7 +435,9 @@ namespace
material.stateFlags = static_cast<unsigned char>(jMaterial.stateFlags);
material.cameraRegion = jMaterial.cameraRegion;
#ifdef FEATURE_T6
#if defined(FEATURE_T5)
material.maxStreamedMips = jMaterial.maxStreamedMips;
#elif defined(FEATURE_T6)
material.probeMipBits = jMaterial.probeMipBits;
#endif

View File

@@ -1,4 +1,4 @@
#options GAME (IW3, IW4, IW5, T6)
#options GAME (IW3, IW4, IW5, T5, T6)
#filename "Game/" + GAME + "/Material/JsonMaterialLoader" + GAME + ".h"