feat: add support for t4 materials (#891)

* feat: add support for t4 materials

* fix: t4 material struct
This commit is contained in:
Jan Laupetin
2026-07-08 22:50:22 +02:00
committed by GitHub
parent a4229788d7
commit c385f50a0e
13 changed files with 402 additions and 45 deletions
@@ -0,0 +1,55 @@
#include "LoaderMaterialT4.h"
#include "Game/T4/Material/JsonMaterialLoaderT4.h"
#include "Game/T4/T4.h"
#include "Material/MaterialCommon.h"
#include "Utils/Logging/Log.h"
#include <format>
#include <iostream>
using namespace T4;
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))
{
con::error("Failed to load material \"{}\"", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace material
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MaterialLoader>(memory, searchPath);
}
} // namespace material
@@ -0,0 +1,12 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T4/T4.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
namespace material
{
std::unique_ptr<AssetCreator<T4::AssetMaterial>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace material
+2
View File
@@ -10,6 +10,7 @@
#include "Game/T4/XAnim/XAnimLoaderT4.h"
#include "Localize/AssetLoaderLocalizeT4.h"
#include "Maps/MapEntsLoaderT4.h"
#include "Material/LoaderMaterialT4.h"
#include "RawFile/AssetLoaderRawFileT4.h"
#include "Weapon/FlameTableLoaderT4.h"
#include "Weapon/WeaponGdtLoaderT4.h"
@@ -98,6 +99,7 @@ namespace
collection.AddAssetCreator(xanim::CreateLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(image::CreateLoaderEmbeddedT4(memory, searchPath));
collection.AddAssetCreator(image::CreateLoaderExternalT4(memory, searchPath));
collection.AddAssetCreator(material::CreateLoaderT4(memory, searchPath));
collection.AddAssetCreator(font::CreateLoaderT4(memory, searchPath));
collection.AddAssetCreator(localize::CreateLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(map_ents::CreateLoaderT4(memory, searchPath));
@@ -1,4 +1,4 @@
#options GAME (IW3, IW4, IW5, T5, T6)
#options GAME (IW3, IW4, IW5, T4, 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 == "T4"
#define FEATURE_T4
#define HAS_WATER
#define GAME_LOWER "t4"
#elif GAME == "T5"
#define FEATURE_T5
#define HAS_WATER
@@ -104,7 +108,7 @@ namespace
con::error("Cannot load material \"{}\": {}", material.info.name, message);
}
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5)
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5) || defined(FEATURE_T4)
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned char& gameFlags)
#elif defined(FEATURE_T5) || defined(FEATURE_T6)
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned& gameFlags)
@@ -207,7 +211,7 @@ namespace
CreateSamplerStateFromJson(jTexture.samplerState, textureDef.samplerState);
textureDef.semantic = jTexture.semantic;
#if defined(FEATURE_T5) || defined(FEATURE_T6)
#if defined(FEATURE_T4) || defined(FEATURE_T5) || defined(FEATURE_T6)
textureDef.isMatureContent = jTexture.isMatureContent;
#endif
@@ -314,7 +318,7 @@ namespace
structured.alphaTestDisabled = 0;
structured.alphaTest = GFXS_ALPHA_TEST_GT_0;
}
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5)
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5) || defined(FEATURE_T4)
else if (jStateBitsTableEntry.alphaTest == JsonAlphaTest::LT128)
{
structured.alphaTestDisabled = 0;
@@ -419,7 +423,7 @@ namespace
}
material.info.surfaceTypeBits = jMaterial.surfaceTypeBits;
#if defined(FEATURE_T5) || defined(FEATURE_T6)
#if defined(FEATURE_T4) || defined(FEATURE_T5) || defined(FEATURE_T6)
material.info.layeredSurfaceTypes = jMaterial.layeredSurfaceTypes;
#endif
#if defined(FEATURE_T6)
@@ -1,4 +1,4 @@
#options GAME (IW3, IW4, IW5, T5, T6)
#options GAME (IW3, IW4, IW5, T4, T5, T6)
#filename "Game/" + GAME + "/Material/JsonMaterialLoader" + GAME + ".h"