From 0b7ebef497f0bde699e85c8935f7201cf638470d Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 30 Apr 2021 22:51:21 +0300 Subject: [PATCH 1/3] fix path separator in md3 shader loading --- code/AssetLib/MD3/MD3Loader.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index e27079766..fc8bd9037 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -483,8 +483,9 @@ void MD3Importer::ReadShader(Q3Shader::ShaderData &fill) const { // If no specific dir or file is given, use our default search behaviour if (!configShaderFile.length()) { - if (!Q3Shader::LoadShader(fill, path + "..\\..\\..\\scripts\\" + model_file + ".shader", mIOHandler)) { - Q3Shader::LoadShader(fill, path + "..\\..\\..\\scripts\\" + filename + ".shader", mIOHandler); + const char sep = mIOHandler->getOsSeparator(); + if (!Q3Shader::LoadShader(fill, path + ".." + sep + ".." + sep + ".." + sep + "scripts" + sep + model_file + ".shader", mIOHandler)) { + Q3Shader::LoadShader(fill, path + ".." + sep + ".." + sep + ".." + sep + "scripts" + sep + filename + ".shader", mIOHandler); } } else { // If the given string specifies a file, load this file. From 55abc49d6de53bfdbc66937932f63019a3aad5c5 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 30 Apr 2021 22:59:05 +0300 Subject: [PATCH 2/3] improve md3::Q3 shader::cull keyword support only use nonstandard winding order with `cull back`; might be excess too, since engine doesn't support this --- code/AssetLib/MD3/MD3Loader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index fc8bd9037..87fe2509c 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -196,11 +196,11 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * // 'cull' specifies culling behaviour for the model else if (TokenMatchI(buff, "cull", 4)) { SkipSpaces(&buff); - if (!ASSIMP_strincmp(buff, "back", 4)) { + if (!ASSIMP_strincmp(buff, "back", 4)) { // render face's backside, does not function in Q3 engine (bug) curData->cull = Q3Shader::CULL_CCW; - } else if (!ASSIMP_strincmp(buff, "front", 5)) { + } else if (!ASSIMP_strincmp(buff, "front", 5)) { // is not valid keyword in Q3, but occurs in shaders curData->cull = Q3Shader::CULL_CW; - } else if (!ASSIMP_strincmp(buff, "none", 4) || !ASSIMP_strincmp(buff, "disable", 7)) { + } else if (!ASSIMP_strincmp(buff, "none", 4) || !ASSIMP_strincmp(buff, "twosided", 8) || !ASSIMP_strincmp(buff, "disable", 7)) { curData->cull = Q3Shader::CULL_NONE; } else { ASSIMP_LOG_ERROR("Q3Shader: Unrecognized cull mode"); @@ -986,8 +986,8 @@ void MD3Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[index].U; pcMesh->mTextureCoords[0][iCurrent].y = 1.0f - pcUVs[index].V; } - // Flip face order if necessary - if (!shader || shader->cull == Q3Shader::CULL_CW) { + // Flip face order normally, unless shader is backfacing + if (!(shader && shader->cull == Q3Shader::CULL_CCW)) { std::swap(pcMesh->mFaces[i].mIndices[2], pcMesh->mFaces[i].mIndices[1]); } ++pcTriangles; From eab1c9c3c04bb8e9244f485684f7d3ed5b79a15a Mon Sep 17 00:00:00 2001 From: Garux Date: Sat, 1 May 2021 00:27:28 +0300 Subject: [PATCH 3/3] add `AI_CONFIG_IMPORT_MD3_LOAD_SHADERS` bool option the purpose is use of this loader with idtech3 FS this requires full original material name, which euqals to Q3 shader path result of deduction is not usable inside Q3 FS at all option in general is "do not tinker with the path" --- code/AssetLib/MD3/MD3Loader.cpp | 14 ++++++++++++-- code/AssetLib/MD3/MD3Loader.h | 3 +++ include/assimp/config.h.in | 13 +++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index 87fe2509c..53a0eea41 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -450,6 +450,9 @@ void MD3Importer::SetupProperties(const Importer *pImp) { // AI_CONFIG_IMPORT_MD3_SKIN_NAME configSkinFile = (pImp->GetPropertyString(AI_CONFIG_IMPORT_MD3_SKIN_NAME, "default")); + // AI_CONFIG_IMPORT_MD3_LOAD_SHADERS + configLoadShaders = (pImp->GetPropertyBool(AI_CONFIG_IMPORT_MD3_LOAD_SHADERS, true)); + // AI_CONFIG_IMPORT_MD3_SHADER_SRC configShaderFile = (pImp->GetPropertyString(AI_CONFIG_IMPORT_MD3_SHADER_SRC, "")); @@ -781,7 +784,9 @@ void MD3Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // And check whether we can locate a shader file for this model Q3Shader::ShaderData shaders; - ReadShader(shaders); + if (configLoadShaders){ + ReadShader(shaders); + } // Adjust all texture paths in the shader const char *header_name = pcHeader->NAME; @@ -863,7 +868,12 @@ void MD3Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy std::string convertedPath; if (texture_name) { - ConvertPath(texture_name, header_name, convertedPath); + if (configLoadShaders){ + ConvertPath(texture_name, header_name, convertedPath); + } + else{ + convertedPath = texture_name; + } } const Q3Shader::ShaderDataBlock *shader = nullptr; diff --git a/code/AssetLib/MD3/MD3Loader.h b/code/AssetLib/MD3/MD3Loader.h index d34df2d77..1a4e5982c 100644 --- a/code/AssetLib/MD3/MD3Loader.h +++ b/code/AssetLib/MD3/MD3Loader.h @@ -297,6 +297,9 @@ protected: /** Configuration option: name of skin file to be read */ std::string configSkinFile; + /** Configuration option: whether to load shaders */ + bool configLoadShaders; + /** Configuration option: name or path of shader */ std::string configShaderFile; diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index d78568da7..016cabbad 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -669,7 +669,7 @@ enum aiComponent // --------------------------------------------------------------------------- /** @brief Set wether the importer shall not remove empty bones. - * + * * Empty bone are often used to define connections for other models. */ #define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \ @@ -854,6 +854,15 @@ enum aiComponent #define AI_CONFIG_IMPORT_MD3_SKIN_NAME \ "IMPORT_MD3_SKIN_NAME" +// --------------------------------------------------------------------------- +/** @brief Specify if to try load Quake 3 shader files. This also controls + * original surface name handling: when disabled it will be used unchanged. + * + * Property type: bool. Default value: true. + */ +#define AI_CONFIG_IMPORT_MD3_LOAD_SHADERS \ + "IMPORT_MD3_LOAD_SHADERS" + // --------------------------------------------------------------------------- /** @brief Specify the Quake 3 shader file to be used for a particular * MD3 file. This can also be a search path. @@ -1058,7 +1067,7 @@ enum aiComponent #define AI_CONFIG_EXPORT_XFILE_64BIT "EXPORT_XFILE_64BIT" /** @brief Specifies whether the assimp export shall be able to export point clouds - * + * * When this flag is not defined the render data has to contain valid faces. * Point clouds are only a collection of vertices which have nor spatial organization * by a face and the validation process will remove them. Enabling this feature will