From aab3c8010c690db86affc2670ed3b72f2b108e88 Mon Sep 17 00:00:00 2001 From: Scott Johnston Date: Thu, 15 Jun 2023 12:16:06 -0700 Subject: [PATCH 01/29] Correct from full FOV to assimp half-fov in camera. Compute from filmWidth and focalLength if FOV not specified. --- code/AssetLib/FBX/FBXConverter.cpp | 24 ++++++++++++++++++++---- code/AssetLib/FBX/FBXDocument.h | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 51ec79583..cca5da596 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -93,6 +93,8 @@ FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBo mSceneOut(out), doc(doc), mRemoveEmptyBones(removeEmptyBones) { + + // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -427,12 +429,26 @@ void FBXConverter::ConvertCamera(const Camera &cam, const std::string &orig_name out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f); out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f); - out_camera->mHorizontalFOV = AI_DEG_TO_RAD(cam.FieldOfView()); + // NOTE: Some software (maya) does not put FieldOfView in FBX, so we compute + // mHorizontalFOV from FocalLength and FilmWidth with unit conversion. - out_camera->mClipPlaneNear = cam.NearPlane(); - out_camera->mClipPlaneFar = cam.FarPlane(); + // TODO: This is not a complete solution for how FBX cameras can be stored. + // TODO: Incorporate non-square pixel aspect ratio. + // TODO: FBX aperture mode might be storing vertical FOV in need of conversion with aspect ratio. + + float fov_deg = cam.FieldOfView(); + // If FOV not specified in file, compute using FilmWidth and FocalLength. + if (fov_deg == FBX_FOV_UNKNOWN) { + float film_width_inches = cam.FilmWidth(); + float focal_length_mm = cam.FocalLength(); + ASSIMP_LOG_VERBOSE_DEBUG("FBX FOV unspecified. Computing from FilmWidth (", film_width_inches, "inches) and FocalLength (", focal_length_mm, "mm)."); + double half_fov_rad = std::atan2(film_width_inches * 25.4 * 0.5, focal_length_mm); + out_camera->mHorizontalFOV = half_fov_rad; + } else { + // FBX fov is full-view degrees. We want half-view radians. + out_camera->mHorizontalFOV = AI_DEG_TO_RAD(fov_deg) * 0.5; + } - out_camera->mHorizontalFOV = AI_DEG_TO_RAD(cam.FieldOfView()); out_camera->mClipPlaneNear = cam.NearPlane(); out_camera->mClipPlaneFar = cam.FarPlane(); } diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index e229eef52..503c94833 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -55,9 +55,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define _AI_CONCAT(a,b) a ## b #define AI_CONCAT(a,b) _AI_CONCAT(a,b) +/* Use an 'illegal' default FOV value to detect if the FBX camera has set the FOV. */ +#define FBX_FOV_UNKNOWN -1.0f + namespace Assimp { namespace FBX { + class Parser; class Object; struct ImportSettings; @@ -247,7 +251,7 @@ public: fbx_simple_property(FilmAspectRatio, float, 1.0f) fbx_simple_property(ApertureMode, int, 0) - fbx_simple_property(FieldOfView, float, 1.0f) + fbx_simple_property(FieldOfView, float, FBX_FOV_UNKNOWN) fbx_simple_property(FocalLength, float, 1.0f) }; From 26c4505c5355730cd89ed42ce6f29e241b59ac47 Mon Sep 17 00:00:00 2001 From: mosfet80 Date: Thu, 22 Jun 2023 21:41:26 +0200 Subject: [PATCH 02/29] Update run-cmake into sanitizer.yml --- .github/workflows/sanitizer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml index b23f4520f..41b8468e2 100644 --- a/.github/workflows/sanitizer.yml +++ b/.github/workflows/sanitizer.yml @@ -22,7 +22,7 @@ jobs: CC: clang - name: configure and build - uses: lukka/run-cmake@v3 + uses: lukka/run-cmake@v10 with: cmakeListsOrSettingsJson: CMakeListsTxtAdvanced cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' @@ -46,7 +46,7 @@ jobs: CC: clang - name: configure and build - uses: lukka/run-cmake@v2 + uses: lukka/run-cmake@v10 with: cmakeListsOrSettingsJson: CMakeListsTxtAdvanced cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' From 46ea0a7d7c37c4fa7f9b39aca6994e2d5d0afd30 Mon Sep 17 00:00:00 2001 From: mosfet80 Date: Thu, 22 Jun 2023 21:43:52 +0200 Subject: [PATCH 03/29] Update sanitizer.yml --- .github/workflows/sanitizer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml index 41b8468e2..483ee8fc1 100644 --- a/.github/workflows/sanitizer.yml +++ b/.github/workflows/sanitizer.yml @@ -22,7 +22,7 @@ jobs: CC: clang - name: configure and build - uses: lukka/run-cmake@v10 + uses: lukka/run-cmake@v3 with: cmakeListsOrSettingsJson: CMakeListsTxtAdvanced cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' @@ -46,7 +46,7 @@ jobs: CC: clang - name: configure and build - uses: lukka/run-cmake@v10 + uses: lukka/run-cmake@v3 with: cmakeListsOrSettingsJson: CMakeListsTxtAdvanced cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' From 02560471681f2a4eeb9937305e52eae710e1513c Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Thu, 22 Jun 2023 14:04:21 +0200 Subject: [PATCH 04/29] Extend token search flag from alpha to graph. This way we can fix Blender exported files being wrongly detected as obj files. --- code/Common/BaseImporter.cpp | 7 ++++--- include/assimp/BaseImporter.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 87b385268..8f8e41d39 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -158,7 +158,7 @@ void BaseImporter::GetExtensionList(std::set &extensions) { std::size_t numTokens, unsigned int searchBytes /* = 200 */, bool tokensSol /* false */, - bool noAlphaBeforeTokens /* false */) { + bool noGraphBeforeTokens /* false */) { ai_assert(nullptr != tokens); ai_assert(0 != numTokens); ai_assert(0 != searchBytes); @@ -207,8 +207,9 @@ void BaseImporter::GetExtensionList(std::set &extensions) { continue; } // We need to make sure that we didn't accidentally identify the end of another token as our token, - // e.g. in a previous version the "gltf " present in some gltf files was detected as "f " - if (noAlphaBeforeTokens && (r != buffer && isalpha(static_cast(r[-1])))) { + // e.g. in a previous version the "gltf " present in some gltf files was detected as "f ", or a + // Blender-exported glb file containing "Khronos glTF Blender I/O " was detected as "o " + if (noGraphBeforeTokens && (r != buffer && isgraph(static_cast(r[-1])))) { continue; } // We got a match, either we don't care where it is, or it happens to diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index 06b87f1e1..42b537b91 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -259,7 +259,7 @@ public: // static utilities std::size_t numTokens, unsigned int searchBytes = 200, bool tokensSol = false, - bool noAlphaBeforeTokens = false); + bool noGraphBeforeTokens = false); // ------------------------------------------------------------------- /** @brief Check whether a file has a specific file extension From 506baa21e68dfe928cecc7f53f4027d94ecd1fb3 Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Tue, 4 Jul 2023 09:25:45 +0200 Subject: [PATCH 05/29] Unify extension check for importers. This enables proper checking for all kinds of extensions (including the ones with multiple dots) for all importers and internal usage. --- code/Common/BaseImporter.cpp | 39 +++++++++++++++++++---------------- code/Common/Importer.cpp | 20 +++--------------- include/assimp/BaseImporter.h | 10 +++++++++ 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 87b385268..a37297b9a 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -229,27 +229,30 @@ void BaseImporter::GetExtensionList(std::set &extensions) { const char *ext0, const char *ext1, const char *ext2) { - std::string::size_type pos = pFile.find_last_of('.'); - - // no file extension - can't read - if (pos == std::string::npos) { - return false; + std::set extensions; + for (const char* ext : {ext0, ext1, ext2}) { + if (ext == nullptr) continue; + extensions.emplace(ext); } + return HasExtension(pFile, extensions); +} - const char *ext_real = &pFile[pos + 1]; - if (!ASSIMP_stricmp(ext_real, ext0)) { - return true; +// ------------------------------------------------------------------------------------------------ +// Check for file extension +/*static*/ bool BaseImporter::HasExtension(const std::string &pFile, const std::set &extensions) { + // CAUTION: Do not just search for the extension! + // GetExtension() returns the part after the *last* dot, but some extensions + // have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the + // string. + for (std::set::const_iterator it = extensions.cbegin(); it != extensions.cend(); ++it) { + // Yay for C++<20 not having std::string::ends_with() + const std::string extension = "." + *it; + if (extension.length() > pFile.length()) continue; + // Possible optimization: Fetch the lowercase filename! + if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - extension.length(), extension.c_str())) { + return true; + } } - - // check for other, optional, file extensions - if (ext1 && !ASSIMP_stricmp(ext_real, ext1)) { - return true; - } - - if (ext2 && !ASSIMP_stricmp(ext_real, ext2)) { - return true; - } - return false; } diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index b66059397..bdf64ac8f 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -637,24 +637,10 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) { std::set extensions; pimpl->mImporter[a]->GetExtensionList(extensions); - // CAUTION: Do not just search for the extension! - // GetExtension() returns the part after the *last* dot, but some extensions have dots - // inside them, e.g. ogre.mesh.xml. Compare the entire end of the string. - for (std::set::const_iterator it = extensions.cbegin(); it != extensions.cend(); ++it) { - - // Yay for C++<20 not having std::string::ends_with() - std::string extension = "." + *it; - if (extension.length() <= pFile.length()) { - // Possible optimization: Fetch the lowercase filename! - if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - extension.length(), extension.c_str())) { - ImporterAndIndex candidate = { pimpl->mImporter[a], a }; - possibleImporters.push_back(candidate); - break; - } - } - + if (BaseImporter::HasExtension(pFile, extensions)) { + ImporterAndIndex candidate = { pimpl->mImporter[a], a }; + possibleImporters.push_back(candidate); } - } // If just one importer supports this extension, pick it and close the case. diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index 06b87f1e1..bf425a849 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -275,6 +275,16 @@ public: // static utilities const char *ext1 = nullptr, const char *ext2 = nullptr); + // ------------------------------------------------------------------- + /** @brief Check whether a file has one of the passed file extensions + * @param pFile Input file + * @param extensions Extensions to check for. Lowercase characters only, no dot! + * @note Case-insensitive + */ + static bool HasExtension( + const std::string &pFile, + const std::set &extensions); + // ------------------------------------------------------------------- /** @brief Extract file extension from a string * @param pFile Input file From bdde96867705d9cbfc0b95f5864d6bc6357c52fd Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Tue, 4 Jul 2023 12:29:17 +0200 Subject: [PATCH 06/29] Address reviewer comment. --- code/Common/BaseImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index a37297b9a..d03b2adfc 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -244,7 +244,7 @@ void BaseImporter::GetExtensionList(std::set &extensions) { // GetExtension() returns the part after the *last* dot, but some extensions // have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the // string. - for (std::set::const_iterator it = extensions.cbegin(); it != extensions.cend(); ++it) { + for (auto it = extensions.cbegin(); it != extensions.cend(); ++it) { // Yay for C++<20 not having std::string::ends_with() const std::string extension = "." + *it; if (extension.length() > pFile.length()) continue; From 87cac888e474880efdacba4cddd28f83c582fd97 Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Tue, 4 Jul 2023 13:18:22 +0200 Subject: [PATCH 07/29] More simplifications. --- code/Common/BaseImporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index d03b2adfc..39c93e4be 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -244,12 +244,12 @@ void BaseImporter::GetExtensionList(std::set &extensions) { // GetExtension() returns the part after the *last* dot, but some extensions // have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the // string. - for (auto it = extensions.cbegin(); it != extensions.cend(); ++it) { + for (const std::string& ext : extensions) { // Yay for C++<20 not having std::string::ends_with() - const std::string extension = "." + *it; - if (extension.length() > pFile.length()) continue; + const std::string dotExt = "." + ext; + if (dotExt.length() > pFile.length()) continue; // Possible optimization: Fetch the lowercase filename! - if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - extension.length(), extension.c_str())) { + if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - dotExt.length(), dotExt.c_str())) { return true; } } From bf38d67935ba3c7bf663c4bb8a5c79f47392c2c1 Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Thu, 13 Jul 2023 11:51:56 +0200 Subject: [PATCH 08/29] Fix detection of KHR_materials_specular. --- code/AssetLib/glTF2/glTF2Exporter.cpp | 2 +- test/unit/utglTF2ImportExport.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index f7fa9cd42..d4568fa31 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -730,7 +730,7 @@ bool glTF2Exporter::GetMatSpecGloss(const aiMaterial &mat, glTF2::PbrSpecularGlo bool glTF2Exporter::GetMatSpecular(const aiMaterial &mat, glTF2::MaterialSpecular &specular) { // Specular requires either/or, default factors of zero disables specular, so do not export - if (GetMatColor(mat, specular.specularColorFactor, AI_MATKEY_COLOR_SPECULAR) != AI_SUCCESS || mat.Get(AI_MATKEY_SPECULAR_FACTOR, specular.specularFactor) != AI_SUCCESS) { + if (GetMatColor(mat, specular.specularColorFactor, AI_MATKEY_COLOR_SPECULAR) != AI_SUCCESS && mat.Get(AI_MATKEY_SPECULAR_FACTOR, specular.specularFactor) != AI_SUCCESS) { return false; } // The spec states that the default is 1.0 and [1.0, 1.0, 1.0]. We if both are 0, which should disable specular. Otherwise, if one is 0, set to 1.0 diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 91ac87ee5..ba1c859ad 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -60,7 +60,7 @@ using namespace Assimp; class utglTF2ImportExport : public AbstractImportExportBase { public: - virtual bool importerMatTest(const char *file, bool spec_gloss, std::array exp_modes = { aiTextureMapMode_Wrap, aiTextureMapMode_Wrap }) { + virtual bool importerMatTest(const char *file, bool spec, bool gloss, std::array exp_modes = { aiTextureMapMode_Wrap, aiTextureMapMode_Wrap }) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(file, aiProcess_ValidateDataStructure); EXPECT_NE(scene, nullptr); @@ -105,16 +105,19 @@ public: aiColor3D spec_color = { 0, 0, 0 }; ai_real glossiness = ai_real(0.5); - if (spec_gloss) { + if (spec) { EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_COLOR_SPECULAR, spec_color)); constexpr ai_real spec_val(0.20000000298023225); // From the file EXPECT_EQ(spec_val, spec_color.r); EXPECT_EQ(spec_val, spec_color.g); EXPECT_EQ(spec_val, spec_color.b); + } else { + EXPECT_EQ(aiReturn_FAILURE, material->Get(AI_MATKEY_COLOR_SPECULAR, spec_color)); + } + if (gloss) { EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_GLOSSINESS_FACTOR, glossiness)); EXPECT_EQ(ai_real(1.0), glossiness); } else { - EXPECT_EQ(aiReturn_FAILURE, material->Get(AI_MATKEY_COLOR_SPECULAR, spec_color)); EXPECT_EQ(aiReturn_FAILURE, material->Get(AI_MATKEY_GLOSSINESS_FACTOR, glossiness)); } @@ -143,7 +146,7 @@ public: }; TEST_F(utglTF2ImportExport, importglTF2FromFileTest) { - EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", false, {aiTextureMapMode_Mirror, aiTextureMapMode_Clamp})); + EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", false, false, {aiTextureMapMode_Mirror, aiTextureMapMode_Clamp})); } TEST_F(utglTF2ImportExport, importBinaryglTF2FromFileTest) { @@ -151,7 +154,7 @@ TEST_F(utglTF2ImportExport, importBinaryglTF2FromFileTest) { } TEST_F(utglTF2ImportExport, importglTF2_KHR_materials_pbrSpecularGlossiness) { - EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured.gltf", true)); + EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured.gltf", true, true)); } void VerifyClearCoatScene(const aiScene *scene) { @@ -223,13 +226,16 @@ TEST_F(utglTF2ImportExport, importglTF2AndExport_KHR_materials_pbrSpecularGlossi // Export with specular glossiness disabled EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured_out.glb")); + // And re-import + EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured_out.glb", true, false)); + // Export with specular glossiness enabled ExportProperties props; props.SetPropertyBool(AI_CONFIG_USE_GLTF_PBR_SPECULAR_GLOSSINESS, true); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured_out.glb", 0, &props)); // And re-import - EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured_out.glb", true)); + EXPECT_TRUE(importerMatTest(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-pbrSpecularGlossiness/BoxTextured_out.glb", true, true)); } TEST_F(utglTF2ImportExport, importglTF2AndExportToOBJ) { From 1e6c7063b6e5209c156a628a2cb3a1ea33598176 Mon Sep 17 00:00:00 2001 From: Steve M Date: Thu, 13 Jul 2023 20:28:48 -0700 Subject: [PATCH 09/29] Fix typos --- test/models/IRR/scenegraphAnim.irr | 2 +- test/models/IRR/scenegraphAnim_UTF16LE.irr | Bin 47408 -> 47404 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/IRR/scenegraphAnim.irr b/test/models/IRR/scenegraphAnim.irr index 1c6fd0ef4..2300ea18f 100644 --- a/test/models/IRR/scenegraphAnim.irr +++ b/test/models/IRR/scenegraphAnim.irr @@ -126,7 +126,7 @@ - + diff --git a/test/models/IRR/scenegraphAnim_UTF16LE.irr b/test/models/IRR/scenegraphAnim_UTF16LE.irr index b22aaf4b7906af22e1cb74617cd2cd312887e143..f6794351f77b67a498679d9809865b883acca8a5 100644 GIT binary patch delta 21 dcmdn+iD}IzrVTIDCihKon7l!mWwC+!BmjCF3GM&@ delta 21 bcmZ4UiD?56y-=GRu*PNb24$ATI_i@Ecx?&D From 0e7cd18c8bab64b9975e663cc4be8fd5485acabc Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Fri, 14 Jul 2023 09:37:48 +0200 Subject: [PATCH 10/29] Strip aws gcs version string. --- code/Common/BaseImporter.cpp | 33 ++++++++++++++++++++++++++++++--- test/unit/utImporter.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index efcc00d4f..d2ff4a9dd 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -59,6 +59,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +namespace { +// Checks whether the passed string is a gcs version. +bool IsGcsVersion(const std::string &s) { + if (s.empty()) return false; + return std::all_of(s.cbegin(), s.cend(), [](const char c) { + // gcs only permits numeric characters. + return std::isdigit(static_cast(c)); + }); +} + +// Removes a possible version hash from a filename, as found for example in +// gcs uris (e.g. `gs://bucket/model.glb#1234`), see also +// https://github.com/GoogleCloudPlatform/gsutil/blob/c80f329bc3c4011236c78ce8910988773b2606cb/gslib/storage_url.py#L39. +std::string StripVersionHash(const std::string &filename) { + const std::string::size_type pos = filename.find_last_of('#'); + // Only strip if the hash is behind a possible file extension and the part + // behind the hash is a version string. + if (pos != std::string::npos && pos > filename.find_last_of('.') && + IsGcsVersion(filename.substr(pos + 1))) { + return filename.substr(0, pos); + } + return filename; +} +} // namespace + using namespace Assimp; // ------------------------------------------------------------------------------------------------ @@ -241,6 +266,7 @@ void BaseImporter::GetExtensionList(std::set &extensions) { // ------------------------------------------------------------------------------------------------ // Check for file extension /*static*/ bool BaseImporter::HasExtension(const std::string &pFile, const std::set &extensions) { + const std::string file = StripVersionHash(pFile); // CAUTION: Do not just search for the extension! // GetExtension() returns the part after the *last* dot, but some extensions // have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the @@ -248,9 +274,9 @@ void BaseImporter::GetExtensionList(std::set &extensions) { for (const std::string& ext : extensions) { // Yay for C++<20 not having std::string::ends_with() const std::string dotExt = "." + ext; - if (dotExt.length() > pFile.length()) continue; + if (dotExt.length() > file.length()) continue; // Possible optimization: Fetch the lowercase filename! - if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - dotExt.length(), dotExt.c_str())) { + if (0 == ASSIMP_stricmp(file.c_str() + file.length() - dotExt.length(), dotExt.c_str())) { return true; } } @@ -259,7 +285,8 @@ void BaseImporter::GetExtensionList(std::set &extensions) { // ------------------------------------------------------------------------------------------------ // Get file extension from path -std::string BaseImporter::GetExtension(const std::string &file) { +std::string BaseImporter::GetExtension(const std::string &pFile) { + const std::string file = StripVersionHash(pFile); std::string::size_type pos = file.find_last_of('.'); // no file extension at all diff --git a/test/unit/utImporter.cpp b/test/unit/utImporter.cpp index 98080c526..5ecc45e34 100644 --- a/test/unit/utImporter.cpp +++ b/test/unit/utImporter.cpp @@ -361,3 +361,37 @@ TEST_F(ImporterTest, unexpectedException) { EXPECT_TRUE(false); } } + +// ------------------------------------------------------------------------------------------------ + +struct ExtensionTestCase { + std::string testName; + std::string filename; + std::string getExtensionResult; + std::string hasExtension; + bool hasExtensionResult; +}; + +using ExtensionTest = ::testing::TestWithParam; + +TEST_P(ExtensionTest, testGetAndHasExtension) { + const ExtensionTestCase& testCase = GetParam(); + EXPECT_EQ(testCase.getExtensionResult, BaseImporter::GetExtension(testCase.filename)); + EXPECT_EQ(testCase.hasExtensionResult, BaseImporter::HasExtension(testCase.filename, {testCase.hasExtension})); +} + +INSTANTIATE_TEST_SUITE_P( + ExtensionTests, ExtensionTest, + ::testing::ValuesIn({ + {"NoExtension", "name", "", "glb", false}, + {"NoExtensionAndEmptyVersion", "name#", "", "glb", false}, + {"WithExtensionAndEmptyVersion", "name.glb#", "glb#", "glb", false}, + {"WithExtensionAndVersion", "name.glb#1234", "glb", "glb", true}, + {"WithExtensionAndHashInStem", "name#1234.glb", "glb", "glb", true}, + {"WithExtensionAndInvalidVersion", "name.glb#_", "glb#_", "glb", false}, + {"WithExtensionAndDotAndHashInStem", "name.glb#.abc", "abc", "glb", false}, + {"WithTwoExtensions", "name.abc.def", "def", "abc.def", true}, + }), + [](const ::testing::TestParamInfo& info) { + return info.param.testName; + }); From 3161f0e754252b04e88d69d4800c4faccfc045e5 Mon Sep 17 00:00:00 2001 From: Steve M Date: Fri, 14 Jul 2023 20:19:28 -0700 Subject: [PATCH 11/29] Introduce alternate versions with animations disabled to allow sucessful load --- test/models/IRR/scenegraphAnimMod.irr | 554 ++++++++++++++++++ test/models/IRR/scenegraphAnimMod_UTF16LE.irr | Bin 0 -> 47672 bytes 2 files changed, 554 insertions(+) create mode 100644 test/models/IRR/scenegraphAnimMod.irr create mode 100644 test/models/IRR/scenegraphAnimMod_UTF16LE.irr diff --git a/test/models/IRR/scenegraphAnimMod.irr b/test/models/IRR/scenegraphAnimMod.irr new file mode 100644 index 000000000..21408b245 --- /dev/null +++ b/test/models/IRR/scenegraphAnimMod.irr @@ -0,0 +1,554 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/models/IRR/scenegraphAnimMod_UTF16LE.irr b/test/models/IRR/scenegraphAnimMod_UTF16LE.irr new file mode 100644 index 0000000000000000000000000000000000000000..7384ae29ada86ec6b7aaa1952ca7138f0280983f GIT binary patch literal 47672 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 literal 0 HcmV?d00001 From 46be2d3380c26948883ebbaf95c70681a16ef714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sat, 15 Jul 2023 15:54:15 +0200 Subject: [PATCH 12/29] Remove /WX from CMakeLists for MSVC --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 224f6e48f..dfaa2b791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -286,9 +286,9 @@ IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT MINGW) ELSEIF(MSVC) # enable multi-core compilation with MSVC IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - ADD_COMPILE_OPTIONS(/bigobj /W4 /WX ) + ADD_COMPILE_OPTIONS(/bigobj) ELSE() # msvc - ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX) + ADD_COMPILE_OPTIONS(/MP /bigobj) ENDIF() # disable "elements of array '' will be default initialized" warning on MSVC2013 From 52e5c3f39ecd9ed241048b6f1bf3e682adb64194 Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Fri, 21 Jul 2023 09:48:45 +0200 Subject: [PATCH 13/29] Fix violation of strict aliasing rule. --- code/Common/BaseImporter.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index d2ff4a9dd..a169c8a10 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -312,12 +312,7 @@ std::string BaseImporter::GetExtension(const std::string &pFile) { if (!pIOHandler) { return false; } - union { - const char *magic; - const uint16_t *magic_u16; - const uint32_t *magic_u32; - }; - magic = reinterpret_cast(_magic); + const char *magic = reinterpret_cast(_magic); std::unique_ptr pStream(pIOHandler->Open(pFile)); if (pStream) { @@ -339,15 +334,15 @@ std::string BaseImporter::GetExtension(const std::string &pFile) { // that's just for convenience, the chance that we cause conflicts // is quite low and it can save some lines and prevent nasty bugs if (2 == size) { - uint16_t rev = *magic_u16; - ByteSwap::Swap(&rev); - if (data_u16[0] == *magic_u16 || data_u16[0] == rev) { + uint16_t magic_u16; + memcpy(&magic_u16, magic, 2); + if (data_u16[0] == magic_u16 || data_u16[0] == ByteSwap::Swapped(magic_u16)) { return true; } } else if (4 == size) { - uint32_t rev = *magic_u32; - ByteSwap::Swap(&rev); - if (data_u32[0] == *magic_u32 || data_u32[0] == rev) { + uint32_t magic_u32; + memcpy(&magic_u32, magic, 4); + if (data_u32[0] == magic_u32 || data_u32[0] == ByteSwap::Swapped(magic_u32)) { return true; } } else { From 37a1366fb7ea92a0d0456ced515ad45a11c1d992 Mon Sep 17 00:00:00 2001 From: Marco Feuerstein Date: Fri, 21 Jul 2023 11:30:21 +0200 Subject: [PATCH 14/29] Add missing rapidjson headers. --- code/AssetLib/glTF2/glTF2Asset.inl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 227f3878c..53ffdaf31 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -45,6 +45,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include +#include // clang-format off #ifdef ASSIMP_ENABLE_DRACO From 0ab7de70cd77a1ea4a2df87acde969d4cb33e6ab Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 23 Jul 2023 12:49:25 +0200 Subject: [PATCH 15/29] Remove deprecated swig files. --- port/swig/DONOTUSEYET | 1 - port/swig/assimp.i | 140 ---------------------------- port/swig/d/build.sh | 2 - port/swig/d/generate.sh | 4 - port/swig/interface/DefaultLogger.i | 5 - port/swig/interface/IOStream.i | 5 - port/swig/interface/IOSystem.i | 11 --- port/swig/interface/LogStream.i | 5 - port/swig/interface/Logger.i | 5 - port/swig/interface/NullLogger.i | 5 - port/swig/interface/aiAnim.i | 8 -- port/swig/interface/aiAssert.i | 5 - port/swig/interface/aiCamera.i | 5 - port/swig/interface/aiColor4D.i | 5 - port/swig/interface/aiConfig.i | 5 - port/swig/interface/aiDefines.i | 5 - port/swig/interface/aiFileIO.i | 5 - port/swig/interface/aiLight.i | 5 - port/swig/interface/aiMaterial.i | 33 ------- port/swig/interface/aiMatrix3x3.i | 5 - port/swig/interface/aiMatrix4x4.i | 5 - port/swig/interface/aiMesh.i | 29 ------ port/swig/interface/aiPostProcess.i | 7 -- port/swig/interface/aiQuaternion.i | 5 - port/swig/interface/aiScene.i | 17 ---- port/swig/interface/aiTexture.i | 5 - port/swig/interface/aiTypes.i | 8 -- port/swig/interface/aiVector2D.i | 5 - port/swig/interface/aiVector3D.i | 5 - port/swig/interface/aiVersion.i | 5 - port/swig/interface/assimp.i | 45 --------- 31 files changed, 400 deletions(-) delete mode 100644 port/swig/DONOTUSEYET delete mode 100644 port/swig/assimp.i delete mode 100755 port/swig/d/build.sh delete mode 100755 port/swig/d/generate.sh delete mode 100644 port/swig/interface/DefaultLogger.i delete mode 100644 port/swig/interface/IOStream.i delete mode 100644 port/swig/interface/IOSystem.i delete mode 100644 port/swig/interface/LogStream.i delete mode 100644 port/swig/interface/Logger.i delete mode 100644 port/swig/interface/NullLogger.i delete mode 100644 port/swig/interface/aiAnim.i delete mode 100644 port/swig/interface/aiAssert.i delete mode 100644 port/swig/interface/aiCamera.i delete mode 100644 port/swig/interface/aiColor4D.i delete mode 100644 port/swig/interface/aiConfig.i delete mode 100644 port/swig/interface/aiDefines.i delete mode 100644 port/swig/interface/aiFileIO.i delete mode 100644 port/swig/interface/aiLight.i delete mode 100644 port/swig/interface/aiMaterial.i delete mode 100644 port/swig/interface/aiMatrix3x3.i delete mode 100644 port/swig/interface/aiMatrix4x4.i delete mode 100644 port/swig/interface/aiMesh.i delete mode 100644 port/swig/interface/aiPostProcess.i delete mode 100644 port/swig/interface/aiQuaternion.i delete mode 100644 port/swig/interface/aiScene.i delete mode 100644 port/swig/interface/aiTexture.i delete mode 100644 port/swig/interface/aiTypes.i delete mode 100644 port/swig/interface/aiVector2D.i delete mode 100644 port/swig/interface/aiVector3D.i delete mode 100644 port/swig/interface/aiVersion.i delete mode 100644 port/swig/interface/assimp.i diff --git a/port/swig/DONOTUSEYET b/port/swig/DONOTUSEYET deleted file mode 100644 index 87c6e0699..000000000 --- a/port/swig/DONOTUSEYET +++ /dev/null @@ -1 +0,0 @@ -The interface files are by no means complete yet and only work with the not-yet-released D SWIG backend, although adding support for other languages should not be too much of problem via #ifdefs. diff --git a/port/swig/assimp.i b/port/swig/assimp.i deleted file mode 100644 index 58e1546e7..000000000 --- a/port/swig/assimp.i +++ /dev/null @@ -1,140 +0,0 @@ -%module assimp - -// SWIG helpers for std::string and std::vector wrapping. -%include -%include - -// Globally enable enum prefix stripping. -%dstripprefix; - - -// PACK_STRUCT is a no-op for SWIG – it does not matter for the generated -// bindings how the underlying C++ code manages its memory. -#define PACK_STRUCT - - -// Helper macros for wrapping the pointer-and-length arrays used in the -// Assimp API. - -%define ASSIMP_ARRAY(CLASS, TYPE, NAME, LENGTH) -%newobject CLASS::NAME; -%extend CLASS { - std::vector *NAME() const { - std::vector *result = new std::vector; - result->reserve(LENGTH); - - for (unsigned int i = 0; i < LENGTH; ++i) { - result->push_back($self->NAME[i]); - } - - return result; - } -} -%ignore CLASS::NAME; -%enddef - -%define ASSIMP_POINTER_ARRAY(CLASS, TYPE, NAME, LENGTH) -%newobject CLASS::NAME; -%extend CLASS { - std::vector *NAME() const { - std::vector *result = new std::vector; - result->reserve(LENGTH); - - TYPE *currentValue = $self->NAME; - TYPE *valueLimit = $self->NAME + LENGTH; - while (currentValue < valueLimit) { - result->push_back(currentValue); - ++currentValue; - } - - return result; - } -} -%ignore CLASS::NAME; -%enddef - -%define ASSIMP_POINTER_ARRAY_ARRAY(CLASS, TYPE, NAME, OUTER_LENGTH, INNER_LENGTH) -%newobject CLASS::NAME; -%extend CLASS { - std::vector > *NAME() const { - std::vector > *result = new std::vector >; - result->reserve(OUTER_LENGTH); - - for (unsigned int i = 0; i < OUTER_LENGTH; ++i) { - std::vector currentElements; - - if ($self->NAME[i] != 0) { - currentElements.reserve(INNER_LENGTH); - - TYPE *currentValue = $self->NAME[i]; - TYPE *valueLimit = $self->NAME[i] + INNER_LENGTH; - while (currentValue < valueLimit) { - currentElements.push_back(currentValue); - ++currentValue; - } - } - - result->push_back(currentElements); - } - - return result; - } -} -%ignore CLASS::NAME; -%enddef - - -%include "interface/aiDefines.i" -%include "interface/aiTypes.i" -%include "interface/assimp.i" -%include "interface/aiTexture.i" -%include "interface/aiMatrix4x4.i" -%include "interface/aiMatrix3x3.i" -%include "interface/aiVector3D.i" -%include "interface/aiVector2D.i" -%include "interface/aiColor4D.i" -%include "interface/aiLight.i" -%include "interface/aiCamera.i" -%include "interface/aiFileIO.i" -%include "interface/aiAssert.i" -%include "interface/aiVersion.i" -%include "interface/aiAnim.i" -%include "interface/aiMaterial.i" -%include "interface/aiMesh.i" -%include "interface/aiPostProcess.i" -%include "interface/aiConfig.i" -%include "interface/assimp.i" -%include "interface/aiQuaternion.i" -%include "interface/aiScene.i" -%include "interface/Logger.i" -%include "interface/DefaultLogger.i" -%include "interface/NullLogger.i" -%include "interface/LogStream.i" -%include "interface/IOStream.i" -%include "interface/IOSystem.i" - - -// We have to "instantiate" the templates used by the ASSSIMP_*_ARRAY macros -// here at the end to avoid running into forward reference issues (SWIG would -// spit out the helper functions before the header includes for the element -// types otherwise). - -%template(UintVector) std::vector; -%template(aiAnimationVector) std::vector; -%template(aiAnimMeshVector) std::vector; -%template(aiBonesVector) std::vector; -%template(aiCameraVector) std::vector; -%template(aiColor4DVector) std::vector; -%template(aiColor4DVectorVector) std::vector >; -%template(aiFaceVector) std::vector; -%template(aiLightVector) std::vector; -%template(aiMaterialVector) std::vector; -%template(aiMaterialPropertyVector) std::vector; -%template(aiMeshAnimVector) std::vector; -%template(aiMeshVector) std::vector; -%template(aiNodeVector) std::vector; -%template(aiNodeAnimVector) std::vector; -%template(aiTextureVector) std::vector; -%template(aiVector3DVector) std::vector; -%template(aiVector3DVectorVector) std::vector >; -%template(aiVertexWeightVector) std::vector; diff --git a/port/swig/d/build.sh b/port/swig/d/build.sh deleted file mode 100755 index 0bf6bff6a..000000000 --- a/port/swig/d/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -gcc -shared -fPIC -g3 -I../../../include/ -lassimp -olibassimp_wrap.so assimp_wrap.cxx diff --git a/port/swig/d/generate.sh b/port/swig/d/generate.sh deleted file mode 100755 index 7de66b1ff..000000000 --- a/port/swig/d/generate.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -rm -rf assimp/ -mkdir assimp -swig -c++ -d -outcurrentdir -I../../../include -splitproxy -package assimp $@ ../assimp.i diff --git a/port/swig/interface/DefaultLogger.i b/port/swig/interface/DefaultLogger.i deleted file mode 100644 index 600d28e84..000000000 --- a/port/swig/interface/DefaultLogger.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "DefaultLogger.h" -%} - -%include "DefaultLogger.h" diff --git a/port/swig/interface/IOStream.i b/port/swig/interface/IOStream.i deleted file mode 100644 index baca5ef45..000000000 --- a/port/swig/interface/IOStream.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "IOStream.h" -%} - -%include "IOStream.h" diff --git a/port/swig/interface/IOSystem.i b/port/swig/interface/IOSystem.i deleted file mode 100644 index 3e3e04a67..000000000 --- a/port/swig/interface/IOSystem.i +++ /dev/null @@ -1,11 +0,0 @@ -%{ -#include "IOSystem.h" -%} - -// The const char* overload is used instead. -%ignore Assimp::IOSystem::Exists(const std::string&) const; -%ignore Assimp::IOSystem::Open(const std::string& pFile); -%ignore Assimp::IOSystem::Open(const std::string& pFile, const std::string& pMode); -%ignore Assimp::IOSystem::ComparePaths(const std::string& one, const std::string& second) const; - -%include "IOSystem.h" diff --git a/port/swig/interface/LogStream.i b/port/swig/interface/LogStream.i deleted file mode 100644 index 022f8e586..000000000 --- a/port/swig/interface/LogStream.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "LogStream.h" -%} - -%include "LogStream.h" diff --git a/port/swig/interface/Logger.i b/port/swig/interface/Logger.i deleted file mode 100644 index cadc50b8e..000000000 --- a/port/swig/interface/Logger.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "Logger.h" -%} - -%include "Logger.h" diff --git a/port/swig/interface/NullLogger.i b/port/swig/interface/NullLogger.i deleted file mode 100644 index 5cf42edf5..000000000 --- a/port/swig/interface/NullLogger.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "NullLogger.h" -%} - -%include "NullLogger.h" diff --git a/port/swig/interface/aiAnim.i b/port/swig/interface/aiAnim.i deleted file mode 100644 index de497008f..000000000 --- a/port/swig/interface/aiAnim.i +++ /dev/null @@ -1,8 +0,0 @@ -%{ -#include "aiAnim.h" -%} - -ASSIMP_ARRAY(aiAnimation, aiNodeAnim*, mChannels, $self->mNumChannels); -ASSIMP_ARRAY(aiAnimation, aiMeshAnim*, mMeshChannels, $self->mNumMeshChannels); - -%include "aiAnim.h" diff --git a/port/swig/interface/aiAssert.i b/port/swig/interface/aiAssert.i deleted file mode 100644 index bc8a9b88c..000000000 --- a/port/swig/interface/aiAssert.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiAssert.h" -%} - -%include "aiAssert.h" diff --git a/port/swig/interface/aiCamera.i b/port/swig/interface/aiCamera.i deleted file mode 100644 index 5c2124501..000000000 --- a/port/swig/interface/aiCamera.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiCamera.h" -%} - -%include "aiCamera.h" diff --git a/port/swig/interface/aiColor4D.i b/port/swig/interface/aiColor4D.i deleted file mode 100644 index 3c009168b..000000000 --- a/port/swig/interface/aiColor4D.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiColor4D.h" -%} - -%include "aiColor4D.h" diff --git a/port/swig/interface/aiConfig.i b/port/swig/interface/aiConfig.i deleted file mode 100644 index 110abb3d6..000000000 --- a/port/swig/interface/aiConfig.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiConfig.h" -%} - -%include "aiConfig.h" diff --git a/port/swig/interface/aiDefines.i b/port/swig/interface/aiDefines.i deleted file mode 100644 index 3a61ea62f..000000000 --- a/port/swig/interface/aiDefines.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiDefines.h" -%} - -%include "aiDefines.h" diff --git a/port/swig/interface/aiFileIO.i b/port/swig/interface/aiFileIO.i deleted file mode 100644 index 5a1e0923e..000000000 --- a/port/swig/interface/aiFileIO.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiFileIO.h" -%} - -%include "aiFileIO.h" diff --git a/port/swig/interface/aiLight.i b/port/swig/interface/aiLight.i deleted file mode 100644 index fbefde7c0..000000000 --- a/port/swig/interface/aiLight.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiLight.h" -%} - -%include "aiLight.h" diff --git a/port/swig/interface/aiMaterial.i b/port/swig/interface/aiMaterial.i deleted file mode 100644 index 630e6b711..000000000 --- a/port/swig/interface/aiMaterial.i +++ /dev/null @@ -1,33 +0,0 @@ -%{ -#include "aiMaterial.h" -%} - -ASSIMP_ARRAY(aiMaterial, aiMaterialProperty*, mProperties, $self->mNumProperties) - -%include -%apply enum SWIGTYPE *OUTPUT { aiTextureMapping* mapping }; -%apply unsigned int *OUTPUT { unsigned int* uvindex }; -%apply float *OUTPUT { float* blend }; -%apply enum SWIGTYPE *OUTPUT { aiTextureOp* op }; -%apply unsigned int *OUTPUT { unsigned int* flags }; - -%include "aiMaterial.h" - -%clear unsigned int* flags; -%clear aiTextureOp* op; -%clear float *blend; -%clear unsigned int* uvindex; -%clear aiTextureMapping* mapping; - - -%apply int &OUTPUT { int &pOut }; -%apply float &OUTPUT { float &pOut }; - -%template(GetInteger) aiMaterial::Get; -%template(GetFloat) aiMaterial::Get; -%template(GetColor4D) aiMaterial::Get; -%template(GetColor3D) aiMaterial::Get; -%template(GetString) aiMaterial::Get; - -%clear int &pOut; -%clear float &pOut; diff --git a/port/swig/interface/aiMatrix3x3.i b/port/swig/interface/aiMatrix3x3.i deleted file mode 100644 index 8336d447a..000000000 --- a/port/swig/interface/aiMatrix3x3.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiMatrix3x3.h" -%} - -%include "aiMatrix3x3.h" diff --git a/port/swig/interface/aiMatrix4x4.i b/port/swig/interface/aiMatrix4x4.i deleted file mode 100644 index 976c56b03..000000000 --- a/port/swig/interface/aiMatrix4x4.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiMatrix4x4.h" -%} - -%include "aiMatrix4x4.h" diff --git a/port/swig/interface/aiMesh.i b/port/swig/interface/aiMesh.i deleted file mode 100644 index 141366c2e..000000000 --- a/port/swig/interface/aiMesh.i +++ /dev/null @@ -1,29 +0,0 @@ -%{ -#include "aiMesh.h" -%} - - -ASSIMP_ARRAY(aiFace, unsigned int, mIndices, $self->mNumIndices); - -ASSIMP_POINTER_ARRAY(aiBone, aiVertexWeight, mWeights, $self->mNumWeights); - -ASSIMP_POINTER_ARRAY(aiAnimMesh, aiVector3D, mVertices, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiAnimMesh, aiVector3D, mNormals, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiAnimMesh, aiVector3D, mTangents, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiAnimMesh, aiVector3D, mBitangents, $self->mNumVertices); -ASSIMP_POINTER_ARRAY_ARRAY(aiAnimMesh, aiVector3D, mTextureCoords, AI_MAX_NUMBER_OF_TEXTURECOORDS, $self->mNumVertices); -ASSIMP_POINTER_ARRAY_ARRAY(aiAnimMesh, aiColor4D, mColors, AI_MAX_NUMBER_OF_COLOR_SETS, $self->mNumVertices); - -ASSIMP_ARRAY(aiMesh, aiAnimMesh*, mAnimMeshes, $self->mNumAnimMeshes); -ASSIMP_ARRAY(aiMesh, aiBone*, mBones, $self->mNumBones); -ASSIMP_ARRAY(aiMesh, unsigned int, mNumUVComponents, AI_MAX_NUMBER_OF_TEXTURECOORDS); -ASSIMP_POINTER_ARRAY(aiMesh, aiVector3D, mVertices, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiMesh, aiVector3D, mNormals, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiMesh, aiVector3D, mTangents, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiMesh, aiVector3D, mBitangents, $self->mNumVertices); -ASSIMP_POINTER_ARRAY(aiMesh, aiFace, mFaces, $self->mNumFaces); -ASSIMP_POINTER_ARRAY_ARRAY(aiMesh, aiVector3D, mTextureCoords, AI_MAX_NUMBER_OF_TEXTURECOORDS, $self->mNumVertices); -ASSIMP_POINTER_ARRAY_ARRAY(aiMesh, aiColor4D, mColors, AI_MAX_NUMBER_OF_COLOR_SETS, $self->mNumVertices); - - -%include "aiMesh.h" diff --git a/port/swig/interface/aiPostProcess.i b/port/swig/interface/aiPostProcess.i deleted file mode 100644 index 5f64ec53a..000000000 --- a/port/swig/interface/aiPostProcess.i +++ /dev/null @@ -1,7 +0,0 @@ -%{ -#include "aiPostProcess.h" -%} - -%feature("d:stripprefix", "aiProcess_") aiPostProcessSteps; - -%include "aiPostProcess.h" diff --git a/port/swig/interface/aiQuaternion.i b/port/swig/interface/aiQuaternion.i deleted file mode 100644 index 256057a22..000000000 --- a/port/swig/interface/aiQuaternion.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiQuaternion.h" -%} - -%include "aiQuaternion.h" diff --git a/port/swig/interface/aiScene.i b/port/swig/interface/aiScene.i deleted file mode 100644 index 7278f3368..000000000 --- a/port/swig/interface/aiScene.i +++ /dev/null @@ -1,17 +0,0 @@ -%{ -#include "aiScene.h" -%} - - -ASSIMP_ARRAY(aiScene, aiAnimation*, mAnimations, $self->mNumAnimations); -ASSIMP_ARRAY(aiScene, aiCamera*, mCameras, $self->mNumCameras); -ASSIMP_ARRAY(aiScene, aiLight*, mLights, $self->mNumLights); -ASSIMP_ARRAY(aiScene, aiMaterial*, mMaterials, $self->mNumMaterials); -ASSIMP_ARRAY(aiScene, aiMesh*, mMeshes, $self->mNumMeshes); -ASSIMP_ARRAY(aiScene, aiTexture*, mTextures, $self->mNumTextures); - -ASSIMP_ARRAY(aiNode, aiNode*, mChildren, $self->mNumChildren); -ASSIMP_ARRAY(aiNode, unsigned int, mMeshes, $self->mNumMeshes); - - -%include "aiScene.h" diff --git a/port/swig/interface/aiTexture.i b/port/swig/interface/aiTexture.i deleted file mode 100644 index d07d00190..000000000 --- a/port/swig/interface/aiTexture.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiTexture.h" -%} - -%include "aiTexture.h" diff --git a/port/swig/interface/aiTypes.i b/port/swig/interface/aiTypes.i deleted file mode 100644 index a086dfd30..000000000 --- a/port/swig/interface/aiTypes.i +++ /dev/null @@ -1,8 +0,0 @@ -%{ -#include "aiTypes.h" -%} - -// The const char* overload is used instead. -%ignore aiString::Set(const std::string& pString); - -%include "aiTypes.h" diff --git a/port/swig/interface/aiVector2D.i b/port/swig/interface/aiVector2D.i deleted file mode 100644 index 5db15c0e6..000000000 --- a/port/swig/interface/aiVector2D.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiVector2D.h" -%} - -%include "aiVector2D.h" diff --git a/port/swig/interface/aiVector3D.i b/port/swig/interface/aiVector3D.i deleted file mode 100644 index 2c83f605f..000000000 --- a/port/swig/interface/aiVector3D.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiVector3D.h" -%} - -%include "aiVector3D.h" diff --git a/port/swig/interface/aiVersion.i b/port/swig/interface/aiVersion.i deleted file mode 100644 index 9ddd532ef..000000000 --- a/port/swig/interface/aiVersion.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "aiVersion.h" -%} - -%include "aiVersion.h" diff --git a/port/swig/interface/assimp.i b/port/swig/interface/assimp.i deleted file mode 100644 index a1b1404a0..000000000 --- a/port/swig/interface/assimp.i +++ /dev/null @@ -1,45 +0,0 @@ -%{ -#include "assimp.hpp" -%} - - -namespace Assimp { - -// See docs in assimp.hpp. -%ignore Importer::ReadFile(const std::string& pFile, unsigned int pFlags); -%ignore Importer::GetExtensionList(std::string& szOut); -%ignore Importer::IsExtensionSupported(const std::string& szExtension); - -// These are only necessary for extending Assimp with custom importers or post -// processing steps, which would require wrapping the internal BaseImporter and -// BaseProcess classes. -%ignore Importer::RegisterLoader(BaseImporter* pImp); -%ignore Importer::UnregisterLoader(BaseImporter* pImp); -%ignore Importer::RegisterPPStep(BaseProcess* pImp); -%ignore Importer::UnregisterPPStep(BaseProcess* pImp); -%ignore Importer::FindLoader(const char* szExtension); - -} - - -// Each aiScene has to keep a reference to the Importer to prevent it from -// being garbage collected, whose destructor would release the underlying -// C++ memory the scene is stored in. -%typemap(dcode) aiScene "package Object m_importer;" -%typemap(dout) - aiScene* GetScene, - aiScene* ReadFile, - aiScene* ApplyPostProcessing, - aiScene* ReadFileFromMemory { - void* cPtr = $wcall; - $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode - ret.m_importer = this; - return ret; -} - -%include -%apply bool *OUTPUT { bool *bWasExisting }; - -%include "assimp.hpp" - -%clear bool *bWasExisting; From dd40b0ccee0a21b864b2039f0f1294a4e652fef2 Mon Sep 17 00:00:00 2001 From: sfjohnston Date: Sun, 23 Jul 2023 12:05:01 -0700 Subject: [PATCH 16/29] Changed #define FBX_FOV_UNKNOWN to const float kFovUnknown --- code/AssetLib/FBX/FBXConverter.cpp | 2 +- code/AssetLib/FBX/FBXDocument.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index cca5da596..032089906 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -438,7 +438,7 @@ void FBXConverter::ConvertCamera(const Camera &cam, const std::string &orig_name float fov_deg = cam.FieldOfView(); // If FOV not specified in file, compute using FilmWidth and FocalLength. - if (fov_deg == FBX_FOV_UNKNOWN) { + if (fov_deg == kFovUnknown) { float film_width_inches = cam.FilmWidth(); float focal_length_mm = cam.FocalLength(); ASSIMP_LOG_VERBOSE_DEBUG("FBX FOV unspecified. Computing from FilmWidth (", film_width_inches, "inches) and FocalLength (", focal_length_mm, "mm)."); diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index 503c94833..3af757a19 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -55,12 +55,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define _AI_CONCAT(a,b) a ## b #define AI_CONCAT(a,b) _AI_CONCAT(a,b) -/* Use an 'illegal' default FOV value to detect if the FBX camera has set the FOV. */ -#define FBX_FOV_UNKNOWN -1.0f namespace Assimp { namespace FBX { +// Use an 'illegal' default FOV value to detect if the FBX camera has set the FOV. +static const float kFovUnknown = -1.0f; + class Parser; class Object; @@ -251,7 +252,7 @@ public: fbx_simple_property(FilmAspectRatio, float, 1.0f) fbx_simple_property(ApertureMode, int, 0) - fbx_simple_property(FieldOfView, float, FBX_FOV_UNKNOWN) + fbx_simple_property(FieldOfView, float, kFovUnknown) fbx_simple_property(FocalLength, float, 1.0f) }; From d7dc88e0d04726d0e0e053832cae8c506fa02df5 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Aug 2023 13:04:16 +0000 Subject: [PATCH 17/29] Fix UNKNOWN READ in Assimp::MDLImporter::InternReadFile_Quake1 --- code/AssetLib/MDL/MDLLoader.cpp | 10 ++++++++-- code/AssetLib/MDL/MDLLoader.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 098b53e76..9efbc821c 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -271,10 +271,16 @@ void MDLImporter::InternReadFile(const std::string &pFile, } } +// ------------------------------------------------------------------------------------------------ +// Check whether we're still inside the valid file range +bool MDLImporter::IsPosValid(const void *szPos) { + return szPos && (const unsigned char *)szPos <= this->mBuffer + this->iFileSize && szPos >= this->mBuffer; +} + // ------------------------------------------------------------------------------------------------ // Check whether we're still inside the valid file range void MDLImporter::SizeCheck(const void *szPos) { - if (!szPos || (const unsigned char *)szPos > this->mBuffer + this->iFileSize || szPos < this->mBuffer) { + if (!IsPosValid(szPos)) { throw DeadlyImportError("Invalid MDL file. The file is too small " "or contains invalid data."); } @@ -284,7 +290,7 @@ void MDLImporter::SizeCheck(const void *szPos) { // Just for debugging purposes void MDLImporter::SizeCheck(const void *szPos, const char *szFile, unsigned int iLine) { ai_assert(nullptr != szFile); - if (!szPos || (const unsigned char *)szPos > mBuffer + iFileSize) { + if (!IsPosValid(szPos)) { // remove a directory if there is one const char *szFilePtr = ::strrchr(szFile, '\\'); if (!szFilePtr) { diff --git a/code/AssetLib/MDL/MDLLoader.h b/code/AssetLib/MDL/MDLLoader.h index 433100938..de690b1e7 100644 --- a/code/AssetLib/MDL/MDLLoader.h +++ b/code/AssetLib/MDL/MDLLoader.h @@ -150,6 +150,7 @@ protected: */ void SizeCheck(const void* szPos); void SizeCheck(const void* szPos, const char* szFile, unsigned int iLine); + bool IsPosValid(const void* szPos); // ------------------------------------------------------------------- /** Validate the header data structure of a game studio MDL7 file From f7e7f82b9dbb63369c8d22261cbd291e57c8bb4f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 3 Aug 2023 17:10:17 +0000 Subject: [PATCH 18/29] Add const --- code/AssetLib/MDL/MDLLoader.cpp | 2 +- code/AssetLib/MDL/MDLLoader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 9efbc821c..7b2ec7115 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -273,7 +273,7 @@ void MDLImporter::InternReadFile(const std::string &pFile, // ------------------------------------------------------------------------------------------------ // Check whether we're still inside the valid file range -bool MDLImporter::IsPosValid(const void *szPos) { +bool MDLImporter::IsPosValid(const void *szPos) const { return szPos && (const unsigned char *)szPos <= this->mBuffer + this->iFileSize && szPos >= this->mBuffer; } diff --git a/code/AssetLib/MDL/MDLLoader.h b/code/AssetLib/MDL/MDLLoader.h index de690b1e7..44ff21e3e 100644 --- a/code/AssetLib/MDL/MDLLoader.h +++ b/code/AssetLib/MDL/MDLLoader.h @@ -150,7 +150,7 @@ protected: */ void SizeCheck(const void* szPos); void SizeCheck(const void* szPos, const char* szFile, unsigned int iLine); - bool IsPosValid(const void* szPos); + bool IsPosValid(const void* szPos) const; // ------------------------------------------------------------------- /** Validate the header data structure of a game studio MDL7 file From 8312b31d2798d16574943259b9ae4522af80b4c6 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Sat, 5 Aug 2023 15:39:47 +0200 Subject: [PATCH 19/29] fix warning-as-error --- code/AssetLib/FBX/FBXConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 032089906..6c7cb67c8 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -443,7 +443,7 @@ void FBXConverter::ConvertCamera(const Camera &cam, const std::string &orig_name float focal_length_mm = cam.FocalLength(); ASSIMP_LOG_VERBOSE_DEBUG("FBX FOV unspecified. Computing from FilmWidth (", film_width_inches, "inches) and FocalLength (", focal_length_mm, "mm)."); double half_fov_rad = std::atan2(film_width_inches * 25.4 * 0.5, focal_length_mm); - out_camera->mHorizontalFOV = half_fov_rad; + out_camera->mHorizontalFOV = static_cast(half_fov_rad); } else { // FBX fov is full-view degrees. We want half-view radians. out_camera->mHorizontalFOV = AI_DEG_TO_RAD(fov_deg) * 0.5; From 49ed0711d160f2b455463709b1cf9cddeb1446fb Mon Sep 17 00:00:00 2001 From: Gargaj Date: Sat, 5 Aug 2023 15:43:31 +0200 Subject: [PATCH 20/29] Fix another warning --- code/AssetLib/FBX/FBXConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 6c7cb67c8..498da43ca 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -446,7 +446,7 @@ void FBXConverter::ConvertCamera(const Camera &cam, const std::string &orig_name out_camera->mHorizontalFOV = static_cast(half_fov_rad); } else { // FBX fov is full-view degrees. We want half-view radians. - out_camera->mHorizontalFOV = AI_DEG_TO_RAD(fov_deg) * 0.5; + out_camera->mHorizontalFOV = AI_DEG_TO_RAD(fov_deg) * 0.5f; } out_camera->mClipPlaneNear = cam.NearPlane(); From b9460dd9591583fa287cf031bf57629bffb20a84 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 8 Aug 2023 16:01:00 +0000 Subject: [PATCH 21/29] Fix UNKNOWN READ in std::__1::basic_string, std::__1::allocator #include #include +#include using namespace Assimp; @@ -160,6 +161,9 @@ void NDOImporter::InternReadFile( const std::string& pFile, temp = file_format >= 12 ? reader.GetU4() : reader.GetU2(); head = (const char*)reader.GetPtr(); + if (std::numeric_limits::max() - 76 < temp) { + throw DeadlyImportError("Invalid name length"); + } reader.IncPtr(temp + 76); /* skip unknown stuff */ obj.name = std::string(head, temp); From 2baadf2fe53718079ba86dc2b6510716a51b809e Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 8 Aug 2023 18:34:13 +0200 Subject: [PATCH 22/29] Be more precise regarding index buffer --- include/assimp/postprocess.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/assimp/postprocess.h b/include/assimp/postprocess.h index cdcbf0577..d69c2924e 100644 --- a/include/assimp/postprocess.h +++ b/include/assimp/postprocess.h @@ -94,6 +94,7 @@ enum aiPostProcessSteps * indexed geometry, this step is compulsory or you'll just waste rendering * time. If this flag is not specified, no vertices are referenced by * more than one face and no index buffer is required for rendering. + * Unless #aiProcess_Triangulate is specified. Then you need one regardless. */ aiProcess_JoinIdenticalVertices = 0x2, From 20a2cc4c94e4acd29a417f76c516c211b20477d8 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Wed, 9 Aug 2023 02:05:44 +0200 Subject: [PATCH 23/29] it is the importer, not the postproc --- include/assimp/postprocess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/postprocess.h b/include/assimp/postprocess.h index d69c2924e..a905a8be0 100644 --- a/include/assimp/postprocess.h +++ b/include/assimp/postprocess.h @@ -94,7 +94,7 @@ enum aiPostProcessSteps * indexed geometry, this step is compulsory or you'll just waste rendering * time. If this flag is not specified, no vertices are referenced by * more than one face and no index buffer is required for rendering. - * Unless #aiProcess_Triangulate is specified. Then you need one regardless. + * Unless the importer (like ply) had to split vertices. Then you need one regardless. */ aiProcess_JoinIdenticalVertices = 0x2, From 5c45cdc0adb50e3b169cada0ea5ce0126d04184a Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Aug 2023 07:45:23 +0000 Subject: [PATCH 24/29] Fix Invalid-free in Assimp::FBX::Scope::Scope --- code/AssetLib/FBX/FBXParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index c7b579665..955e811cb 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -211,7 +211,7 @@ Scope::Scope(Parser& parser,bool topLevel) elements.insert(ElementMap::value_type(str, element)); return; } - delete element; + delete_Element(element); ParseError("unexpected end of file",parser.LastToken()); } else { elements.insert(ElementMap::value_type(str, element)); From bc7ef58b4947a01f4f7163b47b96ca273473d7eb Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Aug 2023 12:00:22 +0000 Subject: [PATCH 25/29] bump openddl-parser to v0.5.1 --- contrib/openddlparser/CMakeLists.txt | 9 ++- contrib/openddlparser/README.md | 27 +++++--- contrib/openddlparser/code/OpenDDLExport.cpp | 5 +- contrib/openddlparser/code/OpenDDLParser.cpp | 67 ++++++++++++------- .../include/openddlparser/OpenDDLCommon.h | 31 +++++---- .../include/openddlparser/OpenDDLParser.h | 9 --- .../openddlparser/OpenDDLParserUtils.h | 10 ++- 7 files changed, 93 insertions(+), 65 deletions(-) diff --git a/contrib/openddlparser/CMakeLists.txt b/contrib/openddlparser/CMakeLists.txt index 51f18077c..28f3d5986 100644 --- a/contrib/openddlparser/CMakeLists.txt +++ b/contrib/openddlparser/CMakeLists.txt @@ -15,9 +15,11 @@ option( DDL_STATIC_LIBRARY "Deprecated, use BUILD_SHARED_LIBS instead." # for backwards compatibility use DDL_STATIC_LIBRARY as initial value for cmake variable BUILD_SHARED_LIBS # https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html if ( DDL_STATIC_LIBRARY ) - set ( build_shared_libs_default OFF ) + message("Building shared lib.") + set ( build_shared_libs_default OFF ) else() - set ( build_shared_libs_default ON ) + message("Building static lib.") + set ( build_shared_libs_default ON ) endif() option( DDL_BUILD_SHARED_LIBS "Set to ON to build shared libary of OpenDDL Parser." ${build_shared_libs_default} ) option( COVERALLS "Generate coveralls data" OFF ) @@ -36,6 +38,7 @@ endif() add_definitions( -D_VARIADIC_MAX=10 ) add_definitions( -DGTEST_HAS_PTHREAD=0 ) if ( DDL_DEBUG_OUTPUT ) + message("Enable debug output.") add_definitions( -DDDL_DEBUG_HEADER_NAME) endif() @@ -62,10 +65,12 @@ if (COVERALLS) include(Coveralls) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") + message("Enable coveralls.") endif() # Include the doc component. if(DDL_DOCUMENTATION) + message("Generate doxygen documentation.") find_package(Doxygen REQUIRED) CONFIGURE_FILE( doc/openddlparser_doc.in doc/doxygenfile @ONLY ) add_custom_target(doc ALL diff --git a/contrib/openddlparser/README.md b/contrib/openddlparser/README.md index a48ea1be0..78db2a310 100644 --- a/contrib/openddlparser/README.md +++ b/contrib/openddlparser/README.md @@ -5,13 +5,15 @@ The OpenDDL-Parser is a small and easy to use library for OpenDDL-file-format-pa Build status ============ -Linux build status: [![Build Status](https://travis-ci.org/kimkulling/openddl-parser.png)](https://travis-ci.org/kimkulling/openddl-parser) + +Linux build status: [![Build Status](https://travis-ci.com/kimkulling/openddl-parser.svg?branch=master)](https://travis-ci.com/kimkulling/openddl-parser) Current coverity check status: Coverity Scan Build Status Current test coverage:[![Coverage Status](https://coveralls.io/repos/github/kimkulling/openddl-parser/badge.svg?branch=master)](https://coveralls.io/github/kimkulling/openddl-parser?branch=cpp_coveralls) + Get the source code =================== You can get the code from our git repository, which is located at GitHub. You can clone the repository with the following command: @@ -57,11 +59,11 @@ USE_ODDLPARSER_NS; int main( int argc, char *argv[] ) { if( argc < 3 ) { - return 1; + return Error; } char *filename( nullptr ); - if( 0 == strncmp( FileOption, argv[ 1 ], strlen( FileOption ) ) ) { + if( 0 == strncmp( FileOption, argv[1], strlen( FileOption ) ) ) { filename = argv[ 2 ]; } std::cout << "file to import: " << filename << std::endl; @@ -73,24 +75,27 @@ int main( int argc, char *argv[] ) { FILE *fileStream = fopen( filename, "r+" ); if( NULL == filename ) { std::cerr << "Cannot open file " << filename << std::endl; - return 1; + return Error; } // obtain file size: fseek( fileStream, 0, SEEK_END ); - const size_t size( ftell( fileStream ) ); + const size_t size = ftell( fileStream ); rewind( fileStream ); if( size > 0 ) { char *buffer = new char[ size ]; - const size_t readSize( fread( buffer, sizeof( char ), size, fileStream ) ); + const size_t readSize = fread( buffer, sizeof( char ), size, fileStream ); assert( readSize == size ); + + // Set the memory buffer OpenDDLParser theParser; theParser.setBuffer( buffer, size ); - const bool result( theParser.parse() ); - if( !result ) { + if( !theParser.parse() ) { std::cerr << "Error while parsing file " << filename << "." << std::endl; + return Error; } } + return 0; } @@ -106,9 +111,9 @@ theParser.setBuffer( buffer, size ); const bool result( theParser.parse() ); if ( result ) { DDLNode *root = theParser.getRoot(); - DDLNode::DllNodeList childs = root->getChildNodeList(); - for ( size_t i=0; igetChildNodeList(); + for ( size_t i=0; igetProperty(); // to get properties std::string type = child->getType(); // to get the node type Value *values = child->getValue(); // to get the data; diff --git a/contrib/openddlparser/code/OpenDDLExport.cpp b/contrib/openddlparser/code/OpenDDLExport.cpp index 8768ca64f..f8d33c48d 100644 --- a/contrib/openddlparser/code/OpenDDLExport.cpp +++ b/contrib/openddlparser/code/OpenDDLExport.cpp @@ -134,9 +134,10 @@ bool OpenDDLExport::writeToStream(const std::string &statement) { } bool OpenDDLExport::writeNode(DDLNode *node, std::string &statement) { + bool success(true); writeNodeHeader(node, statement); if (node->hasProperties()) { - writeProperties(node, statement); + success = writeProperties(node, statement); } writeLineEnd(statement); @@ -160,7 +161,7 @@ bool OpenDDLExport::writeNode(DDLNode *node, std::string &statement) { writeToStream(statement); - return true; + return success; } bool OpenDDLExport::writeNodeHeader(DDLNode *node, std::string &statement) { diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index fe9d23ab5..cdccd073b 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -30,7 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #ifdef _WIN32 -#include +# define WIN32_LEAN_AND_MEAN +# include #endif // _WIN32 BEGIN_ODDLPARSER_NS @@ -71,7 +72,7 @@ const char *getTypeToken(Value::ValueType type) { return Grammar::PrimitiveTypeToken[(size_t)type]; } -static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) { +static void logInvalidTokenError(const char *in, const std::string &exp, OpenDDLParser::logCallback callback) { if (callback) { std::string full(in); std::string part(full.substr(0, 50)); @@ -338,20 +339,25 @@ char *OpenDDLParser::parseStructure(char *in, char *end) { bool error(false); in = lookForNextToken(in, end); - if (*in == *Grammar::OpenBracketToken) { - // loop over all children ( data and nodes ) - do { - in = parseStructureBody(in, end, error); - if (in == nullptr) { - return nullptr; + if (in != end) { + if (*in == *Grammar::OpenBracketToken) { + // loop over all children ( data and nodes ) + do { + in = parseStructureBody(in, end, error); + if (in == nullptr) { + return nullptr; + } + } while (in != end && + *in != *Grammar::CloseBracketToken); + if (in != end) { + ++in; } - } while (*in != *Grammar::CloseBracketToken); - ++in; - } else { - ++in; - logInvalidTokenError(in, std::string(Grammar::OpenBracketToken), m_logCallback); - error = true; - return nullptr; + } else { + ++in; + logInvalidTokenError(in, std::string(Grammar::OpenBracketToken), m_logCallback); + error = true; + return nullptr; + } } in = lookForNextToken(in, end); @@ -418,8 +424,8 @@ char *OpenDDLParser::parseStructureBody(char *in, char *end, bool &error) { } in = lookForNextToken(in, end); - if (*in != '}') { - logInvalidTokenError(in, std::string(Grammar::CloseBracketToken), m_logCallback); + if (in == end || *in != '}') { + logInvalidTokenError(in == end ? "" : in, std::string(Grammar::CloseBracketToken), m_logCallback); return nullptr; } else { //in++; @@ -455,7 +461,7 @@ DDLNode *OpenDDLParser::top() { return nullptr; } - DDLNode *top(m_stack.back()); + DDLNode *top = m_stack.back(); return top; } @@ -647,12 +653,15 @@ char *OpenDDLParser::parseBooleanLiteral(char *in, char *end, Value **boolean) { in = lookForNextToken(in, end); char *start(in); + + size_t len(0); while (!isSeparator(*in) && in != end) { ++in; + ++len; } - int res = ::strncmp(Grammar::BoolTrue, start, strlen(Grammar::BoolTrue)); + int res = ::strncmp(Grammar::BoolTrue, start, len); if (0 != res) { - res = ::strncmp(Grammar::BoolFalse, start, strlen(Grammar::BoolFalse)); + res = ::strncmp(Grammar::BoolFalse, start, len); if (0 != res) { *boolean = nullptr; return in; @@ -733,7 +742,7 @@ char *OpenDDLParser::parseFloatingLiteral(char *in, char *end, Value **floating, in = lookForNextToken(in, end); char *start(in); - while (!isSeparator(*in) && in != end) { + while (in != end && !isSeparator(*in)) { ++in; } @@ -838,6 +847,13 @@ char *OpenDDLParser::parseHexaLiteral(char *in, char *end, Value **data) { int value(0); while (pos > 0) { int v = hex2Decimal(*start); + if (v < 0) { + while (isEndofLine(*in)) { + ++in; + } + return in; + } + --pos; value = (value << 4) | v; ++start; @@ -901,10 +917,10 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V } in = lookForNextToken(in, end); - if (*in == '{') { + if (in != end && *in == '{') { ++in; Value *current(nullptr), *prev(nullptr); - while ('}' != *in) { + while (in != end && '}' != *in) { current = nullptr; in = lookForNextToken(in, end); if (Value::ValueType::ddl_ref == type) { @@ -962,11 +978,12 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V } in = getNextSeparator(in, end); - if (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in)) { + if (in == end || (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in))) { break; } } - ++in; + if (in != end) + ++in; } return in; diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index 6ccc83b88..85fadde00 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -26,25 +26,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -#include -#include +#include +#include #ifndef _WIN32 #include #endif -#if defined(_MSC_VER) && !defined(OPENDDL_STATIC_LIBARY) - -#define TAG_DLL_EXPORT __declspec(dllexport) -#define TAG_DLL_IMPORT __declspec(dllimport) -#ifdef OPENDDLPARSER_BUILD -#define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT +#ifdef OPENDDL_STATIC_LIBARY +# define DLL_ODDLPARSER_EXPORT #else -#define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT -#endif // OPENDDLPARSER_BUILD -#pragma warning(disable : 4251) -#else -#define DLL_ODDLPARSER_EXPORT -#endif // _WIN32 +# ifdef _WIN32 +# ifdef openddlparser_EXPORTS +# define DLL_ODDLPARSER_EXPORT __declspec(dllexport) +# else +# define DLL_ODDLPARSER_EXPORT __declspec(dllimport) +# endif // openddlparser_EXPORTS +# ifdef _MSC_VER +# pragma warning(disable : 4251) +# endif // _MSC_VER +# else +# define DLL_ODDLPARSER_EXPORT __attribute__((visibility("default"))) +# endif // _WIN32 +#endif // OPENDDL_STATIC_LIBARY // Namespace declarations, override this to avoid any conflicts #define BEGIN_ODDLPARSER_NS namespace ODDLParser { diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParser.h b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h index 3fbb4b6af..735e784e3 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParser.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h @@ -40,15 +40,6 @@ struct Identifier; struct Reference; struct Property; -template -inline bool isEmbeddedCommentOpenTag(T *in, T *end) { - if (in == '/' && in + 1 == '*') { - return true; - } - - return false; -} - /// @brief Utility function to search for the next token or the end of the buffer. /// @param in [in] The start position in the buffer. /// @param end [in] The end position in the buffer. diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h index 42ad675f8..62144a01c 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h @@ -54,7 +54,9 @@ inline bool isSeparator(T in) { return false; } -static const unsigned char chartype_table[256] = { +const size_t CharTableSize = 256; + +static const unsigned char chartype_table[CharTableSize] = { 0, 0, 0, @@ -318,6 +320,10 @@ static const unsigned char chartype_table[256] = { template inline bool isNumeric(const T in) { + if (static_cast(in) >= CharTableSize) { + return '\0'; + } + size_t idx = static_cast(in); return idx < sizeof(chartype_table) && (chartype_table[idx] == 1); } @@ -433,7 +439,7 @@ inline bool isEndofLine(const T in) { template inline static T *getNextSeparator(T *in, T *end) { - while (!isSeparator(*in) || in == end) { + while (in != end && !isSeparator(*in)) { ++in; } return in; From 7cbf4c4136bf9884fad408e6e388b10ba3ace635 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Aug 2023 12:35:44 +0000 Subject: [PATCH 26/29] Fix win build --- .../include/openddlparser/OpenDDLCommon.h | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index 85fadde00..4b92d1406 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -32,22 +32,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #endif -#ifdef OPENDDL_STATIC_LIBARY -# define DLL_ODDLPARSER_EXPORT +#if defined(_MSC_VER) && !defined(OPENDDL_STATIC_LIBARY) + +#define TAG_DLL_EXPORT __declspec(dllexport) +#define TAG_DLL_IMPORT __declspec(dllimport) +#ifdef OPENDDLPARSER_BUILD +#define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT #else -# ifdef _WIN32 -# ifdef openddlparser_EXPORTS -# define DLL_ODDLPARSER_EXPORT __declspec(dllexport) -# else -# define DLL_ODDLPARSER_EXPORT __declspec(dllimport) -# endif // openddlparser_EXPORTS -# ifdef _MSC_VER -# pragma warning(disable : 4251) -# endif // _MSC_VER -# else -# define DLL_ODDLPARSER_EXPORT __attribute__((visibility("default"))) -# endif // _WIN32 -#endif // OPENDDL_STATIC_LIBARY +#define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT +#endif // OPENDDLPARSER_BUILD +#pragma warning(disable : 4251) +#else +#define DLL_ODDLPARSER_EXPORT +#endif // _WIN32 // Namespace declarations, override this to avoid any conflicts #define BEGIN_ODDLPARSER_NS namespace ODDLParser { From 081cae6a950204ced52f5ca09b78fe7446286967 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Aug 2023 13:25:30 +0000 Subject: [PATCH 27/29] Fix WIN32_LEAN_AND_MEAN redefinition --- contrib/openddlparser/code/OpenDDLParser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index cdccd073b..3d7dce45e 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -30,7 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include #endif // _WIN32 From 4389c3d80ce687a243be49b640a83e19b350b0c4 Mon Sep 17 00:00:00 2001 From: tangxin Date: Wed, 23 Aug 2023 14:54:40 +0800 Subject: [PATCH 28/29] The texture strength attribute in aiMaterial set when importing and exporting gltf files is inconsistent --- code/AssetLib/glTF2/glTF2Importer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 86fd0ab7e..0fed11cef 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -234,7 +234,8 @@ inline void SetMaterialTextureProperty(std::vector &embeddedTexIdxs, Asset SetMaterialTextureProperty(embeddedTexIdxs, r, (glTF2::TextureInfo)prop, mat, texType, texSlot); if (prop.texture && prop.texture->source) { - mat->AddProperty(&prop.strength, 1, AI_MATKEY_GLTF_TEXTURE_STRENGTH(texType, texSlot)); + std::string textureStrengthKey = std::string(_AI_MATKEY_TEXTURE_BASE) + "." + "strength"; + mat->AddProperty(&prop.strength, 1, textureStrengthKey.c_str(), texType, texSlot); } } From e50233b2c1e0eccaad8ace908c66dc7425d5d500 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 23 Aug 2023 17:19:01 +0100 Subject: [PATCH 29/29] Use correct PDB paths The previously-specified paths were only correct for a static library build. I therefore fenced off that code to be specific to static library builds. For shared library builds, I added a generator-expression-based alternative. Annoyingly, this won't work with static library builds, so we don't get the concise, reliable version in all circumstances. I've avoided modifying any of the paths anything ends up at to avoid breaking changes. Resolves https://github.com/assimp/assimp/issues/4269 --- code/CMakeLists.txt | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index f7aa847bc..08a79ef19 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1418,25 +1418,29 @@ if(MSVC AND ASSIMP_INSTALL_PDB) COMPILE_PDB_NAME assimp${LIBRARY_SUFFIX} COMPILE_PDB_NAME_DEBUG assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX} ) - ENDIF() - IF(CMAKE_GENERATOR MATCHES "^Visual Studio") - install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS Debug - ) - install(FILES ${Assimp_BINARY_DIR}/code/RelWithDebInfo/assimp${LIBRARY_SUFFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS RelWithDebInfo - ) + IF(GENERATOR_IS_MULTI_CONFIG) + install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS Debug + ) + install(FILES ${Assimp_BINARY_DIR}/code/RelWithDebInfo/assimp${LIBRARY_SUFFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS RelWithDebInfo + ) + ELSE() + install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS Debug + ) + install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS RelWithDebInfo + ) + ENDIF() ELSE() - install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + install(FILES $ DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS Debug - ) - install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS RelWithDebInfo ) ENDIF() ENDIF ()