2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-05 12:33:02 +00:00

chore: make sure TechsetCompilerT6 sets proper worldVertFormat

This commit is contained in:
Jan Laupetin
2026-01-22 21:43:06 +00:00
parent e61ec8582a
commit bf9beb1458
16 changed files with 255 additions and 17 deletions

View File

@@ -1,16 +1,81 @@
#include "TechsetCompilerT6.h"
#include "Game/T6/T6.h"
#include "Game/T6/Techset/TechsetConstantsT6.h"
#include "Techset/CommonTechsetLoader.h"
#include "Techset/TechsetCommon.h"
using namespace T6;
namespace
{
class TechsetCompilerT6 final : public AssetCreator<T6::AssetTechniqueSet>
MaterialWorldVertexFormat GetWorldVertexFormat(const std::string& name)
{
if (name.contains("lit_"))
{
size_t texCount = 0u, normalCount = 0u;
techset::CountWorldVertFormatParameters(name, texCount, normalCount);
// 0 and 1 seem to be treated equally
texCount = std::max(texCount, 1u);
normalCount = std::max(normalCount, 1u);
if (texCount == 1 && normalCount == 1)
return MTL_WORLDVERT_TEX_1_NRM_1;
if (texCount == 2 && normalCount == 1)
return MTL_WORLDVERT_TEX_2_NRM_1;
if (texCount == 2 && normalCount == 2)
return MTL_WORLDVERT_TEX_2_NRM_2;
if (texCount == 3 && normalCount == 1)
return MTL_WORLDVERT_TEX_3_NRM_1;
if (texCount == 3 && normalCount == 2)
return MTL_WORLDVERT_TEX_3_NRM_2;
if (texCount == 3 && normalCount == 3)
return MTL_WORLDVERT_TEX_3_NRM_3;
if (texCount == 4 && normalCount == 1)
return MTL_WORLDVERT_TEX_4_NRM_1;
if (texCount == 4 && normalCount == 2)
return MTL_WORLDVERT_TEX_4_NRM_2;
if (texCount == 4 && normalCount == 3)
return MTL_WORLDVERT_TEX_4_NRM_3;
}
return static_cast<MaterialWorldVertexFormat>(0);
}
MaterialTechniqueSet* ConvertTechniqueSet(const techset::CommonTechset& commonTechset, MemoryManager& memory)
{
auto* techset = memory.Alloc<MaterialTechniqueSet>();
techset->name = memory.Dup(commonTechset.m_name.c_str());
techset->worldVertFormat = GetWorldVertexFormat(commonTechset.m_name);
return techset;
}
class TechsetCompilerT6 final : public AssetCreator<AssetTechniqueSet>
{
public:
TechsetCompilerT6(ISearchPath& searchPath, MemoryManager& memory)
: m_search_path(searchPath),
m_memory(memory)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
return AssetCreationResult::NoAction();
bool failure = false;
const auto commonTechset = techset::LoadCommonTechset(assetName, commonTechniqueTypeNames, m_search_path, failure);
if (!commonTechset)
return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction();
auto* techset = ConvertTechniqueSet(*commonTechset, m_memory);
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetTechniqueSet>(assetName, techset)));
}
private:
ISearchPath& m_search_path;
MemoryManager& m_memory;
};
} // namespace
@@ -18,6 +83,6 @@ namespace techset
{
std::unique_ptr<IAssetCreator> CreateCompilerT6(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<TechsetCompilerT6>();
return std::make_unique<TechsetCompilerT6>(searchPath, memory);
}
} // namespace techset