mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-06 00:37:26 +00:00
feat: add json material loading/writing for iw3
This commit is contained in:
54
src/ObjLoading/Game/IW3/Material/LoaderMaterialIW3.cpp
Normal file
54
src/ObjLoading/Game/IW3/Material/LoaderMaterialIW3.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "LoaderMaterialIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/Material/JsonMaterialLoaderIW3.h"
|
||||
#include "Material/MaterialCommon.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
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 IW3
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<MaterialLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace IW3
|
12
src/ObjLoading/Game/IW3/Material/LoaderMaterialIW3.h
Normal file
12
src/ObjLoading/Game/IW3/Material/LoaderMaterialIW3.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace IW3
|
@@ -5,6 +5,7 @@
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/AssetLoaderImageIW3.h"
|
||||
#include "Localize/AssetLoaderLocalizeIW3.h"
|
||||
#include "Material/LoaderMaterialIW3.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "RawFile/AssetLoaderRawFileIW3.h"
|
||||
#include "StringTable/AssetLoaderStringTableIW3.h"
|
||||
@@ -90,7 +91,7 @@ namespace
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderMaterial>(memory));
|
||||
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
||||
collection.AddAssetCreator(CreateImageLoader(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
||||
|
@@ -1,8 +1,12 @@
|
||||
#options GAME (IW4, IW5, T6)
|
||||
#options GAME (IW3, IW4, IW5, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Material/JsonMaterialLoader" + GAME + ".cpp"
|
||||
|
||||
#if GAME == "IW4"
|
||||
#if GAME == "IW3"
|
||||
#define FEATURE_IW3
|
||||
#define HAS_WATER
|
||||
#define GAME_LOWER "iw3"
|
||||
#elif GAME == "IW4"
|
||||
#define FEATURE_IW4
|
||||
#define HAS_WATER
|
||||
#define GAME_LOWER "iw4"
|
||||
@@ -94,7 +98,7 @@ namespace
|
||||
std::cerr << std::format("Cannot load material \"{}\": {}\n", material.info.name, message);
|
||||
}
|
||||
|
||||
#if defined(FEATURE_IW4) || defined(FEATURE_IW5)
|
||||
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5)
|
||||
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned char& gameFlags)
|
||||
#elif defined(FEATURE_T6)
|
||||
static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned& gameFlags)
|
||||
@@ -304,7 +308,7 @@ namespace
|
||||
structured.alphaTestDisabled = 0;
|
||||
structured.alphaTest = GFXS_ALPHA_TEST_GT_0;
|
||||
}
|
||||
#if defined(FEATURE_IW4) || defined(FEATURE_IW5)
|
||||
#if defined(FEATURE_IW3) || defined(FEATURE_IW4) || defined(FEATURE_IW5)
|
||||
else if (jStateBitsTableEntry.alphaTest == JsonAlphaTest::LT128)
|
||||
{
|
||||
structured.alphaTestDisabled = 0;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#options GAME (IW4, IW5, T6)
|
||||
#options GAME (IW3, IW4, IW5, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Material/JsonMaterialLoader" + GAME + ".h"
|
||||
|
||||
|
Reference in New Issue
Block a user