From 10059e64318f0c5bac24c55ed230b1e859693fd9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:21:35 +0200 Subject: [PATCH 1/6] Add handling for negative indices. --- code/AssetLib/DXF/DXFLoader.cpp | 49 ++++++++++++++------------------- code/AssetLib/DXF/DXFLoader.h | 4 +-- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index 1fb9490cc..a458d0fd8 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -71,7 +71,7 @@ static const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f)); // color indices for DXF - 16 are supported, the table is // taken directly from the DXF spec. static aiColor4D g_aclrDxfIndexColors[] = { - aiColor4D (0.6f, 0.6f, 0.6f, 1.0f), + aiColor4D(0.6f, 0.6f, 0.6f, 1.0f), aiColor4D (1.0f, 0.0f, 0.0f, 1.0f), // red aiColor4D (0.0f, 1.0f, 0.0f, 1.0f), // green aiColor4D (0.0f, 0.0f, 1.0f, 1.0f), // blue @@ -88,6 +88,7 @@ static aiColor4D g_aclrDxfIndexColors[] = { aiColor4D (1.0f, 1.0f, 1.0f, 1.0f), // white aiColor4D (0.6f, 0.0f, 1.0f, 1.0f) // violet }; + #define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0])) #define AI_DXF_ENTITIES_MAGIC_BLOCK "$ASSIMP_ENTITIES_MAGIC" @@ -109,14 +110,6 @@ static const aiImporterDesc desc = { "dxf" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -DXFImporter::DXFImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -DXFImporter::~DXFImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool DXFImporter::CanRead( const std::string& filename, IOSystem* pIOHandler, bool /*checkSig*/ ) const { @@ -229,7 +222,7 @@ void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output) { ASSIMP_LOG_VERBOSE_DEBUG("DXF: Unexpanded polycount is ", icount, ", vertex count is ", vcount); } - if (! output.blocks.size() ) { + if (output.blocks.empty()) { throw DeadlyImportError("DXF: no data blocks loaded"); } @@ -587,10 +580,10 @@ void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output) } } -#define DXF_POLYLINE_FLAG_CLOSED 0x1 -#define DXF_POLYLINE_FLAG_3D_POLYLINE 0x8 -#define DXF_POLYLINE_FLAG_3D_POLYMESH 0x10 -#define DXF_POLYLINE_FLAG_POLYFACEMESH 0x40 +static constexpr unsigned int DXF_POLYLINE_FLAG_CLOSED = 0x1; +static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYLINE = 0x8; +static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYMESH = 0x10; +static constexpr unsigned int DXF_POLYLINE_FLAG_POLYFACEMESH = 0x40; // ------------------------------------------------------------------------------------------------ void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output) { @@ -639,12 +632,6 @@ void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output) reader++; } - //if (!(line.flags & DXF_POLYLINE_FLAG_POLYFACEMESH)) { - // DefaultLogger::get()->warn((Formatter::format("DXF: polyline not currently supported: "),line.flags)); - // output.blocks.back().lines.pop_back(); - // return; - //} - if (vguess && line.positions.size() != vguess) { ASSIMP_LOG_WARN("DXF: unexpected vertex count in polymesh: ", line.positions.size(),", expected ", vguess ); @@ -734,12 +721,18 @@ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& li case 71: case 72: case 73: - case 74: - if (cnti == 4) { - ASSIMP_LOG_WARN("DXF: more than 4 indices per face not supported; ignoring"); - break; + case 74: { + if (cnti == 4) { + ASSIMP_LOG_WARN("DXF: more than 4 indices per face not supported; ignoring"); + break; + } + const int index = reader.ValueAsSignedInt(); + if (index >= 0) { + indices[cnti++] = static_cast(index); + } else { + ASSIMP_LOG_WARN("DXF: Skip invisible face."); + } } - indices[cnti++] = reader.ValueAsUnsignedInt(); break; // color @@ -777,8 +770,7 @@ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& li } // ------------------------------------------------------------------------------------------------ -void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output) -{ +void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output) { // (note) this is also used for for parsing line entities, so we // must handle the vertex_count == 2 case as well. @@ -795,8 +787,7 @@ void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output) if (reader.GroupCode() == 0) { break; } - switch (reader.GroupCode()) - { + switch (reader.GroupCode()) { // 8 specifies the layer case 8: diff --git a/code/AssetLib/DXF/DXFLoader.h b/code/AssetLib/DXF/DXFLoader.h index b32ae106f..89a0b79c2 100644 --- a/code/AssetLib/DXF/DXFLoader.h +++ b/code/AssetLib/DXF/DXFLoader.h @@ -68,8 +68,8 @@ namespace DXF { */ class DXFImporter : public BaseImporter { public: - DXFImporter(); - ~DXFImporter() override; + DXFImporter() = default; + ~DXFImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. From 7f0c388ad8b9ebf521f52b3ae1e491126c37bd37 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:27:32 +0200 Subject: [PATCH 2/6] Fix: Put unused var into comments to later use. --- code/AssetLib/DXF/DXFLoader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index a458d0fd8..94d071647 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -581,7 +581,8 @@ void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output) } static constexpr unsigned int DXF_POLYLINE_FLAG_CLOSED = 0x1; -static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYLINE = 0x8; +// Currently unused +//static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYLINE = 0x8; static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYMESH = 0x10; static constexpr unsigned int DXF_POLYLINE_FLAG_POLYFACEMESH = 0x40; From 9c9d72169ff9a65cf711eabaab79e08707167d7b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:34:14 +0200 Subject: [PATCH 3/6] Fix: Put unused var into comments to later use. --- contrib/zlib/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/zlib/CMakeLists.txt b/contrib/zlib/CMakeLists.txt index 5bc2d6065..e37efe07a 100644 --- a/contrib/zlib/CMakeLists.txt +++ b/contrib/zlib/CMakeLists.txt @@ -77,13 +77,13 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") + #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) else() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") + S#ET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") endif() endif() From 3d19cd9362f72bd866f38e7df31b935e7ad5dbfb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:35:50 +0200 Subject: [PATCH 4/6] Fix: Put unused var into comments to later use. --- contrib/zlib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/zlib/CMakeLists.txt b/contrib/zlib/CMakeLists.txt index e37efe07a..5fda54bdd 100644 --- a/contrib/zlib/CMakeLists.txt +++ b/contrib/zlib/CMakeLists.txt @@ -83,7 +83,7 @@ if(MSVC) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) else() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - S#ET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") + #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") endif() endif() From 6502b97d3e6c1ee7bcd836e70e7929da5d653b39 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:38:57 +0200 Subject: [PATCH 5/6] Fix: Put unused var into comments to later use. --- code/AssetLib/DXF/DXFLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index 94d071647..6b820d046 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -583,7 +583,7 @@ void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output) static constexpr unsigned int DXF_POLYLINE_FLAG_CLOSED = 0x1; // Currently unused //static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYLINE = 0x8; -static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYMESH = 0x10; +//static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYMESH = 0x10; static constexpr unsigned int DXF_POLYLINE_FLAG_POLYFACEMESH = 0x40; // ------------------------------------------------------------------------------------------------ From 63e1b071df002a1cf263be9e22ffc0f1f99280d3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Jun 2023 23:50:32 +0200 Subject: [PATCH 6/6] Remove deprecated switch to disable warning. --- contrib/zlib/CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/contrib/zlib/CMakeLists.txt b/contrib/zlib/CMakeLists.txt index 5fda54bdd..af8aa4f65 100644 --- a/contrib/zlib/CMakeLists.txt +++ b/contrib/zlib/CMakeLists.txt @@ -76,15 +76,7 @@ if(MSVC) set(CMAKE_DEBUG_POSTFIX "d") add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") - endif() - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -else() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # clang-cl - #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-non-prototype") - endif() endif() if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)