mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-25 09:23:03 +00:00
chore: make sure TechsetCompilerT6 sets proper worldVertFormat
This commit is contained in:
@@ -1468,10 +1468,26 @@ namespace IW3
|
||||
TECHNIQUE_NONE = 0x24,
|
||||
};
|
||||
|
||||
enum MaterialWorldVertexFormat : unsigned char
|
||||
{
|
||||
MTL_WORLDVERT_TEX_1_NRM_1 = 0x0,
|
||||
MTL_WORLDVERT_TEX_2_NRM_1 = 0x1,
|
||||
MTL_WORLDVERT_TEX_2_NRM_2 = 0x2,
|
||||
MTL_WORLDVERT_TEX_3_NRM_1 = 0x3,
|
||||
MTL_WORLDVERT_TEX_3_NRM_2 = 0x4,
|
||||
MTL_WORLDVERT_TEX_3_NRM_3 = 0x5,
|
||||
MTL_WORLDVERT_TEX_4_NRM_1 = 0x6,
|
||||
MTL_WORLDVERT_TEX_4_NRM_2 = 0x7,
|
||||
MTL_WORLDVERT_TEX_4_NRM_3 = 0x8,
|
||||
MTL_WORLDVERT_TEX_5_NRM_1 = 0x9,
|
||||
MTL_WORLDVERT_TEX_5_NRM_2 = 0xA,
|
||||
MTL_WORLDVERT_TEX_5_NRM_3 = 0xB,
|
||||
};
|
||||
|
||||
struct MaterialTechniqueSet
|
||||
{
|
||||
const char* name;
|
||||
char worldVertFormat;
|
||||
MaterialWorldVertexFormat worldVertFormat;
|
||||
bool hasBeenUploaded;
|
||||
char unused[1];
|
||||
MaterialTechniqueSet* remappedTechniqueSet;
|
||||
|
||||
@@ -1721,10 +1721,26 @@ namespace IW4
|
||||
TECHNIQUE_COUNT
|
||||
};
|
||||
|
||||
enum MaterialWorldVertexFormat : unsigned char
|
||||
{
|
||||
MTL_WORLDVERT_TEX_1_NRM_1 = 0x0,
|
||||
MTL_WORLDVERT_TEX_2_NRM_1 = 0x1,
|
||||
MTL_WORLDVERT_TEX_2_NRM_2 = 0x2,
|
||||
MTL_WORLDVERT_TEX_3_NRM_1 = 0x3,
|
||||
MTL_WORLDVERT_TEX_3_NRM_2 = 0x4,
|
||||
MTL_WORLDVERT_TEX_3_NRM_3 = 0x5,
|
||||
MTL_WORLDVERT_TEX_4_NRM_1 = 0x6,
|
||||
MTL_WORLDVERT_TEX_4_NRM_2 = 0x7,
|
||||
MTL_WORLDVERT_TEX_4_NRM_3 = 0x8,
|
||||
MTL_WORLDVERT_TEX_5_NRM_1 = 0x9,
|
||||
MTL_WORLDVERT_TEX_5_NRM_2 = 0xA,
|
||||
MTL_WORLDVERT_TEX_5_NRM_3 = 0xB,
|
||||
};
|
||||
|
||||
struct MaterialTechniqueSet
|
||||
{
|
||||
const char* name;
|
||||
unsigned char worldVertFormat;
|
||||
MaterialWorldVertexFormat worldVertFormat;
|
||||
bool hasBeenUploaded;
|
||||
unsigned char unused[1];
|
||||
MaterialTechniqueSet* remappedTechniqueSet;
|
||||
|
||||
@@ -1102,10 +1102,26 @@ namespace IW5
|
||||
MaterialPass passArray[1];
|
||||
};
|
||||
|
||||
enum MaterialWorldVertexFormat : unsigned char
|
||||
{
|
||||
MTL_WORLDVERT_TEX_1_NRM_1 = 0x0,
|
||||
MTL_WORLDVERT_TEX_2_NRM_1 = 0x1,
|
||||
MTL_WORLDVERT_TEX_2_NRM_2 = 0x2,
|
||||
MTL_WORLDVERT_TEX_3_NRM_1 = 0x3,
|
||||
MTL_WORLDVERT_TEX_3_NRM_2 = 0x4,
|
||||
MTL_WORLDVERT_TEX_3_NRM_3 = 0x5,
|
||||
MTL_WORLDVERT_TEX_4_NRM_1 = 0x6,
|
||||
MTL_WORLDVERT_TEX_4_NRM_2 = 0x7,
|
||||
MTL_WORLDVERT_TEX_4_NRM_3 = 0x8,
|
||||
MTL_WORLDVERT_TEX_5_NRM_1 = 0x9,
|
||||
MTL_WORLDVERT_TEX_5_NRM_2 = 0xA,
|
||||
MTL_WORLDVERT_TEX_5_NRM_3 = 0xB,
|
||||
};
|
||||
|
||||
struct MaterialTechniqueSet
|
||||
{
|
||||
const char* name;
|
||||
unsigned char worldVertFormat;
|
||||
MaterialWorldVertexFormat worldVertFormat;
|
||||
unsigned char unused[2];
|
||||
MaterialTechniqueSet* remappedTechniqueSet;
|
||||
MaterialTechnique* techniques[54];
|
||||
|
||||
@@ -1720,10 +1720,23 @@ namespace T5
|
||||
TECHNIQUE_COUNT
|
||||
};
|
||||
|
||||
enum MaterialWorldVertexFormat : unsigned char
|
||||
{
|
||||
MTL_WORLDVERT_TEX_1_NRM_1 = 0x0,
|
||||
MTL_WORLDVERT_TEX_2_NRM_1 = 0x1,
|
||||
MTL_WORLDVERT_TEX_2_NRM_2 = 0x2,
|
||||
MTL_WORLDVERT_TEX_3_NRM_1 = 0x3,
|
||||
MTL_WORLDVERT_TEX_3_NRM_2 = 0x4,
|
||||
MTL_WORLDVERT_TEX_3_NRM_3 = 0x5,
|
||||
MTL_WORLDVERT_TEX_4_NRM_1 = 0x6,
|
||||
MTL_WORLDVERT_TEX_4_NRM_2 = 0x7,
|
||||
MTL_WORLDVERT_TEX_4_NRM_3 = 0x8,
|
||||
};
|
||||
|
||||
struct MaterialTechniqueSet
|
||||
{
|
||||
const char* name;
|
||||
char worldVertFormat;
|
||||
MaterialWorldVertexFormat worldVertFormat;
|
||||
char unused[1];
|
||||
uint16_t techsetFlags;
|
||||
MaterialTechnique* techniques[130];
|
||||
|
||||
@@ -840,10 +840,23 @@ namespace T6
|
||||
TECHNIQUE_COUNT
|
||||
};
|
||||
|
||||
enum MaterialWorldVertexFormat : unsigned char
|
||||
{
|
||||
MTL_WORLDVERT_TEX_1_NRM_1 = 0x0,
|
||||
MTL_WORLDVERT_TEX_2_NRM_1 = 0x1,
|
||||
MTL_WORLDVERT_TEX_2_NRM_2 = 0x2,
|
||||
MTL_WORLDVERT_TEX_3_NRM_1 = 0x3,
|
||||
MTL_WORLDVERT_TEX_3_NRM_2 = 0x4,
|
||||
MTL_WORLDVERT_TEX_3_NRM_3 = 0x5,
|
||||
MTL_WORLDVERT_TEX_4_NRM_1 = 0x6,
|
||||
MTL_WORLDVERT_TEX_4_NRM_2 = 0x7,
|
||||
MTL_WORLDVERT_TEX_4_NRM_3 = 0x8,
|
||||
};
|
||||
|
||||
struct MaterialTechniqueSet
|
||||
{
|
||||
const char* name;
|
||||
char worldVertFormat;
|
||||
MaterialWorldVertexFormat worldVertFormat;
|
||||
MaterialTechnique* techniques[36];
|
||||
};
|
||||
|
||||
|
||||
@@ -46,4 +46,10 @@ namespace techset
|
||||
m_technique_names(std::move(techniqueNames))
|
||||
{
|
||||
}
|
||||
|
||||
CommonTechset::CommonTechset(std::string name, const size_t techniqueTypeCount)
|
||||
: m_name(std::move(name)),
|
||||
m_technique_names(techniqueTypeCount)
|
||||
{
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace techset
|
||||
CommonTechset() = default;
|
||||
explicit CommonTechset(size_t techniqueTypeCount);
|
||||
CommonTechset(std::string name, std::vector<std::string> techniqueNames);
|
||||
CommonTechset(std::string name, size_t techniqueTypeCount);
|
||||
|
||||
std::string m_name;
|
||||
std::vector<std::string> m_technique_names;
|
||||
|
||||
@@ -18,4 +18,28 @@ namespace techset
|
||||
{
|
||||
return std::format("techsets/{}.techset", assetName);
|
||||
}
|
||||
|
||||
void CountWorldVertFormatParameters(const std::string& assetName, size_t& texCount, size_t& normalCount)
|
||||
{
|
||||
texCount = 0;
|
||||
normalCount = 0;
|
||||
|
||||
if (assetName.empty())
|
||||
return;
|
||||
|
||||
const auto nameLen = assetName.size();
|
||||
for (auto pos = 1u; pos < nameLen - 1u; pos++)
|
||||
{
|
||||
if (assetName[pos - 1] != '_' && !isdigit(assetName[pos - 1]))
|
||||
continue;
|
||||
if (!isdigit(assetName[pos + 1]))
|
||||
continue;
|
||||
|
||||
const auto c = tolower(assetName[pos]);
|
||||
if (c == 'c')
|
||||
texCount++;
|
||||
else if (c == 'n')
|
||||
normalCount++;
|
||||
}
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -7,4 +7,6 @@ namespace techset
|
||||
std::string GetFileNameForStateMapName(const std::string& stateMapName);
|
||||
std::string GetFileNameForTechniqueName(const std::string& assetName);
|
||||
std::string GetFileNameForTechsetName(const std::string& assetName);
|
||||
|
||||
void CountWorldVertFormatParameters(const std::string& assetName, size_t& texCount, size_t& normalCount);
|
||||
} // namespace techset
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace techset
|
||||
{
|
||||
failure = false;
|
||||
|
||||
const auto fileName = GetFileNameForTechniqueName(assetName);
|
||||
const auto fileName = GetFileNameForTechsetName(assetName);
|
||||
const auto techniqueFile = searchPath.Open(fileName);
|
||||
if (!techniqueFile.IsOpen())
|
||||
return nullptr;
|
||||
@@ -36,7 +36,7 @@ namespace techset
|
||||
CommentRemovingStreamProxy commentProxy(&baseStream);
|
||||
const auto lexer = std::make_unique<SimpleLexer>(&commentProxy, std::move(lexerConfig));
|
||||
|
||||
const auto parser = std::make_unique<TechsetParser>(*lexer, techniqueTypeNames);
|
||||
const auto parser = std::make_unique<TechsetParser>(*lexer, assetName, techniqueTypeNames);
|
||||
|
||||
const auto success = parser->Parse();
|
||||
if (success)
|
||||
|
||||
@@ -72,8 +72,8 @@ namespace
|
||||
|
||||
namespace techset
|
||||
{
|
||||
TechsetParser::TechsetParser(SimpleLexer& lexer, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: AbstractParser(&lexer, std::make_unique<TechsetParserState>(techniqueTypeNames))
|
||||
TechsetParser::TechsetParser(SimpleLexer& lexer, std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: AbstractParser(&lexer, std::make_unique<TechsetParserState>(std::move(techsetName), techniqueTypeNames))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace techset
|
||||
class TechsetParser final : public AbstractParser<SimpleParserValue, TechsetParserState>
|
||||
{
|
||||
public:
|
||||
TechsetParser(SimpleLexer& lexer, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
TechsetParser(SimpleLexer& lexer, std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
[[nodiscard]] std::unique_ptr<CommonTechset> GetParsingResult() const;
|
||||
|
||||
|
||||
protected:
|
||||
const std::vector<sequence_t*>& GetTestsForState() override;
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace techset
|
||||
{
|
||||
TechsetParserState::TechsetParserState(const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
TechsetParserState::TechsetParserState(std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: m_technique_type_names(techniqueTypeNames),
|
||||
m_definition(std::make_unique<CommonTechset>(techniqueTypeNames.GetTechniqueTypeCount()))
|
||||
m_definition(std::make_unique<CommonTechset>(std::move(techsetName), techniqueTypeNames.GetTechniqueTypeCount()))
|
||||
{
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
@@ -11,7 +12,7 @@ namespace techset
|
||||
class TechsetParserState
|
||||
{
|
||||
public:
|
||||
explicit TechsetParserState(const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
TechsetParserState(std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
|
||||
const CommonTechniqueTypeNames& m_technique_type_names;
|
||||
std::unique_ptr<CommonTechset> m_definition;
|
||||
|
||||
Reference in New Issue
Block a user