2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-06-06 08:42:35 +00:00

Added the ability to dump and load technique sets.

note: techniques should be dumped in seperate files from technique sets, but compiling them all into the techset works as well but is harder to read.
This commit is contained in:
LJW-Dev
2025-07-07 15:53:45 +08:00
committed by Jan Laupetin
parent 264139fb4e
commit a045518f7d
6 changed files with 326 additions and 1 deletions
@@ -0,0 +1,115 @@
#include "AssetDumperTechniqueSet.h"
#include <nlohmann/json.hpp>
#include <sstream>
#include <unordered_set>
using namespace T6;
void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, const XAssetInfo<T6::AssetTechniqueSet::Type>& asset)
{
const auto* techniqueSet = asset.Asset();
const auto assetFile = context.OpenAssetFile(std::format("techniquesets/{}.json", techniqueSet->name));
if (!assetFile)
return;
nlohmann::json js;
js["name"] = techniqueSet->name;
js["worldVertFormat"] = techniqueSet->worldVertFormat;
js["techniques"] = nlohmann::json::array();
for (const auto* technique : techniqueSet->techniques)
{
nlohmann::json techniqueJs = nlohmann::json::object();
if (technique != NULL)
{
techniqueJs["name"] = technique->name;
techniqueJs["flags"] = technique->flags;
techniqueJs["passCount"] = technique->passCount;
_ASSERT(technique->passCount == 1);
techniqueJs["passArray"] = nlohmann::json::array();
for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++)
{
const MaterialPass* currPass = &technique->passArray[passIndex];
nlohmann::json passJs = nlohmann::json::object();
passJs["perPrimArgCount"] = currPass->perPrimArgCount;
passJs["perObjArgCount"] = currPass->perObjArgCount;
passJs["stableArgCount"] = currPass->stableArgCount;
passJs["customSamplerFlags"] = currPass->customSamplerFlags;
passJs["precompiledIndex"] = currPass->precompiledIndex;
passJs["materialType"] = currPass->materialType;
nlohmann::json vertDeclJs = nlohmann::json::object();
if (currPass->vertexDecl != NULL)
{
vertDeclJs["streamCount"] = currPass->vertexDecl->streamCount;
vertDeclJs["hasOptionalSource"] = currPass->vertexDecl->hasOptionalSource;
vertDeclJs["isLoaded"] = currPass->vertexDecl->isLoaded;
for (int i = 0; i < 16; i++)
{
vertDeclJs["routing"][i]["source"] = currPass->vertexDecl->routing.data[i].source;
vertDeclJs["routing"][i]["dest"] = currPass->vertexDecl->routing.data[i].dest;
_ASSERT(currPass->vertexDecl->routing.decl[i] == NULL);
}
}
passJs["vertexDecl"] = vertDeclJs;
passJs["args"] = nlohmann::json::array();
if (currPass->args != NULL)
{
for (int i = 0; i < currPass->perPrimArgCount + currPass->perObjArgCount + currPass->stableArgCount; i++)
{
nlohmann::json argsJs = nlohmann::json::object();
MaterialShaderArgument* currArg = &currPass->args[i];
argsJs["type"] = currArg->type;
argsJs["location"] = currArg->location.offset;
argsJs["size"] = currArg->size;
argsJs["buffer"] = currArg->buffer;
if (currArg->type == MTL_ARG_LITERAL_VERTEX_CONST || currArg->type == MTL_ARG_LITERAL_PIXEL_CONST)
{
argsJs["u"]["const0"] = currArg->u.literalConst[0];
argsJs["u"]["const1"] = currArg->u.literalConst[1];
argsJs["u"]["const2"] = currArg->u.literalConst[2];
argsJs["u"]["const3"] = currArg->u.literalConst[3];
}
else
{
argsJs["u"]["value"] = currArg->u.nameHash;
}
passJs["args"].push_back(argsJs);
}
}
nlohmann::json pixelJs = nlohmann::json::object();
if (currPass->pixelShader != NULL)
{
pixelJs["name"] = currPass->pixelShader->name;
}
passJs["pixelShader"] = pixelJs;
nlohmann::json vertexJs = nlohmann::json::object();
if (currPass->vertexShader != NULL)
{
vertexJs["name"] = currPass->vertexShader->name;
}
passJs["vertexShader"] = vertexJs;
techniqueJs["passArray"].push_back(passJs);
}
}
js["techniques"].push_back(techniqueJs);
}
std::string jsonString = js.dump(4);
assetFile->write(jsonString.c_str(), jsonString.size());
}
@@ -0,0 +1,10 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
class AssetDumperTechniqueSet final : public AbstractAssetDumper<T6::AssetTechniqueSet>
{
protected:
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T6::AssetTechniqueSet::Type>& asset) override;
};
+2
View File
@@ -1,5 +1,6 @@
#include "ObjWriterT6.h"
#include "AssetDumpers/AssetDumperTechniqueSet.h"
#include "FontIcon/FontIconDumperT6.h"
#include "Game/T6/Material/MaterialJsonDumperT6.h"
#include "Game/T6/Techset/TechsetDumperT6.h"
@@ -35,6 +36,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
// REGISTER_DUMPER(AssetDumperXAnimParts, m_xanim_parts)
RegisterAssetDumper(std::make_unique<xmodel::DumperT6>());
RegisterAssetDumper(std::make_unique<material::JsonDumperT6>());
RegisterAssetDumper(std::make_unique<AssetDumperTechniqueSet>());
RegisterAssetDumper(std::make_unique<techset::DumperT6>(
#ifdef TECHSET_DEBUG
true