diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3859c04db..db152b813 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -54,7 +54,7 @@ jobs: - name: Cache DX SDK id: dxcache if: contains(matrix.name, 'windows') - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '${{ github.workspace }}/DX_SDK' key: ${{ runner.os }}-DX_SDK @@ -98,7 +98,7 @@ jobs: run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }} shell: bash - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: matrix.name == 'windows-msvc' with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index a84be8cbc..38f54ce06 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -19,7 +19,7 @@ jobs: dry-run: false language: c++ - name: Upload Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() && steps.build.outcome == 'success' with: name: artifacts diff --git a/CMakeLists.txt b/CMakeLists.txt index 88f69174a..05b722c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- -# Copyright (c) 2006-2023, assimp team +# Copyright (c) 2006-2024, assimp team # # All rights reserved. # @@ -38,9 +38,9 @@ SET(CMAKE_POLICY_DEFAULT_CMP0012 NEW) SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW) SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW) -CMAKE_MINIMUM_REQUIRED( VERSION 3.10 ) +CMAKE_MINIMUM_REQUIRED( VERSION 3.22 ) -# Disabled importers: m3d for 5.1 +# Disabled importers: m3d for 5.1 or later ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_IMPORTER) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_EXPORTER) # Toggles the use of the hunter package manager @@ -49,13 +49,13 @@ option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF) IF(ASSIMP_HUNTER_ENABLED) include("cmake-modules/HunterGate.cmake") HunterGate( - URL "https://github.com/cpp-pm/hunter/archive/v0.24.18.tar.gz" - SHA1 "1292e4d661e1770d6d6ca08c12c07cf34a0bf718" + URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz" + SHA1 "a20151e4c0740ee7d0f9994476856d813cdead29" ) add_definitions(-DASSIMP_USE_HUNTER) ENDIF() -PROJECT(Assimp VERSION 5.3.0) +PROJECT(Assimp VERSION 5.4.0) # All supported options ############################################### @@ -131,18 +131,18 @@ OPTION ( ASSIMP_IGNORE_GIT_HASH IF (WIN32) OPTION( ASSIMP_BUILD_ZLIB - "Build your own zlib" + "Build your zlib" ON ) ELSE() OPTION( ASSIMP_BUILD_ZLIB - "Build your own zlib" - ON + "Build your zlib" + OFF ) ENDIF() IF (WIN32) - # Use subset of Windows.h + # Use a subset of Windows.h ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN ) IF(MSVC) @@ -150,16 +150,16 @@ IF (WIN32) "Install MSVC debug files." ON ) IF(NOT (MSVC_VERSION LESS 1900)) - # Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) + # Multibyte character set has been deprecated since at least MSVC2015 (possibly earlier) ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ENDIF() - # Link statically against c/c++ lib to avoid missing redistriburable such as + # Link statically against c/c++ lib to avoid missing redistributable such as # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users # a choice to opt for the shared runtime if they want. option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) - # The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative + # The CMAKE_CXX_FLAGS vars can be overridden by some Visual Studio generators, so we use an alternative # global method here: if (${USE_STATIC_CRT}) add_compile_options( @@ -249,9 +249,9 @@ SET(ASSIMP_LIBRARY_SUFFIX "" CACHE STRING "Suffix to append to library names") IF( UNIX ) # Use GNUInstallDirs for Unix predefined directories INCLUDE(GNUInstallDirs) - # Ensure that we do not run into issues like http://www.tcm.phy.cam.ac.uk/sw/inodes64.html on 32 bit linux + # Ensure that we do not run into issues like http://www.tcm.phy.cam.ac.uk/sw/inodes64.html on 32 bit Linux IF(NOT ${OPERATING_SYSTEM} MATCHES "Android") - IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit linux + IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit Linux ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 ) ENDIF() ENDIF() @@ -289,7 +289,7 @@ ELSEIF(MSVC) IF(MSVC12) ADD_COMPILE_OPTIONS(/wd4351) ENDIF() - # supress warning for double to float conversion if Double precission is activated + # supress warning for double to float conversion if Double precision is activated ADD_COMPILE_OPTIONS(/wd4244) SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /Zi /Od") SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") @@ -311,9 +311,9 @@ ELSEIF( MINGW ) SET(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") ENDIF() IF (CMAKE_BUILD_TYPE STREQUAL "Debug") - SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -Wa,-mbig-obj -g ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wno-dangling-reference -Wall -Wno-long-long -Wa,-mbig-obj -g ${CMAKE_CXX_FLAGS}") ELSE() - SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -Wa,-mbig-obj -O3 ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wno-dangling-reference -Wall -Wno-long-long -Wa,-mbig-obj -O3 ${CMAKE_CXX_FLAGS}") ENDIF() SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}") ENDIF() @@ -452,18 +452,20 @@ configure_package_config_file( INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}" ) -install( - FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}" - DESTINATION "${CONFIG_INSTALL_DIR}" - COMPONENT ${LIBASSIMP-DEV_COMPONENT} -) +if(ASSIMP_INSTALL) + install( + FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}" + DESTINATION "${CONFIG_INSTALL_DIR}" + COMPONENT ${LIBASSIMP-DEV_COMPONENT} + ) -install( - EXPORT "${TARGETS_EXPORT_NAME}" - NAMESPACE "${NAMESPACE}" - DESTINATION "${CONFIG_INSTALL_DIR}" - COMPONENT ${LIBASSIMP-DEV_COMPONENT} -) + install( + EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${NAMESPACE}" + DESTINATION "${CONFIG_INSTALL_DIR}" + COMPONENT ${LIBASSIMP-DEV_COMPONENT} + ) +endif() IF( ASSIMP_BUILD_DOCS ) ADD_SUBDIRECTORY(doc) @@ -481,7 +483,7 @@ IF(ASSIMP_HUNTER_ENABLED) set(ASSIMP_BUILD_MINIZIP TRUE) ELSE() # If the zlib is already found outside, add an export in case assimpTargets can't find it. - IF( ZLIB_FOUND ) + IF( ZLIB_FOUND AND ASSIMP_INSTALL) INSTALL( TARGETS zlib zlibstatic EXPORT "${TARGETS_EXPORT_NAME}") ENDIF() @@ -563,9 +565,9 @@ SET ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER OFF CACHE BOOL ) IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) - IF ( MSVC ) - SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/includes") + SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/includes") + IF (WIN32) # pick the correct prebuilt library IF(MSVC143) SET(C4D_LIB_POSTFIX "_2022") @@ -583,7 +585,7 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) SET(C4D_LIB_POSTFIX "_2010") ELSE() MESSAGE( FATAL_ERROR - "C4D is currently only supported with MSVC 10, 11, 12, 14, 14.2, 14.3" + "C4D for Windows is currently only supported with MSVC 10, 11, 12, 14, 14.2, 14.3" ) ENDIF() @@ -601,15 +603,30 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) # winsock and winmm are necessary (and undocumented) dependencies of Cineware SDK because # it can be used to communicate with a running Cinema 4D instance SET(C4D_EXTRA_LIBRARIES WSock32.lib Winmm.lib) + ELSEIF (APPLE) + SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/libraries/osx") + + SET(C4D_DEBUG_LIBRARIES + "${C4D_LIB_BASE_PATH}/debug/libcinewarelib.a" + "${C4D_LIB_BASE_PATH}/debug/libjpeglib.a" + ) + SET(C4D_RELEASE_LIBRARIES + "${C4D_LIB_BASE_PATH}/release/libcinewarelib.a" + "${C4D_LIB_BASE_PATH}/release/libjpeglib.a" + ) ELSE () MESSAGE( FATAL_ERROR - "C4D is currently only available on Windows with Cineware SDK installed in contrib/Cineware" + "C4D is currently only available on Windows and macOS with Cineware SDK installed in contrib/Cineware" ) ENDIF () ELSE () ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER ) ENDIF () +if(ASSIMP_BUILD_DRACO_STATIC) + set(ASSIMP_BUILD_DRACO ON) +endif() + # Draco requires cmake 3.12 IF (DEFINED CMAKE_VERSION AND "${CMAKE_VERSION}" VERSION_LESS "3.12") message(NOTICE "draco requires cmake 3.12 or newer, cmake is ${CMAKE_VERSION} . Draco is disabled") @@ -645,22 +662,29 @@ ELSE() "-Wno-sign-compare" "-Wno-unused-local-typedefs" ) - # Draco 1.4.1 does not explicitly export any symbols under GCC/clang - list(APPEND DRACO_CXX_FLAGS - "-fvisibility=default" - ) + + if(NOT ASSIMP_BUILD_DRACO_STATIC) + # Draco 1.4.1 does not explicitly export any symbols under GCC/clang + list(APPEND DRACO_CXX_FLAGS + "-fvisibility=default" + ) + endif() ENDIF() # Don't build or install all of Draco by default ADD_SUBDIRECTORY( "contrib/draco" EXCLUDE_FROM_ALL ) + if(ASSIMP_BUILD_DRACO_STATIC) + set_property(DIRECTORY "contrib/draco" PROPERTY BUILD_SHARED_LIBS OFF) + endif() + if(MSVC OR WIN32) set(draco_LIBRARIES "draco") else() - if(BUILD_SHARED_LIBS) - set(draco_LIBRARIES "draco_shared") - else() + if(ASSIMP_BUILD_DRACO_STATIC) set(draco_LIBRARIES "draco_static") + else() + set(draco_LIBRARIES "draco_shared") endif() endif() @@ -683,15 +707,17 @@ ELSE() set(draco_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/draco/src") # This is probably wrong - INSTALL( TARGETS ${draco_LIBRARIES} - EXPORT "${TARGETS_EXPORT_NAME}" - LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} - FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - COMPONENT ${LIBASSIMP_COMPONENT} - INCLUDES DESTINATION include - ) + if (ASSIMP_INSTALL) + INSTALL( TARGETS ${draco_LIBRARIES} + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} + FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + COMPONENT ${LIBASSIMP_COMPONENT} + INCLUDES DESTINATION include + ) + endif() ENDIF() ENDIF() ENDIF() diff --git a/Dockerfile b/Dockerfile index 5da5458f8..eb5715d0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y ninja-build \ RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update WORKDIR /opt +RUN apt install zlib1g-dev # Build Assimp RUN git clone https://github.com/assimp/assimp.git /opt/assimp diff --git a/Readme.md b/Readme.md index a1f707a95..eae0cf00a 100644 --- a/Readme.md +++ b/Readme.md @@ -16,26 +16,27 @@ APIs are provided for C and C++. There are various bindings to other languages ( Additionally, assimp features various __mesh post-processing tools__: normals and tangent space generation, triangulation, vertex cache locality optimization, removal of degenerate primitives and duplicate vertices, sorting by primitive type, merging of redundant materials and many more. ### Documentation ### -Please check the latest documents at [Asset-Importer-Lib-Doc](https://assimp-docs.readthedocs.io/en/latest/). +Read [our latest documentation](https://assimp-docs.readthedocs.io/en/latest/). ### Pre-built binaries ### -Please check our [Itchi Projectspace](https://kimkulling.itch.io/the-asset-importer-lib) +Download binaries from [our Itchi Projectspace](https://kimkulling.itch.io/the-asset-importer-lib). -If you want to check our Model-Database, use the following repo: https://github.com/assimp/assimp-mdb +### Test data ### +Clone [our model database](https://github.com/assimp/assimp-mdb). ### Communities ### -- Ask a question at [The Assimp-Discussion Board](https://github.com/assimp/assimp/discussions) -- Ask on [Assimp-Community on Reddit](https://www.reddit.com/r/Assimp/) +- Ask questions at [the Assimp Discussion Board](https://github.com/assimp/assimp/discussions). +- Ask [the Assimp community on Reddit](https://www.reddit.com/r/Assimp/). - Ask on [StackOverflow with the assimp-tag](http://stackoverflow.com/questions/tagged/assimp?sort=newest). - Nothing has worked? File a question or an issue-report at [The Assimp-Issue Tracker](https://github.com/assimp/assimp/issues) And we also have a Gitter-channel:Gitter [![Join the chat at https://gitter.im/assimp/assimp](https://badges.gitter.im/assimp/assimp.svg)](https://gitter.im/assimp/assimp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
#### Supported file formats #### -You can find the complete list of supported file-formats [here](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md) +See [the complete list of supported formats](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md). ### Building ### -Take a look [here](https://github.com/assimp/assimp/blob/master/Build.md) to get started. We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do. +Start by reading [our build instructions](https://github.com/assimp/assimp/blob/master/Build.md). We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do. ### Ports ### * [Android](port/AndroidJNI/README.md) diff --git a/code/AssetLib/3DS/3DSConverter.cpp b/code/AssetLib/3DS/3DSConverter.cpp index 6d3f09cb7..7ae756668 100644 --- a/code/AssetLib/3DS/3DSConverter.cpp +++ b/code/AssetLib/3DS/3DSConverter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3DS/3DSExporter.cpp b/code/AssetLib/3DS/3DSExporter.cpp index 1b335a272..8477ed09f 100644 --- a/code/AssetLib/3DS/3DSExporter.cpp +++ b/code/AssetLib/3DS/3DSExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3DS/3DSExporter.h b/code/AssetLib/3DS/3DSExporter.h index 66e91e10d..9e3e42911 100644 --- a/code/AssetLib/3DS/3DSExporter.h +++ b/code/AssetLib/3DS/3DSExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 2279d105c..8f85f2e4d 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3DS/3DSLoader.cpp b/code/AssetLib/3DS/3DSLoader.cpp index a406ea1d2..3317017be 100644 --- a/code/AssetLib/3DS/3DSLoader.cpp +++ b/code/AssetLib/3DS/3DSLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3DS/3DSLoader.h b/code/AssetLib/3DS/3DSLoader.h index c579507e0..1d6953e29 100644 --- a/code/AssetLib/3DS/3DSLoader.h +++ b/code/AssetLib/3DS/3DSLoader.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3MF/3MFTypes.h b/code/AssetLib/3MF/3MFTypes.h index 8207b568b..57d2b281a 100644 --- a/code/AssetLib/3MF/3MFTypes.h +++ b/code/AssetLib/3MF/3MFTypes.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -57,6 +57,7 @@ enum class ResourceType { RT_BaseMaterials, RT_EmbeddedTexture2D, RT_Texture2DGroup, + RT_ColorGroup, RT_Unknown }; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...) @@ -117,6 +118,21 @@ public: } }; +class ColorGroup : public Resource { +public: + std::vector mColors; + ColorGroup(int id) : + Resource(id){ + // empty + } + + ~ColorGroup() override = default; + + ResourceType getType() const override { + return ResourceType::RT_ColorGroup; + } +}; + class BaseMaterials : public Resource { public: std::vector mMaterialIndex; diff --git a/code/AssetLib/3MF/3MFXmlTags.h b/code/AssetLib/3MF/3MFXmlTags.h index 333d169aa..aea66667b 100644 --- a/code/AssetLib/3MF/3MFXmlTags.h +++ b/code/AssetLib/3MF/3MFXmlTags.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -98,6 +98,11 @@ namespace XmlTag { const char *const texture_cuurd_u = "u"; const char *const texture_cuurd_v = "v"; + // vertex color definitions + const char *const colorgroup = "m:colorgroup"; + const char *const color_item = "m:color"; + const char *const color_vaule = "color"; + // Meta info tags const char* const CONTENT_TYPES_ARCHIVE = "[Content_Types].xml"; const char* const ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels"; diff --git a/code/AssetLib/3MF/D3MFExporter.cpp b/code/AssetLib/3MF/D3MFExporter.cpp index 4ba3bbf24..6caa4c84e 100644 --- a/code/AssetLib/3MF/D3MFExporter.cpp +++ b/code/AssetLib/3MF/D3MFExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3MF/D3MFExporter.h b/code/AssetLib/3MF/D3MFExporter.h index 680d54f91..6be0c32ca 100644 --- a/code/AssetLib/3MF/D3MFExporter.h +++ b/code/AssetLib/3MF/D3MFExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3MF/D3MFImporter.cpp b/code/AssetLib/3MF/D3MFImporter.cpp index e8529064c..987cdd492 100644 --- a/code/AssetLib/3MF/D3MFImporter.cpp +++ b/code/AssetLib/3MF/D3MFImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -81,12 +81,17 @@ static constexpr aiImporterDesc desc = { "3mf" }; -bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool /*checkSig*/) const { +bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool ) const { if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) { return false; } - D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename); - return opcPackage.validate(); + static const char *const ModelRef = "3D/3dmodel.model"; + ZipArchiveIOSystem archive(pIOHandler, filename); + if (!archive.Exists(ModelRef)) { + return false; + } + + return true; } void D3MFImporter::SetupProperties(const Importer*) { diff --git a/code/AssetLib/3MF/D3MFImporter.h b/code/AssetLib/3MF/D3MFImporter.h index 9ae68acb0..82a1546cd 100644 --- a/code/AssetLib/3MF/D3MFImporter.h +++ b/code/AssetLib/3MF/D3MFImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3MF/D3MFOpcPackage.cpp b/code/AssetLib/3MF/D3MFOpcPackage.cpp index e772d8b7e..be0615904 100644 --- a/code/AssetLib/3MF/D3MFOpcPackage.cpp +++ b/code/AssetLib/3MF/D3MFOpcPackage.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -119,9 +119,9 @@ public: static bool IsEmbeddedTexture( const std::string &filename ) { const std::string extension = BaseImporter::GetExtension(filename); - if (extension == "jpg" || extension == "png") { + if (extension == "jpg" || extension == "png" || extension == "jpeg") { std::string::size_type pos = filename.find("thumbnail"); - if (pos == std::string::npos) { + if (pos != std::string::npos) { return false; } return true; diff --git a/code/AssetLib/3MF/D3MFOpcPackage.h b/code/AssetLib/3MF/D3MFOpcPackage.h index f6803a0ef..9782752bf 100644 --- a/code/AssetLib/3MF/D3MFOpcPackage.h +++ b/code/AssetLib/3MF/D3MFOpcPackage.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/3MF/XmlSerializer.cpp b/code/AssetLib/3MF/XmlSerializer.cpp index 5fcdc0ccc..354ed19bb 100644 --- a/code/AssetLib/3MF/XmlSerializer.cpp +++ b/code/AssetLib/3MF/XmlSerializer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -75,7 +75,7 @@ aiFace ReadTriangle(XmlNode &node, int &texId0, int &texId1, int &texId2) { face.mIndices[1] = static_cast(std::atoi(node.attribute(XmlTag::v2).as_string())); face.mIndices[2] = static_cast(std::atoi(node.attribute(XmlTag::v3).as_string())); - texId0 = texId1 = texId2 = -1; + texId0 = texId1 = texId2 = IdNotSet; XmlParser::getIntAttribute(node, XmlTag::p1, texId0); XmlParser::getIntAttribute(node, XmlTag::p2, texId1); XmlParser::getIntAttribute(node, XmlTag::p3, texId2); @@ -236,6 +236,8 @@ void XmlSerializer::ImportXml(aiScene *scene) { ReadBaseMaterials(currentNode); } else if (currentNodeName == XmlTag::meta) { ReadMetadata(currentNode); + } else if (currentNodeName == XmlTag::colorgroup) { + ReadColorGroup(currentNode); } } StoreMaterialsInScene(scene); @@ -331,9 +333,49 @@ void XmlSerializer::ReadObject(XmlNode &node) { if (hasPid) { auto it = mResourcesDictionnary.find(pid); - if (hasPindex && it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_BaseMaterials) { - BaseMaterials *materials = static_cast(it->second); - mesh->mMaterialIndex = materials->mMaterialIndex[pindex]; + if (hasPindex && it != mResourcesDictionnary.end()) { + if (it->second->getType() == ResourceType::RT_BaseMaterials) { + BaseMaterials *materials = static_cast(it->second); + mesh->mMaterialIndex = materials->mMaterialIndex[pindex]; + } else if (it->second->getType() == ResourceType::RT_Texture2DGroup) { + Texture2DGroup *group = static_cast(it->second); + if (mesh->mTextureCoords[0] == nullptr) { + mesh->mNumUVComponents[0] = 2; + for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { + mesh->mNumUVComponents[i] = 0; + } + + const std::string name = ai_to_string(group->mTexId); + for (size_t i = 0; i < mMaterials.size(); ++i) { + if (name == mMaterials[i]->GetName().C_Str()) { + mesh->mMaterialIndex = static_cast(i); + } + } + + mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices]; + for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { + mesh->mTextureCoords[0][vertex_idx] = + aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f); + } + } else { + for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { + if (mesh->mTextureCoords[0][vertex_idx].z < 0) { + // use default + mesh->mTextureCoords[0][vertex_idx] = + aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f); + } + } + } + }else if (it->second->getType() == ResourceType::RT_ColorGroup) { + if (mesh->mColors[0] == nullptr) { + mesh->mColors[0] = new aiColor4D[mesh->mNumVertices]; + + ColorGroup *group = static_cast(it->second); + for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { + mesh->mColors[0][vertex_idx] = group->mColors[pindex]; + } + } + } } } @@ -415,27 +457,36 @@ void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) { for (XmlNode ¤tNode : node.children()) { const std::string currentName = currentNode.name(); if (currentName == XmlTag::triangle) { - int pid = IdNotSet, p1 = IdNotSet; + int pid = IdNotSet; bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid); - bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1); - int texId[3]; - Texture2DGroup *group = nullptr; - aiFace face = ReadTriangle(currentNode, texId[0], texId[1], texId[2]); - if (hasPid && hasP1) { + int pindex[3]; + aiFace face = ReadTriangle(currentNode, pindex[0], pindex[1], pindex[2]); + if (hasPid && (pindex[0] != IdNotSet || pindex[1] != IdNotSet || pindex[2] != IdNotSet)) { auto it = mResourcesDictionnary.find(pid); if (it != mResourcesDictionnary.end()) { if (it->second->getType() == ResourceType::RT_BaseMaterials) { BaseMaterials *baseMaterials = static_cast(it->second); - mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1]; + + auto update_material = [&](int idx) { + if (pindex[idx] != IdNotSet) { + mesh->mMaterialIndex = baseMaterials->mMaterialIndex[pindex[idx]]; + } + }; + + update_material(0); + update_material(1); + update_material(2); + } else if (it->second->getType() == ResourceType::RT_Texture2DGroup) { + // Load texture coordinates into mesh, when any + Texture2DGroup *group = static_cast(it->second); // fix bug if (mesh->mTextureCoords[0] == nullptr) { mesh->mNumUVComponents[0] = 2; for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { mesh->mNumUVComponents[i] = 0; } - group = static_cast(it->second); const std::string name = ai_to_string(group->mTexId); for (size_t i = 0; i < mMaterials.size(); ++i) { if (name == mMaterials[i]->GetName().C_Str()) { @@ -443,21 +494,44 @@ void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) { } } mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices]; + for (unsigned int vertex_index = 0; vertex_index < mesh->mNumVertices; vertex_index++) { + mesh->mTextureCoords[0][vertex_index].z = IdNotSet;//mark not set + } } + + auto update_texture = [&](int idx) { + if (pindex[idx] != IdNotSet) { + size_t vertex_index = face.mIndices[idx]; + mesh->mTextureCoords[0][vertex_index] = + aiVector3D(group->mTex2dCoords[pindex[idx]].x, group->mTex2dCoords[pindex[idx]].y, 0.0f); + } + }; + + update_texture(0); + update_texture(1); + update_texture(2); + + } else if (it->second->getType() == ResourceType::RT_ColorGroup) { + // Load vertex color into mesh, when any + ColorGroup *group = static_cast(it->second); + if (mesh->mColors[0] == nullptr) { + mesh->mColors[0] = new aiColor4D[mesh->mNumVertices]; + } + + auto update_color = [&](int idx) { + if (pindex[idx] != IdNotSet) { + size_t vertex_index = face.mIndices[idx]; + mesh->mColors[0][vertex_index] = group->mColors[pindex[idx]]; + } + }; + + update_color(0); + update_color(1); + update_color(2); } } } - // Load texture coordinates into mesh, when any - if (group != nullptr) { - size_t i0 = face.mIndices[0]; - size_t i1 = face.mIndices[1]; - size_t i2 = face.mIndices[2]; - mesh->mTextureCoords[0][i0] = aiVector3D(group->mTex2dCoords[texId[0]].x, group->mTex2dCoords[texId[0]].y, 0.0f); - mesh->mTextureCoords[0][i1] = aiVector3D(group->mTex2dCoords[texId[1]].x, group->mTex2dCoords[texId[1]].y, 0.0f); - mesh->mTextureCoords[0][i2] = aiVector3D(group->mTex2dCoords[texId[2]].x, group->mTex2dCoords[texId[2]].y, 0.0f); - } - faces.push_back(face); } } @@ -598,6 +672,38 @@ aiMaterial *XmlSerializer::readMaterialDef(XmlNode &node, unsigned int basemater return material; } +void XmlSerializer::ReadColor(XmlNode &node, ColorGroup *colorGroup) { + if (node.empty() || nullptr == colorGroup) { + return; + } + + for (XmlNode currentNode : node.children()) { + const std::string currentName = currentNode.name(); + if (currentName == XmlTag::color_item) { + const char *color = currentNode.attribute(XmlTag::color_vaule).as_string(); + aiColor4D color_value; + if (parseColor(color, color_value)) { + colorGroup->mColors.push_back(color_value); + } + } + } +} + +void XmlSerializer::ReadColorGroup(XmlNode &node) { + if (node.empty()) { + return; + } + + int id = IdNotSet; + if (!XmlParser::getIntAttribute(node, XmlTag::id, id)) { + return; + } + + ColorGroup *group = new ColorGroup(id); + ReadColor(node, group); + mResourcesDictionnary.insert(std::make_pair(id, group)); +} + void XmlSerializer::StoreMaterialsInScene(aiScene *scene) { if (nullptr == scene) { return; diff --git a/code/AssetLib/3MF/XmlSerializer.h b/code/AssetLib/3MF/XmlSerializer.h index 6cf6a70a9..d0700a631 100644 --- a/code/AssetLib/3MF/XmlSerializer.h +++ b/code/AssetLib/3MF/XmlSerializer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -57,6 +57,7 @@ class D3MFOpcPackage; class Object; class Texture2DGroup; class EmbeddedTexture; +class ColorGroup; class XmlSerializer { public: @@ -78,6 +79,8 @@ private: void ReadTextureGroup(XmlNode &node); aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId); void StoreMaterialsInScene(aiScene *scene); + void ReadColorGroup(XmlNode &node); + void ReadColor(XmlNode &node, ColorGroup *colorGroup); private: struct MetaEntry { diff --git a/code/AssetLib/AC/ACLoader.cpp b/code/AssetLib/AC/ACLoader.cpp index 1bb77c441..dbcb39b30 100644 --- a/code/AssetLib/AC/ACLoader.cpp +++ b/code/AssetLib/AC/ACLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -77,8 +77,8 @@ static constexpr aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // skip to the next token -inline const char *AcSkipToNextToken(const char *buffer) { - if (!SkipSpaces(&buffer)) { +inline const char *AcSkipToNextToken(const char *buffer, const char *end) { + if (!SkipSpaces(&buffer, end)) { ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL"); } return buffer; @@ -86,13 +86,13 @@ inline const char *AcSkipToNextToken(const char *buffer) { // ------------------------------------------------------------------------------------------------ // read a string (may be enclosed in double quotation marks). buffer must point to " -inline const char *AcGetString(const char *buffer, std::string &out) { +inline const char *AcGetString(const char *buffer, const char *end, std::string &out) { if (*buffer == '\0') { throw DeadlyImportError("AC3D: Unexpected EOF in string"); } ++buffer; const char *sz = buffer; - while ('\"' != *buffer) { + while ('\"' != *buffer && buffer != end) { if (IsLineEnd(*buffer)) { ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL in string"); out = "ERROR"; @@ -112,8 +112,8 @@ inline const char *AcGetString(const char *buffer, std::string &out) { // ------------------------------------------------------------------------------------------------ // read 1 to n floats prefixed with an optional predefined identifier template -inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name, size_t name_length, size_t num, T *out) { - buffer = AcSkipToNextToken(buffer); +inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *end, const char *name, size_t name_length, size_t num, T *out) { + buffer = AcSkipToNextToken(buffer, end); if (0 != name_length) { if (0 != strncmp(buffer, name, name_length) || !IsSpace(buffer[name_length])) { ASSIMP_LOG_ERROR("AC3D: Unexpected token. ", name, " was expected."); @@ -122,7 +122,7 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name buffer += name_length + 1; } for (unsigned int _i = 0; _i < num; ++_i) { - buffer = AcSkipToNextToken(buffer); + buffer = AcSkipToNextToken(buffer, end); buffer = fast_atoreal_move(buffer, ((float *)out)[_i]); } @@ -132,7 +132,7 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer AC3DImporter::AC3DImporter() : - buffer(), + mBuffer(), configSplitBFCull(), configEvalSubdivision(), mNumMeshes(), @@ -164,17 +164,17 @@ const aiImporterDesc *AC3DImporter::GetInfo() const { // ------------------------------------------------------------------------------------------------ // Get a pointer to the next line from the file bool AC3DImporter::GetNextLine() { - SkipLine(&buffer); - return SkipSpaces(&buffer); + SkipLine(&mBuffer.data, mBuffer.end); + return SkipSpaces(&mBuffer.data, mBuffer.end); } // ------------------------------------------------------------------------------------------------ // Parse an object section in an AC file -void AC3DImporter::LoadObjectSection(std::vector &objects) { - if (!TokenMatch(buffer, "OBJECT", 6)) - return; +bool AC3DImporter::LoadObjectSection(std::vector &objects) { + if (!TokenMatch(mBuffer.data, "OBJECT", 6)) + return false; - SkipSpaces(&buffer); + SkipSpaces(&mBuffer.data, mBuffer.end); ++mNumMeshes; @@ -182,7 +182,7 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { Object &obj = objects.back(); aiLight *light = nullptr; - if (!ASSIMP_strincmp(buffer, "light", 5)) { + if (!ASSIMP_strincmp(mBuffer.data, "light", 5)) { // This is a light source. Add it to the list mLights->push_back(light = new aiLight()); @@ -198,62 +198,66 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered"); obj.type = Object::Light; - } else if (!ASSIMP_strincmp(buffer, "group", 5)) { + } else if (!ASSIMP_strincmp(mBuffer.data, "group", 5)) { obj.type = Object::Group; - } else if (!ASSIMP_strincmp(buffer, "world", 5)) { + } else if (!ASSIMP_strincmp(mBuffer.data, "world", 5)) { obj.type = Object::World; } else obj.type = Object::Poly; while (GetNextLine()) { - if (TokenMatch(buffer, "kids", 4)) { - SkipSpaces(&buffer); - unsigned int num = strtoul10(buffer, &buffer); + if (TokenMatch(mBuffer.data, "kids", 4)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + unsigned int num = strtoul10(mBuffer.data, &mBuffer.data); GetNextLine(); if (num) { // load the children of this object recursively obj.children.reserve(num); - for (unsigned int i = 0; i < num; ++i) - LoadObjectSection(obj.children); + for (unsigned int i = 0; i < num; ++i) { + if (!LoadObjectSection(obj.children)) { + ASSIMP_LOG_WARN("AC3D: wrong number of kids"); + break; + } + } } - return; - } else if (TokenMatch(buffer, "name", 4)) { - SkipSpaces(&buffer); - buffer = AcGetString(buffer, obj.name); + return true; + } else if (TokenMatch(mBuffer.data, "name", 4)) { + SkipSpaces(&mBuffer.data, mBuffer.data); + mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, obj.name); // If this is a light source, we'll also need to store // the name of the node in it. if (light) { light->mName.Set(obj.name); } - } else if (TokenMatch(buffer, "texture", 7)) { - SkipSpaces(&buffer); + } else if (TokenMatch(mBuffer.data, "texture", 7)) { + SkipSpaces(&mBuffer.data, mBuffer.end); std::string texture; - buffer = AcGetString(buffer, texture); + mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, texture); obj.textures.push_back(texture); - } else if (TokenMatch(buffer, "texrep", 6)) { - SkipSpaces(&buffer); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &obj.texRepeat); + } else if (TokenMatch(mBuffer.data, "texrep", 6)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &obj.texRepeat); if (!obj.texRepeat.x || !obj.texRepeat.y) obj.texRepeat = aiVector2D(1.f, 1.f); - } else if (TokenMatch(buffer, "texoff", 6)) { - SkipSpaces(&buffer); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &obj.texOffset); - } else if (TokenMatch(buffer, "rot", 3)) { - SkipSpaces(&buffer); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 9, &obj.rotation); - } else if (TokenMatch(buffer, "loc", 3)) { - SkipSpaces(&buffer); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 3, &obj.translation); - } else if (TokenMatch(buffer, "subdiv", 6)) { - SkipSpaces(&buffer); - obj.subDiv = strtoul10(buffer, &buffer); - } else if (TokenMatch(buffer, "crease", 6)) { - SkipSpaces(&buffer); - obj.crease = fast_atof(buffer); - } else if (TokenMatch(buffer, "numvert", 7)) { - SkipSpaces(&buffer); + } else if (TokenMatch(mBuffer.data, "texoff", 6)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &obj.texOffset); + } else if (TokenMatch(mBuffer.data, "rot", 3)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 9, &obj.rotation); + } else if (TokenMatch(mBuffer.data, "loc", 3)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 3, &obj.translation); + } else if (TokenMatch(mBuffer.data, "subdiv", 6)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + obj.subDiv = strtoul10(mBuffer.data, &mBuffer.data); + } else if (TokenMatch(mBuffer.data, "crease", 6)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + obj.crease = fast_atof(mBuffer.data); + } else if (TokenMatch(mBuffer.data, "numvert", 7)) { + SkipSpaces(&mBuffer.data, mBuffer.end); - unsigned int t = strtoul10(buffer, &buffer); + unsigned int t = strtoul10(mBuffer.data, &mBuffer.data); if (t >= AI_MAX_ALLOC(aiVector3D)) { throw DeadlyImportError("AC3D: Too many vertices, would run out of memory"); } @@ -262,59 +266,59 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { if (!GetNextLine()) { ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: not all vertices have been parsed yet"); break; - } else if (!IsNumeric(*buffer)) { + } else if (!IsNumeric(*mBuffer.data)) { ASSIMP_LOG_ERROR("AC3D: Unexpected token: not all vertices have been parsed yet"); - --buffer; // make sure the line is processed a second time + --mBuffer.data; // make sure the line is processed a second time break; } obj.vertices.emplace_back(); aiVector3D &v = obj.vertices.back(); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 3, &v.x); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 3, &v.x); } - } else if (TokenMatch(buffer, "numsurf", 7)) { - SkipSpaces(&buffer); + } else if (TokenMatch(mBuffer.data, "numsurf", 7)) { + SkipSpaces(&mBuffer.data, mBuffer.end); bool Q3DWorkAround = false; - const unsigned int t = strtoul10(buffer, &buffer); + const unsigned int t = strtoul10(mBuffer.data, &mBuffer.data); obj.surfaces.reserve(t); for (unsigned int i = 0; i < t; ++i) { GetNextLine(); - if (!TokenMatch(buffer, "SURF", 4)) { + if (!TokenMatch(mBuffer.data, "SURF", 4)) { // FIX: this can occur for some files - Quick 3D for // example writes no surf chunks if (!Q3DWorkAround) { ASSIMP_LOG_WARN("AC3D: SURF token was expected"); ASSIMP_LOG_VERBOSE_DEBUG("Continuing with Quick3D Workaround enabled"); } - --buffer; // make sure the line is processed a second time + --mBuffer.data; // make sure the line is processed a second time // break; --- see fix notes above Q3DWorkAround = true; } - SkipSpaces(&buffer); + SkipSpaces(&mBuffer.data, mBuffer.end); obj.surfaces.emplace_back(); Surface &surf = obj.surfaces.back(); - surf.flags = strtoul_cppstyle(buffer); + surf.flags = strtoul_cppstyle(mBuffer.data); while (true) { if (!GetNextLine()) { throw DeadlyImportError("AC3D: Unexpected EOF: surface is incomplete"); } - if (TokenMatch(buffer, "mat", 3)) { - SkipSpaces(&buffer); - surf.mat = strtoul10(buffer); - } else if (TokenMatch(buffer, "refs", 4)) { + if (TokenMatch(mBuffer.data, "mat", 3)) { + SkipSpaces(&mBuffer.data, mBuffer.end); + surf.mat = strtoul10(mBuffer.data); + } else if (TokenMatch(mBuffer.data, "refs", 4)) { // --- see fix notes above if (Q3DWorkAround) { if (!surf.entries.empty()) { - buffer -= 6; + mBuffer.data -= 6; break; } } - SkipSpaces(&buffer); - const unsigned int m = strtoul10(buffer); + SkipSpaces(&mBuffer.data, mBuffer.end); + const unsigned int m = strtoul10(mBuffer.data); surf.entries.reserve(m); obj.numRefs += m; @@ -327,12 +331,12 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { surf.entries.emplace_back(); Surface::SurfaceEntry &entry = surf.entries.back(); - entry.first = strtoul10(buffer, &buffer); - SkipSpaces(&buffer); - buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &entry.second); + entry.first = strtoul10(mBuffer.data, &mBuffer.data); + SkipSpaces(&mBuffer.data, mBuffer.end); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &entry.second); } } else { - --buffer; // make sure the line is processed a second time + --mBuffer.data; // make sure the line is processed a second time break; } } @@ -340,6 +344,7 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { } } ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: \'kids\' line was expected"); + return false; } // ------------------------------------------------------------------------------------------------ @@ -445,7 +450,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, idx = 0; } if ((*it).entries.empty()) { - ASSIMP_LOG_WARN("AC3D: surface her zero vertex references"); + ASSIMP_LOG_WARN("AC3D: surface has zero vertex references"); } // validate all vertex indices to make sure we won't crash here @@ -463,16 +468,15 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, } switch ((*it).GetType()) { - // closed line - case Surface::ClosedLine: - needMat[idx].first += (unsigned int)(*it).entries.size(); - needMat[idx].second += (unsigned int)(*it).entries.size() << 1u; + case Surface::ClosedLine: // closed line + needMat[idx].first += static_cast((*it).entries.size()); + needMat[idx].second += static_cast((*it).entries.size() << 1u); break; // unclosed line case Surface::OpenLine: - needMat[idx].first += (unsigned int)(*it).entries.size() - 1; - needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; + needMat[idx].first += static_cast((*it).entries.size() - 1); + needMat[idx].second += static_cast(((*it).entries.size() - 1) << 1u); break; // triangle strip @@ -574,15 +578,6 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; const Surface::SurfaceEntry &entry3 = src.entries[i + 2]; - // skip degenerate triangles - if (object.vertices[entry1.first] == object.vertices[entry2.first] || - object.vertices[entry1.first] == object.vertices[entry3.first] || - object.vertices[entry2.first] == object.vertices[entry3.first]) { - mesh->mNumFaces--; - mesh->mNumVertices -= 3; - continue; - } - aiFace &face = *faces++; face.mNumIndices = 3; face.mIndices = new unsigned int[face.mNumIndices]; @@ -760,17 +755,18 @@ void AC3DImporter::InternReadFile(const std::string &pFile, std::vector mBuffer2; TextFileToBuffer(file.get(), mBuffer2); - buffer = &mBuffer2[0]; + mBuffer.data = &mBuffer2[0]; + mBuffer.end = &mBuffer2[0] + mBuffer2.size(); mNumMeshes = 0; mLightsCounter = mPolysCounter = mWorldsCounter = mGroupsCounter = 0; - if (::strncmp(buffer, "AC3D", 4)) { + if (::strncmp(mBuffer.data, "AC3D", 4)) { throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found"); } // print the file format version to the console - unsigned int version = HexDigitToDecimal(buffer[4]); + unsigned int version = HexDigitToDecimal(mBuffer.data[4]); char msg[3]; ASSIMP_itoa10(msg, 3, version); ASSIMP_LOG_INFO("AC3D file format version: ", msg); @@ -785,30 +781,31 @@ void AC3DImporter::InternReadFile(const std::string &pFile, mLights = &lights; while (GetNextLine()) { - if (TokenMatch(buffer, "MATERIAL", 8)) { + if (TokenMatch(mBuffer.data, "MATERIAL", 8)) { materials.emplace_back(); Material &mat = materials.back(); // manually parse the material ... sscanf would use the buldin atof ... // Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f - buffer = AcSkipToNextToken(buffer); - if ('\"' == *buffer) { - buffer = AcGetString(buffer, mat.name); - buffer = AcSkipToNextToken(buffer); + mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end); + if ('\"' == *mBuffer.data) { + mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, mat.name); + mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end); } - buffer = TAcCheckedLoadFloatArray(buffer, "rgb", 3, 3, &mat.rgb); - buffer = TAcCheckedLoadFloatArray(buffer, "amb", 3, 3, &mat.amb); - buffer = TAcCheckedLoadFloatArray(buffer, "emis", 4, 3, &mat.emis); - buffer = TAcCheckedLoadFloatArray(buffer, "spec", 4, 3, &mat.spec); - buffer = TAcCheckedLoadFloatArray(buffer, "shi", 3, 1, &mat.shin); - buffer = TAcCheckedLoadFloatArray(buffer, "trans", 5, 1, &mat.trans); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "rgb", 3, 3, &mat.rgb); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "amb", 3, 3, &mat.amb); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "emis", 4, 3, &mat.emis); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "spec", 4, 3, &mat.spec); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "shi", 3, 1, &mat.shin); + mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "trans", 5, 1, &mat.trans); + } else { + LoadObjectSection(rootObjects); } - LoadObjectSection(rootObjects); } - if (rootObjects.empty() || !mNumMeshes) { + if (rootObjects.empty() || mNumMeshes == 0u) { throw DeadlyImportError("AC3D: No meshes have been loaded"); } if (materials.empty()) { @@ -824,7 +821,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile, materials.reserve(mNumMeshes); // generate a dummy root if there are multiple objects on the top layer - Object *root; + Object *root = nullptr; if (1 == rootObjects.size()) root = &rootObjects[0]; else { @@ -837,7 +834,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile, delete root; } - if (!::strncmp(pScene->mRootNode->mName.data, "Node", 4)) { + if (::strncmp(pScene->mRootNode->mName.data, "Node", 4) == 0) { pScene->mRootNode->mName.Set(""); } @@ -856,7 +853,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile, // copy lights pScene->mNumLights = (unsigned int)lights.size(); - if (lights.size()) { + if (!lights.empty()) { pScene->mLights = new aiLight *[lights.size()]; ::memcpy(pScene->mLights, &lights[0], lights.size() * sizeof(void *)); } diff --git a/code/AssetLib/AC/ACLoader.h b/code/AssetLib/AC/ACLoader.h index 7f8dfd03c..22f7d0d09 100644 --- a/code/AssetLib/AC/ACLoader.h +++ b/code/AssetLib/AC/ACLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -216,7 +216,7 @@ private: * load subobjects, the method returns after a 'kids 0' was * encountered. * @objects List of output objects*/ - void LoadObjectSection(std::vector &objects); + bool LoadObjectSection(std::vector &objects); // ------------------------------------------------------------------- /** Convert all objects into meshes and nodes. @@ -242,7 +242,7 @@ private: private: // points to the next data line - const char *buffer; + aiBuffer mBuffer; // Configuration option: if enabled, up to two meshes // are generated per material: those faces who have diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index eabdb35e1..7c0d3b4e9 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/AMF/AMFImporter.hpp b/code/AssetLib/AMF/AMFImporter.hpp index fbaf4fc6d..50be465ce 100644 --- a/code/AssetLib/AMF/AMFImporter.hpp +++ b/code/AssetLib/AMF/AMFImporter.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/AMF/AMFImporter_Geometry.cpp b/code/AssetLib/AMF/AMFImporter_Geometry.cpp index 341999f56..db262dfbd 100644 --- a/code/AssetLib/AMF/AMFImporter_Geometry.cpp +++ b/code/AssetLib/AMF/AMFImporter_Geometry.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/AMF/AMFImporter_Material.cpp b/code/AssetLib/AMF/AMFImporter_Material.cpp index 676e74856..ae27f5d37 100644 --- a/code/AssetLib/AMF/AMFImporter_Material.cpp +++ b/code/AssetLib/AMF/AMFImporter_Material.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/AMF/AMFImporter_Node.hpp b/code/AssetLib/AMF/AMFImporter_Node.hpp index dd27316d3..21068a9ba 100644 --- a/code/AssetLib/AMF/AMFImporter_Node.hpp +++ b/code/AssetLib/AMF/AMFImporter_Node.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp index d5160870a..969c64bd2 100644 --- a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp +++ b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/ASE/ASELoader.cpp b/code/AssetLib/ASE/ASELoader.cpp index f98316661..7e411fc03 100644 --- a/code/AssetLib/ASE/ASELoader.cpp +++ b/code/AssetLib/ASE/ASELoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/ASE/ASELoader.h b/code/AssetLib/ASE/ASELoader.h index 2509671ef..5654fa630 100644 --- a/code/AssetLib/ASE/ASELoader.h +++ b/code/AssetLib/ASE/ASELoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/ASE/ASEParser.cpp b/code/AssetLib/ASE/ASEParser.cpp index 90f462598..7efab0da3 100644 --- a/code/AssetLib/ASE/ASEParser.cpp +++ b/code/AssetLib/ASE/ASEParser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -110,10 +110,12 @@ using namespace Assimp::ASE; ++filePtr; // ------------------------------------------------------------------------------------------------ -Parser::Parser(const char *szFile, unsigned int fileFormatDefault) { +Parser::Parser(const char *szFile, unsigned int fileFormatDefault) : + filePtr(nullptr), mEnd (nullptr) { ai_assert(nullptr != szFile); filePtr = szFile; + mEnd = filePtr + std::strlen(filePtr); iFileFormat = fileFormatDefault; // make sure that the color values are invalid @@ -179,14 +181,22 @@ bool Parser::SkipToNextToken() { while (true) { char me = *filePtr; + if (filePtr == mEnd) { + return false; + } + // increase the line number counter if necessary if (IsLineEnd(me) && !bLastWasEndLine) { ++iLineNumber; bLastWasEndLine = true; } else bLastWasEndLine = false; - if ('*' == me || '}' == me || '{' == me) return true; - if ('\0' == me) return false; + if ('*' == me || '}' == me || '{' == me) { + return true; + } + if ('\0' == me) { + return false; + } ++filePtr; } @@ -344,8 +354,9 @@ void Parser::ParseLV1SoftSkinBlock() { unsigned int numVerts = 0; const char *sz = filePtr; - while (!IsSpaceOrNewLine(*filePtr)) + while (!IsSpaceOrNewLine(*filePtr)) { ++filePtr; + } const unsigned int diff = (unsigned int)(filePtr - sz); if (diff) { @@ -363,24 +374,24 @@ void Parser::ParseLV1SoftSkinBlock() { // Skip the mesh data - until we find a new mesh // or the end of the *MESH_SOFTSKINVERTS section while (true) { - SkipSpacesAndLineEnd(&filePtr); + SkipSpacesAndLineEnd(&filePtr, mEnd); if (*filePtr == '}') { ++filePtr; return; } else if (!IsNumeric(*filePtr)) break; - SkipLine(&filePtr); + SkipLine(&filePtr, mEnd); } } else { - SkipSpacesAndLineEnd(&filePtr); + SkipSpacesAndLineEnd(&filePtr, mEnd); ParseLV4MeshLong(numVerts); // Reserve enough storage curMesh->mBoneVertices.reserve(numVerts); for (unsigned int i = 0; i < numVerts; ++i) { - SkipSpacesAndLineEnd(&filePtr); + SkipSpacesAndLineEnd(&filePtr, mEnd); unsigned int numWeights; ParseLV4MeshLong(numWeights); @@ -422,7 +433,7 @@ void Parser::ParseLV1SoftSkinBlock() { if (*filePtr == '\0') return; ++filePtr; - SkipSpacesAndLineEnd(&filePtr); + SkipSpacesAndLineEnd(&filePtr, mEnd); } } @@ -489,6 +500,13 @@ void Parser::ParseLV1MaterialListBlock() { continue; } if (TokenMatch(filePtr, "MATERIAL", 8)) { + // ensure we have at least one material allocated + if (iMaterialCount == 0) { + LogWarning("*MATERIAL_COUNT unspecified or 0"); + iMaterialCount = 1; + m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID")); + } + unsigned int iIndex = 0; ParseLV4MeshLong(iIndex); @@ -642,6 +660,12 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) { } // submaterial chunks if (TokenMatch(filePtr, "SUBMATERIAL", 11)) { + // ensure we have at least one material allocated + if (iNumSubMaterials == 0) { + LogWarning("*NUMSUBMTLS unspecified or 0"); + iNumSubMaterials = 1; + mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL")); + } unsigned int iIndex = 0; ParseLV4MeshLong(iIndex); @@ -743,7 +767,7 @@ void Parser::ParseLV3MapBlock(Texture &map) { // ------------------------------------------------------------------------------------------------ bool Parser::ParseString(std::string &out, const char *szName) { char szBuffer[1024]; - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL", szName); LogWarning(szBuffer); @@ -1355,7 +1379,7 @@ void Parser::ParseLV4MeshBones(unsigned int iNumBones, ASE::Mesh &mesh) { // Mesh bone with name ... if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) { // parse an index ... - if (SkipSpaces(&filePtr)) { + if (SkipSpaces(&filePtr, mEnd)) { unsigned int iIndex = strtoul10(filePtr, &filePtr); if (iIndex >= iNumBones) { LogWarning("Bone index is out of bounds"); @@ -1395,11 +1419,11 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes std::pair pairOut; while (true) { // first parse the bone index ... - if (!SkipSpaces(&filePtr)) break; + if (!SkipSpaces(&filePtr, mEnd)) break; pairOut.first = strtoul10(filePtr, &filePtr); // then parse the vertex weight - if (!SkipSpaces(&filePtr)) break; + if (!SkipSpaces(&filePtr, mEnd)) break; filePtr = fast_atoreal_move(filePtr, pairOut.second); // -1 marks unused entries @@ -1675,7 +1699,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) { // ------------------------------------------------------------------------------------------------ void Parser::ParseLV4MeshFace(ASE::Face &out) { // skip spaces and tabs - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]"); SkipToNextToken(); return; @@ -1685,7 +1709,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { out.iFace = strtoul10(filePtr, &filePtr); // next character should be ':' - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { // FIX: there are some ASE files which haven't got : here .... LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]"); SkipToNextToken(); @@ -1697,7 +1721,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { // Parse all mesh indices for (unsigned int i = 0; i < 3; ++i) { unsigned int iIndex = 0; - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL"); SkipToNextToken(); return; @@ -1723,7 +1747,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { ++filePtr; // next character should be ':' - if (!SkipSpaces(&filePtr) || ':' != *filePtr) { + if (!SkipSpaces(&filePtr, mEnd) || ':' != *filePtr) { LogWarning("Unable to parse *MESH_FACE Element: " "Unexpected EOL. \':\' expected [#2]"); SkipToNextToken(); @@ -1731,9 +1755,9 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { } ++filePtr; - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. " - "Vertex index ecpected [#4]"); + "Vertex index expected [#4]"); SkipToNextToken(); return; } @@ -1752,7 +1776,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { // parse the smoothing group of the face if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) { - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { LogWarning("Unable to parse *MESH_SMOOTHING Element: " "Unexpected EOL. Smoothing group(s) expected [#5]"); SkipToNextToken(); @@ -1771,12 +1795,12 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { LogWarning(message.c_str()); } } - SkipSpaces(&filePtr); + SkipSpaces(&filePtr, mEnd); if (',' != *filePtr) { break; } ++filePtr; - SkipSpaces(&filePtr); + SkipSpaces(&filePtr, mEnd); } } @@ -1792,7 +1816,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { } if (TokenMatch(filePtr, "*MESH_MTLID", 11)) { - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. " "Material index expected [#6]"); SkipToNextToken(); @@ -1840,7 +1864,7 @@ void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) { // ------------------------------------------------------------------------------------------------ void Parser::ParseLV4MeshFloat(ai_real &fOut) { // skip spaces and tabs - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { // LOG LogWarning("Unable to parse float: unexpected EOL [#1]"); fOut = 0.0; @@ -1853,7 +1877,7 @@ void Parser::ParseLV4MeshFloat(ai_real &fOut) { // ------------------------------------------------------------------------------------------------ void Parser::ParseLV4MeshLong(unsigned int &iOut) { // Skip spaces and tabs - if (!SkipSpaces(&filePtr)) { + if (!SkipSpaces(&filePtr, mEnd)) { // LOG LogWarning("Unable to parse long: unexpected EOL [#1]"); iOut = 0; diff --git a/code/AssetLib/ASE/ASEParser.h b/code/AssetLib/ASE/ASEParser.h index c41cd59d3..263b5ca73 100644 --- a/code/AssetLib/ASE/ASEParser.h +++ b/code/AssetLib/ASE/ASEParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -620,6 +620,9 @@ public: //! Pointer to current data const char *filePtr; + /// The end pointer of the file data + const char *mEnd; + //! background color to be passed to the viewer //! QNAN if none was found aiColor3D m_clrBackground; diff --git a/code/AssetLib/Assbin/AssbinExporter.cpp b/code/AssetLib/Assbin/AssbinExporter.cpp index 149b3c5f3..b8465f866 100644 --- a/code/AssetLib/Assbin/AssbinExporter.cpp +++ b/code/AssetLib/Assbin/AssbinExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assbin/AssbinExporter.h b/code/AssetLib/Assbin/AssbinExporter.h index 8b721994d..271b6b833 100644 --- a/code/AssetLib/Assbin/AssbinExporter.h +++ b/code/AssetLib/Assbin/AssbinExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assbin/AssbinFileWriter.cpp b/code/AssetLib/Assbin/AssbinFileWriter.cpp index 782595bc1..90bcccf90 100644 --- a/code/AssetLib/Assbin/AssbinFileWriter.cpp +++ b/code/AssetLib/Assbin/AssbinFileWriter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assbin/AssbinFileWriter.h b/code/AssetLib/Assbin/AssbinFileWriter.h index cfed3b400..84641df46 100644 --- a/code/AssetLib/Assbin/AssbinFileWriter.h +++ b/code/AssetLib/Assbin/AssbinFileWriter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assbin/AssbinLoader.cpp b/code/AssetLib/Assbin/AssbinLoader.cpp index 6995ea976..d2566a85c 100644 --- a/code/AssetLib/Assbin/AssbinLoader.cpp +++ b/code/AssetLib/Assbin/AssbinLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assbin/AssbinLoader.h b/code/AssetLib/Assbin/AssbinLoader.h index f922b91fd..2b85e6655 100644 --- a/code/AssetLib/Assbin/AssbinLoader.h +++ b/code/AssetLib/Assbin/AssbinLoader.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assxml/AssxmlExporter.cpp b/code/AssetLib/Assxml/AssxmlExporter.cpp index 731916a25..b9691b822 100644 --- a/code/AssetLib/Assxml/AssxmlExporter.cpp +++ b/code/AssetLib/Assxml/AssxmlExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assxml/AssxmlExporter.h b/code/AssetLib/Assxml/AssxmlExporter.h index 6fcdebfab..28a9b7f35 100644 --- a/code/AssetLib/Assxml/AssxmlExporter.h +++ b/code/AssetLib/Assxml/AssxmlExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assxml/AssxmlFileWriter.cpp b/code/AssetLib/Assxml/AssxmlFileWriter.cpp index 8f8e76bd2..f6fdc4a0c 100644 --- a/code/AssetLib/Assxml/AssxmlFileWriter.cpp +++ b/code/AssetLib/Assxml/AssxmlFileWriter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Assxml/AssxmlFileWriter.h b/code/AssetLib/Assxml/AssxmlFileWriter.h index 0620c9db7..1051a03a0 100644 --- a/code/AssetLib/Assxml/AssxmlFileWriter.h +++ b/code/AssetLib/Assxml/AssxmlFileWriter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/B3D/B3DImporter.cpp b/code/AssetLib/B3D/B3DImporter.cpp index 670f3de53..d0029277c 100644 --- a/code/AssetLib/B3D/B3DImporter.cpp +++ b/code/AssetLib/B3D/B3DImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/B3D/B3DImporter.h b/code/AssetLib/B3D/B3DImporter.h index e47d9078b..0fcfae620 100644 --- a/code/AssetLib/B3D/B3DImporter.h +++ b/code/AssetLib/B3D/B3DImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/BVH/BVHLoader.cpp b/code/AssetLib/BVH/BVHLoader.cpp index 4d2cfde15..2b37286ea 100644 --- a/code/AssetLib/BVH/BVHLoader.cpp +++ b/code/AssetLib/BVH/BVHLoader.cpp @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/AssetLib/BVH/BVHLoader.h b/code/AssetLib/BVH/BVHLoader.h index 56c32bd99..2c5e24114 100644 --- a/code/AssetLib/BVH/BVHLoader.h +++ b/code/AssetLib/BVH/BVHLoader.h @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderBMesh.cpp b/code/AssetLib/Blender/BlenderBMesh.cpp index a82e7c678..0660967bd 100644 --- a/code/AssetLib/Blender/BlenderBMesh.cpp +++ b/code/AssetLib/Blender/BlenderBMesh.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/Blender/BlenderBMesh.h b/code/AssetLib/Blender/BlenderBMesh.h index 7d2f71717..1798aaf74 100644 --- a/code/AssetLib/Blender/BlenderBMesh.h +++ b/code/AssetLib/Blender/BlenderBMesh.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/Blender/BlenderDNA.cpp b/code/AssetLib/Blender/BlenderDNA.cpp index d22c4bfd7..311911249 100644 --- a/code/AssetLib/Blender/BlenderDNA.cpp +++ b/code/AssetLib/Blender/BlenderDNA.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderDNA.h b/code/AssetLib/Blender/BlenderDNA.h index 494dc4b34..f6a691fd6 100644 --- a/code/AssetLib/Blender/BlenderDNA.h +++ b/code/AssetLib/Blender/BlenderDNA.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderDNA.inl b/code/AssetLib/Blender/BlenderDNA.inl index 4f64987a5..9bcb602ba 100644 --- a/code/AssetLib/Blender/BlenderDNA.inl +++ b/code/AssetLib/Blender/BlenderDNA.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderIntermediate.h b/code/AssetLib/Blender/BlenderIntermediate.h index 546b79f09..700beb7b0 100644 --- a/code/AssetLib/Blender/BlenderIntermediate.h +++ b/code/AssetLib/Blender/BlenderIntermediate.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderLoader.cpp b/code/AssetLib/Blender/BlenderLoader.cpp index 35b35f08d..1a40a2fe5 100644 --- a/code/AssetLib/Blender/BlenderLoader.cpp +++ b/code/AssetLib/Blender/BlenderLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderLoader.h b/code/AssetLib/Blender/BlenderLoader.h index 2bdc24ae2..5c800c627 100644 --- a/code/AssetLib/Blender/BlenderLoader.h +++ b/code/AssetLib/Blender/BlenderLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderModifier.cpp b/code/AssetLib/Blender/BlenderModifier.cpp index f925de608..2cd8bda7c 100644 --- a/code/AssetLib/Blender/BlenderModifier.cpp +++ b/code/AssetLib/Blender/BlenderModifier.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderModifier.h b/code/AssetLib/Blender/BlenderModifier.h index 180a456a1..2d6940357 100644 --- a/code/AssetLib/Blender/BlenderModifier.h +++ b/code/AssetLib/Blender/BlenderModifier.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderScene.h b/code/AssetLib/Blender/BlenderScene.h index ba7ded909..671891c68 100644 --- a/code/AssetLib/Blender/BlenderScene.h +++ b/code/AssetLib/Blender/BlenderScene.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderTessellator.cpp b/code/AssetLib/Blender/BlenderTessellator.cpp index 84bc2ea1a..f51cf9780 100644 --- a/code/AssetLib/Blender/BlenderTessellator.cpp +++ b/code/AssetLib/Blender/BlenderTessellator.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Blender/BlenderTessellator.h b/code/AssetLib/Blender/BlenderTessellator.h index 21a4f4701..e43535f6c 100644 --- a/code/AssetLib/Blender/BlenderTessellator.h +++ b/code/AssetLib/Blender/BlenderTessellator.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/C4D/C4DImporter.cpp b/code/AssetLib/C4D/C4DImporter.cpp index c11ec0280..daef6ebe4 100644 --- a/code/AssetLib/C4D/C4DImporter.cpp +++ b/code/AssetLib/C4D/C4DImporter.cpp @@ -46,10 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // no #ifdefing here, Cinema4D support is carried out in a branch of assimp // where it is turned on in the CMake settings. -#ifndef _MSC_VER -# error C4D support is currently MSVC only -#endif - #include "C4DImporter.h" #include #include @@ -111,7 +107,7 @@ C4DImporter::C4DImporter() = default; C4DImporter::~C4DImporter() = default; // ------------------------------------------------------------------------------------------------ -bool C4DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const { +bool C4DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const { const std::string& extension = GetExtension(pFile); if (extension == "c4d") { return true; @@ -305,7 +301,7 @@ void C4DImporter::RecurseHierarchy(BaseObject* object, aiNode* parent) { // based on Cineware sample code while (object) { - const LONG type = object->GetType(); + const Int32 type = object->GetType(); const Matrix& ml = object->GetMl(); aiNode* const nd = new aiNode(); @@ -368,8 +364,8 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) { PolygonObject* const polyObject = dynamic_cast(object); ai_assert(polyObject != nullptr); - const LONG pointCount = polyObject->GetPointCount(); - const LONG polyCount = polyObject->GetPolygonCount(); + const Int32 pointCount = polyObject->GetPointCount(); + const Int32 polyCount = polyObject->GetPolygonCount(); if(!polyObject || !pointCount) { LogWarn("ignoring mesh with zero vertices or faces"); return nullptr; @@ -391,7 +387,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) { unsigned int vcount = 0; // first count vertices - for (LONG i = 0; i < polyCount; i++) + for (Int32 i = 0; i < polyCount; i++) { vcount += 3; @@ -434,7 +430,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) { } // copy vertices and extra channels over and populate faces - for (LONG i = 0; i < polyCount; ++i, ++face) { + for (Int32 i = 0; i < polyCount; ++i, ++face) { ai_assert(polys[i].a < pointCount && polys[i].a >= 0); const Vector& pointA = points[polys[i].a]; verts->x = pointA.x; @@ -511,7 +507,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) { if (tangents_src) { for(unsigned int k = 0; k < face->mNumIndices; ++k) { - LONG l; + Int32 l; switch(k) { case 0: l = polys[i].a; diff --git a/code/AssetLib/C4D/C4DImporter.h b/code/AssetLib/C4D/C4DImporter.h index c44cf5e37..effd2af09 100644 --- a/code/AssetLib/C4D/C4DImporter.h +++ b/code/AssetLib/C4D/C4DImporter.h @@ -78,6 +78,8 @@ namespace Assimp { // ------------------------------------------------------------------------------------------- class C4DImporter : public BaseImporter, public LogFunctions { public: + C4DImporter(); + ~C4DImporter() override; bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override; protected: diff --git a/code/AssetLib/COB/COBLoader.cpp b/code/AssetLib/COB/COBLoader.cpp index 9a6e32f6d..f0899bddd 100644 --- a/code/AssetLib/COB/COBLoader.cpp +++ b/code/AssetLib/COB/COBLoader.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -473,8 +473,9 @@ void COBImporter::ReadBasicNodeInfo_Ascii(Node &msh, LineSplitter &splitter, con } else if (splitter.match_start("Transform")) { for (unsigned int y = 0; y < 4 && ++splitter; ++y) { const char *s = splitter->c_str(); + const char *end = s + splitter->size(); for (unsigned int x = 0; x < 4; ++x) { - SkipSpaces(&s); + SkipSpaces(&s, end); msh.transform[y][x] = fast_atof(&s); } } @@ -486,12 +487,12 @@ void COBImporter::ReadBasicNodeInfo_Ascii(Node &msh, LineSplitter &splitter, con // ------------------------------------------------------------------------------------------------ template -void COBImporter::ReadFloat3Tuple_Ascii(T &fill, const char **in) { +void COBImporter::ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end) { const char *rgb = *in; for (unsigned int i = 0; i < 3; ++i) { - SkipSpaces(&rgb); + SkipSpaces(&rgb, end); if (*rgb == ',') ++rgb; - SkipSpaces(&rgb); + SkipSpaces(&rgb, end); fill[i] = fast_atof(&rgb); } @@ -538,7 +539,7 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk } const char *rgb = splitter[1]; - ReadFloat3Tuple_Ascii(mat.rgb, &rgb); + ReadFloat3Tuple_Ascii(mat.rgb, &rgb, splitter.getEnd()); ++splitter; if (!splitter.match_start("alpha ")) { @@ -617,20 +618,21 @@ void COBImporter::ReadLght_Ascii(Scene &out, LineSplitter &splitter, const Chunk } const char *rgb = splitter[1]; - ReadFloat3Tuple_Ascii(msh.color, &rgb); + const char *end = splitter.getEnd(); + ReadFloat3Tuple_Ascii(msh.color, &rgb, end); - SkipSpaces(&rgb); + SkipSpaces(&rgb, end); if (strncmp(rgb, "cone angle", 10) != 0) { ASSIMP_LOG_WARN("Expected `cone angle` entity in `color` line in `Lght` chunk ", nfo.id); } - SkipSpaces(rgb + 10, &rgb); + SkipSpaces(rgb + 10, &rgb, end); msh.angle = fast_atof(&rgb); - SkipSpaces(&rgb); + SkipSpaces(&rgb, end); if (strncmp(rgb, "inner angle", 11) != 0) { ASSIMP_LOG_WARN("Expected `inner angle` entity in `color` line in `Lght` chunk ", nfo.id); } - SkipSpaces(rgb + 11, &rgb); + SkipSpaces(rgb + 11, &rgb, end); msh.inner_angle = fast_atof(&rgb); // skip the rest for we can't handle this kind of physically-based lighting information. @@ -703,14 +705,14 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) { const char *s = splitter->c_str(); - + const char *end = splitter.getEnd(); aiVector3D &v = msh.vertex_positions[cur]; - SkipSpaces(&s); + SkipSpaces(&s, end); v.x = fast_atof(&s); - SkipSpaces(&s); + SkipSpaces(&s, end); v.y = fast_atof(&s); - SkipSpaces(&s); + SkipSpaces(&s, end); v.z = fast_atof(&s); } } else if (splitter.match_start("Texture Vertices")) { @@ -719,12 +721,13 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) { const char *s = splitter->c_str(); + const char *end = splitter.getEnd(); aiVector2D &v = msh.texture_coords[cur]; - SkipSpaces(&s); + SkipSpaces(&s, end); v.x = fast_atof(&s); - SkipSpaces(&s); + SkipSpaces(&s, end); v.y = fast_atof(&s); } } else if (splitter.match_start("Faces")) { @@ -749,8 +752,9 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk face.material = strtoul10(splitter[6]); const char *s = (++splitter)->c_str(); + const char *end = splitter.getEnd(); for (size_t i = 0; i < face.indices.size(); ++i) { - if (!SkipSpaces(&s)) { + if (!SkipSpaces(&s, end)) { ThrowException("Expected EOL token in Face entry"); } if ('<' != *s++) { diff --git a/code/AssetLib/COB/COBLoader.h b/code/AssetLib/COB/COBLoader.h index a9755f5d7..ec3c7756b 100644 --- a/code/AssetLib/COB/COBLoader.h +++ b/code/AssetLib/COB/COBLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -120,7 +120,7 @@ private: void ReadChunkInfo_Ascii(COB::ChunkInfo &out, const LineSplitter &splitter); void ReadBasicNodeInfo_Ascii(COB::Node &msh, LineSplitter &splitter, const COB::ChunkInfo &nfo); template - void ReadFloat3Tuple_Ascii(T &fill, const char **in); + void ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end); void ReadPolH_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo); void ReadBitM_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo); diff --git a/code/AssetLib/COB/COBScene.h b/code/AssetLib/COB/COBScene.h index cc49de276..ea4c01251 100644 --- a/code/AssetLib/COB/COBScene.h +++ b/code/AssetLib/COB/COBScene.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/CSM/CSMLoader.cpp b/code/AssetLib/CSM/CSMLoader.cpp index 20f2343f5..47beee514 100644 --- a/code/AssetLib/CSM/CSMLoader.cpp +++ b/code/AssetLib/CSM/CSMLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team @@ -82,23 +82,20 @@ CSMImporter::CSMImporter() : noSkeletonMesh(){ // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const -{ +bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const { static const char* tokens[] = {"$Filename"}; return SearchFileHeaderForToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens)); } // ------------------------------------------------------------------------------------------------ // Build a string of all file extensions supported -const aiImporterDesc* CSMImporter::GetInfo () const -{ +const aiImporterDesc* CSMImporter::GetInfo () const { return &desc; } // ------------------------------------------------------------------------------------------------ // Setup configuration properties for the loader -void CSMImporter::SetupProperties(const Importer* pImp) -{ +void CSMImporter::SetupProperties(const Importer* pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; } @@ -118,29 +115,29 @@ void CSMImporter::InternReadFile( const std::string& pFile, std::vector mBuffer2; TextFileToBuffer(file.get(),mBuffer2); const char* buffer = &mBuffer2[0]; - + const char *end = &mBuffer2[mBuffer2.size() - 1] + 1; std::unique_ptr anim(new aiAnimation()); int first = 0, last = 0x00ffffff; // now process the file and look out for '$' sections while (true) { - SkipSpaces(&buffer); + SkipSpaces(&buffer, end); if ('\0' == *buffer) break; if ('$' == *buffer) { ++buffer; if (TokenMatchI(buffer,"firstframe",10)) { - SkipSpaces(&buffer); + SkipSpaces(&buffer, end); first = strtol10(buffer,&buffer); } else if (TokenMatchI(buffer,"lastframe",9)) { - SkipSpaces(&buffer); + SkipSpaces(&buffer, end); last = strtol10(buffer,&buffer); } else if (TokenMatchI(buffer,"rate",4)) { - SkipSpaces(&buffer); - float d; + SkipSpaces(&buffer, end); + float d = { 0.0f }; buffer = fast_atoreal_move(buffer,d); anim->mTicksPerSecond = d; } @@ -148,8 +145,8 @@ void CSMImporter::InternReadFile( const std::string& pFile, std::vector< aiNodeAnim* > anims_temp; anims_temp.reserve(30); while (true) { - SkipSpaces(&buffer); - if (IsLineEnd(*buffer) && SkipSpacesAndLineEnd(&buffer) && *buffer == '$') + SkipSpaces(&buffer, end); + if (IsLineEnd(*buffer) && SkipSpacesAndLineEnd(&buffer, end) && *buffer == '$') break; // next section // Construct a new node animation channel and setup its name @@ -157,41 +154,43 @@ void CSMImporter::InternReadFile( const std::string& pFile, aiNodeAnim* nda = anims_temp.back(); char* ot = nda->mNodeName.data; - while (!IsSpaceOrNewLine(*buffer)) + while (!IsSpaceOrNewLine(*buffer)) { *ot++ = *buffer++; + } *ot = '\0'; nda->mNodeName.length = static_cast(ot-nda->mNodeName.data); } anim->mNumChannels = static_cast(anims_temp.size()); - if (!anim->mNumChannels) + if (!anim->mNumChannels) { throw DeadlyImportError("CSM: Empty $order section"); + } // copy over to the output animation anim->mChannels = new aiNodeAnim*[anim->mNumChannels]; ::memcpy(anim->mChannels,&anims_temp[0],sizeof(aiNodeAnim*)*anim->mNumChannels); - } - else if (TokenMatchI(buffer,"points",6)) { - if (!anim->mNumChannels) + } else if (TokenMatchI(buffer,"points",6)) { + if (!anim->mNumChannels) { throw DeadlyImportError("CSM: \'$order\' section is required to appear prior to \'$points\'"); + } // If we know how many frames we'll read, we can preallocate some storage unsigned int alloc = 100; - if (last != 0x00ffffff) - { + if (last != 0x00ffffff) { alloc = last-first; alloc += alloc>>2u; // + 25% - for (unsigned int i = 0; i < anim->mNumChannels;++i) + for (unsigned int i = 0; i < anim->mNumChannels; ++i) { anim->mChannels[i]->mPositionKeys = new aiVectorKey[alloc]; + } } unsigned int filled = 0; // Now read all point data. while (true) { - SkipSpaces(&buffer); - if (IsLineEnd(*buffer) && (!SkipSpacesAndLineEnd(&buffer) || *buffer == '$')) { + SkipSpaces(&buffer, end); + if (IsLineEnd(*buffer) && (!SkipSpacesAndLineEnd(&buffer, end) || *buffer == '$')) { break; // next section } @@ -202,8 +201,8 @@ void CSMImporter::InternReadFile( const std::string& pFile, for (unsigned int i = 0; i < anim->mNumChannels;++i) { aiNodeAnim* s = anim->mChannels[i]; - if (s->mNumPositionKeys == alloc) { /* need to reallocate? */ - + if (s->mNumPositionKeys == alloc) { + // need to reallocate? aiVectorKey* old = s->mPositionKeys; s->mPositionKeys = new aiVectorKey[s->mNumPositionKeys = alloc*2]; ::memcpy(s->mPositionKeys,old,sizeof(aiVectorKey)*alloc); @@ -211,24 +210,26 @@ void CSMImporter::InternReadFile( const std::string& pFile, } // read x,y,z - if(!SkipSpacesAndLineEnd(&buffer)) + if (!SkipSpacesAndLineEnd(&buffer, end)) { throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample x coord"); + } if (TokenMatchI(buffer, "DROPOUT", 7)) { // seems this is invalid marker data; at least the doc says it's possible ASSIMP_LOG_WARN("CSM: Encountered invalid marker data (DROPOUT)"); - } - else { + } else { aiVectorKey* sub = s->mPositionKeys + s->mNumPositionKeys; sub->mTime = (double)frame; buffer = fast_atoreal_move(buffer, (float&)sub->mValue.x); - if(!SkipSpacesAndLineEnd(&buffer)) + if (!SkipSpacesAndLineEnd(&buffer, end)) { throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample y coord"); + } buffer = fast_atoreal_move(buffer, (float&)sub->mValue.y); - if(!SkipSpacesAndLineEnd(&buffer)) + if (!SkipSpacesAndLineEnd(&buffer, end)) { throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample z coord"); + } buffer = fast_atoreal_move(buffer, (float&)sub->mValue.z); ++s->mNumPositionKeys; @@ -236,22 +237,22 @@ void CSMImporter::InternReadFile( const std::string& pFile, } // update allocation granularity - if (filled == alloc) + if (filled == alloc) { alloc *= 2; + } ++filled; } // all channels must be complete in order to continue safely. for (unsigned int i = 0; i < anim->mNumChannels;++i) { - - if (!anim->mChannels[i]->mNumPositionKeys) + if (!anim->mChannels[i]->mNumPositionKeys) { throw DeadlyImportError("CSM: Invalid marker track"); + } } } - } - else { + } else { // advance to the next line - SkipLine(&buffer); + SkipLine(&buffer, end); } } @@ -265,7 +266,7 @@ void CSMImporter::InternReadFile( const std::string& pFile, pScene->mRootNode->mNumChildren = anim->mNumChannels; pScene->mRootNode->mChildren = new aiNode* [anim->mNumChannels]; - for (unsigned int i = 0; i < anim->mNumChannels;++i) { + for (unsigned int i = 0; i < anim->mNumChannels;++i) { aiNodeAnim* na = anim->mChannels[i]; aiNode* nd = pScene->mRootNode->mChildren[i] = new aiNode(); diff --git a/code/AssetLib/CSM/CSMLoader.h b/code/AssetLib/CSM/CSMLoader.h index fc9017d17..2bad73717 100644 --- a/code/AssetLib/CSM/CSMLoader.h +++ b/code/AssetLib/CSM/CSMLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaExporter.cpp b/code/AssetLib/Collada/ColladaExporter.cpp index 29b714bd7..3fc3a6e15 100644 --- a/code/AssetLib/Collada/ColladaExporter.cpp +++ b/code/AssetLib/Collada/ColladaExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaExporter.h b/code/AssetLib/Collada/ColladaExporter.h index e372a5c5c..05e076034 100644 --- a/code/AssetLib/Collada/ColladaExporter.h +++ b/code/AssetLib/Collada/ColladaExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaHelper.cpp b/code/AssetLib/Collada/ColladaHelper.cpp index 0fb172fbb..b5de70624 100644 --- a/code/AssetLib/Collada/ColladaHelper.cpp +++ b/code/AssetLib/Collada/ColladaHelper.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaHelper.h b/code/AssetLib/Collada/ColladaHelper.h index c5b6a2d13..6662d7354 100644 --- a/code/AssetLib/Collada/ColladaHelper.h +++ b/code/AssetLib/Collada/ColladaHelper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 41e529de0..2574fd2ea 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -247,7 +247,9 @@ aiNode *ColladaLoader::BuildHierarchy(const ColladaParser &pParser, const Collad // add children. first the *real* ones node->mNumChildren = static_cast(pNode->mChildren.size() + instances.size()); - node->mChildren = new aiNode *[node->mNumChildren]; + if (node->mNumChildren != 0) { + node->mChildren = new aiNode * [node->mNumChildren]; + } for (size_t a = 0; a < pNode->mChildren.size(); ++a) { node->mChildren[a] = BuildHierarchy(pParser, pNode->mChildren[a]); diff --git a/code/AssetLib/Collada/ColladaLoader.h b/code/AssetLib/Collada/ColladaLoader.h index 3cea7f531..0603d419c 100644 --- a/code/AssetLib/Collada/ColladaLoader.h +++ b/code/AssetLib/Collada/ColladaLoader.h @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index 42a8d6052..a563f6f9c 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -635,7 +635,8 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &controlle const std::string ¤tName = currentNode.name(); if (currentName == "morph") { controller.mType = Morph; - controller.mMeshId = currentNode.attribute("source").as_string(); + std::string id = currentNode.attribute("source").as_string(); + controller.mMeshId = id.substr(1, id.size() - 1); int methodIndex = currentNode.attribute("method").as_int(); if (methodIndex > 0) { std::string method; @@ -654,12 +655,13 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &controlle std::string v; XmlParser::getValueAsString(currentNode, v); const char *content = v.c_str(); + const char *end = content + v.size(); for (unsigned int a = 0; a < 16; a++) { - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); // read a number content = fast_atoreal_move(content, controller.mBindShapeMatrix[a]); // skip whitespace after it - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } } else if (currentName == "source") { ReadSource(currentNode); @@ -740,7 +742,9 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC throw DeadlyImportError("Unknown semantic \"", attrSemantic, "\" in data element"); } } else if (currentName == "vcount" && vertexCount > 0) { - const char *text = currentNode.text().as_string(); + const std::string stdText = currentNode.text().as_string(); + const char *text = stdText.c_str(); + const char *end = text + stdText.size(); size_t numWeights = 0; for (std::vector::iterator it = pController.mWeightCounts.begin(); it != pController.mWeightCounts.end(); ++it) { if (*text == 0) { @@ -749,7 +753,7 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC *it = strtoul10(text, &text); numWeights += *it; - SkipSpacesAndLineEnd(&text); + SkipSpacesAndLineEnd(&text, end); } // reserve weight count pController.mWeights.resize(numWeights); @@ -758,18 +762,19 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC std::string stdText; XmlParser::getValueAsString(currentNode, stdText); const char *text = stdText.c_str(); + const char *end = text + stdText.size(); for (std::vector>::iterator it = pController.mWeights.begin(); it != pController.mWeights.end(); ++it) { if (text == nullptr) { throw DeadlyImportError("Out of data while reading "); } - SkipSpacesAndLineEnd(&text); + SkipSpacesAndLineEnd(&text, end); it->first = strtoul10(text, &text); - SkipSpacesAndLineEnd(&text); + SkipSpacesAndLineEnd(&text, end); if (*text == 0) { throw DeadlyImportError("Out of data while reading "); } it->second = strtoul10(text, &text); - SkipSpacesAndLineEnd(&text); + SkipSpacesAndLineEnd(&text, end); } } } @@ -952,15 +957,16 @@ void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) { std::string v; XmlParser::getValueAsString(currentNode, v); const char *content = v.c_str(); + const char *end = content + v.size(); content = fast_atoreal_move(content, (ai_real &)pLight.mColor.r); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); content = fast_atoreal_move(content, (ai_real &)pLight.mColor.g); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); content = fast_atoreal_move(content, (ai_real &)pLight.mColor.b); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } else if (currentName == "constant_attenuation") { XmlParser::getValueAsFloat(currentNode, pLight.mAttConstant); } else if (currentName == "linear_attenuation") { @@ -1220,18 +1226,19 @@ void ColladaParser::ReadEffectColor(XmlNode &node, aiColor4D &pColor, Sampler &p std::string v; XmlParser::getValueAsString(currentNode, v); const char *content = v.c_str(); + const char *end = v.c_str() + v.size() + 1; content = fast_atoreal_move(content, (ai_real &)pColor.r); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); content = fast_atoreal_move(content, (ai_real &)pColor.g); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); content = fast_atoreal_move(content, (ai_real &)pColor.b); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); content = fast_atoreal_move(content, (ai_real &)pColor.a); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } else if (currentName == "texture") { // get name of source texture/sampler XmlParser::getStdStrAttribute(currentNode, "texture", pSampler.mName); @@ -1345,6 +1352,7 @@ void ColladaParser::ReadGeometry(XmlNode &node, Collada::Mesh &pMesh) { if (node.empty()) { return; } + for (XmlNode ¤tNode : node.children()) { const std::string ¤tName = currentNode.name(); if (currentName == "mesh") { @@ -1415,6 +1423,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) { XmlParser::getValueAsString(node, v); v = ai_trim(v); const char *content = v.c_str(); + const char *end = content + v.size(); // read values and store inside an array in the data library mDataLibrary[id] = Data(); @@ -1433,11 +1442,13 @@ void ColladaParser::ReadDataArray(XmlNode &node) { } s.clear(); - while (!IsSpaceOrNewLine(*content)) - s += *content++; + while (!IsSpaceOrNewLine(*content)) { + s += *content; + content++; + } data.mStrings.push_back(s); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } } else { data.mValues.reserve(count); @@ -1452,7 +1463,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) { content = fast_atoreal_move(content, value); data.mValues.push_back(value); // skip whitespace after it - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } } } @@ -1617,8 +1628,10 @@ void ColladaParser::ReadIndexData(XmlNode &node, Mesh &pMesh) { std::string v; XmlParser::getValueAsString(currentNode, v); const char *content = v.c_str(); + const char *end = content + v.size(); + vcount.reserve(numPrimitives); - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); for (unsigned int a = 0; a < numPrimitives; a++) { if (*content == 0) { throw DeadlyImportError("Expected more values while reading contents."); @@ -1626,7 +1639,7 @@ void ColladaParser::ReadIndexData(XmlNode &node, Mesh &pMesh) { // read a number vcount.push_back((size_t)strtoul10(content, &content)); // skip whitespace after it - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); } } } @@ -1735,14 +1748,16 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vectormData) { acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource); + const size_t dataSize = acc->mOffset + acc->mCount * acc->mStride; + if (dataSize > acc->mData->mValues.size()) { + throw DeadlyImportError("Not enough data for accessor"); + } } } // and the same for the per-index channels @@ -1796,13 +1815,19 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vectormData) { acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource); + const size_t dataSize = acc->mOffset + acc->mCount * acc->mStride; + if (dataSize > acc->mData->mValues.size()) { + throw DeadlyImportError("Not enough data for accessor"); + } } } // For continued primitives, the given count does not come all in one

, but only one primitive per

size_t numPrimitives = pNumPrimitives; - if (pPrimType == Prim_TriFans || pPrimType == Prim_Polygon) + if (pPrimType == Prim_TriFans || pPrimType == Prim_Polygon) { numPrimitives = 1; + } + // For continued primitives, the given count is actually the number of

's inside the parent tag if (pPrimType == Prim_TriStrips) { size_t numberOfVertices = indices.size() / numOffsets; @@ -2166,15 +2191,15 @@ void ColladaParser::ReadNodeTransformation(XmlNode &node, Node *pNode, Transform } // how many parameters to read per transformation type - static const unsigned int sNumParameters[] = { 9, 4, 3, 3, 7, 16 }; + static constexpr unsigned int sNumParameters[] = { 9, 4, 3, 3, 7, 16 }; std::string value; XmlParser::getValueAsString(node, value); const char *content = value.c_str(); - + const char *end = value.c_str() + value.size(); // read as many parameters and store in the transformation for (unsigned int a = 0; a < sNumParameters[pType]; a++) { // skip whitespace before the number - SkipSpacesAndLineEnd(&content); + SkipSpacesAndLineEnd(&content, end); // read a number content = fast_atoreal_move(content, tf.f[a]); } diff --git a/code/AssetLib/Collada/ColladaParser.h b/code/AssetLib/Collada/ColladaParser.h index 15982934f..d428ad674 100644 --- a/code/AssetLib/Collada/ColladaParser.h +++ b/code/AssetLib/Collada/ColladaParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- - Copyright (c) 2006-2022, assimp team + Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/DXF/DXFHelper.h b/code/AssetLib/DXF/DXFHelper.h index 4d7893cc4..0bbecdc9e 100644 --- a/code/AssetLib/DXF/DXFHelper.h +++ b/code/AssetLib/DXF/DXFHelper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index f69cdfce2..0f3da2626 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -43,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the DXF importer class */ - #ifndef ASSIMP_BUILD_NO_DXF_IMPORTER #include "AssetLib/DXF/DXFLoader.h" @@ -68,25 +67,267 @@ static constexpr size_t AI_DXF_BINARY_IDENT_LEN = sizeof AI_DXF_BINARY_IDENT; // default vertex color that all uncolored vertices will receive 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 const aiColor4D g_aclrDxfIndexColors[] = { - 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 - aiColor4D (0.3f, 1.0f, 0.3f, 1.0f), // light green - aiColor4D (0.3f, 0.3f, 1.0f, 1.0f), // light blue - aiColor4D (1.0f, 0.3f, 0.3f, 1.0f), // light red - aiColor4D (1.0f, 0.0f, 1.0f, 1.0f), // pink - aiColor4D (1.0f, 0.6f, 0.0f, 1.0f), // orange - aiColor4D (0.6f, 0.3f, 0.0f, 1.0f), // dark orange - aiColor4D (1.0f, 1.0f, 0.0f, 1.0f), // yellow - aiColor4D (0.3f, 0.3f, 0.3f, 1.0f), // dark gray - aiColor4D (0.8f, 0.8f, 0.8f, 1.0f), // light gray - aiColor4D (0.0f, 00.f, 0.0f, 1.0f), // black - aiColor4D (1.0f, 1.0f, 1.0f, 1.0f), // white - aiColor4D (0.6f, 0.0f, 1.0f, 1.0f) // violet +// color indices for DXF - 256 are supported, the table is +// taken directly from the AutoCad Index (ACI) table +// https://gohtx.com/acadcolors.php +//STH 2024-0126 +static const aiColor4D g_aclrDxfIndexColors[256] = { + aiColor4D (0.0f, 0.0f ,0.0f, 1.0f), //dxf color code 0 + aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 1 + aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 2 + aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 3 + aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 4 + aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 5 + aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 6 + aiColor4D (1.0f, 1.0f ,1.0f, 1.0f), //dxf color code 7 + aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 8 + aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 9 + aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 10 + aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 11 + aiColor4D (0.7f, 0.0f ,0.0f, 1.0f), //dxf color code 12 + aiColor4D (0.7f, 0.5f ,0.5f, 1.0f), //dxf color code 13 + aiColor4D (0.5f, 0.0f ,0.0f, 1.0f), //dxf color code 14 + aiColor4D (0.5f, 0.3f ,0.3f, 1.0f), //dxf color code 15 + aiColor4D (0.4f, 0.0f ,0.0f, 1.0f), //dxf color code 16 + aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 17 + aiColor4D (0.3f, 0.0f ,0.0f, 1.0f), //dxf color code 18 + aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 19 + aiColor4D (1.0f, 0.2f ,0.0f, 1.0f), //dxf color code 20 + aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 21 + aiColor4D (0.7f, 0.2f ,0.0f, 1.0f), //dxf color code 22 + aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 23 + aiColor4D (0.5f, 0.1f ,0.0f, 1.0f), //dxf color code 24 + aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 25 + aiColor4D (0.4f, 0.1f ,0.0f, 1.0f), //dxf color code 26 + aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 27 + aiColor4D (0.3f, 0.1f ,0.0f, 1.0f), //dxf color code 28 + aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 29 + aiColor4D (1.0f, 0.5f ,0.0f, 1.0f), //dxf color code 30 + aiColor4D (1.0f, 0.8f ,0.7f, 1.0f), //dxf color code 31 + aiColor4D (0.7f, 0.4f ,0.0f, 1.0f), //dxf color code 32 + aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 33 + aiColor4D (0.5f, 0.3f ,0.0f, 1.0f), //dxf color code 34 + aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 35 + aiColor4D (0.4f, 0.2f ,0.0f, 1.0f), //dxf color code 36 + aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 37 + aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 38 + aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 39 + aiColor4D (1.0f, 0.7f ,0.0f, 1.0f), //dxf color code 40 + aiColor4D (1.0f, 0.9f ,0.7f, 1.0f), //dxf color code 41 + aiColor4D (0.7f, 0.6f ,0.0f, 1.0f), //dxf color code 42 + aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 43 + aiColor4D (0.5f, 0.4f ,0.0f, 1.0f), //dxf color code 44 + aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 45 + aiColor4D (0.4f, 0.3f ,0.0f, 1.0f), //dxf color code 46 + aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 47 + aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 48 + aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 49 + aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 50 + aiColor4D (1.0f, 1.0f ,0.7f, 1.0f), //dxf color code 51 + aiColor4D (0.7f, 0.7f ,0.0f, 1.0f), //dxf color code 52 + aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 53 + aiColor4D (0.5f, 0.5f ,0.0f, 1.0f), //dxf color code 54 + aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 55 + aiColor4D (0.4f, 0.4f ,0.0f, 1.0f), //dxf color code 56 + aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 57 + aiColor4D (0.3f, 0.3f ,0.0f, 1.0f), //dxf color code 58 + aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 59 + aiColor4D (0.7f, 1.0f ,0.0f, 1.0f), //dxf color code 60 + aiColor4D (0.9f, 1.0f ,0.7f, 1.0f), //dxf color code 61 + aiColor4D (0.6f, 0.7f ,0.0f, 1.0f), //dxf color code 62 + aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 63 + aiColor4D (0.4f, 0.5f ,0.0f, 1.0f), //dxf color code 64 + aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 65 + aiColor4D (0.3f, 0.4f ,0.0f, 1.0f), //dxf color code 66 + aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 67 + aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 68 + aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 69 + aiColor4D (0.5f, 1.0f ,0.0f, 1.0f), //dxf color code 70 + aiColor4D (0.8f, 1.0f ,0.7f, 1.0f), //dxf color code 71 + aiColor4D (0.4f, 0.7f ,0.0f, 1.0f), //dxf color code 72 + aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 73 + aiColor4D (0.3f, 0.5f ,0.0f, 1.0f), //dxf color code 74 + aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 75 + aiColor4D (0.2f, 0.4f ,0.0f, 1.0f), //dxf color code 76 + aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 77 + aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 78 + aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 79 + aiColor4D (0.2f, 1.0f ,0.0f, 1.0f), //dxf color code 80 + aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 81 + aiColor4D (0.2f, 0.7f ,0.0f, 1.0f), //dxf color code 82 + aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 83 + aiColor4D (0.1f, 0.5f ,0.0f, 1.0f), //dxf color code 84 + aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 85 + aiColor4D (0.1f, 0.4f ,0.0f, 1.0f), //dxf color code 86 + aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 87 + aiColor4D (0.1f, 0.3f ,0.0f, 1.0f), //dxf color code 88 + aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 89 + aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 90 + aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 91 + aiColor4D (0.0f, 0.7f ,0.0f, 1.0f), //dxf color code 92 + aiColor4D (0.5f, 0.7f ,0.5f, 1.0f), //dxf color code 93 + aiColor4D (0.0f, 0.5f ,0.0f, 1.0f), //dxf color code 94 + aiColor4D (0.3f, 0.5f ,0.3f, 1.0f), //dxf color code 95 + aiColor4D (0.0f, 0.4f ,0.0f, 1.0f), //dxf color code 96 + aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 97 + aiColor4D (0.0f, 0.3f ,0.0f, 1.0f), //dxf color code 98 + aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 99 + aiColor4D (0.0f, 1.0f ,0.2f, 1.0f), //dxf color code 100 + aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 101 + aiColor4D (0.0f, 0.7f ,0.2f, 1.0f), //dxf color code 102 + aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 103 + aiColor4D (0.0f, 0.5f ,0.1f, 1.0f), //dxf color code 104 + aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 105 + aiColor4D (0.0f, 0.4f ,0.1f, 1.0f), //dxf color code 106 + aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 107 + aiColor4D (0.0f, 0.3f ,0.1f, 1.0f), //dxf color code 108 + aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 109 + aiColor4D (0.0f, 1.0f ,0.5f, 1.0f), //dxf color code 110 + aiColor4D (0.7f, 1.0f ,0.8f, 1.0f), //dxf color code 111 + aiColor4D (0.0f, 0.7f ,0.4f, 1.0f), //dxf color code 112 + aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 113 + aiColor4D (0.0f, 0.5f ,0.3f, 1.0f), //dxf color code 114 + aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 115 + aiColor4D (0.0f, 0.4f ,0.2f, 1.0f), //dxf color code 116 + aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 117 + aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 118 + aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 119 + aiColor4D (0.0f, 1.0f ,0.7f, 1.0f), //dxf color code 120 + aiColor4D (0.7f, 1.0f ,0.9f, 1.0f), //dxf color code 121 + aiColor4D (0.0f, 0.7f ,0.6f, 1.0f), //dxf color code 122 + aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 123 + aiColor4D (0.0f, 0.5f ,0.4f, 1.0f), //dxf color code 124 + aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 125 + aiColor4D (0.0f, 0.4f ,0.3f, 1.0f), //dxf color code 126 + aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 127 + aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 128 + aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 129 + aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 130 + aiColor4D (0.7f, 1.0f ,1.0f, 1.0f), //dxf color code 131 + aiColor4D (0.0f, 0.7f ,0.7f, 1.0f), //dxf color code 132 + aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 133 + aiColor4D (0.0f, 0.5f ,0.5f, 1.0f), //dxf color code 134 + aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 135 + aiColor4D (0.0f, 0.4f ,0.4f, 1.0f), //dxf color code 136 + aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 137 + aiColor4D (0.0f, 0.3f ,0.3f, 1.0f), //dxf color code 138 + aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 139 + aiColor4D (0.0f, 0.7f ,1.0f, 1.0f), //dxf color code 140 + aiColor4D (0.7f, 0.9f ,1.0f, 1.0f), //dxf color code 141 + aiColor4D (0.0f, 0.6f ,0.7f, 1.0f), //dxf color code 142 + aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 143 + aiColor4D (0.0f, 0.4f ,0.5f, 1.0f), //dxf color code 144 + aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 145 + aiColor4D (0.0f, 0.3f ,0.4f, 1.0f), //dxf color code 146 + aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 147 + aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 148 + aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 149 + aiColor4D (0.0f, 0.5f ,1.0f, 1.0f), //dxf color code 150 + aiColor4D (0.7f, 0.8f ,1.0f, 1.0f), //dxf color code 151 + aiColor4D (0.0f, 0.4f ,0.7f, 1.0f), //dxf color code 152 + aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 153 + aiColor4D (0.0f, 0.3f ,0.5f, 1.0f), //dxf color code 154 + aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 155 + aiColor4D (0.0f, 0.2f ,0.4f, 1.0f), //dxf color code 156 + aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 157 + aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 158 + aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 159 + aiColor4D (0.0f, 0.2f ,1.0f, 1.0f), //dxf color code 160 + aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 161 + aiColor4D (0.0f, 0.2f ,0.7f, 1.0f), //dxf color code 162 + aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 163 + aiColor4D (0.0f, 0.1f ,0.5f, 1.0f), //dxf color code 164 + aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 165 + aiColor4D (0.0f, 0.1f ,0.4f, 1.0f), //dxf color code 166 + aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 167 + aiColor4D (0.0f, 0.1f ,0.3f, 1.0f), //dxf color code 168 + aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 169 + aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 170 + aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 171 + aiColor4D (0.0f, 0.0f ,0.7f, 1.0f), //dxf color code 172 + aiColor4D (0.5f, 0.5f ,0.7f, 1.0f), //dxf color code 173 + aiColor4D (0.0f, 0.0f ,0.5f, 1.0f), //dxf color code 174 + aiColor4D (0.3f, 0.3f ,0.5f, 1.0f), //dxf color code 175 + aiColor4D (0.0f, 0.0f ,0.4f, 1.0f), //dxf color code 176 + aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 177 + aiColor4D (0.0f, 0.0f ,0.3f, 1.0f), //dxf color code 178 + aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 179 + aiColor4D (0.2f, 0.0f ,1.0f, 1.0f), //dxf color code 180 + aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 181 + aiColor4D (0.2f, 0.0f ,0.7f, 1.0f), //dxf color code 182 + aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 183 + aiColor4D (0.1f, 0.0f ,0.5f, 1.0f), //dxf color code 184 + aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 185 + aiColor4D (0.1f, 0.0f ,0.4f, 1.0f), //dxf color code 186 + aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 187 + aiColor4D (0.1f, 0.0f ,0.3f, 1.0f), //dxf color code 188 + aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 189 + aiColor4D (0.5f, 0.0f ,1.0f, 1.0f), //dxf color code 190 + aiColor4D (0.8f, 0.7f ,1.0f, 1.0f), //dxf color code 191 + aiColor4D (0.4f, 0.0f ,0.7f, 1.0f), //dxf color code 192 + aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 193 + aiColor4D (0.3f, 0.0f ,0.5f, 1.0f), //dxf color code 194 + aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 195 + aiColor4D (0.2f, 0.0f ,0.4f, 1.0f), //dxf color code 196 + aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 197 + aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 198 + aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 199 + aiColor4D (0.7f, 0.0f ,1.0f, 1.0f), //dxf color code 200 + aiColor4D (0.9f, 0.7f ,1.0f, 1.0f), //dxf color code 201 + aiColor4D (0.6f, 0.0f ,0.7f, 1.0f), //dxf color code 202 + aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 203 + aiColor4D (0.4f, 0.0f ,0.5f, 1.0f), //dxf color code 204 + aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 205 + aiColor4D (0.3f, 0.0f ,0.4f, 1.0f), //dxf color code 206 + aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 207 + aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 208 + aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 209 + aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 210 + aiColor4D (1.0f, 0.7f ,1.0f, 1.0f), //dxf color code 211 + aiColor4D (0.7f, 0.0f ,0.7f, 1.0f), //dxf color code 212 + aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 213 + aiColor4D (0.5f, 0.0f ,0.5f, 1.0f), //dxf color code 214 + aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 215 + aiColor4D (0.4f, 0.0f ,0.4f, 1.0f), //dxf color code 216 + aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 217 + aiColor4D (0.3f, 0.0f ,0.3f, 1.0f), //dxf color code 218 + aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 219 + aiColor4D (1.0f, 0.0f ,0.7f, 1.0f), //dxf color code 220 + aiColor4D (1.0f, 0.7f ,0.9f, 1.0f), //dxf color code 221 + aiColor4D (0.7f, 0.0f ,0.6f, 1.0f), //dxf color code 222 + aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 223 + aiColor4D (0.5f, 0.0f ,0.4f, 1.0f), //dxf color code 224 + aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 225 + aiColor4D (0.4f, 0.0f ,0.3f, 1.0f), //dxf color code 226 + aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 227 + aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 228 + aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 229 + aiColor4D (1.0f, 0.0f ,0.5f, 1.0f), //dxf color code 230 + aiColor4D (1.0f, 0.7f ,0.8f, 1.0f), //dxf color code 231 + aiColor4D (0.7f, 0.0f ,0.4f, 1.0f), //dxf color code 232 + aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 233 + aiColor4D (0.5f, 0.0f ,0.3f, 1.0f), //dxf color code 234 + aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 235 + aiColor4D (0.4f, 0.0f ,0.2f, 1.0f), //dxf color code 236 + aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 237 + aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 238 + aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 239 + aiColor4D (1.0f, 0.0f ,0.2f, 1.0f), //dxf color code 240 + aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 241 + aiColor4D (0.7f, 0.0f ,0.2f, 1.0f), //dxf color code 242 + aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 243 + aiColor4D (0.5f, 0.0f ,0.1f, 1.0f), //dxf color code 244 + aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 245 + aiColor4D (0.4f, 0.0f ,0.1f, 1.0f), //dxf color code 246 + aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 247 + aiColor4D (0.3f, 0.0f ,0.1f, 1.0f), //dxf color code 248 + aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 249 + aiColor4D (0.2f, 0.2f ,0.2f, 1.0f), //dxf color code 250 + aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 251 + aiColor4D (0.4f, 0.4f ,0.4f, 1.0f), //dxf color code 252 + aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 253 + aiColor4D (0.7f, 0.7f ,0.7f, 1.0f), //dxf color code 254 + aiColor4D (1.0f, 1.0f ,1.0f, 1.0f) //dxf color code 255 }; #define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0])) @@ -372,8 +613,12 @@ void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& bloc // XXX order aiMatrix4x4 trafo, tmp; aiMatrix4x4::Translation(-bl_src.base,trafo); - trafo *= aiMatrix4x4::Scaling(insert.scale,tmp); + //Need to translate position before scaling the insert + //otherwise the position ends up being the position*scaling + //STH 2024.01.17 trafo *= aiMatrix4x4::Translation(insert.pos,tmp); + trafo *= aiMatrix4x4::Scaling(insert.scale,tmp); + //trafo *= aiMatrix4x4::Translation(insert.pos,tmp); // XXX rotation currently ignored - I didn't find an appropriate sample model. if (insert.angle != 0.f) { diff --git a/code/AssetLib/DXF/DXFLoader.h b/code/AssetLib/DXF/DXFLoader.h index 89a0b79c2..9230bccbd 100644 --- a/code/AssetLib/DXF/DXFLoader.h +++ b/code/AssetLib/DXF/DXFLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXAnimation.cpp b/code/AssetLib/FBX/FBXAnimation.cpp index af92ebe51..fdde37f24 100644 --- a/code/AssetLib/FBX/FBXAnimation.cpp +++ b/code/AssetLib/FBX/FBXAnimation.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp index 55424a6a8..b828090e5 100644 --- a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp +++ b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXCommon.h b/code/AssetLib/FBX/FBXCommon.h index c3d715892..7e0fb2553 100644 --- a/code/AssetLib/FBX/FBXCommon.h +++ b/code/AssetLib/FBX/FBXCommon.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXCompileConfig.h b/code/AssetLib/FBX/FBXCompileConfig.h index 927a3c5f6..9885ca346 100644 --- a/code/AssetLib/FBX/FBXCompileConfig.h +++ b/code/AssetLib/FBX/FBXCompileConfig.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 62ada774f..cc73756fb 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -76,6 +76,53 @@ using namespace Util; #define CONVERT_FBX_TIME(time) static_cast(time) / 46186158000LL +static void correctRootTransform(const aiScene *scene) { + if (scene == nullptr) { + return; + } + + if (scene->mMetaData == nullptr) { + return; + } + + int32_t UpAxis = 1, UpAxisSign = 1, FrontAxis = 2, FrontAxisSign = 1, CoordAxis = 0, CoordAxisSign = 1; + double UnitScaleFactor = 1.0; + for (unsigned MetadataIndex = 0; MetadataIndex < scene->mMetaData->mNumProperties; ++MetadataIndex) { + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxis") == 0) { + scene->mMetaData->Get(MetadataIndex, UpAxis); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxisSign") == 0) { + scene->mMetaData->Get(MetadataIndex, UpAxisSign); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxis") == 0) { + scene->mMetaData->Get(MetadataIndex, FrontAxis); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxisSign") == 0) { + scene->mMetaData->Get(MetadataIndex, FrontAxisSign); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxis") == 0) { + scene->mMetaData->Get(MetadataIndex, CoordAxis); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxisSign") == 0) { + scene->mMetaData->Get(MetadataIndex, CoordAxisSign); + } + if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UnitScaleFactor") == 0) { + scene->mMetaData->Get(MetadataIndex, UnitScaleFactor); + } + } + + aiVector3D upVec, forwardVec, rightVec; + upVec[UpAxis] = UpAxisSign * static_cast(UnitScaleFactor); + forwardVec[FrontAxis] = FrontAxisSign * static_cast(UnitScaleFactor); + rightVec[CoordAxis] = CoordAxisSign * (float)UnitScaleFactor; + + aiMatrix4x4 mat(rightVec.x, rightVec.y, rightVec.z, 0.0f, + upVec.x, upVec.y, upVec.z, 0.0f, + forwardVec.x, forwardVec.y, forwardVec.z, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + scene->mRootNode->mTransformation *= mat; +} + FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) : defaultMaterialIndex(), mMeshes(), @@ -133,6 +180,8 @@ FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBo // need not contain geometry (i.e. camera animations, raw armatures). if (out->mNumMeshes == 0) { out->mFlags |= AI_SCENE_FLAGS_INCOMPLETE; + } else { + correctRootTransform(mSceneOut); } } @@ -3239,9 +3288,9 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, } if (keyframeLists[TransformationComp_Rotation].size() > 0) { - InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], AI_DEG_TO_RAD(defRotation), maxTime, minTime, rotOrder); + InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder); } else { - aiQuaternion defQuat = EulerToQuaternion(AI_DEG_TO_RAD(defRotation), rotOrder); + aiQuaternion defQuat = EulerToQuaternion(defRotation, rotOrder); for (size_t i = 0; i < keyCount; ++i) { outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outRotations[i].mValue = defQuat; @@ -3263,7 +3312,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, const aiVector3D& preRotation = PropertyGet(props, "PreRotation", ok); if (ok && preRotation.SquareLength() > zero_epsilon) { - const aiQuaternion preQuat = EulerToQuaternion(AI_DEG_TO_RAD(preRotation), Model::RotOrder_EulerXYZ); + const aiQuaternion preQuat = EulerToQuaternion(preRotation, Model::RotOrder_EulerXYZ); for (size_t i = 0; i < keyCount; ++i) { outRotations[i].mValue = preQuat * outRotations[i].mValue; } @@ -3271,7 +3320,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, const aiVector3D& postRotation = PropertyGet(props, "PostRotation", ok); if (ok && postRotation.SquareLength() > zero_epsilon) { - const aiQuaternion postQuat = EulerToQuaternion(AI_DEG_TO_RAD(postRotation), Model::RotOrder_EulerXYZ); + const aiQuaternion postQuat = EulerToQuaternion(postRotation, Model::RotOrder_EulerXYZ); for (size_t i = 0; i < keyCount; ++i) { outRotations[i].mValue = outRotations[i].mValue * postQuat; } diff --git a/code/AssetLib/FBX/FBXConverter.h b/code/AssetLib/FBX/FBXConverter.h index 41acb6ffe..73dc9e5a7 100644 --- a/code/AssetLib/FBX/FBXConverter.h +++ b/code/AssetLib/FBX/FBXConverter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXDeformer.cpp b/code/AssetLib/FBX/FBXDeformer.cpp index 8f944527a..582042360 100644 --- a/code/AssetLib/FBX/FBXDeformer.cpp +++ b/code/AssetLib/FBX/FBXDeformer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXDocument.cpp b/code/AssetLib/FBX/FBXDocument.cpp index ee4a6632b..3fb0964c4 100644 --- a/code/AssetLib/FBX/FBXDocument.cpp +++ b/code/AssetLib/FBX/FBXDocument.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index 3af757a19..a103321c0 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXDocumentUtil.cpp b/code/AssetLib/FBX/FBXDocumentUtil.cpp index c41eb2747..64105f351 100644 --- a/code/AssetLib/FBX/FBXDocumentUtil.cpp +++ b/code/AssetLib/FBX/FBXDocumentUtil.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXExportNode.cpp b/code/AssetLib/FBX/FBXExportNode.cpp index 21e591425..ae9586968 100644 --- a/code/AssetLib/FBX/FBXExportNode.cpp +++ b/code/AssetLib/FBX/FBXExportNode.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXExportNode.h b/code/AssetLib/FBX/FBXExportNode.h index 99644b216..7661ab1be 100644 --- a/code/AssetLib/FBX/FBXExportNode.h +++ b/code/AssetLib/FBX/FBXExportNode.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXExportProperty.cpp b/code/AssetLib/FBX/FBXExportProperty.cpp index 3216d7d85..5fbe84fa7 100644 --- a/code/AssetLib/FBX/FBXExportProperty.cpp +++ b/code/AssetLib/FBX/FBXExportProperty.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXExportProperty.h b/code/AssetLib/FBX/FBXExportProperty.h index 26d0cf223..93f8cfbe0 100644 --- a/code/AssetLib/FBX/FBXExportProperty.h +++ b/code/AssetLib/FBX/FBXExportProperty.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index 28299544a..ae210eb1a 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -69,6 +69,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // RESOURCES: // https://code.blender.org/2013/08/fbx-binary-file-format-specification/ @@ -1062,7 +1063,7 @@ aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene) } inline int64_t to_ktime(double ticks, const aiAnimation* anim) { - if (anim->mTicksPerSecond <= 0) { + if (FP_ZERO == std::fpclassify(anim->mTicksPerSecond)) { return static_cast(ticks) * FBX::SECOND; } return (static_cast(ticks / anim->mTicksPerSecond)) * FBX::SECOND; @@ -1088,6 +1089,8 @@ void FBXExporter::WriteObjects () bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true); std::vector> vVertexIndice;//save vertex_indices as it is needed later + const auto bTransparencyFactorReferencedToOpacity = mProperties->GetPropertyBool(AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY, false); + // geometry (aiMesh) mesh_uids.clear(); indent = 1; @@ -1444,13 +1447,21 @@ void FBXExporter::WriteObjects () // "TransparentColor" / "TransparencyFactor"... // thanks FBX, for your insightful interpretation of consistency p.AddP70colorA("TransparentColor", c.r, c.g, c.b); - // TransparencyFactor defaults to 0.0, so set it to 1.0. - // note: Maya always sets this to 1.0, - // so we can't use it sensibly as "Opacity". - // In stead we rely on the legacy "Opacity" value, below. - // Blender also relies on "Opacity" not "TransparencyFactor", - // probably for a similar reason. - p.AddP70numberA("TransparencyFactor", 1.0); + + if (!bTransparencyFactorReferencedToOpacity) { + // TransparencyFactor defaults to 0.0, so set it to 1.0. + // note: Maya always sets this to 1.0, + // so we can't use it sensibly as "Opacity". + // In stead we rely on the legacy "Opacity" value, below. + // Blender also relies on "Opacity" not "TransparencyFactor", + // probably for a similar reason. + p.AddP70numberA("TransparencyFactor", 1.0); + } + } + if (bTransparencyFactorReferencedToOpacity) { + if (m->Get(AI_MATKEY_OPACITY, f) == aiReturn_SUCCESS) { + p.AddP70numberA("TransparencyFactor", 1.0 - f); + } } if (m->Get(AI_MATKEY_COLOR_REFLECTIVE, c) == aiReturn_SUCCESS) { p.AddP70colorA("ReflectionColor", c.r, c.g, c.b); @@ -1748,7 +1759,7 @@ void FBXExporter::WriteObjects () int64_t blendshape_uid = generate_uid(); mesh_uids.push_back(blendshape_uid); bsnode.AddProperty(blendshape_uid); - bsnode.AddProperty(blendshape_name + FBX::SEPARATOR + "Blendshape"); + bsnode.AddProperty(blendshape_name + FBX::SEPARATOR + "Geometry"); bsnode.AddProperty("Shape"); bsnode.AddChild("Version", int32_t(100)); bsnode.Begin(outstream, binary, indent); @@ -1807,7 +1818,7 @@ void FBXExporter::WriteObjects () p.AddP70numberA("DeformPercent", 0.0); sdnode.AddChild(p); // TODO: Normally just one weight per channel, adding stub for later development - std::vectorfFullWeights; + std::vectorfFullWeights; fFullWeights.push_back(100.); sdnode.AddChild("FullWeights", fFullWeights); sdnode.Dump(outstream, binary, indent); diff --git a/code/AssetLib/FBX/FBXExporter.h b/code/AssetLib/FBX/FBXExporter.h index 659f9368a..df9029196 100644 --- a/code/AssetLib/FBX/FBXExporter.h +++ b/code/AssetLib/FBX/FBXExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXImportSettings.h b/code/AssetLib/FBX/FBXImportSettings.h index 698901180..74290f7e0 100644 --- a/code/AssetLib/FBX/FBXImportSettings.h +++ b/code/AssetLib/FBX/FBXImportSettings.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index afd4b11c1..3a8fb8b8a 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXImporter.h b/code/AssetLib/FBX/FBXImporter.h index d12b45969..8e8a7db78 100644 --- a/code/AssetLib/FBX/FBXImporter.h +++ b/code/AssetLib/FBX/FBXImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index bcb9bc42a..3872a4b38 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index 8c6499a91..3b706727a 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXMeshGeometry.h b/code/AssetLib/FBX/FBXMeshGeometry.h index 3d67ec567..980d1a334 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.h +++ b/code/AssetLib/FBX/FBXMeshGeometry.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXModel.cpp b/code/AssetLib/FBX/FBXModel.cpp index d731d2e29..c108dd78b 100644 --- a/code/AssetLib/FBX/FBXModel.cpp +++ b/code/AssetLib/FBX/FBXModel.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXNodeAttribute.cpp b/code/AssetLib/FBX/FBXNodeAttribute.cpp index 34fcdcf77..1e7dfa8c0 100644 --- a/code/AssetLib/FBX/FBXNodeAttribute.cpp +++ b/code/AssetLib/FBX/FBXNodeAttribute.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index 7baa7ed39..d0482e067 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXParser.h b/code/AssetLib/FBX/FBXParser.h index 5f231738d..63dbb023b 100644 --- a/code/AssetLib/FBX/FBXParser.h +++ b/code/AssetLib/FBX/FBXParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXProperties.cpp b/code/AssetLib/FBX/FBXProperties.cpp index 1c050617d..df39098fa 100644 --- a/code/AssetLib/FBX/FBXProperties.cpp +++ b/code/AssetLib/FBX/FBXProperties.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXProperties.h b/code/AssetLib/FBX/FBXProperties.h index 18816117a..4799b8056 100644 --- a/code/AssetLib/FBX/FBXProperties.h +++ b/code/AssetLib/FBX/FBXProperties.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXTokenizer.cpp b/code/AssetLib/FBX/FBXTokenizer.cpp index 45d5e7750..007e08d46 100644 --- a/code/AssetLib/FBX/FBXTokenizer.cpp +++ b/code/AssetLib/FBX/FBXTokenizer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXTokenizer.h b/code/AssetLib/FBX/FBXTokenizer.h index 05a0725bd..dedfab66a 100644 --- a/code/AssetLib/FBX/FBXTokenizer.h +++ b/code/AssetLib/FBX/FBXTokenizer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXUtil.cpp b/code/AssetLib/FBX/FBXUtil.cpp index e2903c536..a787a9f1d 100644 --- a/code/AssetLib/FBX/FBXUtil.cpp +++ b/code/AssetLib/FBX/FBXUtil.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/FBX/FBXUtil.h b/code/AssetLib/FBX/FBXUtil.h index 4674a5054..eb9ae14ed 100644 --- a/code/AssetLib/FBX/FBXUtil.h +++ b/code/AssetLib/FBX/FBXUtil.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/HMP/HMPFileData.h b/code/AssetLib/HMP/HMPFileData.h index b297136ba..5f6ca4f55 100644 --- a/code/AssetLib/HMP/HMPFileData.h +++ b/code/AssetLib/HMP/HMPFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -49,7 +49,7 @@ namespace HMP { #include #include -// to make it easier for us, we test the magic word against both "endianesses" +// to make it easier for us, we test the magic word against both "endiannesses" #define AI_HMP_MAGIC_NUMBER_BE_4 AI_MAKE_MAGIC("HMP4") #define AI_HMP_MAGIC_NUMBER_LE_4 AI_MAKE_MAGIC("4PMH") diff --git a/code/AssetLib/HMP/HMPLoader.cpp b/code/AssetLib/HMP/HMPLoader.cpp index 5ccb2b474..30931a920 100644 --- a/code/AssetLib/HMP/HMPLoader.cpp +++ b/code/AssetLib/HMP/HMPLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/HMP/HMPLoader.h b/code/AssetLib/HMP/HMPLoader.h index 4d5f5f22f..e665b8d18 100644 --- a/code/AssetLib/HMP/HMPLoader.h +++ b/code/AssetLib/HMP/HMPLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/HMP/HalfLifeFileData.h b/code/AssetLib/HMP/HalfLifeFileData.h index f47862b7a..687b6108c 100644 --- a/code/AssetLib/HMP/HalfLifeFileData.h +++ b/code/AssetLib/HMP/HalfLifeFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCBoolean.cpp b/code/AssetLib/IFC/IFCBoolean.cpp index f4d53990e..559bd7b2f 100644 --- a/code/AssetLib/IFC/IFCBoolean.cpp +++ b/code/AssetLib/IFC/IFCBoolean.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/IFC/IFCCurve.cpp b/code/AssetLib/IFC/IFCCurve.cpp index 44165befc..847803dfa 100644 --- a/code/AssetLib/IFC/IFCCurve.cpp +++ b/code/AssetLib/IFC/IFCCurve.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCGeometry.cpp b/code/AssetLib/IFC/IFCGeometry.cpp index 83afd2b59..d488b2376 100644 --- a/code/AssetLib/IFC/IFCGeometry.cpp +++ b/code/AssetLib/IFC/IFCGeometry.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/IFC/IFCLoader.cpp b/code/AssetLib/IFC/IFCLoader.cpp index c919d9982..9414697df 100644 --- a/code/AssetLib/IFC/IFCLoader.cpp +++ b/code/AssetLib/IFC/IFCLoader.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCLoader.h b/code/AssetLib/IFC/IFCLoader.h index 9651b633a..d518650b7 100644 --- a/code/AssetLib/IFC/IFCLoader.h +++ b/code/AssetLib/IFC/IFCLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCMaterial.cpp b/code/AssetLib/IFC/IFCMaterial.cpp index 0b7b83e7c..fd4003a67 100644 --- a/code/AssetLib/IFC/IFCMaterial.cpp +++ b/code/AssetLib/IFC/IFCMaterial.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCOpenings.cpp b/code/AssetLib/IFC/IFCOpenings.cpp index c47446dda..1d37dd8ef 100644 --- a/code/AssetLib/IFC/IFCOpenings.cpp +++ b/code/AssetLib/IFC/IFCOpenings.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/IFC/IFCProfile.cpp b/code/AssetLib/IFC/IFCProfile.cpp index 0e4670560..72a96c29b 100644 --- a/code/AssetLib/IFC/IFCProfile.cpp +++ b/code/AssetLib/IFC/IFCProfile.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCReaderGen1_2x3.cpp b/code/AssetLib/IFC/IFCReaderGen1_2x3.cpp index 73e3c91d8..c625f1daf 100644 --- a/code/AssetLib/IFC/IFCReaderGen1_2x3.cpp +++ b/code/AssetLib/IFC/IFCReaderGen1_2x3.cpp @@ -2725,6 +2725,10 @@ template <> size_t GenericFill(const DB& db, const L do { // convert the 'CompositionType' argument std::shared_ptr arg = params[base++]; if (dynamic_cast(&*arg)) { in->ObjectHelper::aux_is_derived[1]=true; break; } + if (dynamic_cast(&*arg)) { + // Consider assigning the default value as in->CompositionType = "ELEMENT". + break; + } try { GenericConvert( in->CompositionType, arg, db ); break; } catch (const TypeError& t) { throw TypeError(t.what() + std::string(" - expected argument 8 to IfcSpatialStructureElement to be a `IfcElementCompositionEnum`")); } } while (false); diff --git a/code/AssetLib/IFC/IFCUtil.cpp b/code/AssetLib/IFC/IFCUtil.cpp index 27f3141c8..3977e22b5 100644 --- a/code/AssetLib/IFC/IFCUtil.cpp +++ b/code/AssetLib/IFC/IFCUtil.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/IFC/IFCUtil.h b/code/AssetLib/IFC/IFCUtil.h index f9063ce22..885bcb48f 100644 --- a/code/AssetLib/IFC/IFCUtil.h +++ b/code/AssetLib/IFC/IFCUtil.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Irr/IRRLoader.cpp b/code/AssetLib/Irr/IRRLoader.cpp index 99e053892..f41a2543d 100644 --- a/code/AssetLib/Irr/IRRLoader.cpp +++ b/code/AssetLib/Irr/IRRLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -1234,7 +1234,10 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // Parse the XML // Find the scene root from document root. const pugi::xml_node &sceneRoot = documentRoot.child("irr_scene"); - if (!sceneRoot) throw new DeadlyImportError("IRR: not found in file"); + if (!sceneRoot) { + delete root; + throw new DeadlyImportError("IRR: not found in file"); + } for (pugi::xml_node &child : sceneRoot.children()) { // XML elements are either nodes, animators, attributes, or materials if (!ASSIMP_stricmp(child.name(), "node")) { diff --git a/code/AssetLib/Irr/IRRLoader.h b/code/AssetLib/Irr/IRRLoader.h index 72ad5d35e..2a8bfd562 100644 --- a/code/AssetLib/Irr/IRRLoader.h +++ b/code/AssetLib/Irr/IRRLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Irr/IRRMeshLoader.cpp b/code/AssetLib/Irr/IRRMeshLoader.cpp index b35a95c12..4a2f70882 100644 --- a/code/AssetLib/Irr/IRRMeshLoader.cpp +++ b/code/AssetLib/Irr/IRRMeshLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -69,14 +69,6 @@ static constexpr aiImporterDesc desc = { "xml irrmesh" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -IRRMeshImporter::IRRMeshImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -IRRMeshImporter::~IRRMeshImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -116,8 +108,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, std::unique_ptr file(pIOHandler->Open(pFile)); // Check whether we can read from the file - if (file == nullptr) + if (file == nullptr) { throw DeadlyImportError("Failed to open IRRMESH file ", pFile); + } // Construct the irrXML parser XmlParser parser; @@ -148,13 +141,11 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, // int vertexFormat = 0; // 0 = normal; 1 = 2 tcoords, 2 = tangents bool useColors = false; - /* - ** irrmesh files have a top level owning multiple nodes. - ** Each contains , , and - ** tags here directly owns the material data specs - ** are a vertex per line, contains position, UV1 coords, maybe UV2, normal, tangent, bitangent - ** is ignored, I think assimp recalculates those? - */ + // irrmesh files have a top level owning multiple nodes. + // Each contains , , and + // tags here directly owns the material data specs + // are a vertex per line, contains position, UV1 coords, maybe UV2, normal, tangent, bitangent + // is ignored, I think assimp recalculates those? // Parse the XML file pugi::xml_node const &meshNode = root.child("mesh"); @@ -201,7 +192,6 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, // This is possible ... remove the mesh from the list and skip further reading ASSIMP_LOG_WARN("IRRMESH: Found mesh with zero vertices"); releaseMaterial(&curMat); - // releaseMesh(&curMesh); continue; // Bail out early }; @@ -250,7 +240,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, }; // We know what format buffer is, collect numbers - ParseBufferVertices(verticesNode.text().get(), vertexFormat, + std::string v = verticesNode.text().get(); + const char *end = v.c_str() + v.size(); + ParseBufferVertices(v.c_str(), end, vertexFormat, curVertices, curNormals, curTangents, curBitangents, curUVs, curUV2s, curColors, useColors); @@ -329,8 +321,10 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, // NOTE this might explode for UTF-16 and wchars const char *sz = indicesNode.text().get(); + const char *end = sz + std::strlen(sz); + // For each index loop over aiMesh faces - while (SkipSpacesAndLineEnd(&sz)) { + while (SkipSpacesAndLineEnd(&sz, end)) { if (curFace >= faceEnd) { ASSIMP_LOG_ERROR("IRRMESH: Too many indices"); break; @@ -354,12 +348,18 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, // Copy over data to aiMesh *pcV++ = curVertices[idx]; - if (pcN) *pcN++ = curNormals[idx]; - if (pcT) *pcT++ = curTangents[idx]; - if (pcB) *pcB++ = curBitangents[idx]; - if (pcC0) *pcC0++ = curColors[idx]; - if (pcT0) *pcT0++ = curUVs[idx]; - if (pcT1) *pcT1++ = curUV2s[idx]; + if (pcN) + *pcN++ = curNormals[idx]; + if (pcT) + *pcT++ = curTangents[idx]; + if (pcB) + *pcB++ = curBitangents[idx]; + if (pcC0) + *pcC0++ = curColors[idx]; + if (pcT0) + *pcT0++ = curUVs[idx]; + if (pcT1) + *pcT1++ = curUV2s[idx]; // start new face if (++curIdx == 3) { @@ -368,8 +368,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, } } // We should be at the end of mFaces - if (curFace != faceEnd) + if (curFace != faceEnd) { ASSIMP_LOG_ERROR("IRRMESH: Not enough indices"); + } } // Finish processing the mesh - do some small material workarounds @@ -379,8 +380,7 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, aiMaterial *mat = (aiMaterial *)curMat; mat->AddProperty(&curColors[0].a, 1, AI_MATKEY_OPACITY); } - // textMeaning = 2; - + // end of previous buffer. A material and a mesh should be there if (!curMat || !curMesh) { ASSIMP_LOG_ERROR("IRRMESH: A buffer must contain a mesh and a material"); @@ -421,37 +421,37 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, }; } -void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFormat, +void IRRMeshImporter::ParseBufferVertices(const char *sz, const char *end, VertexFormat vertexFormat, std::vector &vertices, std::vector &normals, std::vector &tangents, std::vector &bitangents, std::vector &UVs, std::vector &UV2s, std::vector &colors, bool &useColors) { // read vertices do { - SkipSpacesAndLineEnd(&sz); + SkipSpacesAndLineEnd(&sz, end); aiVector3D temp; aiColor4D c; // Read the vertex position sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.z); - SkipSpaces(&sz); + SkipSpaces(&sz, end); vertices.push_back(temp); // Read the vertex normals sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.z); - SkipSpaces(&sz); + SkipSpaces(&sz, end); normals.push_back(temp); // read the vertex colors @@ -463,14 +463,14 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor useColors = true; colors.push_back(c); - SkipSpaces(&sz); + SkipSpaces(&sz, end); // read the first UV coordinate set sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); - SkipSpaces(&sz); + SkipSpaces(&sz, end); temp.z = 0.f; temp.y = 1.f - temp.y; // DX to OGL UVs.push_back(temp); @@ -480,7 +480,7 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor // read the (optional) second UV coordinate set if (vertexFormat == VertexFormat::t2coord) { sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); temp.y = 1.f - temp.y; // DX to OGL @@ -490,33 +490,32 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor else if (vertexFormat == VertexFormat::tangent) { // tangents sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.z); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); - SkipSpaces(&sz); + SkipSpaces(&sz, end); temp.y *= -1.0f; tangents.push_back(temp); // bitangents sz = fast_atoreal_move(sz, (float &)temp.x); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.z); - SkipSpaces(&sz); + SkipSpaces(&sz, end); sz = fast_atoreal_move(sz, (float &)temp.y); - SkipSpaces(&sz); + SkipSpaces(&sz, end); temp.y *= -1.0f; bitangents.push_back(temp); } - } while (SkipLine(&sz)); - /* IMPORTANT: We assume that each vertex is specified in one - line. So we can skip the rest of the line - unknown vertex - elements are ignored. - */ + } while (SkipLine(&sz, end)); + // IMPORTANT: We assume that each vertex is specified in one + // line. So we can skip the rest of the line - unknown vertex + // elements are ignored. } #endif // !! ASSIMP_BUILD_NO_IRRMESH_IMPORTER diff --git a/code/AssetLib/Irr/IRRMeshLoader.h b/code/AssetLib/Irr/IRRMeshLoader.h index 620e40dba..4ab3615ee 100644 --- a/code/AssetLib/Irr/IRRMeshLoader.h +++ b/code/AssetLib/Irr/IRRMeshLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -62,8 +62,11 @@ namespace Assimp { */ class IRRMeshImporter : public BaseImporter, public IrrlichtBase { public: - IRRMeshImporter(); - ~IRRMeshImporter() override; + /// @brief The class constructor. + IRRMeshImporter() = default; + + /// @brief The class destructor. + ~IRRMeshImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. @@ -93,7 +96,7 @@ private: tangent = 2, // "tangents" - standard + tangents and bitangents }; - void ParseBufferVertices(const char *sz, VertexFormat vertexFormat, + void ParseBufferVertices(const char *sz, const char *end, VertexFormat vertexFormat, std::vector &vertices, std::vector &normals, std::vector &tangents, std::vector &bitangents, std::vector &UVs, std::vector &UV2s, diff --git a/code/AssetLib/Irr/IRRShared.cpp b/code/AssetLib/Irr/IRRShared.cpp index a47aeccba..20d56bb02 100644 --- a/code/AssetLib/Irr/IRRShared.cpp +++ b/code/AssetLib/Irr/IRRShared.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -135,21 +135,23 @@ void IrrlichtBase::ReadVectorProperty(VectorProperty &out, pugi::xml_node& vecto } else if (!ASSIMP_stricmp(attrib.name(), "value")) { // three floats, separated with commas const char *ptr = attrib.value(); + size_t len = std::strlen(ptr); + const char *end = ptr + len; - SkipSpaces(&ptr); + SkipSpaces(&ptr, end); ptr = fast_atoreal_move(ptr, (float &)out.value.x); - SkipSpaces(&ptr); + SkipSpaces(&ptr, end); if (',' != *ptr) { ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition"); } else { - SkipSpaces(ptr + 1, &ptr); + SkipSpaces(ptr + 1, &ptr, end); } ptr = fast_atoreal_move(ptr, (float &)out.value.y); - SkipSpaces(&ptr); + SkipSpaces(&ptr, end); if (',' != *ptr) { ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition"); } else { - SkipSpaces(ptr + 1, &ptr); + SkipSpaces(ptr + 1, &ptr, end); } ptr = fast_atoreal_move(ptr, (float &)out.value.z); } diff --git a/code/AssetLib/LWO/LWOAnimation.cpp b/code/AssetLib/LWO/LWOAnimation.cpp index 8dda4586f..5b9c6882e 100644 --- a/code/AssetLib/LWO/LWOAnimation.cpp +++ b/code/AssetLib/LWO/LWOAnimation.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/LWO/LWOAnimation.h b/code/AssetLib/LWO/LWOAnimation.h index 1e419d461..9daa7009c 100644 --- a/code/AssetLib/LWO/LWOAnimation.h +++ b/code/AssetLib/LWO/LWOAnimation.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/LWO/LWOBLoader.cpp b/code/AssetLib/LWO/LWOBLoader.cpp index 4a9792b79..b5c14f158 100644 --- a/code/AssetLib/LWO/LWOBLoader.cpp +++ b/code/AssetLib/LWO/LWOBLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team @@ -152,7 +152,7 @@ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& face } // ------------------------------------------------------------------------------------------------ -void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it, +void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator &it, LE_NCONST uint16_t*& cursor, const uint16_t* const end, unsigned int max) { diff --git a/code/AssetLib/LWO/LWOFileData.h b/code/AssetLib/LWO/LWOFileData.h index 656dd4529..c81111251 100644 --- a/code/AssetLib/LWO/LWOFileData.h +++ b/code/AssetLib/LWO/LWOFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/LWO/LWOLoader.cpp b/code/AssetLib/LWO/LWOLoader.cpp index 7e93b65f8..025ca7408 100644 --- a/code/AssetLib/LWO/LWOLoader.cpp +++ b/code/AssetLib/LWO/LWOLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/LWO/LWOLoader.h b/code/AssetLib/LWO/LWOLoader.h index 9e116a3cc..3f81ff449 100644 --- a/code/AssetLib/LWO/LWOLoader.h +++ b/code/AssetLib/LWO/LWOLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/LWO/LWOMaterial.cpp b/code/AssetLib/LWO/LWOMaterial.cpp index 8d83dfb67..1d7d137e1 100644 --- a/code/AssetLib/LWO/LWOMaterial.cpp +++ b/code/AssetLib/LWO/LWOMaterial.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/AssetLib/LWS/LWSLoader.cpp b/code/AssetLib/LWS/LWSLoader.cpp index dec834495..4c3a44785 100644 --- a/code/AssetLib/LWS/LWSLoader.cpp +++ b/code/AssetLib/LWS/LWSLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -78,14 +78,14 @@ static constexpr aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Recursive parsing of LWS files -void LWS::Element::Parse(const char *&buffer) { - for (; SkipSpacesAndLineEnd(&buffer); SkipLine(&buffer)) { +void LWS::Element::Parse(const char *&buffer, const char *end) { + for (; SkipSpacesAndLineEnd(&buffer, end); SkipLine(&buffer, end)) { // begin of a new element with children bool sub = false; if (*buffer == '{') { ++buffer; - SkipSpaces(&buffer); + SkipSpaces(&buffer, end); sub = true; } else if (*buffer == '}') return; @@ -98,16 +98,15 @@ void LWS::Element::Parse(const char *&buffer) { while (!IsSpaceOrNewLine(*buffer)) ++buffer; children.back().tokens[0] = std::string(cur, (size_t)(buffer - cur)); - SkipSpaces(&buffer); + SkipSpaces(&buffer, end); if (children.back().tokens[0] == "Plugin") { ASSIMP_LOG_VERBOSE_DEBUG("LWS: Skipping over plugin-specific data"); // strange stuff inside Plugin/Endplugin blocks. Needn't // follow LWS syntax, so we skip over it - for (; SkipSpacesAndLineEnd(&buffer); SkipLine(&buffer)) { + for (; SkipSpacesAndLineEnd(&buffer, end); SkipLine(&buffer, end)) { if (!::strncmp(buffer, "EndPlugin", 9)) { - //SkipLine(&buffer); break; } } @@ -122,7 +121,7 @@ void LWS::Element::Parse(const char *&buffer) { // parse more elements recursively if (sub) { - children.back().Parse(buffer); + children.back().Parse(buffer, end); } } } @@ -155,6 +154,8 @@ const aiImporterDesc *LWSImporter::GetInfo() const { return &desc; } +static constexpr int MagicHackNo = 150392; + // ------------------------------------------------------------------------------------------------ // Setup configuration properties void LWSImporter::SetupProperties(const Importer *pImp) { @@ -163,11 +164,11 @@ void LWSImporter::SetupProperties(const Importer *pImp) { // AI_CONFIG_IMPORT_LWS_ANIM_START first = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_LWS_ANIM_START, - 150392 /* magic hack */); + MagicHackNo /* magic hack */); // AI_CONFIG_IMPORT_LWS_ANIM_END last = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_LWS_ANIM_END, - 150392 /* magic hack */); + MagicHackNo /* magic hack */); if (last < first) { std::swap(last, first); @@ -191,15 +192,16 @@ void LWSImporter::ReadEnvelope(const LWS::Element &dad, LWO::Envelope &fill) { for (++it; it != dad.children.end(); ++it) { const char *c = (*it).tokens[1].c_str(); + const char *end = c + (*it).tokens[1].size(); if ((*it).tokens[0] == "Key") { fill.keys.emplace_back(); LWO::Key &key = fill.keys.back(); float f; - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, key.value); - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, f); key.time = f; @@ -231,13 +233,13 @@ void LWSImporter::ReadEnvelope(const LWS::Element &dad, LWO::Envelope &fill) { ASSIMP_LOG_ERROR("LWS: Unknown span type"); } for (unsigned int i = 0; i < num; ++i) { - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, key.params[i]); } } else if ((*it).tokens[0] == "Behaviors") { - SkipSpaces(&c); + SkipSpaces(&c, end); fill.pre = (LWO::PrePostBehaviour)strtoul10(c, &c); - SkipSpaces(&c); + SkipSpaces(&c, end); fill.post = (LWO::PrePostBehaviour)strtoul10(c, &c); } } @@ -245,47 +247,45 @@ void LWSImporter::ReadEnvelope(const LWS::Element &dad, LWO::Envelope &fill) { // ------------------------------------------------------------------------------------------------ // Read animation channels in the old LightWave animation format -void LWSImporter::ReadEnvelope_Old( - std::list::const_iterator &it, - const std::list::const_iterator &end, - LWS::NodeDesc &nodes, - unsigned int /*version*/) { - unsigned int num, sub_num; - if (++it == end) goto unexpected_end; +void LWSImporter::ReadEnvelope_Old(std::list::const_iterator &it,const std::list::const_iterator &endIt, + LWS::NodeDesc &nodes, unsigned int) { + if (++it == endIt) { + ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion"); + return; + } - num = strtoul10((*it).tokens[0].c_str()); + const unsigned int num = strtoul10((*it).tokens[0].c_str()); for (unsigned int i = 0; i < num; ++i) { - nodes.channels.emplace_back(); LWO::Envelope &envl = nodes.channels.back(); envl.index = i; envl.type = (LWO::EnvelopeType)(i + 1); - if (++it == end) { - goto unexpected_end; + if (++it == endIt) { + ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion"); + return; } - sub_num = strtoul10((*it).tokens[0].c_str()); - + + const unsigned int sub_num = strtoul10((*it).tokens[0].c_str()); for (unsigned int n = 0; n < sub_num; ++n) { - - if (++it == end) goto unexpected_end; + if (++it == endIt) { + ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion"); + return; + } // parse value and time, skip the rest for the moment. LWO::Key key; const char *c = fast_atoreal_move((*it).tokens[0].c_str(), key.value); - SkipSpaces(&c); + const char *end = c + (*it).tokens[0].size(); + SkipSpaces(&c, end); float f; fast_atoreal_move((*it).tokens[0].c_str(), f); key.time = f; - envl.keys.push_back(key); + envl.keys.emplace_back(key); } } - return; - -unexpected_end: - ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion"); } // ------------------------------------------------------------------------------------------------ @@ -296,7 +296,6 @@ void LWSImporter::SetupNodeName(aiNode *nd, LWS::NodeDesc &src) { // the name depends on the type. We break LWS's strange naming convention // and return human-readable, but still machine-parsable and unique, strings. if (src.type == LWS::NodeDesc::OBJECT) { - if (src.path.length()) { std::string::size_type s = src.path.find_last_of("\\/"); if (s == std::string::npos) { @@ -501,7 +500,8 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // Parse the file structure LWS::Element root; const char *dummy = &mBuffer[0]; - root.Parse(dummy); + const char *dummyEnd = dummy + mBuffer.size(); + root.Parse(dummy, dummyEnd); // Construct a Batch-importer to read more files recursively BatchLoader batch(pIOHandler); @@ -540,6 +540,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // Now read all elements in a very straightforward manner for (; it != root.children.end(); ++it) { const char *c = (*it).tokens[1].c_str(); + const char *end = c + (*it).tokens[1].size(); // 'FirstFrame': begin of animation slice if ((*it).tokens[0] == "FirstFrame") { @@ -567,14 +568,14 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy LWS::NodeDesc d; d.type = LWS::NodeDesc::OBJECT; if (version >= 4) { // handle LWSC 4 explicit ID - SkipSpaces(&c); + SkipSpaces(&c, end); d.number = strtoul16(c, &c) & AI_LWS_MASK; } else { d.number = cur_object++; } // and add the file to the import list - SkipSpaces(&c); + SkipSpaces(&c, end); std::string path = FindLWOFile(c); d.path = path; d.id = batch.AddLoadRequest(path, 0, &props); @@ -588,7 +589,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy if (version >= 4) { // handle LWSC 4 explicit ID d.number = strtoul16(c, &c) & AI_LWS_MASK; - SkipSpaces(&c); + SkipSpaces(&c, end); } else { d.number = cur_object++; } @@ -604,7 +605,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy d.type = LWS::NodeDesc::OBJECT; if (version >= 4) { // handle LWSC 4 explicit ID d.number = strtoul16(c, &c) & AI_LWS_MASK; - SkipSpaces(&c); + SkipSpaces(&c, end); } else { d.number = cur_object++; } @@ -668,26 +669,25 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // two ints per envelope LWO::Envelope &env = *envelopeIt; env.pre = (LWO::PrePostBehaviour)strtoul10(c, &c); - SkipSpaces(&c); + SkipSpaces(&c, end); env.post = (LWO::PrePostBehaviour)strtoul10(c, &c); - SkipSpaces(&c); + SkipSpaces(&c, end); } } } // 'ParentItem': specifies the parent of the current element else if ((*it).tokens[0] == "ParentItem") { - if (nodes.empty()) + if (nodes.empty()) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'ParentItem\'"); - - else + } else { nodes.back().parent = strtoul16(c, &c); + } } // 'ParentObject': deprecated one for older formats else if (version < 3 && (*it).tokens[0] == "ParentObject") { - if (nodes.empty()) + if (nodes.empty()) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'ParentObject\'"); - - else { + } else { nodes.back().parent = strtoul10(c, &c) | (1u << 28u); } } @@ -700,19 +700,20 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy if (version >= 4) { // handle LWSC 4 explicit ID d.number = strtoul16(c, &c) & AI_LWS_MASK; - } else + } else { d.number = cur_camera++; + } nodes.push_back(d); num_camera++; } // 'CameraName': set name of currently active camera else if ((*it).tokens[0] == "CameraName") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::CAMERA) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::CAMERA) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'CameraName\'"); - - else + } else { nodes.back().name = c; + } } // 'AddLight': add a light to the scenegraph else if ((*it).tokens[0] == "AddLight") { @@ -723,19 +724,20 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy if (version >= 4) { // handle LWSC 4 explicit ID d.number = strtoul16(c, &c) & AI_LWS_MASK; - } else + } else { d.number = cur_light++; + } nodes.push_back(d); num_light++; } // 'LightName': set name of currently active light else if ((*it).tokens[0] == "LightName") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightName\'"); - - else + } else { nodes.back().name = c; + } } // 'LightIntensity': set intensity of currently active light else if ((*it).tokens[0] == "LightIntensity" || (*it).tokens[0] == "LgtIntensity") { @@ -753,62 +755,58 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } // 'LightType': set type of currently active light else if ((*it).tokens[0] == "LightType") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightType\'"); - - else + } else { nodes.back().lightType = strtoul10(c); - + } } // 'LightFalloffType': set falloff type of currently active light else if ((*it).tokens[0] == "LightFalloffType") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightFalloffType\'"); - else + } else { nodes.back().lightFalloffType = strtoul10(c); - + } } // 'LightConeAngle': set cone angle of currently active light else if ((*it).tokens[0] == "LightConeAngle") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightConeAngle\'"); - - else + } else { nodes.back().lightConeAngle = fast_atof(c); - + } } // 'LightEdgeAngle': set area where we're smoothing from min to max intensity else if ((*it).tokens[0] == "LightEdgeAngle") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightEdgeAngle\'"); - - else + } else { nodes.back().lightEdgeAngle = fast_atof(c); - + } } // 'LightColor': set color of currently active light else if ((*it).tokens[0] == "LightColor") { - if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) + if (nodes.empty() || nodes.back().type != LWS::NodeDesc::LIGHT) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'LightColor\'"); - - else { + } else { c = fast_atoreal_move(c, (float &)nodes.back().lightColor.r); - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, (float &)nodes.back().lightColor.g); - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, (float &)nodes.back().lightColor.b); } } // 'PivotPosition': position of local transformation origin else if ((*it).tokens[0] == "PivotPosition" || (*it).tokens[0] == "PivotPoint") { - if (nodes.empty()) + if (nodes.empty()) { ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'PivotPosition\'"); - else { + } else { c = fast_atoreal_move(c, (float &)nodes.back().pivotPos.x); - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, (float &)nodes.back().pivotPos.y); - SkipSpaces(&c); + SkipSpaces(&c, end); c = fast_atoreal_move(c, (float &)nodes.back().pivotPos.z); // Mark pivotPos as set nodes.back().isPivotSet = true; @@ -818,7 +816,6 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // resolve parenting for (std::list::iterator ndIt = nodes.begin(); ndIt != nodes.end(); ++ndIt) { - // check whether there is another node which calls us a parent for (std::list::iterator dit = nodes.begin(); dit != nodes.end(); ++dit) { if (dit != ndIt && *ndIt == (*dit).parent) { @@ -854,7 +851,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy aiNode *nd = master->mRootNode = new aiNode(); // allocate storage for cameras&lights - if (num_camera) { + if (num_camera > 0u) { master->mCameras = new aiCamera *[master->mNumCameras = num_camera]; } aiCamera **cams = master->mCameras; diff --git a/code/AssetLib/LWS/LWSLoader.h b/code/AssetLib/LWS/LWSLoader.h index 4e92ef0d5..f66688249 100644 --- a/code/AssetLib/LWS/LWSLoader.h +++ b/code/AssetLib/LWS/LWSLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -76,7 +76,7 @@ public: std::list children; //! Recursive parsing function - void Parse(const char *&buffer); + void Parse(const char *&buffer, const char *end); }; #define AI_LWS_MASK (0xffffffff >> 4u) diff --git a/code/AssetLib/M3D/M3DExporter.cpp b/code/AssetLib/M3D/M3DExporter.cpp index cf87b6221..5545be415 100644 --- a/code/AssetLib/M3D/M3DExporter.cpp +++ b/code/AssetLib/M3D/M3DExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DExporter.h b/code/AssetLib/M3D/M3DExporter.h index d77743f56..0e9ab4305 100644 --- a/code/AssetLib/M3D/M3DExporter.h +++ b/code/AssetLib/M3D/M3DExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DImporter.cpp b/code/AssetLib/M3D/M3DImporter.cpp index 71f416139..b74b72dc8 100644 --- a/code/AssetLib/M3D/M3DImporter.cpp +++ b/code/AssetLib/M3D/M3DImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DImporter.h b/code/AssetLib/M3D/M3DImporter.h index 9ca8f9211..d9e546f39 100644 --- a/code/AssetLib/M3D/M3DImporter.h +++ b/code/AssetLib/M3D/M3DImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DMaterials.h b/code/AssetLib/M3D/M3DMaterials.h index a1b0fd742..dc87a99c7 100644 --- a/code/AssetLib/M3D/M3DMaterials.h +++ b/code/AssetLib/M3D/M3DMaterials.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DWrapper.cpp b/code/AssetLib/M3D/M3DWrapper.cpp index 05087d592..3741bbca3 100644 --- a/code/AssetLib/M3D/M3DWrapper.cpp +++ b/code/AssetLib/M3D/M3DWrapper.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/M3D/M3DWrapper.h b/code/AssetLib/M3D/M3DWrapper.h index 880aca996..8a3fd92be 100644 --- a/code/AssetLib/M3D/M3DWrapper.h +++ b/code/AssetLib/M3D/M3DWrapper.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team Copyright (c) 2019 bzt All rights reserved. diff --git a/code/AssetLib/MD2/MD2FileData.h b/code/AssetLib/MD2/MD2FileData.h index 3bce8feee..0dba71e56 100644 --- a/code/AssetLib/MD2/MD2FileData.h +++ b/code/AssetLib/MD2/MD2FileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { namespace MD2 { -// to make it easier for us, we test the magic word against both "endianesses" +// to make it easier for us, we test the magic word against both "endiannesses" #define AI_MD2_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP2") #define AI_MD2_MAGIC_NUMBER_LE AI_MAKE_MAGIC("2PDI") diff --git a/code/AssetLib/MD2/MD2Loader.cpp b/code/AssetLib/MD2/MD2Loader.cpp index 596d26414..99dc70d08 100644 --- a/code/AssetLib/MD2/MD2Loader.cpp +++ b/code/AssetLib/MD2/MD2Loader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MD2/MD2Loader.h b/code/AssetLib/MD2/MD2Loader.h index bab026ea0..5ac34ad4c 100644 --- a/code/AssetLib/MD2/MD2Loader.h +++ b/code/AssetLib/MD2/MD2Loader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MD2/MD2NormalTable.h b/code/AssetLib/MD2/MD2NormalTable.h index 1837939e8..7d13b9ad1 100644 --- a/code/AssetLib/MD2/MD2NormalTable.h +++ b/code/AssetLib/MD2/MD2NormalTable.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MD3/MD3FileData.h b/code/AssetLib/MD3/MD3FileData.h index 01475e679..86d2647b6 100644 --- a/code/AssetLib/MD3/MD3FileData.h +++ b/code/AssetLib/MD3/MD3FileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -62,7 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { namespace MD3 { -// to make it easier for us, we test the magic word against both "endianesses" +// to make it easier for us, we test the magic word against both "endiannesses" #define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3") #define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI") diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index e743889e3..3dd8d9c66 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team @@ -123,12 +123,12 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * // remove comments from it (C++ style) CommentRemover::RemoveLineComments("//", &_buff[0]); const char *buff = &_buff[0]; - + const char *end = buff + _buff.size(); Q3Shader::ShaderDataBlock *curData = nullptr; Q3Shader::ShaderMapBlock *curMap = nullptr; // read line per line - for (; SkipSpacesAndLineEnd(&buff); SkipLine(&buff)) { + for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { if (*buff == '{') { ++buff; @@ -140,21 +140,21 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * } // read this data section - for (; SkipSpacesAndLineEnd(&buff); SkipLine(&buff)) { + for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { if (*buff == '{') { ++buff; // add new map section curData->maps.emplace_back(); curMap = &curData->maps.back(); - for (; SkipSpacesAndLineEnd(&buff); SkipLine(&buff)) { + for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { // 'map' - Specifies texture file name if (TokenMatchI(buff, "map", 3) || TokenMatchI(buff, "clampmap", 8)) { - curMap->name = GetNextToken(buff); + curMap->name = GetNextToken(buff, end); } // 'blendfunc' - Alpha blending mode else if (TokenMatchI(buff, "blendfunc", 9)) { - const std::string blend_src = GetNextToken(buff); + const std::string blend_src = GetNextToken(buff, end); if (blend_src == "add") { curMap->blend_src = Q3Shader::BLEND_GL_ONE; curMap->blend_dest = Q3Shader::BLEND_GL_ONE; @@ -166,12 +166,12 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * curMap->blend_dest = Q3Shader::BLEND_GL_ONE_MINUS_SRC_ALPHA; } else { curMap->blend_src = StringToBlendFunc(blend_src); - curMap->blend_dest = StringToBlendFunc(GetNextToken(buff)); + curMap->blend_dest = StringToBlendFunc(GetNextToken(buff, end)); } } // 'alphafunc' - Alpha testing mode else if (TokenMatchI(buff, "alphafunc", 9)) { - const std::string at = GetNextToken(buff); + const std::string at = GetNextToken(buff, end); if (at == "GT0") { curMap->alpha_test = Q3Shader::AT_GT0; } else if (at == "LT128") { @@ -186,7 +186,6 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * break; } } - } else if (*buff == '}') { ++buff; curData = nullptr; @@ -195,7 +194,7 @@ 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); + SkipSpaces(&buff, end); 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)) { // is not valid keyword in Q3, but occurs in shaders @@ -213,9 +212,10 @@ bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem * curData = &fill.blocks.back(); // get the name of this section - curData->name = GetNextToken(buff); + curData->name = GetNextToken(buff, end); } } + return true; } @@ -232,6 +232,7 @@ bool Q3Shader::LoadSkin(SkinData &fill, const std::string &pFile, IOSystem *io) const size_t s = file->FileSize(); std::vector _buff(s + 1); const char *buff = &_buff[0]; + const char *end = buff + _buff.size(); file->Read(&_buff[0], s, 1); _buff[s] = 0; @@ -240,10 +241,10 @@ bool Q3Shader::LoadSkin(SkinData &fill, const std::string &pFile, IOSystem *io) // read token by token and fill output table for (; *buff;) { - SkipSpacesAndLineEnd(&buff); + SkipSpacesAndLineEnd(&buff, end); // get first identifier - std::string ss = GetNextToken(buff); + std::string ss = GetNextToken(buff, end); // ignore tokens starting with tag_ if (!::strncmp(&ss[0], "tag_", std::min((size_t)4, ss.length()))) @@ -253,8 +254,9 @@ bool Q3Shader::LoadSkin(SkinData &fill, const std::string &pFile, IOSystem *io) SkinData::TextureEntry &entry = fill.textures.back(); entry.first = ss; - entry.second = GetNextToken(buff); + entry.second = GetNextToken(buff, end); } + return true; } @@ -293,7 +295,7 @@ void Q3Shader::ConvertShaderToMaterial(aiMaterial *out, const ShaderDataBlock &s // - in any case: set it as diffuse texture // // If the texture is using 'filter' blending - // - take as lightmap + // - take as light-map // // Textures with alpha funcs // - aiTextureFlags_UseAlpha is set (otherwise aiTextureFlags_NoAlpha is explicitly set) diff --git a/code/AssetLib/MD3/MD3Loader.h b/code/AssetLib/MD3/MD3Loader.h index d911bb1da..eee66a3df 100644 --- a/code/AssetLib/MD3/MD3Loader.h +++ b/code/AssetLib/MD3/MD3Loader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MD5/MD5Loader.cpp b/code/AssetLib/MD5/MD5Loader.cpp index 697e758fb..0976484a4 100644 --- a/code/AssetLib/MD5/MD5Loader.cpp +++ b/code/AssetLib/MD5/MD5Loader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -210,7 +210,7 @@ void MD5Importer::MakeDataUnique(MD5::MeshDesc &meshSrc) { const unsigned int guess = (unsigned int)(fWeightsPerVert * iNewNum); meshSrc.mWeights.reserve(guess + (guess >> 3)); // + 12.5% as buffer - for (FaceList::const_iterator iter = meshSrc.mFaces.begin(), iterEnd = meshSrc.mFaces.end(); iter != iterEnd; ++iter) { + for (FaceArray::const_iterator iter = meshSrc.mFaces.begin(), iterEnd = meshSrc.mFaces.end(); iter != iterEnd; ++iter) { const aiFace &face = *iter; for (unsigned int i = 0; i < 3; ++i) { if (face.mIndices[0] >= meshSrc.mVertices.size()) { @@ -231,7 +231,7 @@ void MD5Importer::MakeDataUnique(MD5::MeshDesc &meshSrc) { // ------------------------------------------------------------------------------------------------ // Recursive node graph construction from a MD5MESH -void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &bones) { +void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneArray &bones) { ai_assert(nullptr != piParent); ai_assert(!piParent->mNumChildren); @@ -282,7 +282,7 @@ void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &b // ------------------------------------------------------------------------------------------------ // Recursive node graph construction from a MD5ANIM -void MD5Importer::AttachChilds_Anim(int iParentID, aiNode *piParent, AnimBoneList &bones, const aiNodeAnim **node_anims) { +void MD5Importer::AttachChilds_Anim(int iParentID, aiNode *piParent, AnimBoneArray &bones, const aiNodeAnim **node_anims) { ai_assert(nullptr != piParent); ai_assert(!piParent->mNumChildren); @@ -402,7 +402,7 @@ void MD5Importer::LoadMD5MeshFile() { // copy texture coordinates aiVector3D *pv = mesh->mTextureCoords[0]; - for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { + for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { pv->x = (*iter).mUV.x; pv->y = 1.0f - (*iter).mUV.y; // D3D to OpenGL pv->z = 0.0f; @@ -412,7 +412,7 @@ void MD5Importer::LoadMD5MeshFile() { unsigned int *piCount = new unsigned int[meshParser.mJoints.size()]; ::memset(piCount, 0, sizeof(unsigned int) * meshParser.mJoints.size()); - for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { + for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights; ++w) { MD5::WeightDesc &weightDesc = meshSrc.mWeights[w]; /* FIX for some invalid exporters */ @@ -447,7 +447,7 @@ void MD5Importer::LoadMD5MeshFile() { } pv = mesh->mVertices; - for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { + for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) { // compute the final vertex position from all single weights *pv = aiVector3D(); @@ -585,14 +585,14 @@ void MD5Importer::LoadMD5AnimFile() { // 1 tick == 1 frame anim->mTicksPerSecond = animParser.fFrameRate; - for (FrameList::const_iterator iter = animParser.mFrames.begin(), iterEnd = animParser.mFrames.end(); iter != iterEnd; ++iter) { + for (FrameArray::const_iterator iter = animParser.mFrames.begin(), iterEnd = animParser.mFrames.end(); iter != iterEnd; ++iter) { double dTime = (double)(*iter).iIndex; aiNodeAnim **pcAnimNode = anim->mChannels; if (!(*iter).mValues.empty() || iter == animParser.mFrames.begin()) /* be sure we have at least one frame */ { // now process all values in there ... read all joints MD5::BaseFrameDesc *pcBaseFrame = &animParser.mBaseFrames[0]; - for (AnimBoneList::const_iterator iter2 = animParser.mAnimatedBones.begin(); iter2 != animParser.mAnimatedBones.end(); ++iter2, + for (AnimBoneArray::const_iterator iter2 = animParser.mAnimatedBones.begin(); iter2 != animParser.mAnimatedBones.end(); ++iter2, ++pcAnimNode, ++pcBaseFrame) { if ((*iter2).iFirstKeyIndex >= (*iter).mValues.size()) { diff --git a/code/AssetLib/MD5/MD5Loader.h b/code/AssetLib/MD5/MD5Loader.h index c213c04e6..d64d6f5b8 100644 --- a/code/AssetLib/MD5/MD5Loader.h +++ b/code/AssetLib/MD5/MD5Loader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -118,7 +118,7 @@ protected: * @param node_anims Generated node animations */ void AttachChilds_Anim(int iParentID, aiNode *piParent, - AnimBoneList &bones, const aiNodeAnim **node_anims); + AnimBoneArray &bones, const aiNodeAnim **node_anims); // ------------------------------------------------------------------- /** Construct node hierarchy from a given MD5MESH @@ -126,7 +126,7 @@ protected: * @param piParent Parent node to attach to * @param bones Input bones */ - void AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &bones); + void AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneArray &bones); // ------------------------------------------------------------------- /** Build unique vertex buffers from a given MD5ANIM diff --git a/code/AssetLib/MD5/MD5Parser.cpp b/code/AssetLib/MD5/MD5Parser.cpp index 8da30e28f..24882af7e 100644 --- a/code/AssetLib/MD5/MD5Parser.cpp +++ b/code/AssetLib/MD5/MD5Parser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -138,14 +138,16 @@ bool MD5Parser::ParseSection(Section &out) { char *sz = buffer; while (!IsSpaceOrNewLine(*buffer)) { ++buffer; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } out.mName = std::string(sz, (uintptr_t)(buffer - sz)); while (IsSpace(*buffer)) { ++buffer; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } bool running = true; @@ -153,14 +155,16 @@ bool MD5Parser::ParseSection(Section &out) { if ('{' == *buffer) { // it is a normal section so read all lines ++buffer; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } bool run = true; while (run) { while (IsSpaceOrNewLine(*buffer)) { ++buffer; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } if ('\0' == *buffer) { return false; // seems this was the last section @@ -175,18 +179,21 @@ bool MD5Parser::ParseSection(Section &out) { elem.iLineNumber = lineNumber; elem.szStart = buffer; + elem.end = bufferEnd; // terminate the line with zero while (!IsLineEnd(*buffer)) { ++buffer; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } if (*buffer) { ++lineNumber; *buffer++ = '\0'; - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } } break; @@ -194,89 +201,107 @@ bool MD5Parser::ParseSection(Section &out) { // it is an element at global scope. Parse its value and go on sz = buffer; while (!IsSpaceOrNewLine(*buffer++)) { - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } } out.mGlobalValue = std::string(sz, (uintptr_t)(buffer - sz)); continue; } break; } - if (buffer == bufferEnd) + if (buffer == bufferEnd) { return false; + } while (IsSpaceOrNewLine(*buffer)) { + if (buffer == bufferEnd) { + break; + } ++buffer; - if (buffer == bufferEnd) - return false; } return '\0' != *buffer; } -// ------------------------------------------------------------------------------------------------ -// Some dirty macros just because they're so funny and easy to debug - // skip all spaces ... handle EOL correctly -#define AI_MD5_SKIP_SPACES() \ - if (!SkipSpaces(&sz)) \ - MD5Parser::ReportWarning("Unexpected end of line", elem.iLineNumber); +inline void AI_MD5_SKIP_SPACES(const char **sz, const char *bufferEnd, int linenumber) { + if (!SkipSpaces(sz, bufferEnd)) { + MD5Parser::ReportWarning("Unexpected end of line", linenumber); + } +} // read a triple float in brackets: (1.0 1.0 1.0) -#define AI_MD5_READ_TRIPLE(vec) \ - AI_MD5_SKIP_SPACES(); \ - if ('(' != *sz++) \ - MD5Parser::ReportWarning("Unexpected token: ( was expected", elem.iLineNumber); \ - AI_MD5_SKIP_SPACES(); \ - sz = fast_atoreal_move(sz, (float &)vec.x); \ - AI_MD5_SKIP_SPACES(); \ - sz = fast_atoreal_move(sz, (float &)vec.y); \ - AI_MD5_SKIP_SPACES(); \ - sz = fast_atoreal_move(sz, (float &)vec.z); \ - AI_MD5_SKIP_SPACES(); \ - if (')' != *sz++) \ - MD5Parser::ReportWarning("Unexpected token: ) was expected", elem.iLineNumber); +inline void AI_MD5_READ_TRIPLE(aiVector3D &vec, const char **sz, const char *bufferEnd, int linenumber) { + AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber); + if ('(' != **sz) { + MD5Parser::ReportWarning("Unexpected token: ( was expected", linenumber); + ++*sz; + } + ++*sz; + AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber); + *sz = fast_atoreal_move(*sz, (float &)vec.x); + AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber); + *sz = fast_atoreal_move(*sz, (float &)vec.y); + AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber); + *sz = fast_atoreal_move(*sz, (float &)vec.z); + AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber); + if (')' != **sz) { + MD5Parser::ReportWarning("Unexpected token: ) was expected", linenumber); + } + ++*sz; +} // parse a string, enclosed in quotation marks or not -#define AI_MD5_PARSE_STRING(out) \ - bool bQuota = (*sz == '\"'); \ - const char *szStart = sz; \ - while (!IsSpaceOrNewLine(*sz)) \ - ++sz; \ - const char *szEnd = sz; \ - if (bQuota) { \ - szStart++; \ - if ('\"' != *(szEnd -= 1)) { \ - MD5Parser::ReportWarning("Expected closing quotation marks in string", \ - elem.iLineNumber); \ - continue; \ - } \ - } \ - out.length = (size_t)(szEnd - szStart); \ - ::memcpy(out.data, szStart, out.length); \ +inline bool AI_MD5_PARSE_STRING(const char **sz, const char *bufferEnd, aiString &out, int linenumber) { + bool bQuota = (**sz == '\"'); + const char *szStart = *sz; + while (!IsSpaceOrNewLine(**sz)) { + ++*sz; + if (*sz == bufferEnd) break; + } + const char *szEnd = *sz; + if (bQuota) { + szStart++; + if ('\"' != *(szEnd -= 1)) { + MD5Parser::ReportWarning("Expected closing quotation marks in string", linenumber); + ++*sz; + } + } + out.length = (ai_uint32)(szEnd - szStart); + ::memcpy(out.data, szStart, out.length); out.data[out.length] = '\0'; + return true; +} + // parse a string, enclosed in quotation marks -#define AI_MD5_PARSE_STRING_IN_QUOTATION(out) \ - out.length = 0; \ - while ('\"' != *sz && '\0' != *sz) \ - ++sz; \ - if ('\0' != *sz) { \ - const char *szStart = ++sz; \ - while ('\"' != *sz && '\0' != *sz) \ - ++sz; \ - if ('\0' != *sz) { \ - const char *szEnd = (sz++); \ - out.length = (ai_uint32)(szEnd - szStart); \ - ::memcpy(out.data, szStart, out.length); \ - } \ - } \ +inline void AI_MD5_PARSE_STRING_IN_QUOTATION(const char **sz, const char *bufferEnd, aiString &out) { + out.length = 0u; + while (('\"' != **sz && '\0' != **sz) && *sz != bufferEnd) { + ++*sz; + } + if ('\0' != **sz) { + const char *szStart = ++(*sz); + + while (('\"' != **sz && '\0' != **sz) && *sz != bufferEnd) { + ++*sz; + } + if ('\0' != **sz) { + const char *szEnd = *sz; + ++*sz; + out.length = (ai_uint32)(szEnd - szStart); + ::memcpy(out.data, szStart, out.length); + } + } out.data[out.length] = '\0'; +} + // ------------------------------------------------------------------------------------------------ // .MD5MESH parsing function -MD5MeshParser::MD5MeshParser(SectionList &mSections) { +MD5MeshParser::MD5MeshParser(SectionArray &mSections) { ASSIMP_LOG_DEBUG("MD5MeshParser begin"); // now parse all sections - for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { + for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { if ((*iter).mName == "numMeshes") { mMeshes.reserve(::strtoul10((*iter).mGlobalValue.c_str())); } else if ((*iter).mName == "numJoints") { @@ -288,14 +313,15 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) { BoneDesc &desc = mJoints.back(); const char *sz = elem.szStart; - AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mName); - AI_MD5_SKIP_SPACES(); + AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mName); + + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); // negative values, at least -1, is allowed here desc.mParentIndex = (int)strtol10(sz, &sz); - AI_MD5_READ_TRIPLE(desc.mPositionXYZ); - AI_MD5_READ_TRIPLE(desc.mRotationQuat); // normalized quaternion, so w is not there + AI_MD5_READ_TRIPLE(desc.mPositionXYZ, &sz, elem.end, elem.iLineNumber); + AI_MD5_READ_TRIPLE(desc.mRotationQuat, &sz, elem.end, elem.iLineNumber); // normalized quaternion, so w is not there } } else if ((*iter).mName == "mesh") { mMeshes.emplace_back(); @@ -306,52 +332,52 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) { // shader attribute if (TokenMatch(sz, "shader", 6)) { - AI_MD5_SKIP_SPACES(); - AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mShader); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); + AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mShader); } // numverts attribute else if (TokenMatch(sz, "numverts", 8)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); desc.mVertices.resize(strtoul10(sz)); } // numtris attribute else if (TokenMatch(sz, "numtris", 7)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); desc.mFaces.resize(strtoul10(sz)); } // numweights attribute else if (TokenMatch(sz, "numweights", 10)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); desc.mWeights.resize(strtoul10(sz)); } // vert attribute // "vert 0 ( 0.394531 0.513672 ) 0 1" else if (TokenMatch(sz, "vert", 4)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); const unsigned int idx = ::strtoul10(sz, &sz); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); if (idx >= desc.mVertices.size()) desc.mVertices.resize(idx + 1); VertexDesc &vert = desc.mVertices[idx]; if ('(' != *sz++) MD5Parser::ReportWarning("Unexpected token: ( was expected", elem.iLineNumber); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); sz = fast_atoreal_move(sz, (float &)vert.mUV.x); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); sz = fast_atoreal_move(sz, (float &)vert.mUV.y); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); if (')' != *sz++) MD5Parser::ReportWarning("Unexpected token: ) was expected", elem.iLineNumber); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); vert.mFirstWeight = ::strtoul10(sz, &sz); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); vert.mNumWeights = ::strtoul10(sz, &sz); } // tri attribute // "tri 0 15 13 12" else if (TokenMatch(sz, "tri", 3)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); const unsigned int idx = strtoul10(sz, &sz); if (idx >= desc.mFaces.size()) desc.mFaces.resize(idx + 1); @@ -359,24 +385,24 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) { aiFace &face = desc.mFaces[idx]; face.mIndices = new unsigned int[face.mNumIndices = 3]; for (unsigned int i = 0; i < 3; ++i) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); face.mIndices[i] = strtoul10(sz, &sz); } } // weight attribute // "weight 362 5 0.500000 ( -3.553583 11.893474 9.719339 )" else if (TokenMatch(sz, "weight", 6)) { - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); const unsigned int idx = strtoul10(sz, &sz); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); if (idx >= desc.mWeights.size()) desc.mWeights.resize(idx + 1); WeightDesc &weight = desc.mWeights[idx]; weight.mBone = strtoul10(sz, &sz); - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); sz = fast_atoreal_move(sz, weight.mWeight); - AI_MD5_READ_TRIPLE(weight.vOffsetPosition); + AI_MD5_READ_TRIPLE(weight.vOffsetPosition, &sz, elem.end, elem.iLineNumber); } } } @@ -386,12 +412,12 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) { // ------------------------------------------------------------------------------------------------ // .MD5ANIM parsing function -MD5AnimParser::MD5AnimParser(SectionList &mSections) { +MD5AnimParser::MD5AnimParser(SectionArray &mSections) { ASSIMP_LOG_DEBUG("MD5AnimParser begin"); fFrameRate = 24.0f; mNumAnimatedComponents = UINT_MAX; - for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { + for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { if ((*iter).mName == "hierarchy") { // "sheath" 0 63 6 for (const auto &elem : (*iter).mElements) { @@ -399,18 +425,18 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) { AnimBoneDesc &desc = mAnimatedBones.back(); const char *sz = elem.szStart; - AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mName); - AI_MD5_SKIP_SPACES(); + AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mName); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); // parent index - negative values are allowed (at least -1) desc.mParentIndex = ::strtol10(sz, &sz); // flags (highest is 2^6-1) - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); if (63 < (desc.iFlags = ::strtoul10(sz, &sz))) { MD5Parser::ReportWarning("Invalid flag combination in hierarchy section", elem.iLineNumber); } - AI_MD5_SKIP_SPACES(); + AI_MD5_SKIP_SPACES(& sz, elem.end, elem.iLineNumber); // index of the first animation keyframe component for this joint desc.iFirstKeyIndex = ::strtoul10(sz, &sz); @@ -423,8 +449,8 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) { mBaseFrames.emplace_back(); BaseFrameDesc &desc = mBaseFrames.back(); - AI_MD5_READ_TRIPLE(desc.vPositionXYZ); - AI_MD5_READ_TRIPLE(desc.vRotationQuat); + AI_MD5_READ_TRIPLE(desc.vPositionXYZ, &sz, elem.end, elem.iLineNumber); + AI_MD5_READ_TRIPLE(desc.vRotationQuat, &sz, elem.end, elem.iLineNumber); } } else if ((*iter).mName == "frame") { if (!(*iter).mGlobalValue.length()) { @@ -444,7 +470,7 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) { // now read all elements (continuous list of floats) for (const auto &elem : (*iter).mElements) { const char *sz = elem.szStart; - while (SkipSpacesAndLineEnd(&sz)) { + while (SkipSpacesAndLineEnd(&sz, elem.end)) { float f; sz = fast_atoreal_move(sz, f); desc.mValues.push_back(f); @@ -471,11 +497,11 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) { // ------------------------------------------------------------------------------------------------ // .MD5CAMERA parsing function -MD5CameraParser::MD5CameraParser(SectionList &mSections) { +MD5CameraParser::MD5CameraParser(SectionArray &mSections) { ASSIMP_LOG_DEBUG("MD5CameraParser begin"); fFrameRate = 24.0f; - for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { + for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) { if ((*iter).mName == "numFrames") { frames.reserve(strtoul10((*iter).mGlobalValue.c_str())); } else if ((*iter).mName == "frameRate") { @@ -492,9 +518,9 @@ MD5CameraParser::MD5CameraParser(SectionList &mSections) { frames.emplace_back(); CameraAnimFrameDesc &cur = frames.back(); - AI_MD5_READ_TRIPLE(cur.vPositionXYZ); - AI_MD5_READ_TRIPLE(cur.vRotationQuat); - AI_MD5_SKIP_SPACES(); + AI_MD5_READ_TRIPLE(cur.vPositionXYZ, &sz, elem.end, elem.iLineNumber); + AI_MD5_READ_TRIPLE(cur.vRotationQuat, &sz, elem.end, elem.iLineNumber); + AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber); cur.fFOV = fast_atof(sz); } } diff --git a/code/AssetLib/MD5/MD5Parser.h b/code/AssetLib/MD5/MD5Parser.h index 9b29fbe85..75e3c22f2 100644 --- a/code/AssetLib/MD5/MD5Parser.h +++ b/code/AssetLib/MD5/MD5Parser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -68,12 +68,14 @@ struct Element { //! Elements are terminated with \0 char* szStart; + const char *end; + //! Original line number (can be used in error messages //! if a parsing error occurs) unsigned int iLineNumber; }; -using ElementList = std::vector; +using ElementArray = std::vector; // --------------------------------------------------------------------------- /** Represents a section of a MD5 file (such as the mesh or the joints section) @@ -86,7 +88,7 @@ struct Section { unsigned int iLineNumber; //! List of all elements which have been parsed in this section. - ElementList mElements; + ElementArray mElements; //! Name of the section std::string mName; @@ -96,7 +98,7 @@ struct Section { std::string mGlobalValue; }; -using SectionList = std::vector

; +using SectionArray = std::vector
; // --------------------------------------------------------------------------- /** Basic information about a joint @@ -132,7 +134,7 @@ struct BoneDesc : BaseJointDescription { unsigned int mMap; }; -using BoneList = std::vector; +using BoneArray = std::vector; // --------------------------------------------------------------------------- /** Represents a bone (joint) descriptor in a MD5Anim file @@ -145,7 +147,7 @@ struct AnimBoneDesc : BaseJointDescription { unsigned int iFirstKeyIndex; }; -using AnimBoneList = std::vector< AnimBoneDesc >; +using AnimBoneArray = std::vector< AnimBoneDesc >; // --------------------------------------------------------------------------- /** Represents a base frame descriptor in a MD5Anim file @@ -155,7 +157,7 @@ struct BaseFrameDesc { aiVector3D vRotationQuat; }; -using BaseFrameList = std::vector; +using BaseFrameArray = std::vector; // --------------------------------------------------------------------------- /** Represents a camera animation frame in a MDCamera file @@ -164,7 +166,7 @@ struct CameraAnimFrameDesc : BaseFrameDesc { float fFOV; }; -using CameraFrameList = std::vector; +using CameraFrameArray = std::vector; // --------------------------------------------------------------------------- /** Represents a frame descriptor in a MD5Anim file @@ -177,7 +179,7 @@ struct FrameDesc { std::vector< float > mValues; }; -using FrameList = std::vector; +using FrameArray = std::vector; // --------------------------------------------------------------------------- /** Represents a vertex descriptor in a MD5 file @@ -199,7 +201,7 @@ struct VertexDesc { unsigned int mNumWeights; }; -using VertexList = std::vector; +using VertexArray = std::vector; // --------------------------------------------------------------------------- /** Represents a vertex weight descriptor in a MD5 file @@ -216,27 +218,27 @@ struct WeightDesc { aiVector3D vOffsetPosition; }; -using WeightList = std::vector; -using FaceList = std::vector; +using WeightArray = std::vector; +using FaceArray = std::vector; // --------------------------------------------------------------------------- /** Represents a mesh in a MD5 file */ struct MeshDesc { //! Weights of the mesh - WeightList mWeights; + WeightArray mWeights; //! Vertices of the mesh - VertexList mVertices; + VertexArray mVertices; //! Faces of the mesh - FaceList mFaces; + FaceArray mFaces; //! Name of the shader (=texture) to be assigned to the mesh aiString mShader; }; -using MeshList = std::vector; +using MeshArray = std::vector; // --------------------------------------------------------------------------- // Convert a quaternion to its usual representation @@ -269,13 +271,13 @@ public: * * @param mSections List of file sections (output of MD5Parser) */ - explicit MD5MeshParser(SectionList& mSections); + explicit MD5MeshParser(SectionArray& mSections); //! List of all meshes - MeshList mMeshes; + MeshArray mMeshes; //! List of all joints - BoneList mJoints; + BoneArray mJoints; }; // remove this flag if you need to the bounding box data @@ -292,20 +294,20 @@ public: * * @param mSections List of file sections (output of MD5Parser) */ - explicit MD5AnimParser(SectionList& mSections); + explicit MD5AnimParser(SectionArray& mSections); //! Output frame rate float fFrameRate; //! List of animation bones - AnimBoneList mAnimatedBones; + AnimBoneArray mAnimatedBones; //! List of base frames - BaseFrameList mBaseFrames; + BaseFrameArray mBaseFrames; //! List of animation frames - FrameList mFrames; + FrameArray mFrames; //! Number of animated components unsigned int mNumAnimatedComponents; @@ -322,7 +324,7 @@ public: * * @param mSections List of file sections (output of MD5Parser) */ - explicit MD5CameraParser(SectionList& mSections); + explicit MD5CameraParser(SectionArray& mSections); //! Output frame rate float fFrameRate; @@ -331,7 +333,7 @@ public: std::vector cuts; //! Frames - CameraFrameList frames; + CameraFrameArray frames; }; // --------------------------------------------------------------------------- @@ -375,7 +377,7 @@ public: void ReportWarning (const char* warn); //! List of all sections which have been read - SectionList mSections; + SectionArray mSections; private: bool ParseSection(Section& out); @@ -388,7 +390,7 @@ private: private: char* buffer; - char* bufferEnd; + const char* bufferEnd; unsigned int fileSize; unsigned int lineNumber; }; @@ -406,7 +408,7 @@ inline void MD5Parser::ReportError(const char* error) { // ------------------------------------------------------------------- inline bool MD5Parser::SkipLine(const char* in, const char** out) { ++lineNumber; - return Assimp::SkipLine(in ,out); + return Assimp::SkipLine(in, out, bufferEnd); } // ------------------------------------------------------------------- @@ -450,7 +452,7 @@ inline bool MD5Parser::SkipSpacesAndLineEnd() { // ------------------------------------------------------------------- inline bool MD5Parser::SkipSpaces() { - return Assimp::SkipSpaces((const char**)&buffer); + return Assimp::SkipSpaces((const char**)&buffer, bufferEnd); } } // namespace Assimp diff --git a/code/AssetLib/MDC/MDCFileData.h b/code/AssetLib/MDC/MDCFileData.h index 36c589e91..4c5b4127c 100644 --- a/code/AssetLib/MDC/MDCFileData.h +++ b/code/AssetLib/MDC/MDCFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -61,7 +61,7 @@ http://themdcfile.planetwolfenstein.gamespy.com/MDC_File_Format.pdf namespace Assimp { namespace MDC { -// to make it easier for us, we test the magic word against both "endianesses" +// to make it easier for us, we test the magic word against both "endiannesses" #define AI_MDC_MAGIC_NUMBER_BE AI_MAKE_MAGIC("CPDI") #define AI_MDC_MAGIC_NUMBER_LE AI_MAKE_MAGIC("IDPC") diff --git a/code/AssetLib/MDC/MDCLoader.cpp b/code/AssetLib/MDC/MDCLoader.cpp index 87247adec..c81ba67a6 100644 --- a/code/AssetLib/MDC/MDCLoader.cpp +++ b/code/AssetLib/MDC/MDCLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDC/MDCLoader.h b/code/AssetLib/MDC/MDCLoader.h index a1f8d9fc9..09ecc6865 100644 --- a/code/AssetLib/MDC/MDCLoader.h +++ b/code/AssetLib/MDC/MDCLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1FileData.h b/code/AssetLib/MDL/HalfLife/HL1FileData.h index 28b1b2822..485f538ab 100644 --- a/code/AssetLib/MDL/HalfLife/HL1FileData.h +++ b/code/AssetLib/MDL/HalfLife/HL1FileData.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1ImportDefinitions.h b/code/AssetLib/MDL/HalfLife/HL1ImportDefinitions.h index d412aeede..344574d24 100644 --- a/code/AssetLib/MDL/HalfLife/HL1ImportDefinitions.h +++ b/code/AssetLib/MDL/HalfLife/HL1ImportDefinitions.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h b/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h index 340ba2da5..52f98cb58 100644 --- a/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h +++ b/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index a8141fcc1..2d7f6a7c2 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h index 286b6e64c..ab5bb6942 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h b/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h index 4ef8a13ce..9c389a659 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h +++ b/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/HalfLifeMDLBaseHeader.h b/code/AssetLib/MDL/HalfLife/HalfLifeMDLBaseHeader.h index c7808c401..25ef27bca 100644 --- a/code/AssetLib/MDL/HalfLife/HalfLifeMDLBaseHeader.h +++ b/code/AssetLib/MDL/HalfLife/HalfLifeMDLBaseHeader.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/LogFunctions.h b/code/AssetLib/MDL/HalfLife/LogFunctions.h index 003774dc1..c8cdf9b15 100644 --- a/code/AssetLib/MDL/HalfLife/LogFunctions.h +++ b/code/AssetLib/MDL/HalfLife/LogFunctions.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.cpp b/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.cpp index 3cca8c558..b79ec3613 100644 --- a/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.cpp +++ b/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.h b/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.h index 73b6f9e74..cf190bc3b 100644 --- a/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.h +++ b/code/AssetLib/MDL/HalfLife/UniqueNameGenerator.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/MDLDefaultColorMap.h b/code/AssetLib/MDL/MDLDefaultColorMap.h index 2eecac2dc..cbdc977ad 100644 --- a/code/AssetLib/MDL/MDLDefaultColorMap.h +++ b/code/AssetLib/MDL/MDLDefaultColorMap.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/MDLFileData.h b/code/AssetLib/MDL/MDLFileData.h index 7ec2afe9a..2aff59856 100644 --- a/code/AssetLib/MDL/MDLFileData.h +++ b/code/AssetLib/MDL/MDLFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -67,7 +67,7 @@ namespace Assimp { namespace MDL { // ------------------------------------------------------------------------------------- -// to make it easier for us, we test the magic word against both "endianesses" +// to make it easier for us, we test the magic word against both "endiannesses" // magic bytes used in Quake 1 MDL meshes #define AI_MDL_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDPO") diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 2b14fe980..99b0145af 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/MDLLoader.h b/code/AssetLib/MDL/MDLLoader.h index 333f7c8b1..f99f061ce 100644 --- a/code/AssetLib/MDL/MDLLoader.h +++ b/code/AssetLib/MDL/MDLLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index 3d39fa645..38c42c1a5 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -123,9 +123,8 @@ aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture *pcTexture) { // Read a texture from a MDL3 file void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char *szData) { const MDL::Header *pcHeader = (const MDL::Header *)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function - - VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth * - pcHeader->skinheight); + const size_t len = pcHeader->skinwidth * pcHeader->skinheight; + VALIDATE_FILE_SIZE(szData + len); // allocate a new texture object aiTexture *pcNew = new aiTexture(); diff --git a/code/AssetLib/MMD/MMDCpp14.h b/code/AssetLib/MMD/MMDCpp14.h index 10d376829..4a04bf69e 100644 --- a/code/AssetLib/MMD/MMDCpp14.h +++ b/code/AssetLib/MMD/MMDCpp14.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MMD/MMDImporter.cpp b/code/AssetLib/MMD/MMDImporter.cpp index b96d45c98..1e88cefd2 100644 --- a/code/AssetLib/MMD/MMDImporter.cpp +++ b/code/AssetLib/MMD/MMDImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MMD/MMDImporter.h b/code/AssetLib/MMD/MMDImporter.h index 1f584bf12..71fc534a4 100644 --- a/code/AssetLib/MMD/MMDImporter.h +++ b/code/AssetLib/MMD/MMDImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/MMD/MMDPmdParser.h b/code/AssetLib/MMD/MMDPmdParser.h index 23aaac555..b11c72f8d 100644 --- a/code/AssetLib/MMD/MMDPmdParser.h +++ b/code/AssetLib/MMD/MMDPmdParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MMD/MMDPmxParser.cpp b/code/AssetLib/MMD/MMDPmxParser.cpp index 6b04f02e9..5a3e61dcd 100644 --- a/code/AssetLib/MMD/MMDPmxParser.cpp +++ b/code/AssetLib/MMD/MMDPmxParser.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MMD/MMDPmxParser.h b/code/AssetLib/MMD/MMDPmxParser.h index 424fc725a..e90e554e7 100644 --- a/code/AssetLib/MMD/MMDPmxParser.h +++ b/code/AssetLib/MMD/MMDPmxParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MMD/MMDVmdParser.h b/code/AssetLib/MMD/MMDVmdParser.h index d5c7dedff..2ba9fb931 100644 --- a/code/AssetLib/MMD/MMDVmdParser.h +++ b/code/AssetLib/MMD/MMDVmdParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/MS3D/MS3DLoader.cpp b/code/AssetLib/MS3D/MS3DLoader.cpp index e0f0f8b5a..fac102f5f 100644 --- a/code/AssetLib/MS3D/MS3DLoader.cpp +++ b/code/AssetLib/MS3D/MS3DLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/AssetLib/MS3D/MS3DLoader.h b/code/AssetLib/MS3D/MS3DLoader.h index 3e25f1f59..5a28391eb 100644 --- a/code/AssetLib/MS3D/MS3DLoader.h +++ b/code/AssetLib/MS3D/MS3DLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/NDO/NDOLoader.cpp b/code/AssetLib/NDO/NDOLoader.cpp index 405438dfc..3515c14b4 100644 --- a/code/AssetLib/NDO/NDOLoader.cpp +++ b/code/AssetLib/NDO/NDOLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/NDO/NDOLoader.h b/code/AssetLib/NDO/NDOLoader.h index c4f127851..c3ab15230 100644 --- a/code/AssetLib/NDO/NDOLoader.h +++ b/code/AssetLib/NDO/NDOLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/NFF/NFFLoader.cpp b/code/AssetLib/NFF/NFFLoader.cpp index 78adc27bd..481a4bc19 100644 --- a/code/AssetLib/NFF/NFFLoader.cpp +++ b/code/AssetLib/NFF/NFFLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -85,7 +85,7 @@ const aiImporterDesc *NFFImporter::GetInfo() const { // ------------------------------------------------------------------------------------------------ #define AI_NFF_PARSE_FLOAT(f) \ - SkipSpaces(&sz); \ + SkipSpaces(&sz, lineEnd); \ if (!IsLineEnd(*sz)) sz = fast_atoreal_move(sz, (ai_real &)f); // ------------------------------------------------------------------------------------------------ @@ -111,7 +111,7 @@ const aiImporterDesc *NFFImporter::GetInfo() const { ASSIMP_LOG_WARN("NFF2: Unexpected EOF, can't read next token"); \ break; \ } \ - SkipSpaces(line, &sz); \ + SkipSpaces(line, &sz, lineEnd); \ } while (IsLineEnd(*sz)) // ------------------------------------------------------------------------------------------------ @@ -148,9 +148,9 @@ void NFFImporter::LoadNFF2MaterialTable(std::vector &output, // No read the file line per line char line[4096]; - const char *sz; + const char *sz, *lineEnd = &line[2095]+1; while (GetNextLine(buffer, line)) { - SkipSpaces(line, &sz); + SkipSpaces(line, &sz, lineEnd); // 'version' defines the version of the file format if (TokenMatch(sz, "version", 7)) { @@ -198,18 +198,16 @@ void NFFImporter::LoadNFF2MaterialTable(std::vector &output, // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void NFFImporter::InternReadFile(const std::string &pFile, - aiScene *pScene, IOSystem *pIOHandler) { - std::unique_ptr file(pIOHandler->Open(pFile, "rb")); - - // Check whether we can read from the file - if (!file) - throw DeadlyImportError("Failed to open NFF file ", pFile, "."); +void NFFImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { + std::unique_ptr stream(pIOHandler->Open(file, "rb")); + if (!stream) { + throw DeadlyImportError("Failed to open NFF file ", file, "."); + } // allocate storage and copy the contents of the file to a memory buffer // (terminate it with zero) std::vector mBuffer2; - TextFileToBuffer(file.get(), mBuffer2); + TextFileToBuffer(stream.get(), mBuffer2); const char *buffer = &mBuffer2[0]; // mesh arrays - separate here to make the handling of the pointers below easier. @@ -219,8 +217,10 @@ void NFFImporter::InternReadFile(const std::string &pFile, std::vector meshesLocked; char line[4096]; + const char *lineEnd = &line[4096]; const char *sz; + // camera parameters aiVector3D camPos, camUp(0.f, 1.f, 0.f), camLookAt(0.f, 0.f, 1.f); ai_real angle = 45.f; @@ -265,7 +265,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, CommentRemover::RemoveLineComments("//", &mBuffer2[0]); while (GetNextLine(buffer, line)) { - SkipSpaces(line, &sz); + SkipSpaces(line, &sz, lineEnd); if (TokenMatch(sz, "version", 7)) { ASSIMP_LOG_INFO("NFF (Sense8) file format: ", sz); } else if (TokenMatch(sz, "viewpos", 7)) { @@ -295,7 +295,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // material table - an external file if (TokenMatch(sz, "mtable", 6)) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz3 = sz; while (!IsSpaceOrNewLine(*sz)) ++sz; @@ -316,12 +316,12 @@ void NFFImporter::InternReadFile(const std::string &pFile, std::string::size_type sepPos; if ((std::string::npos == (sepPos = path.find_last_of('\\')) || !sepPos) && (std::string::npos == (sepPos = path.find_last_of('/')) || !sepPos)) { - sepPos = pFile.find_last_of('\\'); + sepPos = file.find_last_of('\\'); if (std::string::npos == sepPos) { - sepPos = pFile.find_last_of('/'); + sepPos = file.find_last_of('/'); } if (std::string::npos != sepPos) { - path = pFile.substr(0, sepPos + 1) + path; + path = file.substr(0, sepPos + 1) + path; } } LoadNFF2MaterialTable(materialTable, path, pIOHandler); @@ -351,7 +351,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // parse all other attributes in the line while (true) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); if (IsLineEnd(*sz)) break; // color definition @@ -403,23 +403,20 @@ void NFFImporter::InternReadFile(const std::string &pFile, tempIdx.reserve(10); for (unsigned int i = 0; i < num; ++i) { AI_NFF2_GET_NEXT_TOKEN(); - SkipSpaces(line, &sz); + SkipSpaces(line, &sz, lineEnd); unsigned int numIdx = strtoul10(sz, &sz); // read all faces indices if (numIdx) { - // mesh.faces.push_back(numIdx); - // tempIdx.erase(tempIdx.begin(),tempIdx.end()); tempIdx.resize(numIdx); for (unsigned int a = 0; a < numIdx; ++a) { - SkipSpaces(sz, &sz); + SkipSpaces(sz, &sz, lineEnd); unsigned int m = strtoul10(sz, &sz); if (m >= (unsigned int)tempPositions.size()) { ASSIMP_LOG_ERROR("NFF2: Vertex index overflow"); m = 0; } - // mesh.vertices.push_back (tempPositions[idx]); tempIdx[a] = m; } } @@ -432,7 +429,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, shader.color = aiColor3D(1.f, 1.f, 1.f); aiColor4D c = aiColor4D(1.f, 1.f, 1.f, 1.f); while (true) { - SkipSpaces(sz, &sz); + SkipSpaces(sz, &sz, lineEnd); if (IsLineEnd(*sz)) break; // per-polygon colors @@ -510,7 +507,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // Material ID? else if (!materialTable.empty() && TokenMatch(sz, "matid", 5)) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); matIdx = strtoul10(sz, &sz); if (matIdx >= materialTable.size()) { ASSIMP_LOG_ERROR("NFF2: Material index overflow."); @@ -527,7 +524,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, shader.specular = mat.specular; shader.shininess = mat.shininess; } else - SkipToken(sz); + SkipToken(sz, lineEnd); } // search the list of all shaders we have for this object whether @@ -649,7 +646,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, sz = &line[1]; out = currentMesh; } - SkipSpaces(sz, &sz); + SkipSpaces(sz, &sz, lineEnd); unsigned int m = strtoul10(sz); // ---- flip the face order @@ -677,13 +674,13 @@ void NFFImporter::InternReadFile(const std::string &pFile, } if (out == currentMeshWithUVCoords) { // FIX: in one test file this wraps over multiple lines - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); if (IsLineEnd(*sz)) { GetNextLine(buffer, line); sz = line; } AI_NFF_PARSE_FLOAT(v.x); - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); if (IsLineEnd(*sz)) { GetNextLine(buffer, line); sz = line; @@ -717,7 +714,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // if the next one is NOT a number we assume it is a texture file name // this feature is used by some NFF files on the internet and it has // been implemented as it can be really useful - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); if (!IsNumeric(*sz)) { // TODO: Support full file names with spaces and quotation marks ... const char *p = sz; @@ -731,10 +728,8 @@ void NFFImporter::InternReadFile(const std::string &pFile, } else { AI_NFF_PARSE_FLOAT(s.ambient); // optional } - } - // 'shader' - other way to specify a texture - else if (TokenMatch(sz, "shader", 6)) { - SkipSpaces(&sz); + } else if (TokenMatch(sz, "shader", 6)) { // 'shader' - other way to specify a texture + SkipSpaces(&sz, lineEnd); const char *old = sz; while (!IsSpaceOrNewLine(*sz)) ++sz; @@ -889,7 +884,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, } // 'tess' - tessellation else if (TokenMatch(sz, "tess", 4)) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); iTesselation = strtoul10(sz); } // 'from' - camera position @@ -929,7 +924,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // '' - comment else if ('#' == line[0]) { const char *space; - SkipSpaces(&line[1], &space); + SkipSpaces(&line[1], &space, lineEnd); if (!IsLineEnd(*space)) { ASSIMP_LOG_INFO(space); } diff --git a/code/AssetLib/NFF/NFFLoader.h b/code/AssetLib/NFF/NFFLoader.h index b402aec84..dfa6a882f 100644 --- a/code/AssetLib/NFF/NFFLoader.h +++ b/code/AssetLib/NFF/NFFLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OFF/OFFLoader.cpp b/code/AssetLib/OFF/OFFLoader.cpp index ce8dfc2d4..566e3212e 100644 --- a/code/AssetLib/OFF/OFFLoader.cpp +++ b/code/AssetLib/OFF/OFFLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -84,10 +84,10 @@ const aiImporterDesc *OFFImporter::GetInfo() const { // skip blank space, lines and comments static void NextToken(const char **car, const char *end) { - SkipSpacesAndLineEnd(car); + SkipSpacesAndLineEnd(car, end); while (*car < end && (**car == '#' || **car == '\n' || **car == '\r')) { - SkipLine(car); - SkipSpacesAndLineEnd(car); + SkipLine(car, end); + SkipSpacesAndLineEnd(car, end); } } @@ -195,6 +195,7 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy char line[4096]; buffer = car; const char *sz = car; + const char *lineEnd = &line[4096]; // now read all vertex lines for (unsigned int i = 0; i < numVertices; ++i) { @@ -210,13 +211,13 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // stop at dimensions: this allows loading 1D or 2D coordinate vertices for (unsigned int dim = 0; dim < dimensions; ++dim) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, *vec[dim]); } // if has homogeneous coordinate, divide others by this one if (hasHomogenous) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); ai_real w = 1.; sz = fast_atoreal_move(sz, w); for (unsigned int dim = 0; dim < dimensions; ++dim) { @@ -227,11 +228,11 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // read optional normals if (hasNormals) { aiVector3D &n = mesh->mNormals[i]; - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)n.x); - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)n.y); - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); fast_atoreal_move(sz, (ai_real &)n.z); } @@ -241,22 +242,22 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // in theory should be testing type ! if (hasColors) { aiColor4D &c = mesh->mColors[0][i]; - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)c.r); if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)c.g); } else { c.g = 0.; } if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)c.b); } else { c.b = 0.; } if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)c.a); } else { c.a = 1.; @@ -264,9 +265,9 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } if (hasTexCoord) { aiVector3D &t = mesh->mTextureCoords[0][i]; - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); sz = fast_atoreal_move(sz, (ai_real &)t.x); - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); fast_atoreal_move(sz, (ai_real &)t.y); } } @@ -280,7 +281,7 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } unsigned int idx; sz = line; - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); idx = strtoul10(sz, &sz); if (!idx || idx > 9) { ASSIMP_LOG_ERROR("OFF: Faces with zero indices aren't allowed"); @@ -291,7 +292,7 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy faces->mNumIndices = idx; faces->mIndices = new unsigned int[faces->mNumIndices]; for (unsigned int m = 0; m < faces->mNumIndices; ++m) { - SkipSpaces(&sz); + SkipSpaces(&sz, lineEnd); idx = strtoul10(sz, &sz); if (idx >= numVertices) { ASSIMP_LOG_ERROR("OFF: Vertex index is out of range"); diff --git a/code/AssetLib/OFF/OFFLoader.h b/code/AssetLib/OFF/OFFLoader.h index b8577e507..02829d360 100644 --- a/code/AssetLib/OFF/OFFLoader.h +++ b/code/AssetLib/OFF/OFFLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Obj/ObjExporter.cpp b/code/AssetLib/Obj/ObjExporter.cpp index a5d8325fc..7c5c051f3 100644 --- a/code/AssetLib/Obj/ObjExporter.cpp +++ b/code/AssetLib/Obj/ObjExporter.cpp @@ -59,9 +59,9 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp -void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) { +void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* props) { // invoke the exporter - ObjExporter exporter(pFile, pScene); + ObjExporter exporter(pFile, pScene, false, props); if (exporter.mOutput.fail() || exporter.mOutputMat.fail()) { throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile)); @@ -86,9 +86,9 @@ void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Wavefront OBJ without the material file. Prototyped and registered in Exporter.cpp -void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* ) { +void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* props) { // invoke the exporter - ObjExporter exporter(pFile, pScene, true); + ObjExporter exporter(pFile, pScene, true, props); if (exporter.mOutput.fail() || exporter.mOutputMat.fail()) { throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile)); @@ -111,7 +111,7 @@ void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* p static const std::string MaterialExt = ".mtl"; // ------------------------------------------------------------------------------------------------ -ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMtl) +ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMtl, const ExportProperties* props) : filename(_filename) , pScene(pScene) , vn() @@ -130,7 +130,10 @@ ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMt mOutputMat.imbue(l); mOutputMat.precision(ASSIMP_AI_REAL_TEXT_PRECISION); - WriteGeometryFile(noMtl); + WriteGeometryFile( + noMtl, + props == nullptr ? true : props->GetPropertyBool("bJoinIdenticalVertices", true) + ); if ( !noMtl ) { WriteMaterialFile(); } @@ -255,14 +258,14 @@ void ObjExporter::WriteMaterialFile() { } } -void ObjExporter::WriteGeometryFile(bool noMtl) { +void ObjExporter::WriteGeometryFile(bool noMtl, bool merge_identical_vertices) { WriteHeader(mOutput); if (!noMtl) mOutput << "mtllib " << GetMaterialLibName() << endl << endl; // collect mesh geometry aiMatrix4x4 mBase; - AddNode(pScene->mRootNode, mBase); + AddNode(pScene->mRootNode, mBase, merge_identical_vertices); // write vertex positions with colors, if any mVpMap.getKeys( vp ); @@ -330,7 +333,7 @@ void ObjExporter::WriteGeometryFile(bool noMtl) { } // ------------------------------------------------------------------------------------------------ -void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat) { +void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat, bool merge_identical_vertices) { mMeshes.emplace_back(); MeshInstance& mesh = mMeshes.back(); @@ -362,13 +365,14 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4 for(unsigned int a = 0; a < f.mNumIndices; ++a) { const unsigned int idx = f.mIndices[a]; + const unsigned int fi = merge_identical_vertices ? 0 : idx; aiVector3D vert = mat * m->mVertices[idx]; if ( nullptr != m->mColors[ 0 ] ) { aiColor4D col4 = m->mColors[ 0 ][ idx ]; - face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(col4.r, col4.g, col4.b)}); + face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(col4.r, col4.g, col4.b), fi}); } else { - face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(0,0,0)}); + face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(0,0,0), fi}); } if (m->mNormals) { @@ -388,21 +392,21 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4 } // ------------------------------------------------------------------------------------------------ -void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent) { +void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent, bool merge_identical_vertices) { const aiMatrix4x4& mAbs = mParent * nd->mTransformation; aiMesh *cm( nullptr ); for(unsigned int i = 0; i < nd->mNumMeshes; ++i) { cm = pScene->mMeshes[nd->mMeshes[i]]; if (nullptr != cm) { - AddMesh(cm->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs); + AddMesh(cm->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs, merge_identical_vertices); } else { - AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs); + AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs, merge_identical_vertices); } } for(unsigned int i = 0; i < nd->mNumChildren; ++i) { - AddNode(nd->mChildren[i], mAbs); + AddNode(nd->mChildren[i], mAbs, merge_identical_vertices); } } diff --git a/code/AssetLib/Obj/ObjExporter.h b/code/AssetLib/Obj/ObjExporter.h index a64f38f74..4c92aa16f 100644 --- a/code/AssetLib/Obj/ObjExporter.h +++ b/code/AssetLib/Obj/ObjExporter.h @@ -51,6 +51,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + struct aiScene; struct aiNode; struct aiMesh; @@ -63,7 +65,7 @@ namespace Assimp { class ObjExporter { public: /// Constructor for a specific scene to export - ObjExporter(const char* filename, const aiScene* pScene, bool noMtl=false); + ObjExporter(const char* filename, const aiScene* pScene, bool noMtl=false, const ExportProperties* props = nullptr); ~ObjExporter(); std::string GetMaterialLibName(); std::string GetMaterialLibFileName(); @@ -97,10 +99,10 @@ private: void WriteHeader(std::ostringstream& out); void WriteMaterialFile(); - void WriteGeometryFile(bool noMtl=false); + void WriteGeometryFile(bool noMtl=false, bool merge_identical_vertices = false); std::string GetMaterialName(unsigned int index); - void AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat); - void AddNode(const aiNode* nd, const aiMatrix4x4& mParent); + void AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat, bool merge_identical_vertices); + void AddNode(const aiNode* nd, const aiMatrix4x4& mParent, bool merge_identical_vertices); private: std::string filename; @@ -109,6 +111,7 @@ private: struct vertexData { aiVector3D vp; aiColor3D vc; // OBJ does not support 4D color + uint32_t index = 0; }; std::vector vn, vt; @@ -133,7 +136,7 @@ private: if (a.vc.g > b.vc.g) return false; if (a.vc.b < b.vc.b) return true; if (a.vc.b > b.vc.b) return false; - return false; + return a.index < b.index; } }; diff --git a/code/AssetLib/Obj/ObjFileData.h b/code/AssetLib/Obj/ObjFileData.h index 22090e63e..3dc20c799 100644 --- a/code/AssetLib/Obj/ObjFileData.h +++ b/code/AssetLib/Obj/ObjFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 339e90b06..e956f83d4 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index acb3f074c..c0f1fc483 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -52,7 +52,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include namespace Assimp { @@ -64,6 +63,7 @@ ObjFileParser::ObjFileParser() : m_pModel(nullptr), m_uiLine(0), m_buffer(), + mEnd(&m_buffer[Buffersize]), m_pIO(nullptr), m_progress(nullptr), m_originalObjFileName() { @@ -97,8 +97,6 @@ ObjFileParser::ObjFileParser(IOStreamBuffer &streamBuffer, const std::stri parseFile(streamBuffer); } -ObjFileParser::~ObjFileParser() = default; - void ObjFileParser::setBuffer(std::vector &buffer) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); @@ -121,6 +119,7 @@ void ObjFileParser::parseFile(IOStreamBuffer &streamBuffer) { while (streamBuffer.getNextDataLine(buffer, '\\')) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); + mEnd = &buffer[buffer.size() - 1] + 1; // Handle progress reporting const size_t filePos(streamBuffer.getFilePos()); @@ -130,7 +129,7 @@ void ObjFileParser::parseFile(IOStreamBuffer &streamBuffer) { m_progress->UpdateFileRead(processed, progressTotal); } - // handle cstype section end (http://paulbourke.net/dataformats/obj/) + // handle c-stype section end (http://paulbourke.net/dataformats/obj/) if (insideCstype) { switch (*m_DataIt) { case 'e': { @@ -301,18 +300,19 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() { } else if (IsLineEnd(*tmp)) { end_of_definition = true; } - if (!SkipSpaces(&tmp)) { + if (!SkipSpaces(&tmp, mEnd)) { break; } const bool isNum(IsNumeric(*tmp) || isNanOrInf(tmp)); - SkipToken(tmp); + SkipToken(tmp, mEnd); if (isNum) { ++numComponents; } - if (!SkipSpaces(&tmp)) { + if (!SkipSpaces(&tmp, mEnd)) { break; } } + return numComponents; } @@ -487,8 +487,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) { ++iStep; } - if (iPos == 1 && !vt && vn) + if (iPos == 1 && !vt && vn) { iPos = 2; // skip texture coords for normals if there are no tex coords + } if (iVal > 0) { // Store parsed index @@ -577,8 +578,9 @@ void ObjFileParser::getMaterialDesc() { // Get name std::string strName(pStart, &(*m_DataIt)); strName = trim_whitespaces(strName); - if (strName.empty()) + if (strName.empty()) { skip = true; + } // If the current mesh has the same material, we simply ignore that 'usemtl' command // There is no need to create another object or even mesh here diff --git a/code/AssetLib/Obj/ObjFileParser.h b/code/AssetLib/Obj/ObjFileParser.h index 0ed724461..f3e149838 100644 --- a/code/AssetLib/Obj/ObjFileParser.h +++ b/code/AssetLib/Obj/ObjFileParser.h @@ -41,6 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OBJ_FILEPARSER_H_INC #define OBJ_FILEPARSER_H_INC +#include "ObjFileData.h" + #include #include #include @@ -53,14 +55,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -namespace ObjFile { -struct Model; -struct Object; -struct Material; -struct Point3; -struct Point2; -} // namespace ObjFile - class ObjFileImporter; class IOSystem; class ProgressHandler; @@ -79,7 +73,7 @@ public: /// @brief Constructor with data array. ObjFileParser(IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem *io, ProgressHandler *progress, const std::string &originalObjFileName); /// @brief Destructor - ~ObjFileParser(); + ~ObjFileParser() = default; /// @brief If you want to load in-core data. void setBuffer(std::vector &buffer); /// @brief Model getter. @@ -149,6 +143,7 @@ private: unsigned int m_uiLine; //! Helper buffer char m_buffer[Buffersize]; + const char *mEnd; /// Pointer to IO system instance. IOSystem *m_pIO; //! Pointer to progress handler diff --git a/code/AssetLib/Obj/ObjTools.h b/code/AssetLib/Obj/ObjTools.h index ca173de0a..664402ee3 100644 --- a/code/AssetLib/Obj/ObjTools.h +++ b/code/AssetLib/Obj/ObjTools.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreBinarySerializer.cpp b/code/AssetLib/Ogre/OgreBinarySerializer.cpp index 738e1181e..ee92785ef 100644 --- a/code/AssetLib/Ogre/OgreBinarySerializer.cpp +++ b/code/AssetLib/Ogre/OgreBinarySerializer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreBinarySerializer.h b/code/AssetLib/Ogre/OgreBinarySerializer.h index eb026ea70..7bba8b768 100644 --- a/code/AssetLib/Ogre/OgreBinarySerializer.h +++ b/code/AssetLib/Ogre/OgreBinarySerializer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreImporter.cpp b/code/AssetLib/Ogre/OgreImporter.cpp index 5bf6901a0..8e58179bc 100644 --- a/code/AssetLib/Ogre/OgreImporter.cpp +++ b/code/AssetLib/Ogre/OgreImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreImporter.h b/code/AssetLib/Ogre/OgreImporter.h index 3a72ae70e..2347956f2 100644 --- a/code/AssetLib/Ogre/OgreImporter.h +++ b/code/AssetLib/Ogre/OgreImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreMaterial.cpp b/code/AssetLib/Ogre/OgreMaterial.cpp index 0def59b79..d1244ada3 100644 --- a/code/AssetLib/Ogre/OgreMaterial.cpp +++ b/code/AssetLib/Ogre/OgreMaterial.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreParsingUtils.h b/code/AssetLib/Ogre/OgreParsingUtils.h index 60dd5cf76..2591644e3 100644 --- a/code/AssetLib/Ogre/OgreParsingUtils.h +++ b/code/AssetLib/Ogre/OgreParsingUtils.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreStructs.cpp b/code/AssetLib/Ogre/OgreStructs.cpp index ed8b9be79..29a8d768d 100644 --- a/code/AssetLib/Ogre/OgreStructs.cpp +++ b/code/AssetLib/Ogre/OgreStructs.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreStructs.h b/code/AssetLib/Ogre/OgreStructs.h index dcdf0670f..1ba8e840f 100644 --- a/code/AssetLib/Ogre/OgreStructs.h +++ b/code/AssetLib/Ogre/OgreStructs.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreXmlSerializer.cpp b/code/AssetLib/Ogre/OgreXmlSerializer.cpp index 8a1b88510..2eaa74c01 100644 --- a/code/AssetLib/Ogre/OgreXmlSerializer.cpp +++ b/code/AssetLib/Ogre/OgreXmlSerializer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ogre/OgreXmlSerializer.h b/code/AssetLib/Ogre/OgreXmlSerializer.h index 406681f55..c6f8e23a2 100644 --- a/code/AssetLib/Ogre/OgreXmlSerializer.h +++ b/code/AssetLib/Ogre/OgreXmlSerializer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OpenGEX/OpenGEXExporter.cpp b/code/AssetLib/OpenGEX/OpenGEXExporter.cpp index f812d0ddb..cbea5f39b 100644 --- a/code/AssetLib/OpenGEX/OpenGEXExporter.cpp +++ b/code/AssetLib/OpenGEX/OpenGEXExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OpenGEX/OpenGEXExporter.h b/code/AssetLib/OpenGEX/OpenGEXExporter.h index 8e31b9ae3..93e5ffc74 100644 --- a/code/AssetLib/OpenGEX/OpenGEXExporter.h +++ b/code/AssetLib/OpenGEX/OpenGEXExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp index 735f56755..20b2e77ac 100644 --- a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp +++ b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OpenGEX/OpenGEXImporter.h b/code/AssetLib/OpenGEX/OpenGEXImporter.h index 997d58af9..cf5773387 100644 --- a/code/AssetLib/OpenGEX/OpenGEXImporter.h +++ b/code/AssetLib/OpenGEX/OpenGEXImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/OpenGEX/OpenGEXStructs.h b/code/AssetLib/OpenGEX/OpenGEXStructs.h index 5f845483d..91b31a41a 100644 --- a/code/AssetLib/OpenGEX/OpenGEXStructs.h +++ b/code/AssetLib/OpenGEX/OpenGEXStructs.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ply/PlyExporter.cpp b/code/AssetLib/Ply/PlyExporter.cpp index 9453e0d4d..2dc3311ff 100644 --- a/code/AssetLib/Ply/PlyExporter.cpp +++ b/code/AssetLib/Ply/PlyExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ply/PlyExporter.h b/code/AssetLib/Ply/PlyExporter.h index ff3a54cb6..810626d69 100644 --- a/code/AssetLib/Ply/PlyExporter.h +++ b/code/AssetLib/Ply/PlyExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ply/PlyLoader.cpp b/code/AssetLib/Ply/PlyLoader.cpp index a747ba5cd..3e92339fb 100644 --- a/code/AssetLib/Ply/PlyLoader.cpp +++ b/code/AssetLib/Ply/PlyLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -159,7 +159,8 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy mBuffer = (unsigned char *)&mBuffer2[0]; char *szMe = (char *)&this->mBuffer[0]; - SkipSpacesAndLineEnd(szMe, (const char **)&szMe); + const char *end = &mBuffer2[0] + mBuffer2.size(); + SkipSpacesAndLineEnd(szMe, (const char **)&szMe, end); // determine the format of the file data and construct the aiMesh PLY::DOM sPlyDom; @@ -167,7 +168,7 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy if (TokenMatch(szMe, "format", 6)) { if (TokenMatch(szMe, "ascii", 5)) { - SkipLine(szMe, (const char **)&szMe); + SkipLine(szMe, (const char **)&szMe, end); if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this)) { if (mGeneratedMesh != nullptr) { delete (mGeneratedMesh); diff --git a/code/AssetLib/Ply/PlyLoader.h b/code/AssetLib/Ply/PlyLoader.h index f85445f91..048f40e3f 100644 --- a/code/AssetLib/Ply/PlyLoader.h +++ b/code/AssetLib/Ply/PlyLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Ply/PlyParser.cpp b/code/AssetLib/Ply/PlyParser.cpp index 662da805e..dbbabc03f 100644 --- a/code/AssetLib/Ply/PlyParser.cpp +++ b/code/AssetLib/Ply/PlyParser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { // ------------------------------------------------------------------------------------------------ PLY::EDataType PLY::Property::ParseDataType(std::vector &buffer) { @@ -296,7 +296,7 @@ bool PLY::Element::ParseElement(IOStreamBuffer &streamBuffer, std::vector< return true; } - //parse the number of occurrences of this element + // parse the number of occurrences of this element const char *pCur = (char *)&buffer[0]; pOut->NumOccur = strtoul10(pCur, &pCur); @@ -321,13 +321,13 @@ bool PLY::Element::ParseElement(IOStreamBuffer &streamBuffer, std::vector< return true; } -// ------------------------------------------------------------------------------------------------ bool PLY::DOM::SkipSpaces(std::vector &buffer) { const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0]; + const char *end = pCur + buffer.size(); bool ret = false; if (pCur) { const char *szCur = pCur; - ret = Assimp::SkipSpaces(pCur, &pCur); + ret = Assimp::SkipSpaces(pCur, &pCur, end); uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur; buffer.erase(buffer.begin(), buffer.begin() + iDiff); @@ -339,10 +339,11 @@ bool PLY::DOM::SkipSpaces(std::vector &buffer) { bool PLY::DOM::SkipLine(std::vector &buffer) { const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0]; + const char *end = pCur + buffer.size(); bool ret = false; if (pCur) { const char *szCur = pCur; - ret = Assimp::SkipLine(pCur, &pCur); + ret = Assimp::SkipLine(pCur, &pCur, end); uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur; buffer.erase(buffer.begin(), buffer.begin() + iDiff); @@ -369,10 +370,11 @@ bool PLY::DOM::TokenMatch(std::vector &buffer, const char *token, unsigned bool PLY::DOM::SkipSpacesAndLineEnd(std::vector &buffer) { const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0]; + const char *end = pCur + buffer.size(); bool ret = false; if (pCur) { const char *szCur = pCur; - ret = Assimp::SkipSpacesAndLineEnd(pCur, &pCur); + ret = Assimp::SkipSpacesAndLineEnd(pCur, &pCur, end); uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur; buffer.erase(buffer.begin(), buffer.begin() + iDiff); @@ -426,7 +428,7 @@ bool PLY::DOM::ParseHeader(IOStreamBuffer &streamBuffer, std::vector } else { // ignore unknown header elements if (!streamBuffer.getNextLine(buffer)) - return false; + return false; } } @@ -446,7 +448,7 @@ bool PLY::DOM::ParseElementInstanceLists(IOStreamBuffer &streamBuffer, std std::vector::iterator a = alElementData.begin(); // parse all element instances - //construct vertices and faces + // construct vertices and faces for (; i != alElements.end(); ++i, ++a) { if ((*i).eSemantic == EEST_Vertex || (*i).eSemantic == EEST_Face || (*i).eSemantic == EEST_TriStrip) { PLY::ElementInstanceList::ParseInstanceList(streamBuffer, buffer, &(*i), nullptr, loader); @@ -528,7 +530,7 @@ bool PLY::DOM::ParseInstance(IOStreamBuffer &streamBuffer, DOM *p_pcOut, P return false; } - //get next line after header + // get next line after header streamBuffer.getNextLine(buffer); if (!p_pcOut->ParseElementInstanceLists(streamBuffer, buffer, loader)) { ASSIMP_LOG_VERBOSE_DEBUG("PLY::DOM::ParseInstance() failure"); @@ -558,23 +560,24 @@ bool PLY::ElementInstanceList::ParseInstanceList( } } else { const char *pCur = (const char *)&buffer[0]; + const char *end = pCur + buffer.size(); // be sure to have enough storage for (unsigned int i = 0; i < pcElement->NumOccur; ++i) { if (p_pcOut) - PLY::ElementInstance::ParseInstance(pCur, pcElement, &p_pcOut->alInstances[i]); + PLY::ElementInstance::ParseInstance(pCur, end, pcElement, &p_pcOut->alInstances[i]); else { ElementInstance elt; - PLY::ElementInstance::ParseInstance(pCur, pcElement, &elt); + PLY::ElementInstance::ParseInstance(pCur, end, pcElement, &elt); // Create vertex or face if (pcElement->eSemantic == EEST_Vertex) { - //call loader instance from here + // call loader instance from here loader->LoadVertex(pcElement, &elt, i); } else if (pcElement->eSemantic == EEST_Face) { - //call loader instance from here + // call loader instance from here loader->LoadFace(pcElement, &elt, i); } else if (pcElement->eSemantic == EEST_TriStrip) { - //call loader instance from here + // call loader instance from here loader->LoadFace(pcElement, &elt, i); } } @@ -611,13 +614,13 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary( // Create vertex or face if (pcElement->eSemantic == EEST_Vertex) { - //call loader instance from here + // call loader instance from here loader->LoadVertex(pcElement, &elt, i); } else if (pcElement->eSemantic == EEST_Face) { - //call loader instance from here + // call loader instance from here loader->LoadFace(pcElement, &elt, i); } else if (pcElement->eSemantic == EEST_TriStrip) { - //call loader instance from here + // call loader instance from here loader->LoadFace(pcElement, &elt, i); } } @@ -626,7 +629,7 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary( } // ------------------------------------------------------------------------------------------------ -bool PLY::ElementInstance::ParseInstance(const char *&pCur, +bool PLY::ElementInstance::ParseInstance(const char *&pCur, const char *end, const PLY::Element *pcElement, PLY::ElementInstance *p_pcOut) { ai_assert(nullptr != pcElement); @@ -638,7 +641,7 @@ bool PLY::ElementInstance::ParseInstance(const char *&pCur, std::vector::iterator i = p_pcOut->alProperties.begin(); std::vector::const_iterator a = pcElement->alProperties.begin(); for (; i != p_pcOut->alProperties.end(); ++i, ++a) { - if (!(PLY::PropertyInstance::ParseInstance(pCur, &(*a), &(*i)))) { + if (!(PLY::PropertyInstance::ParseInstance(pCur, end, &(*a), &(*i)))) { ASSIMP_LOG_WARN("Unable to parse property instance. " "Skipping this element instance"); @@ -678,13 +681,13 @@ bool PLY::ElementInstance::ParseInstanceBinary( } // ------------------------------------------------------------------------------------------------ -bool PLY::PropertyInstance::ParseInstance(const char *&pCur, - const PLY::Property *prop, PLY::PropertyInstance *p_pcOut) { +bool PLY::PropertyInstance::ParseInstance(const char *&pCur, const char *end, const PLY::Property *prop, + PLY::PropertyInstance *p_pcOut) { ai_assert(nullptr != prop); ai_assert(nullptr != p_pcOut); // skip spaces at the beginning - if (!SkipSpaces(&pCur)) { + if (!SkipSpaces(&pCur, end)) { return false; } @@ -699,7 +702,7 @@ bool PLY::PropertyInstance::ParseInstance(const char *&pCur, // parse all list elements p_pcOut->avList.resize(iNum); for (unsigned int i = 0; i < iNum; ++i) { - if (!SkipSpaces(&pCur)) + if (!SkipSpaces(&pCur, end)) return false; PLY::PropertyInstance::ParseValue(pCur, prop->eType, &p_pcOut->avList[i]); @@ -711,7 +714,7 @@ bool PLY::PropertyInstance::ParseInstance(const char *&pCur, PLY::PropertyInstance::ParseValue(pCur, prop->eType, &v); p_pcOut->avList.push_back(v); } - SkipSpacesAndLineEnd(&pCur); + SkipSpacesAndLineEnd(&pCur, end); return true; } @@ -774,7 +777,7 @@ bool PLY::PropertyInstance::ParseValue(const char *&pCur, ai_assert(nullptr != pCur); ai_assert(nullptr != out); - //calc element size + // calc element size bool ret = true; switch (eType) { case EDT_UInt: @@ -824,7 +827,7 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer &streamBuffer, bool p_bBE) { ai_assert(nullptr != out); - //calc element size + // calc element size unsigned int lsize = 0; switch (eType) { case EDT_Char: @@ -852,11 +855,11 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer &streamBuffer, break; } - //read the next file block if needed + // read the next file block if needed if (bufferSize < lsize) { std::vector nbuffer; if (streamBuffer.getNextBlock(nbuffer)) { - //concat buffer contents + // concat buffer contents buffer = std::vector(buffer.end() - bufferSize, buffer.end()); buffer.insert(buffer.end(), nbuffer.begin(), nbuffer.end()); nbuffer.clear(); @@ -958,4 +961,6 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer &streamBuffer, return ret; } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER diff --git a/code/AssetLib/Ply/PlyParser.h b/code/AssetLib/Ply/PlyParser.h index 593791e92..fc6f346af 100644 --- a/code/AssetLib/Ply/PlyParser.h +++ b/code/AssetLib/Ply/PlyParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -324,7 +324,7 @@ public: // ------------------------------------------------------------------- //! Parse a property instance - static bool ParseInstance(const char* &pCur, + static bool ParseInstance(const char* &pCur, const char *end, const Property* prop, PropertyInstance* p_pcOut); // ------------------------------------------------------------------- @@ -364,7 +364,7 @@ public: // ------------------------------------------------------------------- //! Parse an element instance - static bool ParseInstance(const char* &pCur, + static bool ParseInstance(const char *&pCur, const char *end, const Element* pcElement, ElementInstance* p_pcOut); // ------------------------------------------------------------------- diff --git a/code/AssetLib/Q3BSP/Q3BSPFileData.h b/code/AssetLib/Q3BSP/Q3BSPFileData.h index 086cf7842..2d86ce564 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileData.h +++ b/code/AssetLib/Q3BSP/Q3BSPFileData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp b/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp index a82f29cf1..d2ab59eb4 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp +++ b/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Q3BSP/Q3BSPFileImporter.h b/code/AssetLib/Q3BSP/Q3BSPFileImporter.h index 63d6edb21..b779c55a5 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileImporter.h +++ b/code/AssetLib/Q3BSP/Q3BSPFileImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Q3BSP/Q3BSPFileParser.cpp b/code/AssetLib/Q3BSP/Q3BSPFileParser.cpp index 910da5b36..c9c3d24cf 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileParser.cpp +++ b/code/AssetLib/Q3BSP/Q3BSPFileParser.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Q3BSP/Q3BSPFileParser.h b/code/AssetLib/Q3BSP/Q3BSPFileParser.h index 15cc751cc..de4d609e4 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileParser.h +++ b/code/AssetLib/Q3BSP/Q3BSPFileParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index b599ad8f2..ac6b17ec6 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -250,6 +250,10 @@ void Q3DImporter::InternReadFile(const std::string &pFile, c = stream.GetI1(); while (c) { mat.name.data[mat.name.length++] = c; + if (mat.name.length == MAXLEN) { + ASSIMP_LOG_ERROR("String ouverflow detected, skipped material name parsing."); + break; + } c = stream.GetI1(); } diff --git a/code/AssetLib/Q3D/Q3DLoader.h b/code/AssetLib/Q3D/Q3DLoader.h index 54af86dc2..ed33ed7ca 100644 --- a/code/AssetLib/Q3D/Q3DLoader.h +++ b/code/AssetLib/Q3D/Q3DLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Raw/RawLoader.cpp b/code/AssetLib/Raw/RawLoader.cpp index 4c5f852b0..6c04680b8 100644 --- a/code/AssetLib/Raw/RawLoader.cpp +++ b/code/AssetLib/Raw/RawLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -104,11 +104,12 @@ void RAWImporter::InternReadFile(const std::string &pFile, // now read all lines char line[4096]; + const char *end = &line[4096]; while (GetNextLine(buffer, line)) { // if the line starts with a non-numeric identifier, it marks // the beginning of a new group const char *sz = line; - SkipSpaces(&sz); + SkipSpaces(&sz, end); if (IsLineEnd(*sz)) continue; if (!IsNumeric(*sz)) { const char *sz2 = sz; @@ -117,8 +118,8 @@ void RAWImporter::InternReadFile(const std::string &pFile, const unsigned int length = (unsigned int)(sz2 - sz); // find an existing group with this name - for (std::vector::iterator it = outGroups.begin(), end = outGroups.end(); - it != end; ++it) { + for (std::vector::iterator it = outGroups.begin(), endIt = outGroups.end(); + it != endIt; ++it) { if (length == (*it).name.length() && !::strcmp(sz, (*it).name.c_str())) { curGroup = it; sz2 = nullptr; @@ -134,7 +135,7 @@ void RAWImporter::InternReadFile(const std::string &pFile, float data[12]; unsigned int num; for (num = 0; num < 12; ++num) { - if (!SkipSpaces(&sz) || !IsNumeric(*sz)) break; + if (!SkipSpaces(&sz, end) || !IsNumeric(*sz)) break; sz = fast_atoreal_move(sz, data[num]); } if (num != 12 && num != 9) { diff --git a/code/AssetLib/Raw/RawLoader.h b/code/AssetLib/Raw/RawLoader.h index 83e4a9f1f..aa0fbdf81 100644 --- a/code/AssetLib/Raw/RawLoader.h +++ b/code/AssetLib/Raw/RawLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/SIB/SIBImporter.cpp b/code/AssetLib/SIB/SIBImporter.cpp index 840f74b7d..e55e67541 100644 --- a/code/AssetLib/SIB/SIBImporter.cpp +++ b/code/AssetLib/SIB/SIBImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/SIB/SIBImporter.h b/code/AssetLib/SIB/SIBImporter.h index 903c36561..9dd0c0095 100644 --- a/code/AssetLib/SIB/SIBImporter.h +++ b/code/AssetLib/SIB/SIBImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/SMD/SMDLoader.cpp b/code/AssetLib/SMD/SMDLoader.cpp index 4b63dd9d0..df598e5c7 100644 --- a/code/AssetLib/SMD/SMDLoader.cpp +++ b/code/AssetLib/SMD/SMDLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -82,8 +82,10 @@ static constexpr aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer SMDImporter::SMDImporter() : - configFrameID(), - pScene( nullptr ), + configFrameID(), + mBuffer(), + mEnd(nullptr), + pScene(nullptr), iFileSize( 0 ), iSmallestFrame( INT_MAX ), dLengthOfAnim( 0.0 ), @@ -92,9 +94,6 @@ SMDImporter::SMDImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -SMDImporter::~SMDImporter() = default; // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. @@ -632,13 +631,13 @@ void SMDImporter::ParseFile() { // read line per line ... for ( ;; ) { - if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) { + if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent, mEnd)) { break; } // "version \n", should be 1 for hl and hl2 SMD files if (TokenMatch(szCurrent,"version",7)) { - if(!SkipSpaces(szCurrent,&szCurrent)) break; + if(!SkipSpaces(szCurrent,&szCurrent, mEnd)) break; if (1 != strtoul10(szCurrent,&szCurrent)) { ASSIMP_LOG_WARN("SMD.version is not 1. This " "file format is not known. Continuing happily ..."); @@ -647,26 +646,26 @@ void SMDImporter::ParseFile() { } // "nodes\n" - Starts the node section if (TokenMatch(szCurrent,"nodes",5)) { - ParseNodesSection(szCurrent,&szCurrent); + ParseNodesSection(szCurrent, &szCurrent, mEnd); continue; } // "triangles\n" - Starts the triangle section if (TokenMatch(szCurrent,"triangles",9)) { - ParseTrianglesSection(szCurrent,&szCurrent); + ParseTrianglesSection(szCurrent, &szCurrent, mEnd); continue; } // "vertexanimation\n" - Starts the vertex animation section if (TokenMatch(szCurrent,"vertexanimation",15)) { bHasUVs = false; - ParseVASection(szCurrent,&szCurrent); + ParseVASection(szCurrent, &szCurrent, mEnd); continue; } // "skeleton\n" - Starts the skeleton section if (TokenMatch(szCurrent,"skeleton",8)) { - ParseSkeletonSection(szCurrent,&szCurrent); + ParseSkeletonSection(szCurrent, &szCurrent, mEnd); continue; } - SkipLine(szCurrent,&szCurrent); + SkipLine(szCurrent, &szCurrent, mEnd); } } @@ -683,6 +682,7 @@ void SMDImporter::ReadSmd(const std::string &pFile, IOSystem* pIOHandler) { // Allocate storage and copy the contents of the file to a memory buffer mBuffer.resize(iFileSize + 1); TextFileToBuffer(file.get(), mBuffer); + mEnd = &mBuffer[mBuffer.size() - 1] + 1; iSmallestFrame = INT_MAX; bHasUVs = true; @@ -723,26 +723,26 @@ unsigned int SMDImporter::GetTextureIndex(const std::string& filename) { // ------------------------------------------------------------------------------------------------ // Parse the nodes section of the file -void SMDImporter::ParseNodesSection(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseNodesSection(const char* szCurrent, const char** szCurrentOut, const char *end) { for ( ;; ) { // "end\n" - Ends the nodes section - if (0 == ASSIMP_strincmp(szCurrent,"end",3) && IsSpaceOrNewLine(*(szCurrent+3))) { + if (0 == ASSIMP_strincmp(szCurrent, "end", 3) && IsSpaceOrNewLine(*(szCurrent+3))) { szCurrent += 4; break; } - ParseNodeInfo(szCurrent,&szCurrent); + ParseNodeInfo(szCurrent,&szCurrent, end); } - SkipSpacesAndLineEnd(szCurrent,&szCurrent); + SkipSpacesAndLineEnd(szCurrent, &szCurrent, end); *szCurrentOut = szCurrent; } // ------------------------------------------------------------------------------------------------ // Parse the triangles section of the file -void SMDImporter::ParseTrianglesSection(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseTrianglesSection(const char *szCurrent, const char **szCurrentOut, const char *end) { // Parse a triangle, parse another triangle, parse the next triangle ... // and so on until we reach a token that looks quite similar to "end" for ( ;; ) { - if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) { + if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) { break; } @@ -750,17 +750,17 @@ void SMDImporter::ParseTrianglesSection(const char* szCurrent, const char** szCu if (TokenMatch(szCurrent,"end",3)) { break; } - ParseTriangle(szCurrent,&szCurrent); + ParseTriangle(szCurrent,&szCurrent, end); } - SkipSpacesAndLineEnd(szCurrent,&szCurrent); + SkipSpacesAndLineEnd(szCurrent,&szCurrent, end); *szCurrentOut = szCurrent; } // ------------------------------------------------------------------------------------------------ // Parse the vertex animation section of the file -void SMDImporter::ParseVASection(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseVASection(const char *szCurrent, const char **szCurrentOut, const char *end) { unsigned int iCurIndex = 0; for ( ;; ) { - if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) { + if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) { break; } @@ -774,10 +774,10 @@ void SMDImporter::ParseVASection(const char* szCurrent, const char** szCurrentOu // NOTE: The doc says that time values COULD be negative ... // NOTE2: this is the shape key -> valve docs int iTime = 0; - if(!ParseSignedInt(szCurrent,&szCurrent,iTime) || configFrameID != (unsigned int)iTime) { + if (!ParseSignedInt(szCurrent, &szCurrent, end, iTime) || configFrameID != (unsigned int)iTime) { break; } - SkipLine(szCurrent,&szCurrent); + SkipLine(szCurrent,&szCurrent, end); } else { if(0 == iCurIndex) { asTriangles.emplace_back(); @@ -785,7 +785,7 @@ void SMDImporter::ParseVASection(const char* szCurrent, const char** szCurrentOu if (++iCurIndex == 3) { iCurIndex = 0; } - ParseVertex(szCurrent,&szCurrent,asTriangles.back().avVertices[iCurIndex],true); + ParseVertex(szCurrent,&szCurrent, end, asTriangles.back().avVertices[iCurIndex],true); } } @@ -794,16 +794,16 @@ void SMDImporter::ParseVASection(const char* szCurrent, const char** szCurrentOu asTriangles.pop_back(); } - SkipSpacesAndLineEnd(szCurrent,&szCurrent); + SkipSpacesAndLineEnd(szCurrent,&szCurrent, end); *szCurrentOut = szCurrent; } // ------------------------------------------------------------------------------------------------ // Parse the skeleton section of the file -void SMDImporter::ParseSkeletonSection(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseSkeletonSection(const char *szCurrent, const char **szCurrentOut, const char *end) { int iTime = 0; for ( ;; ) { - if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) { + if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) { break; } @@ -811,15 +811,15 @@ void SMDImporter::ParseSkeletonSection(const char* szCurrent, const char** szCur if (TokenMatch(szCurrent,"end",3)) { break; } else if (TokenMatch(szCurrent,"time",4)) { - // "time \n" - Specifies the current animation frame - if(!ParseSignedInt(szCurrent,&szCurrent,iTime)) { + // "time \n" - Specifies the current animation frame + if (!ParseSignedInt(szCurrent, &szCurrent, end, iTime)) { break; } iSmallestFrame = std::min(iSmallestFrame,iTime); - SkipLine(szCurrent,&szCurrent); + SkipLine(szCurrent, &szCurrent, end); } else { - ParseSkeletonElement(szCurrent,&szCurrent,iTime); + ParseSkeletonElement(szCurrent, &szCurrent, end, iTime); } } *szCurrentOut = szCurrent; @@ -827,16 +827,16 @@ void SMDImporter::ParseSkeletonSection(const char* szCurrent, const char** szCur // ------------------------------------------------------------------------------------------------ #define SMDI_PARSE_RETURN { \ - SkipLine(szCurrent,&szCurrent); \ + SkipLine(szCurrent,&szCurrent, end); \ *szCurrentOut = szCurrent; \ return; \ } // ------------------------------------------------------------------------------------------------ // Parse a node line -void SMDImporter::ParseNodeInfo(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseNodeInfo(const char *szCurrent, const char **szCurrentOut, const char *end) { unsigned int iBone = 0; - SkipSpacesAndLineEnd(szCurrent,&szCurrent); - if ( !ParseUnsignedInt(szCurrent,&szCurrent,iBone) || !SkipSpaces(szCurrent,&szCurrent)) { + SkipSpacesAndLineEnd(szCurrent, &szCurrent, end); + if ( !ParseUnsignedInt(szCurrent, &szCurrent, end, iBone) || !SkipSpaces(szCurrent,&szCurrent, end)) { throw DeadlyImportError("Unexpected EOF/EOL while parsing bone index"); } if (iBone == UINT_MAX) { @@ -877,7 +877,7 @@ void SMDImporter::ParseNodeInfo(const char* szCurrent, const char** szCurrentOut szCurrent = szEnd; // the only negative bone parent index that could occur is -1 AFAIK - if(!ParseSignedInt(szCurrent,&szCurrent,(int&)bone.iParent)) { + if(!ParseSignedInt(szCurrent, &szCurrent, end, (int&)bone.iParent)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone parent index. Assuming -1"); SMDI_PARSE_RETURN; } @@ -888,12 +888,12 @@ void SMDImporter::ParseNodeInfo(const char* szCurrent, const char** szCurrentOut // ------------------------------------------------------------------------------------------------ // Parse a skeleton element -void SMDImporter::ParseSkeletonElement(const char* szCurrent, const char** szCurrentOut,int iTime) { +void SMDImporter::ParseSkeletonElement(const char *szCurrent, const char **szCurrentOut, const char *end, int iTime) { aiVector3D vPos; aiVector3D vRot; unsigned int iBone = 0; - if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone)) { + if (!ParseUnsignedInt(szCurrent, &szCurrent, end, iBone)) { ASSIMP_LOG_ERROR("Unexpected EOF/EOL while parsing bone index"); SMDI_PARSE_RETURN; } @@ -907,27 +907,27 @@ void SMDImporter::ParseSkeletonElement(const char* szCurrent, const char** szCur SMD::Bone::Animation::MatrixKey& key = bone.sAnim.asKeys.back(); key.dTime = (double)iTime; - if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.x)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.x)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.x"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.y)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.y)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.y"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.z)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.z)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.z"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.x)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.x)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.x"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.y)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.y)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.y"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.z)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.z)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.z"); SMDI_PARSE_RETURN; } @@ -947,11 +947,11 @@ void SMDImporter::ParseSkeletonElement(const char* szCurrent, const char** szCur // ------------------------------------------------------------------------------------------------ // Parse a triangle -void SMDImporter::ParseTriangle(const char* szCurrent, const char** szCurrentOut) { +void SMDImporter::ParseTriangle(const char *szCurrent, const char **szCurrentOut, const char *end) { asTriangles.emplace_back(); SMD::Face& face = asTriangles.back(); - if(!SkipSpaces(szCurrent,&szCurrent)) { + if(!SkipSpaces(szCurrent, &szCurrent, end)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing a triangle"); return; } @@ -963,19 +963,19 @@ void SMDImporter::ParseTriangle(const char* szCurrent, const char** szCurrentOut // ... and get the index that belongs to this file name face.iTexture = GetTextureIndex(std::string(szLast,(uintptr_t)szCurrent-(uintptr_t)szLast)); - SkipSpacesAndLineEnd(szCurrent,&szCurrent); + SkipSpacesAndLineEnd(szCurrent, &szCurrent, end); // load three vertices for (auto &avVertex : face.avVertices) { - ParseVertex(szCurrent,&szCurrent, avVertex); + ParseVertex(szCurrent, &szCurrent, end, avVertex); } *szCurrentOut = szCurrent; } // ------------------------------------------------------------------------------------------------ // Parse a float -bool SMDImporter::ParseFloat(const char* szCurrent, const char** szCurrentOut, float& out) { - if(!SkipSpaces(&szCurrent)) { +bool SMDImporter::ParseFloat(const char *szCurrent, const char **szCurrentOut, const char *end, float &out) { + if (!SkipSpaces(&szCurrent, end)) { return false; } @@ -985,8 +985,8 @@ bool SMDImporter::ParseFloat(const char* szCurrent, const char** szCurrentOut, f // ------------------------------------------------------------------------------------------------ // Parse an unsigned int -bool SMDImporter::ParseUnsignedInt(const char* szCurrent, const char** szCurrentOut, unsigned int& out) { - if(!SkipSpaces(&szCurrent)) { +bool SMDImporter::ParseUnsignedInt(const char *szCurrent, const char **szCurrentOut, const char *end, unsigned int &out) { + if(!SkipSpaces(&szCurrent, end)) { return false; } @@ -996,8 +996,8 @@ bool SMDImporter::ParseUnsignedInt(const char* szCurrent, const char** szCurrent // ------------------------------------------------------------------------------------------------ // Parse a signed int -bool SMDImporter::ParseSignedInt(const char* szCurrent, const char** szCurrentOut, int& out) { - if(!SkipSpaces(&szCurrent)) { +bool SMDImporter::ParseSignedInt(const char *szCurrent, const char **szCurrentOut, const char *end, int &out) { + if(!SkipSpaces(&szCurrent, end)) { return false; } @@ -1008,37 +1008,37 @@ bool SMDImporter::ParseSignedInt(const char* szCurrent, const char** szCurrentOu // ------------------------------------------------------------------------------------------------ // Parse a vertex void SMDImporter::ParseVertex(const char* szCurrent, - const char** szCurrentOut, SMD::Vertex& vertex, + const char **szCurrentOut, const char *end, SMD::Vertex &vertex, bool bVASection /*= false*/) { - if (SkipSpaces(&szCurrent) && IsLineEnd(*szCurrent)) { - SkipSpacesAndLineEnd(szCurrent,&szCurrent); - return ParseVertex(szCurrent,szCurrentOut,vertex,bVASection); + if (SkipSpaces(&szCurrent, end) && IsLineEnd(*szCurrent)) { + SkipSpacesAndLineEnd(szCurrent,&szCurrent, end); + return ParseVertex(szCurrent, szCurrentOut, end, vertex, bVASection); } - if(!ParseSignedInt(szCurrent,&szCurrent,(int&)vertex.iParentNode)) { + if(!ParseSignedInt(szCurrent, &szCurrent, end, (int&)vertex.iParentNode)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.parent"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.x)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.x)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.x"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.y)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.y)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.y"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.z)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.z)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.z"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.x)) { + if(!ParseFloat(szCurrent,&szCurrent,end, (float&)vertex.nor.x)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.x"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.y)) { + if(!ParseFloat(szCurrent,&szCurrent, end, (float&)vertex.nor.y)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.y"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.z)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.nor.z)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.z"); SMDI_PARSE_RETURN; } @@ -1047,11 +1047,11 @@ void SMDImporter::ParseVertex(const char* szCurrent, SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.x)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.uv.x)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.x"); SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.y)) { + if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.uv.y)) { LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.y"); SMDI_PARSE_RETURN; } @@ -1059,16 +1059,16 @@ void SMDImporter::ParseVertex(const char* szCurrent, // now read the number of bones affecting this vertex // all elements from now are fully optional, we don't need them unsigned int iSize = 0; - if(!ParseUnsignedInt(szCurrent,&szCurrent,iSize)) { + if(!ParseUnsignedInt(szCurrent, &szCurrent, end, iSize)) { SMDI_PARSE_RETURN; } vertex.aiBoneLinks.resize(iSize,std::pair(0,0.0f)); for (auto &aiBoneLink : vertex.aiBoneLinks) { - if(!ParseUnsignedInt(szCurrent,&szCurrent,aiBoneLink.first)) { + if(!ParseUnsignedInt(szCurrent, &szCurrent, end, aiBoneLink.first)) { SMDI_PARSE_RETURN; } - if(!ParseFloat(szCurrent,&szCurrent,aiBoneLink.second)) { + if(!ParseFloat(szCurrent, &szCurrent, end, aiBoneLink.second)) { SMDI_PARSE_RETURN; } } @@ -1077,6 +1077,6 @@ void SMDImporter::ParseVertex(const char* szCurrent, SMDI_PARSE_RETURN; } -} +} // namespace Assimp #endif // !! ASSIMP_BUILD_NO_SMD_IMPORTER diff --git a/code/AssetLib/SMD/SMDLoader.h b/code/AssetLib/SMD/SMDLoader.h index adf80ba14..c2f2f0a49 100644 --- a/code/AssetLib/SMD/SMDLoader.h +++ b/code/AssetLib/SMD/SMDLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -162,7 +162,7 @@ struct Bone { class ASSIMP_API SMDImporter : public BaseImporter { public: SMDImporter(); - ~SMDImporter() override; + ~SMDImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. @@ -206,7 +206,7 @@ protected: * the next section (or to EOF) */ void ParseTrianglesSection(const char* szCurrent, - const char** szCurrentOut); + const char **szCurrentOut, const char *end); // ------------------------------------------------------------------- /** Parse the vertex animation section in VTA files @@ -216,7 +216,7 @@ protected: * the next section (or to EOF) */ void ParseVASection(const char* szCurrent, - const char** szCurrentOut); + const char **szCurrentOu, const char *end); // ------------------------------------------------------------------- /** Parse the nodes section of the SMD file @@ -226,7 +226,7 @@ protected: * the next section (or to EOF) */ void ParseNodesSection(const char* szCurrent, - const char** szCurrentOut); + const char **szCurrentOut, const char *end); // ------------------------------------------------------------------- /** Parse the skeleton section of the SMD file @@ -236,7 +236,7 @@ protected: * the next section (or to EOF) */ void ParseSkeletonSection(const char* szCurrent, - const char** szCurrentOut); + const char **szCurrentOut, const char *end); // ------------------------------------------------------------------- /** Parse a single triangle in the SMD file @@ -245,8 +245,7 @@ protected: * \param szCurrentOut Receives the output cursor position */ void ParseTriangle(const char* szCurrent, - const char** szCurrentOut); - + const char **szCurrentOut, const char *end); // ------------------------------------------------------------------- /** Parse a single vertex in the SMD file @@ -256,7 +255,7 @@ protected: * \param vertex Vertex to be filled */ void ParseVertex(const char* szCurrent, - const char** szCurrentOut, SMD::Vertex& vertex, + const char **szCurrentOut, const char *end, SMD::Vertex &vertex, bool bVASection = false); // ------------------------------------------------------------------- @@ -271,32 +270,31 @@ protected: /** Parse a line in the skeleton section */ void ParseSkeletonElement(const char* szCurrent, - const char** szCurrentOut,int iTime); + const char **szCurrentOut, const char *end, int iTime); // ------------------------------------------------------------------- /** Parse a line in the nodes section */ void ParseNodeInfo(const char* szCurrent, - const char** szCurrentOut); - + const char **szCurrentOut, const char *end); // ------------------------------------------------------------------- /** Parse a floating-point value */ bool ParseFloat(const char* szCurrent, - const char** szCurrentOut, float& out); + const char **szCurrentOut, const char *end, float &out); // ------------------------------------------------------------------- /** Parse an unsigned integer. There may be no sign! */ bool ParseUnsignedInt(const char* szCurrent, - const char** szCurrentOut, unsigned int& out); + const char **szCurrentOut, const char *end, unsigned int &out); // ------------------------------------------------------------------- /** Parse a signed integer. Signs (+,-) are handled. */ bool ParseSignedInt(const char* szCurrent, - const char** szCurrentOut, int& out); + const char **szCurrentOut, const char *end, int &out); // ------------------------------------------------------------------- /** Fix invalid time values in the file @@ -304,7 +302,7 @@ protected: void FixTimeValues(); // ------------------------------------------------------------------- - /** Add all children of a bone as subnodes to a node + /** Add all children of a bone as sub-nodes to a node * \param pcNode Parent node * \param iParent Parent bone index */ @@ -329,17 +327,15 @@ protected: // ------------------------------------------------------------------- - inline bool SkipLine( const char* in, const char** out) - { - Assimp::SkipLine(in,out); + inline bool SkipLine( const char* in, const char** out, const char *end) { + Assimp::SkipLine(in, out, end); ++iLineNumber; return true; } // ------------------------------------------------------------------- - inline bool SkipSpacesAndLineEnd( const char* in, const char** out) - { + inline bool SkipSpacesAndLineEnd(const char *in, const char **out, const char *end) { ++iLineNumber; - return Assimp::SkipSpacesAndLineEnd(in,out); + return Assimp::SkipSpacesAndLineEnd(in, out, end); } private: @@ -349,6 +345,7 @@ private: /** Buffer to hold the loaded file */ std::vector mBuffer; + char *mEnd; /** Output scene to be filled */ diff --git a/code/AssetLib/STEPParser/STEPFileEncoding.cpp b/code/AssetLib/STEPParser/STEPFileEncoding.cpp index 92eb4f284..d7f512cbb 100644 --- a/code/AssetLib/STEPParser/STEPFileEncoding.cpp +++ b/code/AssetLib/STEPParser/STEPFileEncoding.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/STEPParser/STEPFileEncoding.h b/code/AssetLib/STEPParser/STEPFileEncoding.h index 950c9b3e2..6988a5822 100644 --- a/code/AssetLib/STEPParser/STEPFileEncoding.h +++ b/code/AssetLib/STEPParser/STEPFileEncoding.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/STEPParser/STEPFileReader.cpp b/code/AssetLib/STEPParser/STEPFileReader.cpp index 2bcfa1755..6bc8981f1 100644 --- a/code/AssetLib/STEPParser/STEPFileReader.cpp +++ b/code/AssetLib/STEPParser/STEPFileReader.cpp @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -40,9 +39,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -/** @file STEPFileReader.cpp +/** + * @file STEPFileReader.cpp * @brief Implementation of the STEP file parser, which fills a - * STEP::DB with data read from a file. + * STEP::DB with data read from a file. */ #include "STEPFileReader.h" @@ -58,34 +58,28 @@ using namespace Assimp; namespace EXPRESS = STEP::EXPRESS; // ------------------------------------------------------------------------------------------------ -std::string AddLineNumber(const std::string& s,uint64_t line /*= LINE_NOT_SPECIFIED*/, const std::string& prefix = std::string()) -{ +std::string AddLineNumber(const std::string& s,uint64_t line /*= LINE_NOT_SPECIFIED*/, const std::string& prefix = std::string()) { return line == STEP::SyntaxError::LINE_NOT_SPECIFIED ? prefix+s : static_cast( (Formatter::format(),prefix,"(line ",line,") ",s) ); } // ------------------------------------------------------------------------------------------------ -std::string AddEntityID(const std::string& s,uint64_t entity /*= ENTITY_NOT_SPECIFIED*/, const std::string& prefix = std::string()) -{ +std::string AddEntityID(const std::string& s,uint64_t entity /*= ENTITY_NOT_SPECIFIED*/, const std::string& prefix = std::string()) { return entity == STEP::TypeError::ENTITY_NOT_SPECIFIED ? prefix+s : static_cast( (Formatter::format(),prefix,"(entity #",entity,") ",s)); } // ------------------------------------------------------------------------------------------------ -STEP::SyntaxError::SyntaxError (const std::string& s,uint64_t line /* = LINE_NOT_SPECIFIED */) -: DeadlyImportError(AddLineNumber(s,line)) -{ - +STEP::SyntaxError::SyntaxError (const std::string& s,uint64_t line) : DeadlyImportError(AddLineNumber(s,line)) { + // empty } // ------------------------------------------------------------------------------------------------ -STEP::TypeError::TypeError (const std::string& s,uint64_t entity /* = ENTITY_NOT_SPECIFIED */,uint64_t line /*= LINE_NOT_SPECIFIED*/) -: DeadlyImportError(AddLineNumber(AddEntityID(s,entity),line)) -{ - +STEP::TypeError::TypeError (const std::string& s,uint64_t entity, uint64_t line) : DeadlyImportError(AddLineNumber(AddEntityID(s,entity),line)) { + // empty } -static const char *ISO_Token = "ISO-10303-21;"; -static const char *FILE_SCHEMA_Token = "FILE_SCHEMA"; +static constexpr char ISO_Token[] = "ISO-10303-21;"; +static constexpr char FILE_SCHEMA_Token[] = "FILE_SCHEMA"; // ------------------------------------------------------------------------------------------------ STEP::DB* STEP::ReadFileHeader(std::shared_ptr stream) { std::shared_ptr reader = std::shared_ptr(new StreamReaderLE(std::move(stream))); @@ -110,8 +104,9 @@ STEP::DB* STEP::ReadFileHeader(std::shared_ptr stream) { if (s.substr(0,11) == FILE_SCHEMA_Token) { const char* sz = s.c_str()+11; - SkipSpaces(sz,&sz); - std::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz); + const char *end = s.c_str() + s.size(); + SkipSpaces(sz,&sz, end); + std::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz, end); // the file schema should be a regular list entity, although it usually contains exactly one entry // since the list itself is contained in a regular parameter list, we actually have @@ -304,10 +299,10 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, } // ------------------------------------------------------------------------------------------------ -std::shared_ptr EXPRESS::DataType::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= nullptr*/) +std::shared_ptr EXPRESS::DataType::Parse(const char*& inout, const char *end, uint64_t line, const EXPRESS::ConversionSchema* schema /*= nullptr*/) { const char* cur = inout; - SkipSpaces(&cur); + SkipSpaces(&cur, end); if (*cur == ',' || IsSpaceOrNewLine(*cur)) { throw STEP::SyntaxError("unexpected token, expected parameter",line); } @@ -325,7 +320,7 @@ std::shared_ptr EXPRESS::DataType::Parse(const char*& i std::transform(s.begin(),s.end(),s.begin(),&ai_tolower ); if (schema->IsKnownToken(s)) { for(cur = t+1;*cur++ != '(';); - std::shared_ptr dt = Parse(cur); + std::shared_ptr dt = Parse(cur, end); inout = *cur ? cur+1 : cur; return dt; } @@ -348,7 +343,7 @@ std::shared_ptr EXPRESS::DataType::Parse(const char*& i else if (*cur == '(' ) { // start of an aggregate, further parsing is done by the LIST factory constructor inout = cur; - return EXPRESS::LIST::Parse(inout,line,schema); + return EXPRESS::LIST::Parse(inout, end, line, schema); } else if (*cur == '.' ) { // enum (includes boolean) @@ -427,9 +422,10 @@ std::shared_ptr EXPRESS::DataType::Parse(const char*& i } // ------------------------------------------------------------------------------------------------ -std::shared_ptr EXPRESS::LIST::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= nullptr*/) { +std::shared_ptr EXPRESS::LIST::Parse(const char*& inout, const char *end, + uint64_t line, const EXPRESS::ConversionSchema* schema) { const std::shared_ptr list = std::make_shared(); - EXPRESS::LIST::MemberList& members = list->members; + EXPRESS::LIST::MemberList& cur_members = list->members; const char* cur = inout; if (*cur++ != '(') { @@ -442,19 +438,19 @@ std::shared_ptr EXPRESS::LIST::Parse(const char*& inout,uin count += (*c == ',' ? 1 : 0); } - members.reserve(count); + cur_members.reserve(count); for(;;++cur) { if (!*cur) { throw STEP::SyntaxError("unexpected end of line while reading list"); } - SkipSpaces(cur,&cur); + SkipSpaces(cur,&cur, end); if (*cur == ')') { break; } - members.push_back( EXPRESS::DataType::Parse(cur,line,schema)); - SkipSpaces(cur,&cur); + cur_members.push_back(EXPRESS::DataType::Parse(cur, end, line, schema)); + SkipSpaces(cur, &cur, end); if (*cur != ',') { if (*cur == ')') { @@ -464,7 +460,7 @@ std::shared_ptr EXPRESS::LIST::Parse(const char*& inout,uin } } - inout = cur+1; + inout = cur + 1; return list; } @@ -543,7 +539,8 @@ void STEP::LazyObject::LazyInit() const { } const char* acopy = args; - std::shared_ptr conv_args = EXPRESS::LIST::Parse(acopy,(uint64_t)STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema()); + const char *end = acopy + std::strlen(args); + std::shared_ptr conv_args = EXPRESS::LIST::Parse(acopy, end, (uint64_t)STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema()); delete[] args; args = nullptr; diff --git a/code/AssetLib/STEPParser/STEPFileReader.h b/code/AssetLib/STEPParser/STEPFileReader.h index 8a57937c0..85a7c5cb0 100644 --- a/code/AssetLib/STEPParser/STEPFileReader.h +++ b/code/AssetLib/STEPParser/STEPFileReader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -60,8 +60,7 @@ void ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, const char* const* /// @brief Helper to read a file. template -inline -void ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, const char* const (&arr)[N], const char* const (&arr2)[N2]) { +inline void ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, const char* const (&arr)[N], const char* const (&arr2)[N2]) { return ReadFile(db,scheme,arr,N,arr2,N2); } diff --git a/code/AssetLib/STL/STLExporter.cpp b/code/AssetLib/STL/STLExporter.cpp index 9bbc2063f..0ff96296a 100644 --- a/code/AssetLib/STL/STLExporter.cpp +++ b/code/AssetLib/STL/STLExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/STL/STLExporter.h b/code/AssetLib/STL/STLExporter.h index 066dcfefd..b751e196c 100644 --- a/code/AssetLib/STL/STLExporter.h +++ b/code/AssetLib/STL/STLExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 269ee1467..38cd2a0b8 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -98,7 +98,7 @@ static bool IsAsciiSTL(const char *buffer, size_t fileSize) { const char *bufferEnd = buffer + fileSize; - if (!SkipSpaces(&buffer)) { + if (!SkipSpaces(&buffer, bufferEnd)) { return false; } @@ -244,11 +244,11 @@ void STLImporter::LoadASCIIFile(aiNode *root) { aiNode *node = new aiNode; node->mParent = root; nodes.push_back(node); - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); ai_assert(!IsLineEnd(sz)); sz += 5; // skip the "solid" - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); const char *szMe = sz; while (!IsSpaceOrNewLine(*sz)) { sz++; @@ -270,7 +270,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) { unsigned int faceVertexCounter = 3; for (;;) { // go to the next token - if (!SkipSpacesAndLineEnd(&sz)) { + if (!SkipSpacesAndLineEnd(&sz, bufferEnd)) { // seems we're finished although there was no end marker ASSIMP_LOG_WARN("STL: unexpected EOF. \'endsolid\' keyword was expected"); break; @@ -284,7 +284,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) { faceVertexCounter = 0; sz += 6; - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); if (strncmp(sz, "normal", 6)) { ASSIMP_LOG_WARN("STL: a facet normal vector was expected but not found"); } else { @@ -293,11 +293,11 @@ void STLImporter::LoadASCIIFile(aiNode *root) { } aiVector3D vn; sz += 7; - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); sz = fast_atoreal_move(sz, (ai_real &)vn.x); - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); sz = fast_atoreal_move(sz, (ai_real &)vn.y); - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); sz = fast_atoreal_move(sz, (ai_real &)vn.z); normalBuffer.emplace_back(vn); normalBuffer.emplace_back(vn); @@ -312,13 +312,13 @@ void STLImporter::LoadASCIIFile(aiNode *root) { throw DeadlyImportError("STL: unexpected EOF while parsing facet"); } sz += 7; - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); positionBuffer.emplace_back(); aiVector3D *vn = &positionBuffer.back(); sz = fast_atoreal_move(sz, (ai_real &)vn->x); - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); sz = fast_atoreal_move(sz, (ai_real &)vn->y); - SkipSpaces(&sz); + SkipSpaces(&sz, bufferEnd); sz = fast_atoreal_move(sz, (ai_real &)vn->z); faceVertexCounter++; } @@ -326,7 +326,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) { do { ++sz; } while (!IsLineEnd(*sz)); - SkipSpacesAndLineEnd(&sz); + SkipSpacesAndLineEnd(&sz, bufferEnd); // finished! break; } else { // else skip the whole identifier diff --git a/code/AssetLib/STL/STLLoader.h b/code/AssetLib/STL/STLLoader.h index 0be6a95f0..cc6ab9607 100644 --- a/code/AssetLib/STL/STLLoader.h +++ b/code/AssetLib/STL/STLLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Step/STEPFile.h b/code/AssetLib/Step/STEPFile.h index 76a9370f5..d8bc0ac49 100644 --- a/code/AssetLib/Step/STEPFile.h +++ b/code/AssetLib/Step/STEPFile.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -199,35 +199,27 @@ public: } public: - /** parse a variable from a string and set 'inout' to the character - * behind the last consumed character. An optional schema enables, - * if specified, automatic conversion of custom data types. - * - * @throw SyntaxError - */ - static std::shared_ptr Parse(const char *&inout, - uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, - const EXPRESS::ConversionSchema *schema = nullptr); + /// @brief Parse a variable from a string and set 'inout' to the character behind the last consumed character. + /// + /// An optional schema enables, if specified, automatic conversion of custom data types. + /// + /// @throw SyntaxError + static std::shared_ptr Parse(const char *&inout, const char *end, + uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, const EXPRESS::ConversionSchema *schema = nullptr); }; typedef DataType SELECT; typedef DataType LOGICAL; // ------------------------------------------------------------------------------- -/** Sentinel class to represent explicitly unset (optional) fields ($) */ +/// Sentinel class to represent explicitly unset (optional) fields ($) // ------------------------------------------------------------------------------- -class UNSET : public DataType { -public: -private: -}; +class UNSET : public DataType {}; // ------------------------------------------------------------------------------- -/** Sentinel class to represent explicitly derived fields (*) */ +/// Sentinel class to represent explicitly derived fields (*) // ------------------------------------------------------------------------------- -class ISDERIVED : public DataType { -public: -private: -}; +class ISDERIVED : public DataType {}; // ------------------------------------------------------------------------------- /** Shared implementation for some of the primitive data type, i.e. int, float @@ -304,7 +296,7 @@ public: public: /** @see DaraType::Parse */ - static std::shared_ptr Parse(const char *&inout, + static std::shared_ptr Parse(const char *&inout, const char *end, uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, const EXPRESS::ConversionSchema *schema = nullptr); diff --git a/code/AssetLib/Step/StepExporter.cpp b/code/AssetLib/Step/StepExporter.cpp index e13c9edab..2188ddfec 100644 --- a/code/AssetLib/Step/StepExporter.cpp +++ b/code/AssetLib/Step/StepExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Step/StepExporter.h b/code/AssetLib/Step/StepExporter.h index a02262659..9ae5fb820 100644 --- a/code/AssetLib/Step/StepExporter.h +++ b/code/AssetLib/Step/StepExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Terragen/TerragenLoader.cpp b/code/AssetLib/Terragen/TerragenLoader.cpp index b1870414c..150ebd011 100644 --- a/code/AssetLib/Terragen/TerragenLoader.cpp +++ b/code/AssetLib/Terragen/TerragenLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Terragen/TerragenLoader.h b/code/AssetLib/Terragen/TerragenLoader.h index 0c7b686e9..2d529464b 100644 --- a/code/AssetLib/Terragen/TerragenLoader.h +++ b/code/AssetLib/Terragen/TerragenLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/Unreal/UnrealLoader.cpp b/code/AssetLib/Unreal/UnrealLoader.cpp index 5f622da42..3810e5bf4 100644 --- a/code/AssetLib/Unreal/UnrealLoader.cpp +++ b/code/AssetLib/Unreal/UnrealLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -320,17 +320,18 @@ void UnrealImporter::InternReadFile(const std::string &pFile, std::vector _data; TextFileToBuffer(pb.get(), _data); const char *data = &_data[0]; + const char *end = &_data[_data.size() - 1] + 1; std::vector> tempTextures; // do a quick search in the UC file for some known, usually texture-related, tags for (; *data; ++data) { if (TokenMatchI(data, "#exec", 5)) { - SkipSpacesAndLineEnd(&data); + SkipSpacesAndLineEnd(&data, end); // #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...] if (TokenMatchI(data, "TEXTURE", 7)) { - SkipSpacesAndLineEnd(&data); + SkipSpacesAndLineEnd(&data, end); if (TokenMatchI(data, "IMPORT", 6)) { tempTextures.emplace_back(); @@ -348,14 +349,15 @@ void UnrealImporter::InternReadFile(const std::string &pFile, me.second = std::string(d, (size_t)(data - d)); } } - if (!me.first.length() || !me.second.length()) + if (!me.first.length() || !me.second.length()) { tempTextures.pop_back(); + } } } // #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1 // #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2 else if (TokenMatchI(data, "MESHMAP", 7)) { - SkipSpacesAndLineEnd(&data); + SkipSpacesAndLineEnd(&data, end); if (TokenMatchI(data, "SETTEXTURE", 10)) { @@ -369,8 +371,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile, } else if (!ASSIMP_strincmp(data, "TEXTURE=", 8)) { data += 8; const char *d = data; - for (; !IsSpaceOrNewLine(*data); ++data) - ; + for (; !IsSpaceOrNewLine(*data); ++data); me.second = std::string(d, (size_t)(data - d)); // try to find matching path names, doesn't care if we don't find them @@ -408,7 +409,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile, // find out how many output meshes and materials we'll have and build material indices for (Unreal::Triangle &tri : triangles) { Unreal::TempMat mat(tri); - std::vector::iterator nt = std::find(materials.begin(), materials.end(), mat); + auto nt = std::find(materials.begin(), materials.end(), mat); if (nt == materials.end()) { // add material tri.matIndex = static_cast(materials.size()); diff --git a/code/AssetLib/Unreal/UnrealLoader.h b/code/AssetLib/Unreal/UnrealLoader.h index fda784cfb..b32a5fc74 100644 --- a/code/AssetLib/Unreal/UnrealLoader.h +++ b/code/AssetLib/Unreal/UnrealLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileExporter.cpp b/code/AssetLib/X/XFileExporter.cpp index f0b1608c1..15ecf9464 100644 --- a/code/AssetLib/X/XFileExporter.cpp +++ b/code/AssetLib/X/XFileExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileExporter.h b/code/AssetLib/X/XFileExporter.h index 1d9a5ae77..744944062 100644 --- a/code/AssetLib/X/XFileExporter.h +++ b/code/AssetLib/X/XFileExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileHelper.h b/code/AssetLib/X/XFileHelper.h index 4b95672f3..e3fff2b66 100644 --- a/code/AssetLib/X/XFileHelper.h +++ b/code/AssetLib/X/XFileHelper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileImporter.cpp b/code/AssetLib/X/XFileImporter.cpp index 00f44b34b..b386ff959 100644 --- a/code/AssetLib/X/XFileImporter.cpp +++ b/code/AssetLib/X/XFileImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -359,10 +359,18 @@ void XFileImporter::CreateMeshes(aiScene *pScene, aiNode *pNode, const std::vect // set up a vertex-linear array of the weights for quick searching if a bone influences a vertex std::vector oldWeights(sourceMesh->mPositions.size(), 0.0); for (unsigned int d = 0; d < obone.mWeights.size(); ++d) { - const unsigned int boneIdx = obone.mWeights[d].mVertex; - if (boneIdx < obone.mWeights.size()) { + // TODO The conditional against boneIdx which was added in commit f844c33 + // TODO (https://github.com/assimp/assimp/commit/f844c3397d7726477ab0fdca8efd3df56c18366b) + // TODO causes massive breakage as detailed in: + // TODO https://github.com/assimp/assimp/issues/5332 + // TODO In cases like this unit tests are less useful, since the model still has + // TODO meshes, textures, animations etc. and asserts against these values may pass; + // TODO when touching importer code, it is crucial that developers also run manual, visual + // TODO checks to ensure there's no obvious breakage _before_ commiting to main branch + //const unsigned int boneIdx = obone.mWeights[d].mVertex; + //if (boneIdx < obone.mWeights.size()) { oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight; - } + //} } // collect all vertex weights that influence a vertex in the new mesh diff --git a/code/AssetLib/X/XFileImporter.h b/code/AssetLib/X/XFileImporter.h index 7be9cc8ec..cd741deec 100644 --- a/code/AssetLib/X/XFileImporter.h +++ b/code/AssetLib/X/XFileImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileParser.cpp b/code/AssetLib/X/XFileParser.cpp index 770c75a77..63c654b65 100644 --- a/code/AssetLib/X/XFileParser.cpp +++ b/code/AssetLib/X/XFileParser.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X/XFileParser.h b/code/AssetLib/X/XFileParser.h index 36eac2ada..32375511a 100644 --- a/code/AssetLib/X/XFileParser.h +++ b/code/AssetLib/X/XFileParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X3D/X3DGeoHelper.cpp b/code/AssetLib/X3D/X3DGeoHelper.cpp index 0a62ff9b0..1c962a460 100644 --- a/code/AssetLib/X3D/X3DGeoHelper.cpp +++ b/code/AssetLib/X3D/X3DGeoHelper.cpp @@ -188,6 +188,51 @@ mg_m_err: pFaces.clear(); } +void X3DGeoHelper::coordIdx_str2lines_arr(const std::vector &pCoordIdx, std::vector &pFaces) { + std::vector f_data(pCoordIdx); + + if (f_data.back() != (-1)) { + f_data.push_back(-1); + } + + // reserve average size. + pFaces.reserve(f_data.size() / 2); + for (std::vector::const_iterator startIt = f_data.cbegin(), endIt = f_data.cbegin(); endIt != f_data.cend(); ++endIt) { + // check for end of current polyline + if (*endIt != -1) + continue; + + // found end of polyline, check if this is a valid polyline + std::size_t numIndices = std::distance(startIt, endIt); + if (numIndices <= 1) + goto mg_m_err; + + // create line faces out of polyline indices + for (int32_t idx0 = *startIt++; startIt != endIt; ++startIt) { + int32_t idx1 = *startIt; + + aiFace tface; + tface.mNumIndices = 2; + tface.mIndices = new unsigned int[2]; + tface.mIndices[0] = idx0; + tface.mIndices[1] = idx1; + pFaces.push_back(tface); + + idx0 = idx1; + } + + ++startIt; + } + + return; + +mg_m_err: + for (size_t i = 0, i_e = pFaces.size(); i < i_e; i++) + delete[] pFaces[i].mIndices; + + pFaces.clear(); +} + void X3DGeoHelper::add_color(aiMesh &pMesh, const std::list &pColors, const bool pColorPerVertex) { std::list tcol; @@ -528,4 +573,40 @@ aiMesh *X3DGeoHelper::make_mesh(const std::vector &pCoordIdx, const std return tmesh; } +aiMesh *X3DGeoHelper::make_line_mesh(const std::vector &pCoordIdx, const std::list &pVertices) { + std::vector faces; + + // create faces array from input string with vertices indices. + X3DGeoHelper::coordIdx_str2lines_arr(pCoordIdx, faces); + if (!faces.size()) { + throw DeadlyImportError("Failed to create mesh, faces list is empty."); + } + + // + // Create new mesh and copy geometry data. + // + aiMesh *tmesh = new aiMesh; + size_t ts = faces.size(); + // faces + tmesh->mFaces = new aiFace[ts]; + tmesh->mNumFaces = static_cast(ts); + for (size_t i = 0; i < ts; i++) + tmesh->mFaces[i] = faces[i]; + + // vertices + std::list::const_iterator vit = pVertices.begin(); + + ts = pVertices.size(); + tmesh->mVertices = new aiVector3D[ts]; + tmesh->mNumVertices = static_cast(ts); + for (size_t i = 0; i < ts; i++) { + tmesh->mVertices[i] = *vit++; + } + + // set primitive type and return result. + tmesh->mPrimitiveTypes = aiPrimitiveType_LINE; + + return tmesh; +} + } // namespace Assimp diff --git a/code/AssetLib/X3D/X3DGeoHelper.h b/code/AssetLib/X3D/X3DGeoHelper.h index 78e57f9da..c740b4288 100644 --- a/code/AssetLib/X3D/X3DGeoHelper.h +++ b/code/AssetLib/X3D/X3DGeoHelper.h @@ -21,6 +21,7 @@ public: static void polylineIdx_to_lineIdx(const std::list &pPolylineCoordIdx, std::list &pLineCoordIdx); static void rect_parallel_epiped(const aiVector3D &pSize, std::list &pVertices); static void coordIdx_str2faces_arr(const std::vector &pCoordIdx, std::vector &pFaces, unsigned int &pPrimitiveTypes); + static void coordIdx_str2lines_arr(const std::vector &pCoordIdx, std::vector &pFaces); static void add_color(aiMesh &pMesh, const std::list &pColors, const bool pColorPerVertex); static void add_color(aiMesh &pMesh, const std::list &pColors, const bool pColorPerVertex); static void add_color(aiMesh &pMesh, const std::vector &pCoordIdx, const std::vector &pColorIdx, @@ -34,6 +35,7 @@ public: const std::list &pTexCoords); static void add_tex_coord(aiMesh &pMesh, const std::list &pTexCoords); static aiMesh *make_mesh(const std::vector &pCoordIdx, const std::list &pVertices); + static aiMesh *make_line_mesh(const std::vector &pCoordIdx, const std::list &pVertices); }; } // namespace Assimp diff --git a/code/AssetLib/X3D/X3DImporter.cpp b/code/AssetLib/X3D/X3DImporter.cpp index eeb20b7c1..ada388080 100644 --- a/code/AssetLib/X3D/X3DImporter.cpp +++ b/code/AssetLib/X3D/X3DImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X3D/X3DImporter.hpp b/code/AssetLib/X3D/X3DImporter.hpp index 705a2472e..623160a38 100644 --- a/code/AssetLib/X3D/X3DImporter.hpp +++ b/code/AssetLib/X3D/X3DImporter.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp b/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp index 240ff14a8..b4562ace2 100644 --- a/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp +++ b/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/X3D/X3DImporter_Postprocess.cpp b/code/AssetLib/X3D/X3DImporter_Postprocess.cpp index 87121ef5f..216929076 100644 --- a/code/AssetLib/X3D/X3DImporter_Postprocess.cpp +++ b/code/AssetLib/X3D/X3DImporter_Postprocess.cpp @@ -320,7 +320,7 @@ void X3DImporter::Postprocess_BuildMesh(const X3DNodeElementBase &pNodeElement, // at first search for node and create mesh. for (std::list::iterator ch_it = tnemesh.Children.begin(); ch_it != tnemesh.Children.end(); ++ch_it) { if ((*ch_it)->Type == X3DElemType::ENET_Coordinate) { - *pMesh = X3DGeoHelper::make_mesh(tnemesh.CoordIndex, ((X3DNodeElementCoordinate *)*ch_it)->Value); + *pMesh = X3DGeoHelper::make_line_mesh(tnemesh.CoordIndex, ((X3DNodeElementCoordinate *)*ch_it)->Value); } } diff --git a/code/AssetLib/XGL/XGLLoader.cpp b/code/AssetLib/XGL/XGLLoader.cpp index 9efd5d628..614fac641 100644 --- a/code/AssetLib/XGL/XGLLoader.cpp +++ b/code/AssetLib/XGL/XGLLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -700,13 +700,14 @@ unsigned int XGLImporter::ReadIDAttr(XmlNode &node) { float XGLImporter::ReadFloat(XmlNode &node) { std::string v; XmlParser::getValueAsString(node, v); - const char *s = v.c_str(), *se; - if (!SkipSpaces(&s)) { + const char *s = v.c_str(); + const char *end = v.c_str() + v.size(); + if (!SkipSpaces(&s, end)) { LogError("unexpected EOL, failed to parse index element"); return 0.f; } - float t; - se = fast_atoreal_move(s, t); + float t{ 0.0f }; + const char *se = fast_atoreal_move(s, t); if (se == s) { LogError("failed to read float text"); return 0.f; @@ -720,7 +721,8 @@ unsigned int XGLImporter::ReadIndexFromText(XmlNode &node) { std::string v; XmlParser::getValueAsString(node, v); const char *s = v.c_str(); - if (!SkipSpaces(&s)) { + const char *end = v.c_str() + v.size(); + if (!SkipSpaces(&s, end)) { LogError("unexpected EOL, failed to parse index element"); return ErrorId; } @@ -741,16 +743,17 @@ aiVector2D XGLImporter::ReadVec2(XmlNode &node) { std::string val; XmlParser::getValueAsString(node, val); const char *s = val.c_str(); + const char *end = val.c_str() + val.size(); ai_real v[2] = {}; for (int i = 0; i < 2; ++i) { - if (!SkipSpaces(&s)) { + if (!SkipSpaces(&s, end)) { LogError("unexpected EOL, failed to parse vec2"); return vec; } v[i] = fast_atof(&s); - SkipSpaces(&s); + SkipSpaces(&s, end); if (i != 1 && *s != ',') { LogError("expected comma, failed to parse vec2"); return vec; @@ -769,14 +772,15 @@ aiVector3D XGLImporter::ReadVec3(XmlNode &node) { std::string v; XmlParser::getValueAsString(node, v); const char *s = v.c_str(); + const char *end = v.c_str() + v.size(); for (int i = 0; i < 3; ++i) { - if (!SkipSpaces(&s)) { + if (!SkipSpaces(&s, end)) { LogError("unexpected EOL, failed to parse vec3"); return vec; } vec[i] = fast_atof(&s); - SkipSpaces(&s); + SkipSpaces(&s, end); if (i != 2 && *s != ',') { LogError("expected comma, failed to parse vec3"); return vec; diff --git a/code/AssetLib/XGL/XGLLoader.h b/code/AssetLib/XGL/XGLLoader.h index f620561d1..9d39bc811 100644 --- a/code/AssetLib/XGL/XGLLoader.h +++ b/code/AssetLib/XGL/XGLLoader.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFAsset.h b/code/AssetLib/glTF/glTFAsset.h index b5e6375ad..27dfae005 100644 --- a/code/AssetLib/glTF/glTFAsset.h +++ b/code/AssetLib/glTF/glTFAsset.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFAsset.inl b/code/AssetLib/glTF/glTFAsset.inl index eddbf5706..5e554a31e 100644 --- a/code/AssetLib/glTF/glTFAsset.inl +++ b/code/AssetLib/glTF/glTFAsset.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFAssetWriter.h b/code/AssetLib/glTF/glTFAssetWriter.h index 6dbc42420..832c9e847 100644 --- a/code/AssetLib/glTF/glTFAssetWriter.h +++ b/code/AssetLib/glTF/glTFAssetWriter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFAssetWriter.inl b/code/AssetLib/glTF/glTFAssetWriter.inl index 2d80598ac..c0b8edfa2 100644 --- a/code/AssetLib/glTF/glTFAssetWriter.inl +++ b/code/AssetLib/glTF/glTFAssetWriter.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFCommon.cpp b/code/AssetLib/glTF/glTFCommon.cpp index fea680cd3..11e038fa3 100644 --- a/code/AssetLib/glTF/glTFCommon.cpp +++ b/code/AssetLib/glTF/glTFCommon.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFCommon.h b/code/AssetLib/glTF/glTFCommon.h index 187fbbdb5..e42d905ff 100644 --- a/code/AssetLib/glTF/glTFCommon.h +++ b/code/AssetLib/glTF/glTFCommon.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFExporter.cpp b/code/AssetLib/glTF/glTFExporter.cpp index 91d88f1ae..0cffda024 100644 --- a/code/AssetLib/glTF/glTFExporter.cpp +++ b/code/AssetLib/glTF/glTFExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // Header files, standard library. #include @@ -113,6 +114,10 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc mAsset = std::make_shared(pIOSystem); + configEpsilon = mProperties->GetPropertyFloat( + AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON, + (ai_real)AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT); + if (isBinary) { mAsset->SetAsBinary(); } @@ -824,7 +829,7 @@ unsigned int glTFExporter::ExportNodeHierarchy(const aiNode* n) { Ref node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node")); - if (!n->mTransformation.IsIdentity()) { + if (!n->mTransformation.IsIdentity(configEpsilon)) { node->matrix.isPresent = true; CopyValue(n->mTransformation, node->matrix.value); } @@ -851,7 +856,7 @@ unsigned int glTFExporter::ExportNode(const aiNode* n, Ref& parent) node->parent = parent; - if (!n->mTransformation.IsIdentity()) { + if (!n->mTransformation.IsIdentity(configEpsilon)) { node->matrix.isPresent = true; CopyValue(n->mTransformation, node->matrix.value); } diff --git a/code/AssetLib/glTF/glTFExporter.h b/code/AssetLib/glTF/glTFExporter.h index a52695402..adac06197 100644 --- a/code/AssetLib/glTF/glTFExporter.h +++ b/code/AssetLib/glTF/glTFExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -50,6 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -98,6 +99,8 @@ private: std::vector mBodyData; + ai_real configEpsilon; + void WriteBinaryData(IOStream *outfile, std::size_t sceneLength); void GetTexSampler(const aiMaterial *mat, glTF::TexProperty &prop); diff --git a/code/AssetLib/glTF/glTFImporter.cpp b/code/AssetLib/glTF/glTFImporter.cpp index cd8b7762d..1d718fd20 100644 --- a/code/AssetLib/glTF/glTFImporter.cpp +++ b/code/AssetLib/glTF/glTFImporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF/glTFImporter.h b/code/AssetLib/glTF/glTFImporter.h index 529da53cc..384299b1f 100644 --- a/code/AssetLib/glTF/glTFImporter.h +++ b/code/AssetLib/glTF/glTFImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 8d500b156..60ed368d1 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -547,7 +547,7 @@ struct BufferView : public Object { BufferViewTarget target; //! The target that the WebGL buffer should be bound to. void Read(Value &obj, Asset &r); - uint8_t *GetPointer(size_t accOffset); + uint8_t *GetPointerAndTailSize(size_t accOffset, size_t& outTailSize); }; //! A typed view into a BufferView. A BufferView contains raw binary data. @@ -629,7 +629,7 @@ struct Accessor : public Object { std::vector data; //!< Actual data, which may be defaulted to an array of zeros or the original data, with the sparse buffer view applied on top of it. - void PopulateData(size_t numBytes, uint8_t *bytes); + void PopulateData(size_t numBytes, const uint8_t *bytes); void PatchData(unsigned int elementSize); }; }; diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 61964d1b4..457fee8fa 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -785,12 +785,14 @@ inline void BufferView::Read(Value &obj, Asset &r) { } } -inline uint8_t *BufferView::GetPointer(size_t accOffset) { +inline uint8_t *BufferView::GetPointerAndTailSize(size_t accOffset, size_t& outTailSize) { if (!buffer) { + outTailSize = 0; return nullptr; } - uint8_t *basePtr = buffer->GetPointer(); + uint8_t * const basePtr = buffer->GetPointer(); if (!basePtr) { + outTailSize = 0; return nullptr; } @@ -799,17 +801,25 @@ inline uint8_t *BufferView::GetPointer(size_t accOffset) { const size_t begin = buffer->EncodedRegion_Current->Offset; const size_t end = begin + buffer->EncodedRegion_Current->DecodedData_Length; if ((offset >= begin) && (offset < end)) { + outTailSize = end - offset; return &buffer->EncodedRegion_Current->DecodedData[offset - begin]; } } + if (offset >= buffer->byteLength) + { + outTailSize = 0; + return nullptr; + } + + outTailSize = buffer->byteLength - offset; return basePtr + offset; } // // struct Accessor // -inline void Accessor::Sparse::PopulateData(size_t numBytes, uint8_t *bytes) { +inline void Accessor::Sparse::PopulateData(size_t numBytes, const uint8_t *bytes) { if (bytes) { data.assign(bytes, bytes + numBytes); } else { @@ -818,11 +828,21 @@ inline void Accessor::Sparse::PopulateData(size_t numBytes, uint8_t *bytes) { } inline void Accessor::Sparse::PatchData(unsigned int elementSize) { - uint8_t *pIndices = indices->GetPointer(indicesByteOffset); + size_t indicesTailDataSize; + uint8_t *pIndices = indices->GetPointerAndTailSize(indicesByteOffset, indicesTailDataSize); const unsigned int indexSize = int(ComponentTypeSize(indicesType)); uint8_t *indicesEnd = pIndices + count * indexSize; - uint8_t *pValues = values->GetPointer(valuesByteOffset); + if ((uint64_t)indicesEnd > (uint64_t)pIndices + indicesTailDataSize) { + throw DeadlyImportError("Invalid sparse accessor. Indices outside allocated memory."); + } + + size_t valuesTailDataSize; + uint8_t* pValues = values->GetPointerAndTailSize(valuesByteOffset, valuesTailDataSize); + + if (elementSize * count > valuesTailDataSize) { + throw DeadlyImportError("Invalid sparse accessor. Indices outside allocated memory."); + } while (pIndices != indicesEnd) { size_t offset; switch (indicesType) { @@ -894,6 +914,9 @@ inline void Accessor::Read(Value &obj, Asset &r) { if (Value *indicesValue = FindObject(*sparseValue, "indices")) { //indices bufferView Value *indiceViewID = FindUInt(*indicesValue, "bufferView"); + if (!indiceViewID) { + throw DeadlyImportError("A bufferView value is required, when reading ", id.c_str(), name.empty() ? "" : " (" + name + ")"); + } sparse->indices = r.bufferViews.Retrieve(indiceViewID->GetUint()); //indices byteOffset sparse->indicesByteOffset = MemberOrDefault(*indicesValue, "byteOffset", size_t(0)); @@ -909,6 +932,9 @@ inline void Accessor::Read(Value &obj, Asset &r) { if (Value *valuesValue = FindObject(*sparseValue, "values")) { //value bufferView Value *valueViewID = FindUInt(*valuesValue, "bufferView"); + if (!valueViewID) { + throw DeadlyImportError("A bufferView value is required, when reading ", id.c_str(), name.empty() ? "" : " (" + name + ")"); + } sparse->values = r.bufferViews.Retrieve(valueViewID->GetUint()); //value byteOffset sparse->valuesByteOffset = MemberOrDefault(*valuesValue, "byteOffset", size_t(0)); @@ -918,8 +944,18 @@ inline void Accessor::Read(Value &obj, Asset &r) { const unsigned int elementSize = GetElementSize(); const size_t dataSize = count * elementSize; - sparse->PopulateData(dataSize, bufferView ? bufferView->GetPointer(byteOffset) : nullptr); - sparse->PatchData(elementSize); + if (bufferView) { + size_t bufferViewTailSize; + const uint8_t* bufferViewPointer = bufferView->GetPointerAndTailSize(byteOffset, bufferViewTailSize); + if (dataSize > bufferViewTailSize) { + throw DeadlyImportError("Invalid buffer when reading ", id.c_str(), name.empty() ? "" : " (" + name + ")"); + } + sparse->PopulateData(dataSize, bufferViewPointer); + } + else { + sparse->PopulateData(dataSize, nullptr); + } + sparse->PatchData(elementSize); } } diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.h b/code/AssetLib/glTF2/glTF2AssetWriter.h index 4e5177b4e..f57b6558d 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.h +++ b/code/AssetLib/glTF2/glTF2AssetWriter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index bfd9135d3..17e29d8e7 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 836e15f9f..3df9d5dda 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // Header files, standard library. #include @@ -90,6 +91,10 @@ glTF2Exporter::glTF2Exporter(const char *filename, IOSystem *pIOSystem, const ai // Always on as our triangulation process is aware of this type of encoding mAsset->extensionsUsed.FB_ngon_encoding = true; + configEpsilon = mProperties->GetPropertyFloat( + AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON, + (ai_real)AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT); + if (isBinary) { mAsset->SetAsBinary(); } @@ -912,6 +917,7 @@ void glTF2Exporter::ExportMaterials() { if (GetMatSpecular(mat, specular)) { mAsset->extensionsUsed.KHR_materials_specular = true; m->materialSpecular = Nullable(specular); + GetMatColor(mat, m->pbrMetallicRoughness.baseColorFactor, AI_MATKEY_COLOR_DIFFUSE); } MaterialSheen sheen; @@ -1454,7 +1460,7 @@ unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode *n) { node->name = n->mName.C_Str(); - if (!n->mTransformation.IsIdentity()) { + if (!n->mTransformation.IsIdentity(configEpsilon)) { node->matrix.isPresent = true; CopyValue(n->mTransformation, node->matrix.value); } @@ -1484,7 +1490,7 @@ unsigned int glTF2Exporter::ExportNode(const aiNode *n, Ref &parent) { ExportNodeExtras(n->mMetaData, node->extras); - if (!n->mTransformation.IsIdentity()) { + if (!n->mTransformation.IsIdentity(configEpsilon)) { if (mScene->mNumAnimations > 0 || (mProperties && mProperties->HasPropertyBool("GLTF2_NODE_IN_TRS"))) { aiQuaternion quaternion; n->mTransformation.Decompose(*reinterpret_cast(&node->scale.value), quaternion, *reinterpret_cast(&node->translation.value)); diff --git a/code/AssetLib/glTF2/glTF2Exporter.h b/code/AssetLib/glTF2/glTF2Exporter.h index 7bf57b567..27e187854 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.h +++ b/code/AssetLib/glTF2/glTF2Exporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -142,6 +143,7 @@ private: std::map mTexturesByPath; std::shared_ptr mAsset; std::vector mBodyData; + ai_real configEpsilon; }; } // namespace Assimp diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index e89baaf0d..5f895ff74 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/AssetLib/glTF2/glTF2Importer.h b/code/AssetLib/glTF2/glTF2Importer.h index 2be42126c..68af0cb9c 100644 --- a/code/AssetLib/glTF2/glTF2Importer.h +++ b/code/AssetLib/glTF2/glTF2Importer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/CApi/AssimpCExport.cpp b/code/CApi/AssimpCExport.cpp index 21e40205c..99ad41ab7 100644 --- a/code/CApi/AssimpCExport.cpp +++ b/code/CApi/AssimpCExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/CApi/CInterfaceIOWrapper.cpp b/code/CApi/CInterfaceIOWrapper.cpp index f0e46cd08..84648482b 100644 --- a/code/CApi/CInterfaceIOWrapper.cpp +++ b/code/CApi/CInterfaceIOWrapper.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/CApi/CInterfaceIOWrapper.h b/code/CApi/CInterfaceIOWrapper.h index 28d4c3e75..34c4a7311 100644 --- a/code/CApi/CInterfaceIOWrapper.h +++ b/code/CApi/CInterfaceIOWrapper.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 9b0b964c0..b397d5ec4 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1,6 +1,6 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- -# Copyright (c) 2006-2022, assimp team +# Copyright (c) 2006-2024, assimp team # # All rights reserved. # @@ -42,7 +42,7 @@ # 3) Add libassimp using the file lists (eliminates duplication of file names between # source groups and library command) # -cmake_minimum_required( VERSION 3.10 ) +cmake_minimum_required( VERSION 3.22 ) SET( HEADER_PATH ../include/assimp ) if(NOT ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM) @@ -1193,6 +1193,10 @@ ENDIF () TARGET_USE_COMMON_OUTPUT_DIRECTORY(assimp) +add_compile_options( + "$<$:-O0;-g3;-ggdb>" +) + IF (ASSIMP_WARNINGS_AS_ERRORS) MESSAGE(STATUS "Treating all warnings as errors (for assimp library only)") IF (MSVC) @@ -1282,7 +1286,7 @@ IF(ASSIMP_HUNTER_ENABLED) endif() if (ASSIMP_BUILD_DRACO) - target_link_libraries(assimp PUBLIC ${draco_LIBRARIES}) + target_link_libraries(assimp PRIVATE ${draco_LIBRARIES}) endif() ELSE() TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES}) @@ -1396,19 +1400,20 @@ IF (RT_FOUND AND ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC) TARGET_LINK_LIBRARIES(assimp rt) ENDIF () +IF(ASSIMP_INSTALL) + INSTALL( TARGETS assimp + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} + ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP-DEV_COMPONENT} + RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} + FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} + INCLUDES DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR} + ) + INSTALL( FILES ${PUBLIC_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp COMPONENT assimp-dev) + INSTALL( FILES ${COMPILER_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp/Compiler COMPONENT assimp-dev) +ENDIF() -INSTALL( TARGETS assimp - EXPORT "${TARGETS_EXPORT_NAME}" - LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} - ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP-DEV_COMPONENT} - RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} - FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} - INCLUDES DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR} -) -INSTALL( FILES ${PUBLIC_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp COMPONENT assimp-dev) -INSTALL( FILES ${COMPILER_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp/Compiler COMPONENT assimp-dev) - -if (ASSIMP_ANDROID_JNIIOSYSTEM) +if (ASSIMP_ANDROID_JNIIOSYSTEM AND ASSIMP_INSTALL) INSTALL(FILES ${HEADER_PATH}/${ASSIMP_ANDROID_JNIIOSYSTEM_PATH}/AndroidJNIIOSystem.h DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR} COMPONENT assimp-dev) diff --git a/code/Common/AssertHandler.cpp b/code/Common/AssertHandler.cpp index 2fd4046ad..ee2d2b95c 100644 --- a/code/Common/AssertHandler.cpp +++ b/code/Common/AssertHandler.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index e3b39c349..cf57bac4b 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Base64.cpp b/code/Common/Base64.cpp index 65308f4fd..76f9b120e 100644 --- a/code/Common/Base64.cpp +++ b/code/Common/Base64.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 9ef69a8e6..3a4c7c329 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -93,10 +93,6 @@ BaseImporter::BaseImporter() AI_NO_EXCEPT // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -BaseImporter::~BaseImporter() = default; - void BaseImporter::UpdateImporterScale(Importer *pImp) { ai_assert(pImp != nullptr); ai_assert(importerScale != 0.0); diff --git a/code/Common/BaseProcess.cpp b/code/Common/BaseProcess.cpp index 8ff7c98e9..560ee7b94 100644 --- a/code/Common/BaseProcess.cpp +++ b/code/Common/BaseProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -57,10 +57,6 @@ BaseProcess::BaseProcess() AI_NO_EXCEPT // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -BaseProcess::~BaseProcess() = default; - // ------------------------------------------------------------------------------------------------ void BaseProcess::ExecuteOnScene(Importer *pImp) { ai_assert( nullptr != pImp ); diff --git a/code/Common/BaseProcess.h b/code/Common/BaseProcess.h index d2af4faa6..a945ad542 100644 --- a/code/Common/BaseProcess.h +++ b/code/Common/BaseProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -179,11 +179,11 @@ class ASSIMP_API BaseProcess { friend class Importer; public: - /** @brief onstructor to be privately used by Importer */ + /** @brief Constructor to be privately used by Importer */ BaseProcess() AI_NO_EXCEPT; - /** @brief Destructor, private as well */ - virtual ~BaseProcess(); + /** @brief Destructor */ + virtual ~BaseProcess() = default; // ------------------------------------------------------------------- /** diff --git a/code/Common/Bitmap.cpp b/code/Common/Bitmap.cpp index 65dfd1754..246ad9e65 100644 --- a/code/Common/Bitmap.cpp +++ b/code/Common/Bitmap.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Compression.cpp b/code/Common/Compression.cpp index a6a7be7e4..091171771 100644 --- a/code/Common/Compression.cpp +++ b/code/Common/Compression.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Compression.h b/code/Common/Compression.h index cfedc7409..0bec91bba 100644 --- a/code/Common/Compression.h +++ b/code/Common/Compression.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/CreateAnimMesh.cpp b/code/Common/CreateAnimMesh.cpp index 58f3d909d..467651587 100644 --- a/code/Common/CreateAnimMesh.cpp +++ b/code/Common/CreateAnimMesh.cpp @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (C) 2016 The Qt Company Ltd. -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/DefaultIOStream.cpp b/code/Common/DefaultIOStream.cpp index f2c772187..e423eae4f 100644 --- a/code/Common/DefaultIOStream.cpp +++ b/code/Common/DefaultIOStream.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index a72627154..e74add55f 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index 5cb32d38f..828e326e2 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/Common/DefaultProgressHandler.h b/code/Common/DefaultProgressHandler.h index ac1bb68db..2ace9e02a 100644 --- a/code/Common/DefaultProgressHandler.h +++ b/code/Common/DefaultProgressHandler.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Exceptional.cpp b/code/Common/Exceptional.cpp index b25281a97..0629f716e 100644 --- a/code/Common/Exceptional.cpp +++ b/code/Common/Exceptional.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 0795da65c..4da055064 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/FileLogStream.h b/code/Common/FileLogStream.h index 334541485..f64f88f48 100644 --- a/code/Common/FileLogStream.h +++ b/code/Common/FileLogStream.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/IOSystem.cpp b/code/Common/IOSystem.cpp index 1e63827ba..aa91e9b49 100644 --- a/code/Common/IOSystem.cpp +++ b/code/Common/IOSystem.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index bdf64ac8f..284ad89cc 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Importer.h b/code/Common/Importer.h index ab7e3a6b3..2da55f173 100644 --- a/code/Common/Importer.h +++ b/code/Common/Importer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -74,11 +74,11 @@ public: typedef unsigned int KeyType; // typedefs for our configuration maps. - typedef std::map IntPropertyMap; - typedef std::map FloatPropertyMap; - typedef std::map StringPropertyMap; - typedef std::map MatrixPropertyMap; - typedef std::map PointerPropertyMap; + using IntPropertyMap = std::map; + using FloatPropertyMap = std::map; + using StringPropertyMap = std::map; + using MatrixPropertyMap = std::map; + using PointerPropertyMap = std::map; /** IO handler to use for all file accesses. */ IOSystem* mIOHandler; @@ -128,10 +128,12 @@ public: /// The default class constructor. ImporterPimpl() AI_NO_EXCEPT; + + /// The class destructor. + ~ImporterPimpl() = default; }; -inline -ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT : +inline ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT : mIOHandler( nullptr ), mIsDefaultHandler( false ), mProgressHandler( nullptr ), diff --git a/code/Common/ImporterRegistry.cpp b/code/Common/ImporterRegistry.cpp index c67fee936..92a04e692 100644 --- a/code/Common/ImporterRegistry.cpp +++ b/code/Common/ImporterRegistry.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Maybe.h b/code/Common/Maybe.h index 387c1bcaf..99b18b67c 100644 --- a/code/Common/Maybe.h +++ b/code/Common/Maybe.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/PolyTools.h b/code/Common/PolyTools.h index b53de8579..46ceb9d75 100644 --- a/code/Common/PolyTools.h +++ b/code/Common/PolyTools.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/PostStepRegistry.cpp b/code/Common/PostStepRegistry.cpp index de4f39083..fdf33fc40 100644 --- a/code/Common/PostStepRegistry.cpp +++ b/code/Common/PostStepRegistry.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/Common/RemoveComments.cpp b/code/Common/RemoveComments.cpp index 52dd37ff0..a6a472400 100644 --- a/code/Common/RemoveComments.cpp +++ b/code/Common/RemoveComments.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/SGSpatialSort.cpp b/code/Common/SGSpatialSort.cpp index 0ef1853c0..d24ecf1b4 100644 --- a/code/Common/SGSpatialSort.cpp +++ b/code/Common/SGSpatialSort.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -50,16 +48,13 @@ the 3ds loader handling smooth groups correctly */ using namespace Assimp; // ------------------------------------------------------------------------------------------------ -SGSpatialSort::SGSpatialSort() -{ +SGSpatialSort::SGSpatialSort() { // define the reference plane. We choose some arbitrary vector away from all basic axes // in the hope that no model spreads all its vertices along this plane. mPlaneNormal.Set( 0.8523f, 0.34321f, 0.5736f); mPlaneNormal.Normalize(); } -// ------------------------------------------------------------------------------------------------ -// Destructor -SGSpatialSort::~SGSpatialSort() = default; + // ------------------------------------------------------------------------------------------------ void SGSpatialSort::Add(const aiVector3D& vPosition, unsigned int index, unsigned int smoothingGroup) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 0188f5dea..44897a40b 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/ScenePreprocessor.cpp b/code/Common/ScenePreprocessor.cpp index 18a257ad4..b4bbe9d67 100644 --- a/code/Common/ScenePreprocessor.cpp +++ b/code/Common/ScenePreprocessor.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/ScenePreprocessor.h b/code/Common/ScenePreprocessor.h index 49e06ed1c..6ffd7f8bd 100644 --- a/code/Common/ScenePreprocessor.h +++ b/code/Common/ScenePreprocessor.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -56,7 +55,7 @@ class ScenePreprocessorTest; namespace Assimp { // ---------------------------------------------------------------------------------- -/** ScenePreprocessor: Preprocess a scene before any post-processing +/** ScenePreprocessor: Pre-process a scene before any post-processing * steps are executed. * * The step computes data that needn't necessarily be provided by the @@ -79,6 +78,9 @@ public: ScenePreprocessor(aiScene *_scene) : scene(_scene) {} + /// @brief The class destructor. + ~ScenePreprocessor() = default; + // ---------------------------------------------------------------- /** Assign a (new) scene to the object. * diff --git a/code/Common/ScenePrivate.h b/code/Common/ScenePrivate.h index 3910db78c..b8c524aa2 100644 --- a/code/Common/ScenePrivate.h +++ b/code/Common/ScenePrivate.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/SkeletonMeshBuilder.cpp b/code/Common/SkeletonMeshBuilder.cpp index f3c8fb412..167652700 100644 --- a/code/Common/SkeletonMeshBuilder.cpp +++ b/code/Common/SkeletonMeshBuilder.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/SpatialSort.cpp b/code/Common/SpatialSort.cpp index c8c5c30ed..34cb3fb05 100644 --- a/code/Common/SpatialSort.cpp +++ b/code/Common/SpatialSort.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/StackAllocator.h b/code/Common/StackAllocator.h index 191010cac..a5d97c22d 100644 --- a/code/Common/StackAllocator.h +++ b/code/Common/StackAllocator.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -61,9 +61,10 @@ namespace Assimp { class StackAllocator { public: /// @brief Constructs the allocator - inline StackAllocator(); + StackAllocator(); + /// @brief Destructs the allocator and frees all memory - inline ~StackAllocator(); + ~StackAllocator(); // non copyable StackAllocator(const StackAllocator &) = delete; diff --git a/code/Common/StackAllocator.inl b/code/Common/StackAllocator.inl index 2c3164ca7..44f15edbc 100644 --- a/code/Common/StackAllocator.inl +++ b/code/Common/StackAllocator.inl @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -41,11 +41,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "StackAllocator.h" #include +#include using namespace Assimp; -inline StackAllocator::StackAllocator() { -} +inline StackAllocator::StackAllocator() : m_storageBlocks() {} inline StackAllocator::~StackAllocator() { FreeAll(); @@ -56,7 +56,7 @@ inline void *StackAllocator::Allocate(size_t byteSize) { { // double block size every time, up to maximum of g_maxBytesPerBlock. // Block size must be at least as large as byteSize, but we want to use this for small allocations anyway. - m_blockAllocationSize = std::max(std::min(m_blockAllocationSize * 2, g_maxBytesPerBlock), byteSize); + m_blockAllocationSize = std::max(std::min(m_blockAllocationSize * 2, g_maxBytesPerBlock), byteSize); uint8_t *data = new uint8_t[m_blockAllocationSize]; m_storageBlocks.emplace_back(data); m_subIndex = byteSize; diff --git a/code/Common/StandardShapes.cpp b/code/Common/StandardShapes.cpp index abf3c4839..4a967997e 100644 --- a/code/Common/StandardShapes.cpp +++ b/code/Common/StandardShapes.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/StbCommon.h b/code/Common/StbCommon.h index 5de2e176d..aef23ce17 100644 --- a/code/Common/StbCommon.h +++ b/code/Common/StbCommon.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -64,10 +64,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The list can be regenerated using the following: - cat | fgrep STBIDEF | fgrep '(' | sed -E 's/\*|\(.+//g' | \ - awk '{print "#define " $(NF) " assimp_" $(NF) }' | sort | uniq" + cat "path/to/stb/stb_image.h" | fgrep STBIDEF | fgrep '(' | sed -E 's/\*|\(.+//g' | \ + awk '{print "#define " $(NF) " assimp_" $(NF) }' | sort | uniq */ #define stbi_convert_iphone_png_to_rgb assimp_stbi_convert_iphone_png_to_rgb +#define stbi_convert_iphone_png_to_rgb_thread assimp_stbi_convert_iphone_png_to_rgb_thread #define stbi_convert_wchar_to_utf8 assimp_stbi_convert_wchar_to_utf8 #define stbi_failure_reason assimp_stbi_failure_reason #define stbi_hdr_to_ldr_gamma assimp_stbi_hdr_to_ldr_gamma @@ -87,22 +88,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define stbi_is_hdr_from_memory assimp_stbi_is_hdr_from_memory #define stbi_ldr_to_hdr_gamma assimp_stbi_ldr_to_hdr_gamma #define stbi_ldr_to_hdr_scale assimp_stbi_ldr_to_hdr_scale +#define stbi_load assimp_stbi_load #define stbi_load_16 assimp_stbi_load_16 #define stbi_load_16_from_callbacks assimp_stbi_load_16_from_callbacks #define stbi_load_16_from_memory assimp_stbi_load_16_from_memory -#define stbi_load assimp_stbi_load +#define stbi_load_from_callbacks assimp_stbi_load_from_callbacks +#define stbi_load_from_file assimp_stbi_load_from_file +#define stbi_load_from_file_16 assimp_stbi_load_from_file_16 +#define stbi_load_from_memory assimp_stbi_load_from_memory +#define stbi_load_gif_from_memory assimp_stbi_load_gif_from_memory #define stbi_loadf assimp_stbi_loadf #define stbi_loadf_from_callbacks assimp_stbi_loadf_from_callbacks #define stbi_loadf_from_file assimp_stbi_loadf_from_file #define stbi_loadf_from_memory assimp_stbi_loadf_from_memory -#define stbi_load_from_callbacks assimp_stbi_load_from_callbacks -#define stbi_load_from_file_16 assimp_stbi_load_from_file_16 -#define stbi_load_from_file assimp_stbi_load_from_file -#define stbi_load_from_memory assimp_stbi_load_from_memory -#define stbi_load_gif_from_memory assimp_stbi_load_gif_from_memory #define stbi_set_flip_vertically_on_load assimp_stbi_set_flip_vertically_on_load #define stbi_set_flip_vertically_on_load_thread assimp_stbi_set_flip_vertically_on_load_thread #define stbi_set_unpremultiply_on_load assimp_stbi_set_unpremultiply_on_load +#define stbi_set_unpremultiply_on_load_thread assimp_stbi_set_unpremultiply_on_load_thread #define stbi_zlib_decode_buffer assimp_stbi_zlib_decode_buffer #define stbi_zlib_decode_malloc assimp_stbi_zlib_decode_malloc #define stbi_zlib_decode_malloc_guesssize assimp_stbi_zlib_decode_malloc_guesssize diff --git a/code/Common/StdOStreamLogStream.h b/code/Common/StdOStreamLogStream.h index cc0e06263..683c87d5f 100644 --- a/code/Common/StdOStreamLogStream.h +++ b/code/Common/StdOStreamLogStream.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/Common/Subdivision.cpp b/code/Common/Subdivision.cpp index 3aea5d4c5..fc8ab2099 100644 --- a/code/Common/Subdivision.cpp +++ b/code/Common/Subdivision.cpp @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/TargetAnimation.cpp b/code/Common/TargetAnimation.cpp index 5f6d9bad0..9ef4e5d6c 100644 --- a/code/Common/TargetAnimation.cpp +++ b/code/Common/TargetAnimation.cpp @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/TargetAnimation.h b/code/Common/TargetAnimation.h index 863406b94..116b55d2a 100644 --- a/code/Common/TargetAnimation.h +++ b/code/Common/TargetAnimation.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -119,12 +118,16 @@ private: * look-at target */ class TargetAnimationHelper { public: + /// @brief The class constructor. TargetAnimationHelper() : targetPositions(nullptr), objectPositions(nullptr) { // empty } + /// @brief The class destructor. + ~TargetAnimationHelper() = default; + // ------------------------------------------------------------------ /** Sets the target animation channel * diff --git a/code/Common/Version.cpp b/code/Common/Version.cpp index 1699b99d6..10ccf58e7 100644 --- a/code/Common/Version.cpp +++ b/code/Common/Version.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -52,7 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static constexpr char LEGAL_INFORMATION[] = "Open Asset Import Library (Assimp).\n" "A free C/C++ library to import various 3D file formats into applications\n\n" - "(c) 2006-2023, Assimp team\n" + "(c) 2006-2024, Assimp team\n" "License under the terms and conditions of the 3-clause BSD license\n" "https://www.assimp.org\n"; diff --git a/code/Common/VertexTriangleAdjacency.cpp b/code/Common/VertexTriangleAdjacency.cpp index 555e3e386..616e7e797 100644 --- a/code/Common/VertexTriangleAdjacency.cpp +++ b/code/Common/VertexTriangleAdjacency.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/VertexTriangleAdjacency.h b/code/Common/VertexTriangleAdjacency.h index 41d809450..20d3bd32c 100644 --- a/code/Common/VertexTriangleAdjacency.h +++ b/code/Common/VertexTriangleAdjacency.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/Win32DebugLogStream.h b/code/Common/Win32DebugLogStream.h index 34d849e83..f8bc017af 100644 --- a/code/Common/Win32DebugLogStream.h +++ b/code/Common/Win32DebugLogStream.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp index 51a250810..23d7db15d 100644 --- a/code/Common/ZipArchiveIOSystem.cpp +++ b/code/Common/ZipArchiveIOSystem.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -62,13 +62,13 @@ namespace Assimp { // ---------------------------------------------------------------- // A read-only file inside a ZIP -class ZipFile : public IOStream { +class ZipFile final : public IOStream { friend class ZipFileInfo; explicit ZipFile(std::string &filename, size_t size); public: std::string m_Filename; - virtual ~ZipFile() override; + ~ZipFile() override = default; // IOStream interface size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override; @@ -89,6 +89,8 @@ private: // Wraps an existing Assimp::IOSystem for unzip class IOSystem2Unzip { public: + IOSystem2Unzip() = default; + ~IOSystem2Unzip() = default; static voidpf open(voidpf opaque, const char *filename, int mode); static voidpf opendisk(voidpf opaque, voidpf stream, uint32_t number_disk, int mode); static uLong read(voidpf opaque, voidpf stream, void *buf, uLong size); @@ -100,6 +102,7 @@ public: static zlib_filefunc_def get(IOSystem *pIOHandler); }; +// ---------------------------------------------------------------- voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) { IOSystem *io_system = reinterpret_cast(opaque); @@ -119,6 +122,7 @@ voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) { return (voidpf)io_system->Open(filename, mode_fopen); } +// ---------------------------------------------------------------- voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) { ZipFile *io_stream = (ZipFile *)stream; voidpf ret = nullptr; @@ -141,24 +145,28 @@ voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_di return ret; } +// ---------------------------------------------------------------- uLong IOSystem2Unzip::read(voidpf /*opaque*/, voidpf stream, void *buf, uLong size) { IOStream *io_stream = (IOStream *)stream; return static_cast(io_stream->Read(buf, 1, size)); } +// ---------------------------------------------------------------- uLong IOSystem2Unzip::write(voidpf /*opaque*/, voidpf stream, const void *buf, uLong size) { IOStream *io_stream = (IOStream *)stream; return static_cast(io_stream->Write(buf, 1, size)); } +// ---------------------------------------------------------------- long IOSystem2Unzip::tell(voidpf /*opaque*/, voidpf stream) { IOStream *io_stream = (IOStream *)stream; return static_cast(io_stream->Tell()); } +// ---------------------------------------------------------------- long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int origin) { IOStream *io_stream = (IOStream *)stream; @@ -179,6 +187,7 @@ long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int or return (io_stream->Seek(offset, assimp_origin) == aiReturn_SUCCESS ? 0 : -1); } +// ---------------------------------------------------------------- int IOSystem2Unzip::close(voidpf opaque, voidpf stream) { IOSystem *io_system = (IOSystem *)opaque; IOStream *io_stream = (IOStream *)stream; @@ -188,10 +197,12 @@ int IOSystem2Unzip::close(voidpf opaque, voidpf stream) { return 0; } +// ---------------------------------------------------------------- int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) { return 0; } +// ---------------------------------------------------------------- zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) { zlib_filefunc_def mapping; @@ -213,9 +224,10 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) { // ---------------------------------------------------------------- // Info about a read-only file inside a ZIP -class ZipFileInfo { +class ZipFileInfo final { public: explicit ZipFileInfo(unzFile zip_handle, size_t size); + ~ZipFileInfo() = default; // Allocate and Extract data from the ZIP ZipFile *Extract(std::string &filename, unzFile zip_handle) const; @@ -225,6 +237,7 @@ private: unz_file_pos_s m_ZipFilePos; }; +// ---------------------------------------------------------------- ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) : m_Size(size) { ai_assert(m_Size != 0); @@ -234,6 +247,7 @@ ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) : unzGetFilePos(zip_handle, &(m_ZipFilePos)); } +// ---------------------------------------------------------------- ZipFile *ZipFileInfo::Extract(std::string &filename, unzFile zip_handle) const { // Find in the ZIP. This cannot fail unz_file_pos_s *filepos = const_cast(&(m_ZipFilePos)); @@ -273,14 +287,14 @@ ZipFile *ZipFileInfo::Extract(std::string &filename, unzFile zip_handle) const { return zip_file; } +// ---------------------------------------------------------------- ZipFile::ZipFile(std::string &filename, size_t size) : m_Filename(filename), m_Size(size) { ai_assert(m_Size != 0); m_Buffer = std::unique_ptr(new uint8_t[m_Size]); } -ZipFile::~ZipFile() = default; - +// ---------------------------------------------------------------- size_t ZipFile::Read(void *pvBuffer, size_t pSize, size_t pCount) { // Should be impossible ai_assert(m_Buffer != nullptr); @@ -305,10 +319,12 @@ size_t ZipFile::Read(void *pvBuffer, size_t pSize, size_t pCount) { return pCount; } +// ---------------------------------------------------------------- size_t ZipFile::FileSize() const { return m_Size; } +// ---------------------------------------------------------------- aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) { switch (pOrigin) { case aiOrigin_SET: { @@ -334,6 +350,7 @@ aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) { return aiReturn_FAILURE; } +// ---------------------------------------------------------------- size_t ZipFile::Tell() const { return m_SeekPtr; } @@ -365,6 +382,7 @@ private: ZipFileInfoMap m_ArchiveMap; }; +// ---------------------------------------------------------------- ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFilename, const char *pMode) { ai_assert(strcmp(pMode, "r") == 0); ai_assert(pFilename != nullptr); @@ -376,12 +394,14 @@ ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFile m_ZipFileHandle = unzOpen2(pFilename, &mapping); } +// ---------------------------------------------------------------- ZipArchiveIOSystem::Implement::~Implement() { if (m_ZipFileHandle != nullptr) { unzClose(m_ZipFileHandle); } } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::Implement::MapArchive() { if (m_ZipFileHandle == nullptr) return; @@ -408,10 +428,12 @@ void ZipArchiveIOSystem::Implement::MapArchive() { } while (unzGoToNextFile(m_ZipFileHandle) != UNZ_END_OF_LIST_OF_FILE); } +// ---------------------------------------------------------------- bool ZipArchiveIOSystem::Implement::isOpen() const { return (m_ZipFileHandle != nullptr); } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::Implement::getFileList(std::vector &rFileList) { MapArchive(); rFileList.clear(); @@ -421,6 +443,7 @@ void ZipArchiveIOSystem::Implement::getFileList(std::vector &rFileL } } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::Implement::getFileListExtension(std::vector &rFileList, const std::string &extension) { MapArchive(); rFileList.clear(); @@ -431,6 +454,7 @@ void ZipArchiveIOSystem::Implement::getFileListExtension(std::vectorExists(filename); } +// ---------------------------------------------------------------- // This is always '/' in a ZIP char ZipArchiveIOSystem::getOsSeparator() const { return '/'; } +// ---------------------------------------------------------------- // Only supports Reading IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) { ai_assert(pFilename != nullptr); @@ -536,22 +569,27 @@ IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) { return pImpl->OpenFile(filename); } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::Close(IOStream *pFile) { delete pFile; } +// ---------------------------------------------------------------- bool ZipArchiveIOSystem::isOpen() const { return (pImpl->isOpen()); } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::getFileList(std::vector &rFileList) const { return pImpl->getFileList(rFileList); } +// ---------------------------------------------------------------- void ZipArchiveIOSystem::getFileListExtension(std::vector &rFileList, const std::string &extension) const { return pImpl->getFileListExtension(rFileList, extension); } +// ---------------------------------------------------------------- bool ZipArchiveIOSystem::isZipArchive(IOSystem *pIOHandler, const char *pFilename) { Implement tmp(pIOHandler, pFilename, "r"); return tmp.isOpen(); diff --git a/code/Common/material.cpp b/code/Common/material.cpp index ffc2f415b..76676ec1a 100644 --- a/code/Common/material.cpp +++ b/code/Common/material.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/scene.cpp b/code/Common/scene.cpp index b0e882154..e42f4b2e6 100644 --- a/code/Common/scene.cpp +++ b/code/Common/scene.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/simd.cpp b/code/Common/simd.cpp index 0dd437d26..6a48750b0 100644 --- a/code/Common/simd.cpp +++ b/code/Common/simd.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Common/simd.h b/code/Common/simd.h index a1d936629..05d27d253 100644 --- a/code/Common/simd.h +++ b/code/Common/simd.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Geometry/GeometryUtils.cpp b/code/Geometry/GeometryUtils.cpp index cec1e74c5..375e501d3 100644 --- a/code/Geometry/GeometryUtils.cpp +++ b/code/Geometry/GeometryUtils.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Geometry/GeometryUtils.h b/code/Geometry/GeometryUtils.h index b6fff99e1..ae88d376b 100644 --- a/code/Geometry/GeometryUtils.h +++ b/code/Geometry/GeometryUtils.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -49,6 +49,10 @@ namespace Assimp { // --------------------------------------------------------------------------- class ASSIMP_API GeometryUtils { public: + /// @brief Will calculate the area of a triangle. + /// @param a The first vertex of the triangle. + /// @param b The first vertex of the triangle. + /// @param c The first vertex of the triangle. static ai_real heron( ai_real a, ai_real b, ai_real c ); /// @brief Will compute the distance between 2 3D-vectors diff --git a/code/Material/MaterialSystem.cpp b/code/Material/MaterialSystem.cpp index cc8ca2f88..dbae4b7e4 100644 --- a/code/Material/MaterialSystem.cpp +++ b/code/Material/MaterialSystem.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Material/MaterialSystem.h b/code/Material/MaterialSystem.h index 41891ad97..e7c752179 100644 --- a/code/Material/MaterialSystem.h +++ b/code/Material/MaterialSystem.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 67937019f..907e9a6a2 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -89,22 +89,27 @@ using namespace Assimp; namespace Assimp { -void ExportScenePbrt ( - const char* pFile, - IOSystem* pIOSystem, - const aiScene* pScene, - const ExportProperties* /*pProperties*/ -){ +void ExportScenePbrt(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene, + const ExportProperties *) { std::string path = DefaultIOSystem::absolutePath(std::string(pFile)); std::string file = DefaultIOSystem::completeBaseName(std::string(pFile)); - + path = path + file + ".pbrt"; // initialize the exporter PbrtExporter exporter(pScene, pIOSystem, path, file); } } // end of namespace Assimp -// Constructor +static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOSystem) { + if (scene->mNumTextures > 0) { + if (!pIOSystem->Exists("textures")) { + if (!pIOSystem->CreateDirectory("textures")) { + throw DeadlyExportError("Could not create textures/ directory."); + } + } + } +} + PbrtExporter::PbrtExporter( const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file) : @@ -127,10 +132,10 @@ PbrtExporter::PbrtExporter( 0.f, 0.f, 1.f, 0.f, // 0.f, 0.f, 0.f, 1.f // ) * mRootTransform; + // Export embedded textures. - if (mScene->mNumTextures > 0) - if (!mIOSystem->CreateDirectory("textures")) - throw DeadlyExportError("Could not create textures/ directory."); + create_embedded_textures_folder(mScene, mIOSystem); + for (unsigned int i = 0; i < mScene->mNumTextures; ++i) { aiTexture* tex = mScene->mTextures[i]; std::string fn = CleanTextureFilename(tex->mFilename, false); @@ -176,9 +181,6 @@ PbrtExporter::PbrtExporter( outfile->Write(mOutput.str().c_str(), mOutput.str().length(), 1); } -// Destructor -PbrtExporter::~PbrtExporter() = default; - void PbrtExporter::WriteMetaData() { mOutput << "#############################\n"; mOutput << "# Scene metadata:\n"; diff --git a/code/Pbrt/PbrtExporter.h b/code/Pbrt/PbrtExporter.h index c7e8180e2..0242ddcf0 100644 --- a/code/Pbrt/PbrtExporter.h +++ b/code/Pbrt/PbrtExporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -70,15 +70,33 @@ class ExportProperties; // --------------------------------------------------------------------- /** Helper class to export a given scene to a Pbrt file. */ // --------------------------------------------------------------------- -class PbrtExporter -{ +class PbrtExporter { public: /// Constructor for a specific scene to export PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file); /// Destructor - virtual ~PbrtExporter(); + virtual ~PbrtExporter() = default; + +private: + aiMatrix4x4 GetNodeTransform(const aiString &name) const; + static std::string TransformAsString(const aiMatrix4x4 &m); + static std::string RemoveSuffix(std::string filename); + std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const; + void WriteMetaData(); + void WriteWorldDefinition(); + void WriteCameras(); + void WriteCamera(int i); + void WriteLights(); + void WriteTextures(); + static bool TextureHasAlphaMask(const std::string &filename); + void WriteMaterials(); + void WriteMaterial(int i); + void WriteMesh(aiMesh *mesh); + void WriteInstanceDefinition(int i); + void WriteGeometricObjects(aiNode *node, aiMatrix4x4 parentTransform, + std::map &meshUses); private: // the scene to export @@ -96,39 +114,11 @@ private: /// Name of the file (without extension) where the scene will be exported const std::string mFile; -private: // A private set to keep track of which textures have been declared std::set mTextureSet; // Transform to apply to the root node and all root objects such as cameras, lights, etc. aiMatrix4x4 mRootTransform; - - aiMatrix4x4 GetNodeTransform(const aiString& name) const; - static std::string TransformAsString(const aiMatrix4x4& m); - - static std::string RemoveSuffix(std::string filename); - std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const; - - void WriteMetaData(); - - void WriteWorldDefinition(); - - void WriteCameras(); - void WriteCamera(int i); - - void WriteLights(); - - void WriteTextures(); - static bool TextureHasAlphaMask(const std::string &filename); - - void WriteMaterials(); - void WriteMaterial(int i); - - void WriteMesh(aiMesh* mesh); - - void WriteInstanceDefinition(int i); - void WriteGeometricObjects(aiNode* node, aiMatrix4x4 parentTransform, - std::map &meshUses); }; } // namespace Assimp diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index 234a00232..fa524a7fd 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ArmaturePopulate.h b/code/PostProcessing/ArmaturePopulate.h index 52d3adfef..af1792fb0 100644 --- a/code/PostProcessing/ArmaturePopulate.h +++ b/code/PostProcessing/ArmaturePopulate.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/CalcTangentsProcess.cpp b/code/PostProcessing/CalcTangentsProcess.cpp index a23ac856b..abd0aee47 100644 --- a/code/PostProcessing/CalcTangentsProcess.cpp +++ b/code/PostProcessing/CalcTangentsProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team @@ -185,9 +185,9 @@ bool CalcTangentsProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshIndex) { tangent.x = (w.x * sy - v.x * ty) * dirCorrection; tangent.y = (w.y * sy - v.y * ty) * dirCorrection; tangent.z = (w.z * sy - v.z * ty) * dirCorrection; - bitangent.x = (- w.x * sx + v.x * tx) * dirCorrection; - bitangent.y = (- w.y * sx + v.y * tx) * dirCorrection; - bitangent.z = (- w.z * sx + v.z * tx) * dirCorrection; + bitangent.x = (w.x * sx - v.x * tx) * dirCorrection; + bitangent.y = (w.y * sx - v.y * tx) * dirCorrection; + bitangent.z = (w.z * sx - v.z * tx) * dirCorrection; // store for every vertex of that face for (unsigned int b = 0; b < face.mNumIndices; ++b) { @@ -195,7 +195,7 @@ bool CalcTangentsProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshIndex) { // project tangent and bitangent into the plane formed by the vertex' normal aiVector3D localTangent = tangent - meshNorm[p] * (tangent * meshNorm[p]); - aiVector3D localBitangent = bitangent - meshNorm[p] * (bitangent * meshNorm[p]) - localTangent * (bitangent * localTangent); + aiVector3D localBitangent = bitangent - meshNorm[p] * (bitangent * meshNorm[p]); localTangent.NormalizeSafe(); localBitangent.NormalizeSafe(); diff --git a/code/PostProcessing/CalcTangentsProcess.h b/code/PostProcessing/CalcTangentsProcess.h index aaccb5307..3d7bb2a5e 100644 --- a/code/PostProcessing/CalcTangentsProcess.h +++ b/code/PostProcessing/CalcTangentsProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ComputeUVMappingProcess.cpp b/code/PostProcessing/ComputeUVMappingProcess.cpp index f75dc5952..cac51e8d0 100644 --- a/code/PostProcessing/ComputeUVMappingProcess.cpp +++ b/code/PostProcessing/ComputeUVMappingProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -346,16 +346,20 @@ void ComputeUVMappingProcess::Execute(aiScene *pScene) { ASSIMP_LOG_DEBUG("GenUVCoordsProcess begin"); char buffer[1024]; - if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) + if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) { throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here"); + } std::list mappingStack; - /* Iterate through all materials and search for non-UV mapped textures - */ + // Iterate through all materials and search for non-UV mapped textures for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) { mappingStack.clear(); aiMaterial *mat = pScene->mMaterials[i]; + if (mat == nullptr) { + ASSIMP_LOG_INFO("Material pointer in nullptr, skipping."); + continue; + } for (unsigned int a = 0; a < mat->mNumProperties; ++a) { aiMaterialProperty *prop = mat->mProperties[a]; if (!::strcmp(prop->mKey.data, "$tex.mapping")) { diff --git a/code/PostProcessing/ComputeUVMappingProcess.h b/code/PostProcessing/ComputeUVMappingProcess.h index c4158f402..2a40a15b1 100644 --- a/code/PostProcessing/ComputeUVMappingProcess.h +++ b/code/PostProcessing/ComputeUVMappingProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ConvertToLHProcess.cpp b/code/PostProcessing/ConvertToLHProcess.cpp index 80abf84a5..77c7cb853 100644 --- a/code/PostProcessing/ConvertToLHProcess.cpp +++ b/code/PostProcessing/ConvertToLHProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ConvertToLHProcess.h b/code/PostProcessing/ConvertToLHProcess.h index ea001b95b..e5ef19a8d 100644 --- a/code/PostProcessing/ConvertToLHProcess.h +++ b/code/PostProcessing/ConvertToLHProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/DeboneProcess.cpp b/code/PostProcessing/DeboneProcess.cpp index e91196ce2..1ae79ee30 100644 --- a/code/PostProcessing/DeboneProcess.cpp +++ b/code/PostProcessing/DeboneProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/DeboneProcess.h b/code/PostProcessing/DeboneProcess.h index ae4448e0e..cc2d43cb7 100644 --- a/code/PostProcessing/DeboneProcess.h +++ b/code/PostProcessing/DeboneProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/DropFaceNormalsProcess.cpp b/code/PostProcessing/DropFaceNormalsProcess.cpp index c5f6333e0..29967b74b 100644 --- a/code/PostProcessing/DropFaceNormalsProcess.cpp +++ b/code/PostProcessing/DropFaceNormalsProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/DropFaceNormalsProcess.h b/code/PostProcessing/DropFaceNormalsProcess.h index df542f2ba..84f9dbe83 100644 --- a/code/PostProcessing/DropFaceNormalsProcess.h +++ b/code/PostProcessing/DropFaceNormalsProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/EmbedTexturesProcess.cpp b/code/PostProcessing/EmbedTexturesProcess.cpp index d5d2ef872..568031d8f 100644 --- a/code/PostProcessing/EmbedTexturesProcess.cpp +++ b/code/PostProcessing/EmbedTexturesProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/EmbedTexturesProcess.h b/code/PostProcessing/EmbedTexturesProcess.h index 77d4d9c72..8210eec96 100644 --- a/code/PostProcessing/EmbedTexturesProcess.h +++ b/code/PostProcessing/EmbedTexturesProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FindDegenerates.cpp b/code/PostProcessing/FindDegenerates.cpp index d9c14425c..c506b08b5 100644 --- a/code/PostProcessing/FindDegenerates.cpp +++ b/code/PostProcessing/FindDegenerates.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FindDegenerates.h b/code/PostProcessing/FindDegenerates.h index 6b37a47cf..0d046df2d 100644 --- a/code/PostProcessing/FindDegenerates.h +++ b/code/PostProcessing/FindDegenerates.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FindInstancesProcess.cpp b/code/PostProcessing/FindInstancesProcess.cpp index 55974b1c3..9186dd3dd 100644 --- a/code/PostProcessing/FindInstancesProcess.cpp +++ b/code/PostProcessing/FindInstancesProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/FindInstancesProcess.h b/code/PostProcessing/FindInstancesProcess.h index 6927301ca..63e988abf 100644 --- a/code/PostProcessing/FindInstancesProcess.h +++ b/code/PostProcessing/FindInstancesProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FindInvalidDataProcess.cpp b/code/PostProcessing/FindInvalidDataProcess.cpp index 64abf7589..12f345407 100644 --- a/code/PostProcessing/FindInvalidDataProcess.cpp +++ b/code/PostProcessing/FindInvalidDataProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FindInvalidDataProcess.h b/code/PostProcessing/FindInvalidDataProcess.h index 024eb9b1e..516db4272 100644 --- a/code/PostProcessing/FindInvalidDataProcess.h +++ b/code/PostProcessing/FindInvalidDataProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/FixNormalsStep.cpp b/code/PostProcessing/FixNormalsStep.cpp index 54ac05cc8..2bf85430f 100644 --- a/code/PostProcessing/FixNormalsStep.cpp +++ b/code/PostProcessing/FixNormalsStep.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/FixNormalsStep.h b/code/PostProcessing/FixNormalsStep.h index 20be1958b..b25d92282 100644 --- a/code/PostProcessing/FixNormalsStep.h +++ b/code/PostProcessing/FixNormalsStep.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/GenBoundingBoxesProcess.cpp b/code/PostProcessing/GenBoundingBoxesProcess.cpp index ca8e4d6d0..da9fd7137 100644 --- a/code/PostProcessing/GenBoundingBoxesProcess.cpp +++ b/code/PostProcessing/GenBoundingBoxesProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/GenBoundingBoxesProcess.h b/code/PostProcessing/GenBoundingBoxesProcess.h index 0cf8514f4..c24009dc9 100644 --- a/code/PostProcessing/GenBoundingBoxesProcess.h +++ b/code/PostProcessing/GenBoundingBoxesProcess.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/GenFaceNormalsProcess.cpp b/code/PostProcessing/GenFaceNormalsProcess.cpp index 1d259ce22..79a30ca24 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.cpp +++ b/code/PostProcessing/GenFaceNormalsProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/GenFaceNormalsProcess.h b/code/PostProcessing/GenFaceNormalsProcess.h index 94794631e..a5aad13d1 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.h +++ b/code/PostProcessing/GenFaceNormalsProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/GenVertexNormalsProcess.cpp b/code/PostProcessing/GenVertexNormalsProcess.cpp index 4869263ab..f7fef6bc4 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.cpp +++ b/code/PostProcessing/GenVertexNormalsProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/GenVertexNormalsProcess.h b/code/PostProcessing/GenVertexNormalsProcess.h index b7db9c4f2..677c06a43 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.h +++ b/code/PostProcessing/GenVertexNormalsProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ImproveCacheLocality.cpp b/code/PostProcessing/ImproveCacheLocality.cpp index d7bb95698..c165b0114 100644 --- a/code/PostProcessing/ImproveCacheLocality.cpp +++ b/code/PostProcessing/ImproveCacheLocality.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ImproveCacheLocality.h b/code/PostProcessing/ImproveCacheLocality.h index 6f4d55719..30fa59608 100644 --- a/code/PostProcessing/ImproveCacheLocality.h +++ b/code/PostProcessing/ImproveCacheLocality.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/JoinVerticesProcess.cpp b/code/PostProcessing/JoinVerticesProcess.cpp index 4de6c3e1b..f4c623c98 100644 --- a/code/PostProcessing/JoinVerticesProcess.cpp +++ b/code/PostProcessing/JoinVerticesProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/JoinVerticesProcess.h b/code/PostProcessing/JoinVerticesProcess.h index aa8dc5794..60630dae3 100644 --- a/code/PostProcessing/JoinVerticesProcess.h +++ b/code/PostProcessing/JoinVerticesProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/LimitBoneWeightsProcess.cpp b/code/PostProcessing/LimitBoneWeightsProcess.cpp index 16b32143e..816914ada 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.cpp +++ b/code/PostProcessing/LimitBoneWeightsProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/LimitBoneWeightsProcess.h b/code/PostProcessing/LimitBoneWeightsProcess.h index 8e5ebd80d..b2612c313 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.h +++ b/code/PostProcessing/LimitBoneWeightsProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/MakeVerboseFormat.cpp b/code/PostProcessing/MakeVerboseFormat.cpp index 1cc2fdc02..d0c5693e7 100644 --- a/code/PostProcessing/MakeVerboseFormat.cpp +++ b/code/PostProcessing/MakeVerboseFormat.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/MakeVerboseFormat.h b/code/PostProcessing/MakeVerboseFormat.h index f21f5919e..02fe21fa7 100644 --- a/code/PostProcessing/MakeVerboseFormat.h +++ b/code/PostProcessing/MakeVerboseFormat.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/OptimizeGraph.cpp b/code/PostProcessing/OptimizeGraph.cpp index bcd654634..3be5ff514 100644 --- a/code/PostProcessing/OptimizeGraph.cpp +++ b/code/PostProcessing/OptimizeGraph.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/OptimizeGraph.h b/code/PostProcessing/OptimizeGraph.h index 23e59e67d..c32748d7f 100644 --- a/code/PostProcessing/OptimizeGraph.h +++ b/code/PostProcessing/OptimizeGraph.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/OptimizeMeshes.cpp b/code/PostProcessing/OptimizeMeshes.cpp index 0fd597808..44792420c 100644 --- a/code/PostProcessing/OptimizeMeshes.cpp +++ b/code/PostProcessing/OptimizeMeshes.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/code/PostProcessing/OptimizeMeshes.h b/code/PostProcessing/OptimizeMeshes.h index 0b062959a..e424ae24a 100644 --- a/code/PostProcessing/OptimizeMeshes.h +++ b/code/PostProcessing/OptimizeMeshes.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/PretransformVertices.cpp b/code/PostProcessing/PretransformVertices.cpp index aff6e535a..37727c968 100644 --- a/code/PostProcessing/PretransformVertices.cpp +++ b/code/PostProcessing/PretransformVertices.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/PretransformVertices.h b/code/PostProcessing/PretransformVertices.h index 69d3d8400..74c886488 100644 --- a/code/PostProcessing/PretransformVertices.h +++ b/code/PostProcessing/PretransformVertices.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ProcessHelper.cpp b/code/PostProcessing/ProcessHelper.cpp index e55c17648..cfbac3e80 100644 --- a/code/PostProcessing/ProcessHelper.cpp +++ b/code/PostProcessing/ProcessHelper.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -52,8 +52,9 @@ namespace Assimp { // ------------------------------------------------------------------------------- void ConvertListToStrings(const std::string &in, std::list &out) { const char *s = in.c_str(); + const char *end = in.c_str() + in.size(); while (*s) { - SkipSpacesAndLineEnd(&s); + SkipSpacesAndLineEnd(&s, end); if (*s == '\'') { const char *base = ++s; while (*s != '\'') { @@ -66,7 +67,7 @@ void ConvertListToStrings(const std::string &in, std::list &out) { out.emplace_back(base, (size_t)(s - base)); ++s; } else { - out.push_back(GetNextToken(s)); + out.push_back(GetNextToken(s, end)); } } } @@ -176,8 +177,8 @@ unsigned int GetMeshVFormatUnique(const aiMesh *pcMesh) { if (pcMesh->HasTangentsAndBitangents()) iRet |= 0x4; - static_assert(8 >= AI_MAX_NUMBER_OF_COLOR_SETS); - static_assert(8 >= AI_MAX_NUMBER_OF_TEXTURECOORDS); + static_assert(8 >= AI_MAX_NUMBER_OF_COLOR_SETS, "static_assert(8 >= AI_MAX_NUMBER_OF_COLOR_SETS)"); + static_assert(8 >= AI_MAX_NUMBER_OF_TEXTURECOORDS, "static_assert(8 >= AI_MAX_NUMBER_OF_TEXTURECOORDS)"); // texture coordinates unsigned int p = 0; diff --git a/code/PostProcessing/ProcessHelper.h b/code/PostProcessing/ProcessHelper.h index 78df94ca1..273b122ae 100644 --- a/code/PostProcessing/ProcessHelper.h +++ b/code/PostProcessing/ProcessHelper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/RemoveRedundantMaterials.cpp b/code/PostProcessing/RemoveRedundantMaterials.cpp index ea8d154dc..828fcd0ac 100644 --- a/code/PostProcessing/RemoveRedundantMaterials.cpp +++ b/code/PostProcessing/RemoveRedundantMaterials.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -75,124 +75,129 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) { ASSIMP_LOG_DEBUG("RemoveRedundantMatsProcess begin"); unsigned int redundantRemoved = 0, unreferencedRemoved = 0; - if (pScene->mNumMaterials) { - // Find out which materials are referenced by meshes - std::vector abReferenced(pScene->mNumMaterials,false); - for (unsigned int i = 0;i < pScene->mNumMeshes;++i) - abReferenced[pScene->mMeshes[i]->mMaterialIndex] = true; + if (pScene->mNumMaterials == 0) { + return; + } + + // Find out which materials are referenced by meshes + std::vector abReferenced(pScene->mNumMaterials,false); + for (unsigned int i = 0;i < pScene->mNumMeshes;++i) { + abReferenced[pScene->mMeshes[i]->mMaterialIndex] = true; + } - // If a list of materials to be excluded was given, match the list with - // our imported materials and 'salt' all positive matches to ensure that - // we get unique hashes later. - if (mConfigFixedMaterials.length()) { + // If a list of materials to be excluded was given, match the list with + // our imported materials and 'salt' all positive matches to ensure that + // we get unique hashes later. + if (mConfigFixedMaterials.length()) { + std::list strings; + ConvertListToStrings(mConfigFixedMaterials,strings); - std::list strings; - ConvertListToStrings(mConfigFixedMaterials,strings); + for (unsigned int i = 0; i < pScene->mNumMaterials;++i) { + aiMaterial* mat = pScene->mMaterials[i]; + ai_assert(mat != nullptr); + aiString name; + mat->Get(AI_MATKEY_NAME,name); - for (unsigned int i = 0; i < pScene->mNumMaterials;++i) { - aiMaterial* mat = pScene->mMaterials[i]; + if (name.length != 0) { + std::list::const_iterator it = std::find(strings.begin(), strings.end(), name.data); + if (it != strings.end()) { + // Our brilliant 'salt': A single material property with ~ as first + // character to mark it as internal and temporary. + const int dummy = 1; + ((aiMaterial*)mat)->AddProperty(&dummy,1,"~RRM.UniqueMaterial",0,0); - aiString name; - mat->Get(AI_MATKEY_NAME,name); - - if (name.length) { - std::list::const_iterator it = std::find(strings.begin(), strings.end(), name.data); - if (it != strings.end()) { - - // Our brilliant 'salt': A single material property with ~ as first - // character to mark it as internal and temporary. - const int dummy = 1; - ((aiMaterial*)mat)->AddProperty(&dummy,1,"~RRM.UniqueMaterial",0,0); - - // Keep this material even if no mesh references it - abReferenced[i] = true; - ASSIMP_LOG_VERBOSE_DEBUG( "Found positive match in exclusion list: \'", name.data, "\'"); - } + // Keep this material even if no mesh references it + abReferenced[i] = true; + ASSIMP_LOG_VERBOSE_DEBUG( "Found positive match in exclusion list: \'", name.data, "\'"); } } } + } - // TODO: re-implement this algorithm to work in-place - unsigned int *aiMappingTable = new unsigned int[pScene->mNumMaterials]; - for ( unsigned int i=0; imNumMaterials; i++ ) { - aiMappingTable[ i ] = 0; + // TODO: re-implement this algorithm to work in-place + unsigned int *aiMappingTable = new unsigned int[pScene->mNumMaterials]; + for ( unsigned int i=0; imNumMaterials; i++ ) { + aiMappingTable[ i ] = 0; + } + unsigned int iNewNum = 0; + + // Iterate through all materials and calculate a hash for them + // store all hashes in a list and so a quick search whether + // we do already have a specific hash. This allows us to + // determine which materials are identical. + uint32_t *aiHashes = new uint32_t[ pScene->mNumMaterials ]; + for (unsigned int i = 0; i < pScene->mNumMaterials;++i) { + // No mesh is referencing this material, remove it. + if (!abReferenced[i]) { + ++unreferencedRemoved; + delete pScene->mMaterials[i]; + pScene->mMaterials[i] = nullptr; + continue; } - unsigned int iNewNum = 0; - // Iterate through all materials and calculate a hash for them - // store all hashes in a list and so a quick search whether - // we do already have a specific hash. This allows us to - // determine which materials are identical. - uint32_t *aiHashes = new uint32_t[ pScene->mNumMaterials ];; - for (unsigned int i = 0; i < pScene->mNumMaterials;++i) { - // No mesh is referencing this material, remove it. - if (!abReferenced[i]) { - ++unreferencedRemoved; + // Check all previously mapped materials for a matching hash. + // On a match we can delete this material and just make it ref to the same index. + uint32_t me = aiHashes[i] = ComputeMaterialHash(pScene->mMaterials[i]); + for (unsigned int a = 0; a < i;++a) { + if (abReferenced[a] && me == aiHashes[a]) { + ++redundantRemoved; + me = 0; + aiMappingTable[i] = aiMappingTable[a]; delete pScene->mMaterials[i]; pScene->mMaterials[i] = nullptr; + break; + } + } + // This is a new material that is referenced, add to the map. + if (me) { + aiMappingTable[i] = iNewNum++; + } + } + // If the new material count differs from the original, + // we need to rebuild the material list and remap mesh material indexes. + if (iNewNum < 1) { + delete [] aiMappingTable; + delete [] aiHashes; + pScene->mNumMaterials = 0; + return; + } + if (iNewNum != pScene->mNumMaterials) { + ai_assert(iNewNum > 0); + aiMaterial** ppcMaterials = new aiMaterial*[iNewNum]; + ::memset(ppcMaterials,0,sizeof(void*)*iNewNum); + for (unsigned int p = 0; p < pScene->mNumMaterials;++p) { + // if the material is not referenced ... remove it + if (!abReferenced[p]) { continue; } - // Check all previously mapped materials for a matching hash. - // On a match we can delete this material and just make it ref to the same index. - uint32_t me = aiHashes[i] = ComputeMaterialHash(pScene->mMaterials[i]); - for (unsigned int a = 0; a < i;++a) { - if (abReferenced[a] && me == aiHashes[a]) { - ++redundantRemoved; - me = 0; - aiMappingTable[i] = aiMappingTable[a]; - delete pScene->mMaterials[i]; - pScene->mMaterials[i] = nullptr; - break; + // generate new names for modified materials that had no names + const unsigned int idx = aiMappingTable[p]; + if (ppcMaterials[idx]) { + aiString sz; + if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) { + sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p); + ((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME); } - } - // This is a new material that is referenced, add to the map. - if (me) { - aiMappingTable[i] = iNewNum++; + } else { + ppcMaterials[idx] = pScene->mMaterials[p]; } } - // If the new material count differs from the original, - // we need to rebuild the material list and remap mesh material indexes. - if(iNewNum < 1) - throw DeadlyImportError("No materials remaining"); - if (iNewNum != pScene->mNumMaterials) { - ai_assert(iNewNum > 0); - aiMaterial** ppcMaterials = new aiMaterial*[iNewNum]; - ::memset(ppcMaterials,0,sizeof(void*)*iNewNum); - for (unsigned int p = 0; p < pScene->mNumMaterials;++p) - { - // if the material is not referenced ... remove it - if (!abReferenced[p]) { - continue; - } - - // generate new names for modified materials that had no names - const unsigned int idx = aiMappingTable[p]; - if (ppcMaterials[idx]) { - aiString sz; - if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) { - sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p); - ((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME); - } - } else { - ppcMaterials[idx] = pScene->mMaterials[p]; - } - } - // update all material indices - for (unsigned int p = 0; p < pScene->mNumMeshes;++p) { - aiMesh* mesh = pScene->mMeshes[p]; - ai_assert(nullptr != mesh); - mesh->mMaterialIndex = aiMappingTable[mesh->mMaterialIndex]; - } - // delete the old material list - delete[] pScene->mMaterials; - pScene->mMaterials = ppcMaterials; - pScene->mNumMaterials = iNewNum; + // update all material indices + for (unsigned int p = 0; p < pScene->mNumMeshes;++p) { + aiMesh* mesh = pScene->mMeshes[p]; + ai_assert(nullptr != mesh); + mesh->mMaterialIndex = aiMappingTable[mesh->mMaterialIndex]; } - // delete temporary storage - delete[] aiHashes; - delete[] aiMappingTable; + // delete the old material list + delete[] pScene->mMaterials; + pScene->mMaterials = ppcMaterials; + pScene->mNumMaterials = iNewNum; } + // delete temporary storage + delete[] aiHashes; + delete[] aiMappingTable; + if (redundantRemoved == 0 && unreferencedRemoved == 0) { ASSIMP_LOG_DEBUG("RemoveRedundantMatsProcess finished "); } else { diff --git a/code/PostProcessing/RemoveRedundantMaterials.h b/code/PostProcessing/RemoveRedundantMaterials.h index 1b42bea55..107de0daa 100644 --- a/code/PostProcessing/RemoveRedundantMaterials.h +++ b/code/PostProcessing/RemoveRedundantMaterials.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/RemoveVCProcess.cpp b/code/PostProcessing/RemoveVCProcess.cpp index bcad65423..13ef81e23 100644 --- a/code/PostProcessing/RemoveVCProcess.cpp +++ b/code/PostProcessing/RemoveVCProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/RemoveVCProcess.h b/code/PostProcessing/RemoveVCProcess.h index 45c0b3a71..8d9b5167a 100644 --- a/code/PostProcessing/RemoveVCProcess.h +++ b/code/PostProcessing/RemoveVCProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ScaleProcess.cpp b/code/PostProcessing/ScaleProcess.cpp index 1bb9196f1..5cd7eea6e 100644 --- a/code/PostProcessing/ScaleProcess.cpp +++ b/code/PostProcessing/ScaleProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ScaleProcess.h b/code/PostProcessing/ScaleProcess.h index ae1c3ed00..2887c7221 100644 --- a/code/PostProcessing/ScaleProcess.h +++ b/code/PostProcessing/ScaleProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/SortByPTypeProcess.cpp b/code/PostProcessing/SortByPTypeProcess.cpp index 47633dce5..48ebbc573 100644 --- a/code/PostProcessing/SortByPTypeProcess.cpp +++ b/code/PostProcessing/SortByPTypeProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/SortByPTypeProcess.h b/code/PostProcessing/SortByPTypeProcess.h index ce4f7da62..aa7774d7f 100644 --- a/code/PostProcessing/SortByPTypeProcess.h +++ b/code/PostProcessing/SortByPTypeProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/SplitByBoneCountProcess.cpp b/code/PostProcessing/SplitByBoneCountProcess.cpp index 969146fee..f63478767 100644 --- a/code/PostProcessing/SplitByBoneCountProcess.cpp +++ b/code/PostProcessing/SplitByBoneCountProcess.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -394,7 +394,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormNumMeshes == 0 ) { + if( pNode->mNumMeshes != 0 ) { IndexArray newMeshList; for( unsigned int a = 0; a < pNode->mNumMeshes; ++a) { unsigned int srcIndex = pNode->mMeshes[a]; diff --git a/code/PostProcessing/SplitByBoneCountProcess.h b/code/PostProcessing/SplitByBoneCountProcess.h index efe85824f..c90661cb5 100644 --- a/code/PostProcessing/SplitByBoneCountProcess.h +++ b/code/PostProcessing/SplitByBoneCountProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/SplitLargeMeshes.cpp b/code/PostProcessing/SplitLargeMeshes.cpp index b6e5b772a..3bee28521 100644 --- a/code/PostProcessing/SplitLargeMeshes.cpp +++ b/code/PostProcessing/SplitLargeMeshes.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/SplitLargeMeshes.h b/code/PostProcessing/SplitLargeMeshes.h index 4e0d764c1..25bf300d5 100644 --- a/code/PostProcessing/SplitLargeMeshes.h +++ b/code/PostProcessing/SplitLargeMeshes.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/TextureTransform.cpp b/code/PostProcessing/TextureTransform.cpp index 3de357c17..53dba3860 100644 --- a/code/PostProcessing/TextureTransform.cpp +++ b/code/PostProcessing/TextureTransform.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/TextureTransform.h b/code/PostProcessing/TextureTransform.h index c9f0480ba..7c0addf09 100644 --- a/code/PostProcessing/TextureTransform.h +++ b/code/PostProcessing/TextureTransform.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/TriangulateProcess.cpp b/code/PostProcessing/TriangulateProcess.cpp index f16de2196..ac483f215 100644 --- a/code/PostProcessing/TriangulateProcess.cpp +++ b/code/PostProcessing/TriangulateProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/TriangulateProcess.h b/code/PostProcessing/TriangulateProcess.h index ac31e4377..e17a10e33 100644 --- a/code/PostProcessing/TriangulateProcess.h +++ b/code/PostProcessing/TriangulateProcess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ValidateDataStructure.cpp b/code/PostProcessing/ValidateDataStructure.cpp index 14259e11a..a0a73e200 100644 --- a/code/PostProcessing/ValidateDataStructure.cpp +++ b/code/PostProcessing/ValidateDataStructure.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/code/PostProcessing/ValidateDataStructure.h b/code/PostProcessing/ValidateDataStructure.h index 9cfd4ced1..8bc13e60d 100644 --- a/code/PostProcessing/ValidateDataStructure.h +++ b/code/PostProcessing/ValidateDataStructure.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/contrib/clipper/clipper.cpp b/contrib/clipper/clipper.cpp index d75974336..c0a8565bb 100644 --- a/contrib/clipper/clipper.cpp +++ b/contrib/clipper/clipper.cpp @@ -4330,10 +4330,10 @@ double DistanceFromLineSqrd( const IntPoint& pt, const IntPoint& ln1, const IntPoint& ln2) { //The equation of a line in general form (Ax + By + C = 0) - //given 2 points (x�,y�) & (x�,y�) is ... - //(y� - y�)x + (x� - x�)y + (y� - y�)x� - (x� - x�)y� = 0 - //A = (y� - y�); B = (x� - x�); C = (y� - y�)x� - (x� - x�)y� - //perpendicular distance of point (x�,y�) = (Ax� + By� + C)/Sqrt(A� + B�) + //given 2 points (x_1, y_1) & (x_2, y_2) is ... + //(y_1 - y_2)x + (x_2 - x_1)y - (y_1 - y_2)x_1 - (x_2 - x_1)y_1 = 0 + //A = (y_1 - y_2); B = (x_2 - x_1); C = - (y_1 - y_2)x_1 - (x_2 - x_1)y_1 + //perpendicular distance of point (x_0, y_0) = |Ax_0 + By_0 + C| / Sqrt(A^2 + B^2) //see http://en.wikipedia.org/wiki/Perpendicular_distance double A = double(ln1.Y - ln2.Y); double B = double(ln2.X - ln1.X); diff --git a/contrib/poly2tri/poly2tri/sweep/sweep.cc b/contrib/poly2tri/poly2tri/sweep/sweep.cc index 565a198d8..e1f23f11b 100644 --- a/contrib/poly2tri/poly2tri/sweep/sweep.cc +++ b/contrib/poly2tri/poly2tri/sweep/sweep.cc @@ -111,6 +111,9 @@ void Sweep::EdgeEvent(SweepContext& tcx, Edge* edge, Node* node) void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point) { + if (triangle == nullptr) + return; + if (IsEdgeSideOfTriangle(*triangle, ep, eq)) { return; } diff --git a/contrib/pugixml/readme.txt b/contrib/pugixml/readme.txt index 9dffb72a1..2c1865437 100644 --- a/contrib/pugixml/readme.txt +++ b/contrib/pugixml/readme.txt @@ -1,6 +1,6 @@ pugixml 1.13 - an XML processing library -Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) +Copyright (c) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) Report bugs and download new versions at https://pugixml.org/ This is the distribution of pugixml, which is a C++ XML processing library, @@ -26,7 +26,7 @@ The distribution contains the following folders: This library is distributed under the MIT License: -Copyright (c) 2006-2022 Arseny Kapoulkine +Copyright (c) 2006-2024 Arseny Kapoulkine Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/contrib/pugixml/src/pugiconfig.hpp b/contrib/pugixml/src/pugiconfig.hpp index 9bf2efd39..1a3956903 100644 --- a/contrib/pugixml/src/pugiconfig.hpp +++ b/contrib/pugixml/src/pugiconfig.hpp @@ -1,7 +1,7 @@ /** * pugixml parser - version 1.13 * -------------------------------------------------------- - * Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (c) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -52,7 +52,7 @@ #endif /** - * Copyright (c) 2006-2022 Arseny Kapoulkine + * Copyright (c) 2006-2024 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/contrib/pugixml/src/pugixml.cpp b/contrib/pugixml/src/pugixml.cpp index c63645b67..6d6bd0edb 100644 --- a/contrib/pugixml/src/pugixml.cpp +++ b/contrib/pugixml/src/pugixml.cpp @@ -1,7 +1,7 @@ /** * pugixml parser - version 1.13 * -------------------------------------------------------- - * Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (c) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -13133,7 +13133,7 @@ namespace pugi #endif /** - * Copyright (c) 2006-2022 Arseny Kapoulkine + * Copyright (c) 2006-2024 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/contrib/pugixml/src/pugixml.hpp b/contrib/pugixml/src/pugixml.hpp index 050df154c..fde6a4a86 100644 --- a/contrib/pugixml/src/pugixml.hpp +++ b/contrib/pugixml/src/pugixml.hpp @@ -1,7 +1,7 @@ /** * pugixml parser - version 1.13 * -------------------------------------------------------- - * Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (c) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -1481,7 +1481,7 @@ namespace std #endif /** - * Copyright (c) 2006-2022 Arseny Kapoulkine + * Copyright (c) 2006-2024 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/contrib/rapidjson/include/rapidjson/allocators.h b/contrib/rapidjson/include/rapidjson/allocators.h index 44ec5295c..275417bd8 100644 --- a/contrib/rapidjson/include/rapidjson/allocators.h +++ b/contrib/rapidjson/include/rapidjson/allocators.h @@ -16,6 +16,14 @@ #define RAPIDJSON_ALLOCATORS_H_ #include "rapidjson.h" +#include "internal/meta.h" + +#include +#include + +#if RAPIDJSON_HAS_CXX11 +#include +#endif RAPIDJSON_NAMESPACE_BEGIN @@ -89,7 +97,14 @@ public: } return RAPIDJSON_REALLOC(originalPtr, newSize); } - static void Free(void *ptr) { RAPIDJSON_FREE(ptr); } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); } + + bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return true; + } + bool operator!=(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return false; + } }; /////////////////////////////////////////////////////////////////////////////// @@ -113,16 +128,64 @@ public: */ template class MemoryPoolAllocator { + //! Chunk header for perpending to each chunk. + /*! Chunks are stored as a singly linked list. + */ + struct ChunkHeader { + size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). + size_t size; //!< Current size of allocated memory in bytes. + ChunkHeader *next; //!< Next chunk in the linked list. + }; + + struct SharedData { + ChunkHeader *chunkHead; //!< Head of the chunk linked-list. Only the head chunk serves allocation. + BaseAllocator* ownBaseAllocator; //!< base allocator created by this object. + size_t refcount; + bool ownBuffer; + }; + + static const size_t SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData)); + static const size_t SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader)); + + static inline ChunkHeader *GetChunkHead(SharedData *shared) + { + return reinterpret_cast(reinterpret_cast(shared) + SIZEOF_SHARED_DATA); + } + static inline uint8_t *GetChunkBuffer(SharedData *shared) + { + return reinterpret_cast(shared->chunkHead) + SIZEOF_CHUNK_HEADER; + } + + static const size_t kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. + public: static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator) + static const bool kRefCounted = true; //!< Tell users that this allocator is reference counted on copy //! Constructor with chunkSize. /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. \param baseAllocator The allocator for allocating memory chunks. */ + explicit MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : - chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0) + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator ? baseAllocator : RAPIDJSON_NEW(BaseAllocator)()), + shared_(static_cast(baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER) : 0)) { + RAPIDJSON_ASSERT(baseAllocator_ != 0); + RAPIDJSON_ASSERT(shared_ != 0); + if (baseAllocator) { + shared_->ownBaseAllocator = 0; + } + else { + shared_->ownBaseAllocator = baseAllocator_; + } + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = 0; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBuffer = true; + shared_->refcount = 1; } //! Constructor with user-supplied buffer. @@ -136,41 +199,101 @@ public: \param baseAllocator The allocator for allocating memory chunks. */ MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : - chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer), baseAllocator_(baseAllocator), ownBaseAllocator_(0) + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator), + shared_(static_cast(AlignBuffer(buffer, size))) { - RAPIDJSON_ASSERT(buffer != 0); - RAPIDJSON_ASSERT(size > sizeof(ChunkHeader)); - chunkHead_ = reinterpret_cast(buffer); - chunkHead_->capacity = size - sizeof(ChunkHeader); - chunkHead_->size = 0; - chunkHead_->next = 0; + RAPIDJSON_ASSERT(size >= SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER); + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = size - SIZEOF_SHARED_DATA - SIZEOF_CHUNK_HEADER; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBaseAllocator = 0; + shared_->ownBuffer = false; + shared_->refcount = 1; } + MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + ++shared_->refcount; + } + MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + ++rhs.shared_->refcount; + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + return *this; + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + rhs.shared_ = 0; + } + MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + rhs.shared_ = 0; + return *this; + } +#endif + //! Destructor. /*! This deallocates all memory chunks, excluding the user-supplied buffer. */ - ~MemoryPoolAllocator() { + ~MemoryPoolAllocator() RAPIDJSON_NOEXCEPT { + if (!shared_) { + // do nothing if moved + return; + } + if (shared_->refcount > 1) { + --shared_->refcount; + return; + } Clear(); - RAPIDJSON_DELETE(ownBaseAllocator_); + BaseAllocator *a = shared_->ownBaseAllocator; + if (shared_->ownBuffer) { + baseAllocator_->Free(shared_); + } + RAPIDJSON_DELETE(a); } - //! Deallocates all memory chunks, excluding the user-supplied buffer. - void Clear() { - while (chunkHead_ && chunkHead_ != userBuffer_) { - ChunkHeader* next = chunkHead_->next; - baseAllocator_->Free(chunkHead_); - chunkHead_ = next; + //! Deallocates all memory chunks, excluding the first/user one. + void Clear() RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + for (;;) { + ChunkHeader* c = shared_->chunkHead; + if (!c->next) { + break; + } + shared_->chunkHead = c->next; + baseAllocator_->Free(c); } - if (chunkHead_ && chunkHead_ == userBuffer_) - chunkHead_->size = 0; // Clear user buffer + shared_->chunkHead->size = 0; } //! Computes the total capacity of allocated memory chunks. /*! \return total capacity in bytes. */ - size_t Capacity() const { + size_t Capacity() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); size_t capacity = 0; - for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) capacity += c->capacity; return capacity; } @@ -178,25 +301,35 @@ public: //! Computes the memory blocks allocated. /*! \return total used bytes. */ - size_t Size() const { + size_t Size() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); size_t size = 0; - for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) size += c->size; return size; } + //! Whether the allocator is shared. + /*! \return true or false. + */ + bool Shared() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + return shared_->refcount > 1; + } + //! Allocates a memory block. (concept Allocator) void* Malloc(size_t size) { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); if (!size) return NULL; size = RAPIDJSON_ALIGN(size); - if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity) + if (RAPIDJSON_UNLIKELY(shared_->chunkHead->size + size > shared_->chunkHead->capacity)) if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size)) return NULL; - void *buffer = reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size; - chunkHead_->size += size; + void *buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size; + shared_->chunkHead->size += size; return buffer; } @@ -205,6 +338,7 @@ public: if (originalPtr == 0) return Malloc(newSize); + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); if (newSize == 0) return NULL; @@ -216,10 +350,10 @@ public: return originalPtr; // Simply expand it if it is the last allocation and there is sufficient space - if (originalPtr == reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) { + if (originalPtr == GetChunkBuffer(shared_) + shared_->chunkHead->size - originalSize) { size_t increment = static_cast(newSize - originalSize); - if (chunkHead_->size + increment <= chunkHead_->capacity) { - chunkHead_->size += increment; + if (shared_->chunkHead->size + increment <= shared_->chunkHead->capacity) { + shared_->chunkHead->size += increment; return originalPtr; } } @@ -235,50 +369,325 @@ public: } //! Frees a memory block (concept Allocator) - static void Free(void *ptr) { (void)ptr; } // Do nothing + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing + + //! Compare (equality) with another MemoryPoolAllocator + bool operator==(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + return shared_ == rhs.shared_; + } + //! Compare (inequality) with another MemoryPoolAllocator + bool operator!=(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + return !operator==(rhs); + } private: - //! Copy constructor is not permitted. - MemoryPoolAllocator(const MemoryPoolAllocator& rhs) /* = delete */; - //! Copy assignment operator is not permitted. - MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) /* = delete */; - //! Creates a new chunk. /*! \param capacity Capacity of the chunk in bytes. \return true if success. */ bool AddChunk(size_t capacity) { if (!baseAllocator_) - ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); - if (ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) { + shared_->ownBaseAllocator = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); + if (ChunkHeader* chunk = static_cast(baseAllocator_->Malloc(SIZEOF_CHUNK_HEADER + capacity))) { chunk->capacity = capacity; chunk->size = 0; - chunk->next = chunkHead_; - chunkHead_ = chunk; + chunk->next = shared_->chunkHead; + shared_->chunkHead = chunk; return true; } else return false; } - static const int kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. + static inline void* AlignBuffer(void* buf, size_t &size) + { + RAPIDJSON_NOEXCEPT_ASSERT(buf != 0); + const uintptr_t mask = sizeof(void*) - 1; + const uintptr_t ubuf = reinterpret_cast(buf); + if (RAPIDJSON_UNLIKELY(ubuf & mask)) { + const uintptr_t abuf = (ubuf + mask) & ~mask; + RAPIDJSON_ASSERT(size >= abuf - ubuf); + buf = reinterpret_cast(abuf); + size -= abuf - ubuf; + } + return buf; + } - //! Chunk header for perpending to each chunk. - /*! Chunks are stored as a singly linked list. - */ - struct ChunkHeader { - size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). - size_t size; //!< Current size of allocated memory in bytes. - ChunkHeader *next; //!< Next chunk in the linked list. + size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. + BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. + SharedData *shared_; //!< The shared data of the allocator +}; + +namespace internal { + template + struct IsRefCounted : + public FalseType + { }; + template + struct IsRefCounted::Type> : + public TrueType + { }; +} + +template +inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n) +{ + RAPIDJSON_NOEXCEPT_ASSERT(old_n <= (std::numeric_limits::max)() / sizeof(T) && new_n <= (std::numeric_limits::max)() / sizeof(T)); + return static_cast(a.Realloc(old_p, old_n * sizeof(T), new_n * sizeof(T))); +} + +template +inline T *Malloc(A& a, size_t n = 1) +{ + return Realloc(a, NULL, 0, n); +} + +template +inline void Free(A& a, T *p, size_t n = 1) +{ + static_cast(Realloc(a, p, n, 0)); +} + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) // std::allocator can safely be inherited +#endif + +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; +#if RAPIDJSON_HAS_CXX11 + typedef std::allocator_traits traits_type; +#else + typedef allocator_type traits_type; +#endif + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(std::move(rhs)), + baseAllocator_(std::move(rhs.baseAllocator_)) + { } +#endif +#if RAPIDJSON_HAS_CXX11 + using propagate_on_container_move_assignment = std::true_type; + using propagate_on_container_swap = std::true_type; +#endif + + /* implicit */ + StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(baseAllocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; }; - ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head chunk serves allocation. - size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. - void *userBuffer_; //!< User supplied buffer. - BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. - BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object. + typedef typename traits_type::size_type size_type; + typedef typename traits_type::difference_type difference_type; + + typedef typename traits_type::value_type value_type; + typedef typename traits_type::pointer pointer; + typedef typename traits_type::const_pointer const_pointer; + +#if RAPIDJSON_HAS_CXX11 + + typedef typename std::add_lvalue_reference::type &reference; + typedef typename std::add_lvalue_reference::type>::type &const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return traits_type::max_size(*this); + } + + template + void construct(pointer p, Args&&... args) + { + traits_type::construct(*this, p, std::forward(args)...); + } + void destroy(pointer p) + { + traits_type::destroy(*this, p); + } + +#else // !RAPIDJSON_HAS_CXX11 + + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return allocator_type::max_size(); + } + + void construct(pointer p, const_reference r) + { + allocator_type::construct(p, r); + } + void destroy(pointer p) + { + allocator_type::destroy(p); + } + +#endif // !RAPIDJSON_HAS_CXX11 + + template + U* allocate(size_type n = 1, const void* = 0) + { + return RAPIDJSON_NAMESPACE::Malloc(baseAllocator_, n); + } + template + void deallocate(U* p, size_type n = 1) + { + RAPIDJSON_NAMESPACE::Free(baseAllocator_, p, n); + } + + pointer allocate(size_type n = 1, const void* = 0) + { + return allocate(n); + } + void deallocate(pointer p, size_type n = 1) + { + deallocate(p, n); + } + +#if RAPIDJSON_HAS_CXX11 + using is_always_equal = std::is_empty; +#endif + + template + bool operator==(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return baseAllocator_ == rhs.baseAllocator_; + } + template + bool operator!=(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return !operator==(rhs); + } + + //! rapidjson Allocator concept + static const bool kNeedFree = BaseAllocator::kNeedFree; + static const bool kRefCounted = internal::IsRefCounted::Value; + void* Malloc(size_t size) + { + return baseAllocator_.Malloc(size); + } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) + { + return baseAllocator_.Realloc(originalPtr, originalSize, newSize); + } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT + { + BaseAllocator::Free(ptr); + } + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; }; +#if !RAPIDJSON_HAS_CXX17 // std::allocator deprecated in C++17 +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + /* implicit */ + StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(baseAllocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; + }; + + typedef typename allocator_type::value_type value_type; + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; +}; +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ENCODINGS_H_ diff --git a/contrib/rapidjson/include/rapidjson/document.h b/contrib/rapidjson/include/rapidjson/document.h index 028235ec6..f183749ad 100644 --- a/contrib/rapidjson/include/rapidjson/document.h +++ b/contrib/rapidjson/include/rapidjson/document.h @@ -42,12 +42,21 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo RAPIDJSON_DIAG_OFF(effc++) #endif // __GNUC__ +#ifdef GetObject +// see https://github.com/Tencent/rapidjson/issues/1448 +// a former included windows.h might have defined a macro called GetObject, which affects +// GetObject defined here. This ensures the macro does not get applied +#pragma push_macro("GetObject") +#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#undef GetObject +#endif + #ifndef RAPIDJSON_NOMEMBERITERATORCLASS #include // std::random_access_iterator_tag #endif -#if RAPIDJSON_HAS_CXX11_RVALUE_REFS -#include // std::move +#if RAPIDJSON_USE_MEMBERSMAP +#include // std::multimap #endif RAPIDJSON_NAMESPACE_BEGIN @@ -66,7 +75,7 @@ class GenericDocument; User can define this to use CrtAllocator or MemoryPoolAllocator. */ #ifndef RAPIDJSON_DEFAULT_ALLOCATOR -#define RAPIDJSON_DEFAULT_ALLOCATOR MemoryPoolAllocator +#define RAPIDJSON_DEFAULT_ALLOCATOR ::RAPIDJSON_NAMESPACE::MemoryPoolAllocator<::RAPIDJSON_NAMESPACE::CrtAllocator> #endif /*! \def RAPIDJSON_DEFAULT_STACK_ALLOCATOR @@ -76,7 +85,7 @@ class GenericDocument; User can define this to use CrtAllocator or MemoryPoolAllocator. */ #ifndef RAPIDJSON_DEFAULT_STACK_ALLOCATOR -#define RAPIDJSON_DEFAULT_STACK_ALLOCATOR CrtAllocator +#define RAPIDJSON_DEFAULT_STACK_ALLOCATOR ::RAPIDJSON_NAMESPACE::CrtAllocator #endif /*! \def RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY @@ -732,18 +741,8 @@ public: template GenericValue(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings = false) { switch (rhs.GetType()) { - case kObjectType: { - SizeType count = rhs.data_.o.size; - Member* lm = reinterpret_cast(allocator.Malloc(count * sizeof(Member))); - const typename GenericValue::Member* rm = rhs.GetMembersPointer(); - for (SizeType i = 0; i < count; i++) { - new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings); - new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings); - } - data_.f.flags = kObjectFlag; - data_.o.size = data_.o.capacity = count; - SetMembersPointer(lm); - } + case kObjectType: + DoCopyMembers(rhs, allocator, copyConstStrings); break; case kArrayType: { SizeType count = rhs.data_.a.size; @@ -879,25 +878,30 @@ public: /*! Need to destruct elements of array, members of object, or copy-string. */ ~GenericValue() { - if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + // With RAPIDJSON_USE_MEMBERSMAP, the maps need to be destroyed to release + // their Allocator if it's refcounted (e.g. MemoryPoolAllocator). + if (Allocator::kNeedFree || (RAPIDJSON_USE_MEMBERSMAP+0 && + internal::IsRefCounted::Value)) { switch(data_.f.flags) { case kArrayFlag: { GenericValue* e = GetElementsPointer(); for (GenericValue* v = e; v != e + data_.a.size; ++v) v->~GenericValue(); - Allocator::Free(e); + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(e); + } } break; case kObjectFlag: - for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) - m->~Member(); - Allocator::Free(GetMembersPointer()); + DoFreeMembers(); break; case kCopyStringFlag: - Allocator::Free(const_cast(GetStringPointer())); + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(const_cast(GetStringPointer())); + } break; default: @@ -916,8 +920,13 @@ public: */ GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT { if (RAPIDJSON_LIKELY(this != &rhs)) { + // Can't destroy "this" before assigning "rhs", otherwise "rhs" + // could be used after free if it's an sub-Value of "this", + // hence the temporary danse. + GenericValue temp; + temp.RawAssign(rhs); this->~GenericValue(); - RawAssign(rhs); + RawAssign(temp); } return *this; } @@ -1024,7 +1033,7 @@ public: return false; for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) { typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name); - if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value) + if (rhsMemberItr == rhs.MemberEnd() || (!(lhsMemberItr->value == rhsMemberItr->value))) return false; } return true; @@ -1033,7 +1042,7 @@ public: if (data_.a.size != rhs.data_.a.size) return false; for (SizeType i = 0; i < data_.a.size; i++) - if ((*this)[i] != rhs[i]) + if (!((*this)[i] == rhs[i])) return false; return true; @@ -1069,6 +1078,7 @@ public: */ template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr,internal::IsGenericValue >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); } +#ifndef __cpp_impl_three_way_comparison //! Not-equal-to operator /*! \return !(*this == rhs) */ @@ -1093,6 +1103,7 @@ public: */ template friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); } //@} +#endif //!@name Type //@{ @@ -1219,13 +1230,28 @@ public: else { RAPIDJSON_ASSERT(false); // see above note - // This will generate -Wexit-time-destructors in clang - // static GenericValue NullValue; - // return NullValue; - - // Use static buffer and placement-new to prevent destruction - static char buffer[sizeof(GenericValue)]; +#if RAPIDJSON_HAS_CXX11 + // Use thread-local storage to prevent races between threads. + // Use static buffer and placement-new to prevent destruction, with + // alignas() to ensure proper alignment. + alignas(GenericValue) thread_local static char buffer[sizeof(GenericValue)]; return *new (buffer) GenericValue(); +#elif defined(_MSC_VER) && _MSC_VER < 1900 + // There's no way to solve both thread locality and proper alignment + // simultaneously. + __declspec(thread) static char buffer[sizeof(GenericValue)]; + return *new (buffer) GenericValue(); +#elif defined(__GNUC__) || defined(__clang__) + // This will generate -Wexit-time-destructors in clang, but that's + // better than having under-alignment. + __thread static GenericValue buffer; + return buffer; +#else + // Don't know what compiler this is, so don't know how to ensure + // thread-locality. + static GenericValue buffer; + return buffer; +#endif } } template @@ -1258,10 +1284,7 @@ public: */ GenericValue& MemberReserve(SizeType newCapacity, Allocator &allocator) { RAPIDJSON_ASSERT(IsObject()); - if (newCapacity > data_.o.capacity) { - SetMembersPointer(reinterpret_cast(allocator.Realloc(GetMembersPointer(), data_.o.capacity * sizeof(Member), newCapacity * sizeof(Member)))); - data_.o.capacity = newCapacity; - } + DoReserveMembers(newCapacity, allocator); return *this; } @@ -1335,11 +1358,7 @@ public: MemberIterator FindMember(const GenericValue& name) { RAPIDJSON_ASSERT(IsObject()); RAPIDJSON_ASSERT(name.IsString()); - MemberIterator member = MemberBegin(); - for ( ; member != MemberEnd(); ++member) - if (name.StringEqual(member->name)) - break; - return member; + return DoFindMember(name); } template ConstMemberIterator FindMember(const GenericValue& name) const { return const_cast(*this).FindMember(name); } @@ -1368,14 +1387,7 @@ public: GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { RAPIDJSON_ASSERT(IsObject()); RAPIDJSON_ASSERT(name.IsString()); - - ObjectData& o = data_.o; - if (o.size >= o.capacity) - MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity : (o.capacity + (o.capacity + 1) / 2), allocator); - Member* members = GetMembersPointer(); - members[o.size].name.RawAssign(name); - members[o.size].value.RawAssign(value); - o.size++; + DoAddMember(name, value, allocator); return *this; } @@ -1509,9 +1521,7 @@ public: */ void RemoveAllMembers() { RAPIDJSON_ASSERT(IsObject()); - for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) - m->~Member(); - data_.o.size = 0; + DoClearMembers(); } //! Remove a member in object by its name. @@ -1555,14 +1565,7 @@ public: RAPIDJSON_ASSERT(data_.o.size > 0); RAPIDJSON_ASSERT(GetMembersPointer() != 0); RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd()); - - MemberIterator last(GetMembersPointer() + (data_.o.size - 1)); - if (data_.o.size > 1 && m != last) - *m = *last; // Move the last one to this place - else - m->~Member(); // Only one left, just destroy - --data_.o.size; - return m; + return DoRemoveMember(m); } //! Remove a member from an object by iterator. @@ -1594,13 +1597,7 @@ public: RAPIDJSON_ASSERT(first >= MemberBegin()); RAPIDJSON_ASSERT(first <= last); RAPIDJSON_ASSERT(last <= MemberEnd()); - - MemberIterator pos = MemberBegin() + (first - MemberBegin()); - for (MemberIterator itr = pos; itr != last; ++itr) - itr->~Member(); - std::memmove(static_cast(&*pos), &*last, static_cast(MemberEnd() - last) * sizeof(Member)); - data_.o.size -= static_cast(last - first); - return pos; + return DoEraseMembers(first, last); } //! Erase a member in object by its name. @@ -1629,7 +1626,9 @@ public: } Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } + Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } + ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } //@} @@ -1851,12 +1850,12 @@ public: //!@name String //@{ - const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); } + const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return DataString(data_); } //! Get the length of string. /*! Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength(). */ - SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); } + SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return DataStringLength(data_); } //! Set this value as a string without copying source string. /*! This version has better performance with supplied length, and also support string containing null character. @@ -1967,7 +1966,7 @@ public: case kArrayType: if (RAPIDJSON_UNLIKELY(!handler.StartArray())) return false; - for (const GenericValue* v = Begin(); v != End(); ++v) + for (ConstValueIterator v = Begin(); v != End(); ++v) if (RAPIDJSON_UNLIKELY(!v->Accept(handler))) return false; return handler.EndArray(data_.a.size); @@ -2105,6 +2104,13 @@ private: Flag f; }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION + static RAPIDJSON_FORCEINLINE const Ch* DataString(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.str : RAPIDJSON_GETPOINTER(Ch, data.s.str); + } + static RAPIDJSON_FORCEINLINE SizeType DataStringLength(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.GetLength() : data.s.length; + } + RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); } RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); } RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); } @@ -2112,6 +2118,286 @@ private: RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); } RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); } +#if RAPIDJSON_USE_MEMBERSMAP + + struct MapTraits { + struct Less { + bool operator()(const Data& s1, const Data& s2) const { + SizeType n1 = DataStringLength(s1), n2 = DataStringLength(s2); + int cmp = std::memcmp(DataString(s1), DataString(s2), sizeof(Ch) * (n1 < n2 ? n1 : n2)); + return cmp < 0 || (cmp == 0 && n1 < n2); + } + }; + typedef std::pair Pair; + typedef std::multimap > Map; + typedef typename Map::iterator Iterator; + }; + typedef typename MapTraits::Map Map; + typedef typename MapTraits::Less MapLess; + typedef typename MapTraits::Pair MapPair; + typedef typename MapTraits::Iterator MapIterator; + + // + // Layout of the members' map/array, re(al)located according to the needed capacity: + // + // {Map*}<>{capacity}<>{Member[capacity]}<>{MapIterator[capacity]} + // + // (where <> stands for the RAPIDJSON_ALIGN-ment, if needed) + // + + static RAPIDJSON_FORCEINLINE size_t GetMapLayoutSize(SizeType capacity) { + return RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(capacity * sizeof(Member)) + + capacity * sizeof(MapIterator); + } + + static RAPIDJSON_FORCEINLINE SizeType &GetMapCapacity(Map* &map) { + return *reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + static RAPIDJSON_FORCEINLINE Member* GetMapMembers(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType))); + } + + static RAPIDJSON_FORCEINLINE MapIterator* GetMapIterators(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(GetMapCapacity(map) * sizeof(Member))); + } + + static RAPIDJSON_FORCEINLINE Map* &GetMap(Member* members) { + RAPIDJSON_ASSERT(members != 0); + return *reinterpret_cast(reinterpret_cast(members) - + RAPIDJSON_ALIGN(sizeof(SizeType)) - + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + // Some compilers' debug mechanisms want all iterators to be destroyed, for their accounting.. + RAPIDJSON_FORCEINLINE MapIterator DropMapIterator(MapIterator& rhs) { +#if RAPIDJSON_HAS_CXX11 + MapIterator ret = std::move(rhs); +#else + MapIterator ret = rhs; +#endif + rhs.~MapIterator(); + return ret; + } + + Map* &DoReallocMap(Map** oldMap, SizeType newCapacity, Allocator& allocator) { + Map **newMap = static_cast(allocator.Malloc(GetMapLayoutSize(newCapacity))); + GetMapCapacity(*newMap) = newCapacity; + if (!oldMap) { + *newMap = new (allocator.Malloc(sizeof(Map))) Map(MapLess(), allocator); + } + else { + *newMap = *oldMap; + size_t count = (*oldMap)->size(); + std::memcpy(static_cast(GetMapMembers(*newMap)), + static_cast(GetMapMembers(*oldMap)), + count * sizeof(Member)); + MapIterator *oldIt = GetMapIterators(*oldMap), + *newIt = GetMapIterators(*newMap); + while (count--) { + new (&newIt[count]) MapIterator(DropMapIterator(oldIt[count])); + } + Allocator::Free(oldMap); + } + return *newMap; + } + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return GetMapMembers(DoReallocMap(0, capacity, allocator)); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* oldMembers = GetMembersPointer(); + Map **oldMap = oldMembers ? &GetMap(oldMembers) : 0, + *&newMap = DoReallocMap(oldMap, newCapacity, allocator); + RAPIDJSON_SETPOINTER(Member, o.members, GetMapMembers(newMap)); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator mit = map->find(reinterpret_cast(name.data_)); + if (mit != map->end()) { + return MemberIterator(&members[mit->second]); + } + } + return MemberEnd(); + } + + void DoClearMembers() { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < data_.o.size; i++) { + map->erase(DropMapIterator(mit[i])); + members[i].~Member(); + } + data_.o.size = 0; + } + } + + void DoFreeMembers() { + if (Member* members = GetMembersPointer()) { + GetMap(members)->~Map(); + for (SizeType i = 0; i < data_.o.size; i++) { + members[i].~Member(); + } + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Map** map = &GetMap(members); + Allocator::Free(*map); + Allocator::Free(map); + } + } + } + +#else // !RAPIDJSON_USE_MEMBERSMAP + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return Malloc(allocator, capacity); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* newMembers = Realloc(allocator, GetMembersPointer(), o.capacity, newCapacity); + RAPIDJSON_SETPOINTER(Member, o.members, newMembers); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + MemberIterator member = MemberBegin(); + for ( ; member != MemberEnd(); ++member) + if (name.StringEqual(member->name)) + break; + return member; + } + + void DoClearMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + data_.o.size = 0; + } + + void DoFreeMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + Allocator::Free(GetMembersPointer()); + } + +#endif // !RAPIDJSON_USE_MEMBERSMAP + + void DoAddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { + ObjectData& o = data_.o; + if (o.size >= o.capacity) + DoReserveMembers(o.capacity ? (o.capacity + (o.capacity + 1) / 2) : kDefaultObjectCapacity, allocator); + Member* members = GetMembersPointer(); + Member* m = members + o.size; + m->name.RawAssign(name); + m->value.RawAssign(value); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + new (&mit[o.size]) MapIterator(map->insert(MapPair(m->name.data_, o.size))); +#endif + ++o.size; + } + + MemberIterator DoRemoveMember(MemberIterator m) { + ObjectData& o = data_.o; + Member* members = GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + SizeType mpos = static_cast(&*m - members); + map->erase(DropMapIterator(mit[mpos])); +#endif + MemberIterator last(members + (o.size - 1)); + if (o.size > 1 && m != last) { +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[mpos]) MapIterator(DropMapIterator(mit[&*last - members])); + mit[mpos]->second = mpos; +#endif + *m = *last; // Move the last one to this place + } + else { + m->~Member(); // Only one left, just destroy + } + --o.size; + return m; + } + + MemberIterator DoEraseMembers(ConstMemberIterator first, ConstMemberIterator last) { + ObjectData& o = data_.o; + MemberIterator beg = MemberBegin(), + pos = beg + (first - beg), + end = MemberEnd(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(GetMembersPointer()); + MapIterator* mit = GetMapIterators(map); +#endif + for (MemberIterator itr = pos; itr != last; ++itr) { +#if RAPIDJSON_USE_MEMBERSMAP + map->erase(DropMapIterator(mit[itr - beg])); +#endif + itr->~Member(); + } +#if RAPIDJSON_USE_MEMBERSMAP + if (first != last) { + // Move remaining members/iterators + MemberIterator next = pos + (last - first); + for (MemberIterator itr = pos; next != end; ++itr, ++next) { + std::memcpy(static_cast(&*itr), &*next, sizeof(Member)); + SizeType mpos = static_cast(itr - beg); + new (&mit[mpos]) MapIterator(DropMapIterator(mit[next - beg])); + mit[mpos]->second = mpos; + } + } +#else + std::memmove(static_cast(&*pos), &*last, + static_cast(end - last) * sizeof(Member)); +#endif + o.size -= static_cast(last - first); + return pos; + } + + template + void DoCopyMembers(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings) { + RAPIDJSON_ASSERT(rhs.GetType() == kObjectType); + + data_.f.flags = kObjectFlag; + SizeType count = rhs.data_.o.size; + Member* lm = DoAllocMembers(count, allocator); + const typename GenericValue::Member* rm = rhs.GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(lm); + MapIterator* mit = GetMapIterators(map); +#endif + for (SizeType i = 0; i < count; i++) { + new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings); + new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings); +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[i]) MapIterator(map->insert(MapPair(lm[i].name.data_, i))); +#endif + } + data_.o.size = data_.o.capacity = count; + SetMembersPointer(lm); + } + // Initialize this value as array with initial data, without calling destructor. void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) { data_.f.flags = kArrayFlag; @@ -2129,9 +2415,16 @@ private: void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) { data_.f.flags = kObjectFlag; if (count) { - Member* m = static_cast(allocator.Malloc(count * sizeof(Member))); + Member* m = DoAllocMembers(count, allocator); SetMembersPointer(m); std::memcpy(static_cast(m), members, count * sizeof(Member)); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(m); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < count; i++) { + new (&mit[i]) MapIterator(map->insert(MapPair(m[i].name.data_, i))); + } +#endif } else SetMembersPointer(0); @@ -2208,6 +2501,7 @@ public: typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + typedef StackAllocator StackAllocatorType; //!< StackAllocator type from template parameter. //! Constructor /*! Creates an empty document of specified type. @@ -2252,6 +2546,13 @@ public: #endif ~GenericDocument() { + // Clear the ::ValueType before ownAllocator is destroyed, ~ValueType() + // runs last and may access its elements or members which would be freed + // with an allocator like MemoryPoolAllocator (CrtAllocator does not + // free its data when destroyed, but MemoryPoolAllocator does). + if (ownAllocator_) { + ValueType::SetNull(); + } Destroy(); } @@ -2734,4 +3035,9 @@ private: RAPIDJSON_NAMESPACE_END RAPIDJSON_DIAG_POP +#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#pragma pop_macro("GetObject") +#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#endif + #endif // RAPIDJSON_DOCUMENT_H_ diff --git a/contrib/rapidjson/include/rapidjson/error/en.h b/contrib/rapidjson/include/rapidjson/error/en.h index 5d2e57b7f..c87b04eb1 100644 --- a/contrib/rapidjson/include/rapidjson/error/en.h +++ b/contrib/rapidjson/include/rapidjson/error/en.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #ifndef RAPIDJSON_ERROR_EN_H_ @@ -39,13 +39,13 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); - + case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); - + case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); - + case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); @@ -104,15 +104,69 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode val case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'."); case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors."); - case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf'."); + case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf', indices '%matches'."); case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors."); case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors."); case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'."); + case kValidateErrorReadOnly: return RAPIDJSON_ERROR_STRING("Property is read-only but has been provided when validation is for writing."); + case kValidateErrorWriteOnly: return RAPIDJSON_ERROR_STRING("Property is write-only but has been provided when validation is for reading."); + default: return RAPIDJSON_ERROR_STRING("Unknown error."); } } +//! Maps error code of schema document compilation into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param schemaErrorCode Error code obtained from compiling the schema document. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ + inline const RAPIDJSON_ERROR_CHARTYPE* GetSchemaError_En(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kSchemaErrorStartUnknown: return RAPIDJSON_ERROR_STRING("Pointer '%value' to start of schema does not resolve to a location in the document."); + case kSchemaErrorRefPlainName: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' must be a JSON pointer."); + case kSchemaErrorRefInvalid: return RAPIDJSON_ERROR_STRING("$ref must not be an empty string."); + case kSchemaErrorRefPointerInvalid: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' is not a valid JSON pointer at offset '%offset'."); + case kSchemaErrorRefUnknown: return RAPIDJSON_ERROR_STRING("$ref '%value' does not resolve to a location in the target document."); + case kSchemaErrorRefCyclical: return RAPIDJSON_ERROR_STRING("$ref '%value' is cyclical."); + case kSchemaErrorRefNoRemoteProvider: return RAPIDJSON_ERROR_STRING("$ref is remote but there is no remote provider."); + case kSchemaErrorRefNoRemoteSchema: return RAPIDJSON_ERROR_STRING("$ref '%value' is remote but the remote provider did not return a schema."); + case kSchemaErrorRegexInvalid: return RAPIDJSON_ERROR_STRING("Invalid regular expression '%value' in 'pattern' or 'patternProperties'."); + case kSchemaErrorSpecUnknown: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not recognized."); + case kSchemaErrorSpecUnsupported: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not supported."); + case kSchemaErrorSpecIllegal: return RAPIDJSON_ERROR_STRING("Both JSON schema draft and OpenAPI version found in document."); + case kSchemaErrorReadOnlyAndWriteOnly: return RAPIDJSON_ERROR_STRING("Property must not be both 'readOnly' and 'writeOnly'."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } + } + +//! Maps error code of pointer parse into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param pointerParseErrorCode Error code obtained from pointer parse. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetPointerParseError_En(PointerParseErrorCode pointerParseErrorCode) { + switch (pointerParseErrorCode) { + case kPointerParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kPointerParseErrorTokenMustBeginWithSolidus: return RAPIDJSON_ERROR_STRING("A token must begin with a '/'."); + case kPointerParseErrorInvalidEscape: return RAPIDJSON_ERROR_STRING("Invalid escape."); + case kPointerParseErrorInvalidPercentEncoding: return RAPIDJSON_ERROR_STRING("Invalid percent encoding in URI fragment."); + case kPointerParseErrorCharacterMustPercentEncode: return RAPIDJSON_ERROR_STRING("A character must be percent encoded in a URI fragment."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + RAPIDJSON_NAMESPACE_END #ifdef __clang__ diff --git a/contrib/rapidjson/include/rapidjson/error/error.h b/contrib/rapidjson/include/rapidjson/error/error.h index 6270da11a..cae345db3 100644 --- a/contrib/rapidjson/include/rapidjson/error/error.h +++ b/contrib/rapidjson/include/rapidjson/error/error.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #ifndef RAPIDJSON_ERROR_ERROR_H_ @@ -42,7 +42,7 @@ RAPIDJSON_DIAG_OFF(padded) /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_ERROR_STRING -//! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. +//! Macro for converting string literal to \ref RAPIDJSON_ERROR_CHARTYPE[]. /*! \ingroup RAPIDJSON_ERRORS By default this conversion macro does nothing. On Windows, user can define this macro as \c _T(x) for supporting both @@ -185,14 +185,17 @@ enum ValidateErrorCode { kValidateErrorPatternProperties, //!< See other errors. kValidateErrorDependencies, //!< Object has missing property or schema dependencies. - kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values - kValidateErrorType, //!< Property has a type that is not allowed by the schema.. + kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values. + kValidateErrorType, //!< Property has a type that is not allowed by the schema. kValidateErrorOneOf, //!< Property did not match any of the sub-schemas specified by 'oneOf'. kValidateErrorOneOfMatch, //!< Property matched more than one of the sub-schemas specified by 'oneOf'. kValidateErrorAllOf, //!< Property did not match all of the sub-schemas specified by 'allOf'. kValidateErrorAnyOf, //!< Property did not match any of the sub-schemas specified by 'anyOf'. - kValidateErrorNot //!< Property matched the sub-schema specified by 'not'. + kValidateErrorNot, //!< Property matched the sub-schema specified by 'not'. + + kValidateErrorReadOnly, //!< Property is read-only but has been provided when validation is for writing + kValidateErrorWriteOnly //!< Property is write-only but has been provided when validation is for reading }; //! Function pointer type of GetValidateError(). @@ -207,6 +210,72 @@ enum ValidateErrorCode { */ typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetValidateErrorFunc)(ValidateErrorCode); +/////////////////////////////////////////////////////////////////////////////// +// SchemaErrorCode + +//! Error codes when validating. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericSchemaValidator +*/ +enum SchemaErrorCode { + kSchemaErrorNone = 0, //!< No error. + + kSchemaErrorStartUnknown, //!< Pointer to start of schema does not resolve to a location in the document + kSchemaErrorRefPlainName, //!< $ref fragment must be a JSON pointer + kSchemaErrorRefInvalid, //!< $ref must not be an empty string + kSchemaErrorRefPointerInvalid, //!< $ref fragment is not a valid JSON pointer at offset + kSchemaErrorRefUnknown, //!< $ref does not resolve to a location in the target document + kSchemaErrorRefCyclical, //!< $ref is cyclical + kSchemaErrorRefNoRemoteProvider, //!< $ref is remote but there is no remote provider + kSchemaErrorRefNoRemoteSchema, //!< $ref is remote but the remote provider did not return a schema + kSchemaErrorRegexInvalid, //!< Invalid regular expression in 'pattern' or 'patternProperties' + kSchemaErrorSpecUnknown, //!< JSON schema draft or OpenAPI version is not recognized + kSchemaErrorSpecUnsupported, //!< JSON schema draft or OpenAPI version is not supported + kSchemaErrorSpecIllegal, //!< Both JSON schema draft and OpenAPI version found in document + kSchemaErrorReadOnlyAndWriteOnly //!< Property must not be both 'readOnly' and 'writeOnly' +}; + +//! Function pointer type of GetSchemaError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetSchemaError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetSchemaErrorFunc GetSchemaError = GetSchemaError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetSchemaError(validator.GetInvalidSchemaCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetSchemaErrorFunc)(SchemaErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// PointerParseErrorCode + +//! Error code of JSON pointer parsing. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode +*/ +enum PointerParseErrorCode { + kPointerParseErrorNone = 0, //!< The parse is successful + + kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/' + kPointerParseErrorInvalidEscape, //!< Invalid escape + kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment + kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment +}; + +//! Function pointer type of GetPointerParseError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetPointerParseError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetPointerParseErrorFunc GetPointerParseError = GetPointerParseError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetPointerParseError(pointer.GetParseErrorCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetPointerParseErrorFunc)(PointerParseErrorCode); + + RAPIDJSON_NAMESPACE_END #ifdef __clang__ diff --git a/contrib/rapidjson/include/rapidjson/internal/biginteger.h b/contrib/rapidjson/include/rapidjson/internal/biginteger.h index 12455788f..4930043dc 100644 --- a/contrib/rapidjson/include/rapidjson/internal/biginteger.h +++ b/contrib/rapidjson/include/rapidjson/internal/biginteger.h @@ -19,7 +19,11 @@ #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_M_AMD64) #include // for _umul128 +#if !defined(_ARM64EC_) #pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif #endif RAPIDJSON_NAMESPACE_BEGIN @@ -37,7 +41,8 @@ public: digits_[0] = u; } - BigInteger(const char* decimals, size_t length) : count_(1) { + template + BigInteger(const Ch* decimals, size_t length) : count_(1) { RAPIDJSON_ASSERT(length > 0); digits_[0] = 0; size_t i = 0; @@ -221,7 +226,8 @@ public: bool IsZero() const { return count_ == 1 && digits_[0] == 0; } private: - void AppendDecimal64(const char* begin, const char* end) { + template + void AppendDecimal64(const Ch* begin, const Ch* end) { uint64_t u = ParseUint64(begin, end); if (IsZero()) *this = u; @@ -236,11 +242,12 @@ private: digits_[count_++] = digit; } - static uint64_t ParseUint64(const char* begin, const char* end) { + template + static uint64_t ParseUint64(const Ch* begin, const Ch* end) { uint64_t r = 0; - for (const char* p = begin; p != end; ++p) { - RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); - r = r * 10u + static_cast(*p - '0'); + for (const Ch* p = begin; p != end; ++p) { + RAPIDJSON_ASSERT(*p >= Ch('0') && *p <= Ch('9')); + r = r * 10u + static_cast(*p - Ch('0')); } return r; } @@ -252,7 +259,7 @@ private: if (low < k) (*outHigh)++; return low; -#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) __extension__ typedef unsigned __int128 uint128; uint128 p = static_cast(a) * static_cast(b); p += k; diff --git a/contrib/rapidjson/include/rapidjson/internal/diyfp.h b/contrib/rapidjson/include/rapidjson/internal/diyfp.h index a40797ec2..1f60fb60c 100644 --- a/contrib/rapidjson/include/rapidjson/internal/diyfp.h +++ b/contrib/rapidjson/include/rapidjson/internal/diyfp.h @@ -25,7 +25,11 @@ #if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER) #include +#if !defined(_ARM64EC_) #pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif #endif RAPIDJSON_NAMESPACE_BEGIN @@ -75,7 +79,7 @@ struct DiyFp { if (l & (uint64_t(1) << 63)) // rounding h++; return DiyFp(h, e + rhs.e + 64); -#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) __extension__ typedef unsigned __int128 uint128; uint128 p = static_cast(f) * static_cast(rhs.f); uint64_t h = static_cast(p >> 64); diff --git a/contrib/rapidjson/include/rapidjson/internal/dtoa.h b/contrib/rapidjson/include/rapidjson/internal/dtoa.h index 621402fd3..cd456721a 100644 --- a/contrib/rapidjson/include/rapidjson/internal/dtoa.h +++ b/contrib/rapidjson/include/rapidjson/internal/dtoa.h @@ -58,7 +58,11 @@ inline int CountDecimalDigit32(uint32_t n) { } inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { - static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; + static const uint64_t kPow10[] = { 1ULL, 10ULL, 100ULL, 1000ULL, 10000ULL, 100000ULL, 1000000ULL, 10000000ULL, 100000000ULL, + 1000000000ULL, 10000000000ULL, 100000000000ULL, 1000000000000ULL, + 10000000000000ULL, 100000000000000ULL, 1000000000000000ULL, + 10000000000000000ULL, 100000000000000000ULL, 1000000000000000000ULL, + 10000000000000000000ULL }; const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); const DiyFp wp_w = Mp - W; uint32_t p1 = static_cast(Mp.f >> -one.e); @@ -86,7 +90,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff uint64_t tmp = (static_cast(p1) << -one.e) + p2; if (tmp <= delta) { *K += kappa; - GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f); + GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.e, wp_w.f); return; } } @@ -103,7 +107,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff if (p2 < delta) { *K += kappa; int index = -kappa; - GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0)); + GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 20 ? kPow10[index] : 0)); return; } } diff --git a/contrib/rapidjson/include/rapidjson/internal/regex.h b/contrib/rapidjson/include/rapidjson/internal/regex.h index 6446c403a..7740dcd52 100644 --- a/contrib/rapidjson/include/rapidjson/internal/regex.h +++ b/contrib/rapidjson/include/rapidjson/internal/regex.h @@ -615,7 +615,7 @@ public: RAPIDJSON_ASSERT(regex_.IsValid()); if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); - stateSet_ = static_cast(allocator_->Malloc(GetStateSetSize())); + stateSet_ = static_cast(allocator_->Malloc(GetStateSetSize())); state0_.template Reserve(regex_.stateCount_); state1_.template Reserve(regex_.stateCount_); } diff --git a/contrib/rapidjson/include/rapidjson/internal/strfunc.h b/contrib/rapidjson/include/rapidjson/internal/strfunc.h index baecb6cc8..b698a8f43 100644 --- a/contrib/rapidjson/include/rapidjson/internal/strfunc.h +++ b/contrib/rapidjson/include/rapidjson/internal/strfunc.h @@ -45,6 +45,20 @@ inline SizeType StrLen(const wchar_t* s) { return SizeType(std::wcslen(s)); } +//! Custom strcmpn() which works on different character types. +/*! \tparam Ch Character type (e.g. char, wchar_t, short) + \param s1 Null-terminated input string. + \param s2 Null-terminated input string. + \return 0 if equal +*/ +template +inline int StrCmp(const Ch* s1, const Ch* s2) { + RAPIDJSON_ASSERT(s1 != 0); + RAPIDJSON_ASSERT(s2 != 0); + while(*s1 && (*s1 == *s2)) { s1++; s2++; } + return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); +} + //! Returns number of code points in a encoded string. template bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { diff --git a/contrib/rapidjson/include/rapidjson/internal/strtod.h b/contrib/rapidjson/include/rapidjson/internal/strtod.h index d61a67a49..55f0e380b 100644 --- a/contrib/rapidjson/include/rapidjson/internal/strtod.h +++ b/contrib/rapidjson/include/rapidjson/internal/strtod.h @@ -128,17 +128,18 @@ inline bool StrtodFast(double d, int p, double* result) { } // Compute an approximation and see if it is within 1/2 ULP -inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) { +template +inline bool StrtodDiyFp(const Ch* decimals, int dLen, int dExp, double* result) { uint64_t significand = 0; int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 for (; i < dLen; i++) { if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || - (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) + (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > Ch('5'))) break; - significand = significand * 10u + static_cast(decimals[i] - '0'); + significand = significand * 10u + static_cast(decimals[i] - Ch('0')); } - if (i < dLen && decimals[i] >= '5') // Rounding + if (i < dLen && decimals[i] >= Ch('5')) // Rounding significand++; int remaining = dLen - i; @@ -205,7 +206,8 @@ inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); } -inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) { +template +inline double StrtodBigInteger(double approx, const Ch* decimals, int dLen, int dExp) { RAPIDJSON_ASSERT(dLen >= 0); const BigInteger dInt(decimals, static_cast(dLen)); Double a(approx); @@ -223,7 +225,8 @@ inline double StrtodBigInteger(double approx, const char* decimals, int dLen, in return a.NextPositiveDouble(); } -inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { +template +inline double StrtodFullPrecision(double d, int p, const Ch* decimals, size_t length, size_t decimalPosition, int exp) { RAPIDJSON_ASSERT(d >= 0.0); RAPIDJSON_ASSERT(length >= 1); diff --git a/contrib/rapidjson/include/rapidjson/pointer.h b/contrib/rapidjson/include/rapidjson/pointer.h index 90e5903bc..6f4ef3892 100644 --- a/contrib/rapidjson/include/rapidjson/pointer.h +++ b/contrib/rapidjson/include/rapidjson/pointer.h @@ -16,7 +16,9 @@ #define RAPIDJSON_POINTER_H_ #include "document.h" +#include "uri.h" #include "internal/itoa.h" +#include "error/error.h" // PointerParseErrorCode #ifdef __clang__ RAPIDJSON_DIAG_PUSH @@ -30,19 +32,6 @@ RAPIDJSON_NAMESPACE_BEGIN static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token -//! Error code of parsing. -/*! \ingroup RAPIDJSON_ERRORS - \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode -*/ -enum PointerParseErrorCode { - kPointerParseErrorNone = 0, //!< The parse is successful - - kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/' - kPointerParseErrorInvalidEscape, //!< Invalid escape - kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment - kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment -}; - /////////////////////////////////////////////////////////////////////////////// // GenericPointer @@ -68,10 +57,10 @@ enum PointerParseErrorCode { supplied tokens eliminates these. GenericPointer depends on GenericDocument and GenericValue. - + \tparam ValueType The value type of the DOM tree. E.g. GenericValue > \tparam Allocator The allocator type for allocating memory for internal representation. - + \note GenericPointer uses same encoding of ValueType. However, Allocator of GenericPointer is independent of Allocator of Value. */ @@ -80,8 +69,10 @@ class GenericPointer { public: typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value typedef typename ValueType::Ch Ch; //!< Character type from Value + typedef GenericUri UriType; - //! A token is the basic units of internal representation. + + //! A token is the basic units of internal representation. /*! A JSON pointer string representation "/foo/123" is parsed to two tokens: "foo" and 123. 123 will be represented in both numeric form and string form. @@ -163,7 +154,7 @@ public: GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} //! Copy constructor. - GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { *this = rhs; } @@ -520,6 +511,70 @@ public: //@} + //!@name Compute URI + //@{ + + //! Compute the in-scope URI for a subtree. + // For use with JSON pointers into JSON schema documents. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param rootUri Root URI + \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token. + \param allocator Allocator for Uris + \return Uri if it can be resolved. Otherwise null. + + \note + There are only 3 situations when a URI cannot be resolved: + 1. A value in the path is not an array nor object. + 2. An object value does not contain the token. + 3. A token is out of range of an array value. + + Use unresolvedTokenIndex to retrieve the token index. + */ + UriType GetUri(ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + static const Ch kIdString[] = { 'i', 'd', '\0' }; + static const ValueType kIdValue(kIdString, 2); + UriType base = UriType(rootUri, allocator); + RAPIDJSON_ASSERT(IsValid()); + ValueType* v = &root; + for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + switch (v->GetType()) { + case kObjectType: + { + // See if we have an id, and if so resolve with the current base + typename ValueType::MemberIterator m = v->FindMember(kIdValue); + if (m != v->MemberEnd() && (m->value).IsString()) { + UriType here = UriType(m->value, allocator).Resolve(base, allocator); + base = here; + } + m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) + break; + v = &m->value; + } + continue; + case kArrayType: + if (t->index == kPointerInvalidIndex || t->index >= v->Size()) + break; + v = &((*v)[t->index]); + continue; + default: + break; + } + + // Error: unresolved token + if (unresolvedTokenIndex) + *unresolvedTokenIndex = static_cast(t - tokens_); + return UriType(allocator); + } + return base; + } + + UriType GetUri(const ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + return GetUri(const_cast(root), rootUri, unresolvedTokenIndex, allocator); + } + + //!@name Query value //@{ @@ -634,7 +689,7 @@ public: ValueType& GetWithDefault(GenericDocument& document, const Ch* defaultValue) const { return GetWithDefault(document, defaultValue, document.GetAllocator()); } - + #if RAPIDJSON_HAS_STDSTRING //! Query a value in a document with default std::basic_string. template @@ -835,10 +890,16 @@ private: std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize * sizeof(Ch)); } - // Adjust pointers to name buffer - std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_; - for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t) - t->name += diff; + // The names of each token point to a string in the nameBuffer_. The + // previous memcpy copied over string pointers into the rhs.nameBuffer_, + // but they should point to the strings in the new nameBuffer_. + for (size_t i = 0; i < rhs.tokenCount_; ++i) { + // The offset between the string address and the name buffer should + // still be constant, so we can just get this offset and set each new + // token name according the new buffer start + the known offset. + std::ptrdiff_t name_offset = rhs.tokens_[i].name - rhs.nameBuffer_; + tokens_[i].name = nameBuffer_ + name_offset; + } return nameBuffer_ + nameBufferSize; } @@ -928,7 +989,7 @@ private: } i++; - + // Escaping "~0" -> '~', "~1" -> '/' if (c == '~') { if (i < length) { diff --git a/contrib/rapidjson/include/rapidjson/rapidjson.h b/contrib/rapidjson/include/rapidjson/rapidjson.h index 78aa89a0e..5ea694795 100644 --- a/contrib/rapidjson/include/rapidjson/rapidjson.h +++ b/contrib/rapidjson/include/rapidjson/rapidjson.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #ifndef RAPIDJSON_RAPIDJSON_H_ @@ -17,7 +17,7 @@ /*!\file rapidjson.h \brief common definitions and configuration - + \see RAPIDJSON_CONFIG */ @@ -124,6 +124,19 @@ #define RAPIDJSON_NAMESPACE_END } #endif +/////////////////////////////////////////////////////////////////////////////// +// __cplusplus macro + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN + +#if defined(_MSC_VER) +#define RAPIDJSON_CPLUSPLUS _MSVC_LANG +#else +#define RAPIDJSON_CPLUSPLUS __cplusplus +#endif + +//!@endcond + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_HAS_STDSTRING @@ -149,6 +162,24 @@ #include #endif // RAPIDJSON_HAS_STDSTRING +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_USE_MEMBERSMAP + +/*! \def RAPIDJSON_USE_MEMBERSMAP + \ingroup RAPIDJSON_CONFIG + \brief Enable RapidJSON support for object members handling in a \c std::multimap + + By defining this preprocessor symbol to \c 1, \ref rapidjson::GenericValue object + members are stored in a \c std::multimap for faster lookup and deletion times, a + trade off with a slightly slower insertion time and a small object allocat(or)ed + memory overhead. + + \hideinitializer +*/ +#ifndef RAPIDJSON_USE_MEMBERSMAP +#define RAPIDJSON_USE_MEMBERSMAP 0 // not by default +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_NO_INT64DEFINE @@ -164,7 +195,7 @@ */ #ifndef RAPIDJSON_NO_INT64DEFINE //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 +#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 #include "msinttypes/stdint.h" #include "msinttypes/inttypes.h" #else @@ -246,7 +277,7 @@ # elif defined(RAPIDJSON_DOXYGEN_RUNNING) # define RAPIDJSON_ENDIAN # else -# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. # endif #endif // RAPIDJSON_ENDIAN @@ -411,7 +442,7 @@ RAPIDJSON_NAMESPACE_END // Prefer C++11 static_assert, if available #ifndef RAPIDJSON_STATIC_ASSERT -#if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 ) +#if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 ) #define RAPIDJSON_STATIC_ASSERT(x) \ static_assert(x, RAPIDJSON_STRINGIFY(x)) #endif // C++11 @@ -482,7 +513,7 @@ RAPIDJSON_NAMESPACE_END //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#define RAPIDJSON_MULTILINEMACRO_BEGIN do { +#define RAPIDJSON_MULTILINEMACRO_BEGIN do { #define RAPIDJSON_MULTILINEMACRO_END \ } while((void)0, 0) @@ -541,8 +572,14 @@ RAPIDJSON_NAMESPACE_END /////////////////////////////////////////////////////////////////////////////// // C++11 features +#ifndef RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L) +#endif + #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS -#if defined(__clang__) +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 +#elif defined(__clang__) #if __has_feature(cxx_rvalue_references) && \ (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306) #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 @@ -559,8 +596,14 @@ RAPIDJSON_NAMESPACE_END #endif #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS +#include // std::move +#endif + #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT -#if defined(__clang__) +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1 +#elif defined(__clang__) #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept) #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ (defined(_MSC_VER) && _MSC_VER >= 1900) || \ @@ -570,11 +613,13 @@ RAPIDJSON_NAMESPACE_END #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0 #endif #endif +#ifndef RAPIDJSON_NOEXCEPT #if RAPIDJSON_HAS_CXX11_NOEXCEPT #define RAPIDJSON_NOEXCEPT noexcept #else -#define RAPIDJSON_NOEXCEPT /* noexcept */ +#define RAPIDJSON_NOEXCEPT throw() #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT +#endif // no automatic detection, yet #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS @@ -600,9 +645,17 @@ RAPIDJSON_NAMESPACE_END /////////////////////////////////////////////////////////////////////////////// // C++17 features -#if defined(__has_cpp_attribute) -# if __has_cpp_attribute(fallthrough) -# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]] +#ifndef RAPIDJSON_HAS_CXX17 +#define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L) +#endif + +#if RAPIDJSON_HAS_CXX17 +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]] +#elif defined(__has_cpp_attribute) +# if __has_cpp_attribute(clang::fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]] +# elif __has_cpp_attribute(fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough)) # else # define RAPIDJSON_DELIBERATE_FALLTHROUGH # endif @@ -628,12 +681,8 @@ RAPIDJSON_NAMESPACE_END #ifndef RAPIDJSON_NOEXCEPT_ASSERT #ifdef RAPIDJSON_ASSERT_THROWS -#if RAPIDJSON_HAS_CXX11_NOEXCEPT -#define RAPIDJSON_NOEXCEPT_ASSERT(x) -#else #include #define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x) -#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT #else #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x) #endif // RAPIDJSON_ASSERT_THROWS @@ -682,7 +731,7 @@ enum Type { kFalseType = 1, //!< false kTrueType = 2, //!< true kObjectType = 3, //!< object - kArrayType = 4, //!< array + kArrayType = 4, //!< array kStringType = 5, //!< string kNumberType = 6 //!< number }; diff --git a/contrib/rapidjson/include/rapidjson/reader.h b/contrib/rapidjson/include/rapidjson/reader.h index 09ace4eba..55546601e 100644 --- a/contrib/rapidjson/include/rapidjson/reader.h +++ b/contrib/rapidjson/include/rapidjson/reader.h @@ -1404,11 +1404,11 @@ private: } #endif // RAPIDJSON_NEON - template + template class NumberStream; - template - class NumberStream { + template + class NumberStream { public: typedef typename InputStream::Ch Ch; @@ -1421,7 +1421,7 @@ private: size_t Tell() { return is.Tell(); } size_t Length() { return 0; } - const char* Pop() { return 0; } + const StackCharacter* Pop() { return 0; } protected: NumberStream& operator=(const NumberStream&); @@ -1429,45 +1429,47 @@ private: InputStream& is; }; - template - class NumberStream : public NumberStream { - typedef NumberStream Base; + template + class NumberStream : public NumberStream { + typedef NumberStream Base; public: - NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is), stackStream(reader.stack_) {} + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s), stackStream(reader.stack_) {} RAPIDJSON_FORCEINLINE Ch TakePush() { - stackStream.Put(static_cast(Base::is.Peek())); + stackStream.Put(static_cast(Base::is.Peek())); return Base::is.Take(); } - RAPIDJSON_FORCEINLINE void Push(char c) { + RAPIDJSON_FORCEINLINE void Push(StackCharacter c) { stackStream.Put(c); } size_t Length() { return stackStream.Length(); } - const char* Pop() { + const StackCharacter* Pop() { stackStream.Put('\0'); return stackStream.Pop(); } private: - StackStream stackStream; + StackStream stackStream; }; - template - class NumberStream : public NumberStream { - typedef NumberStream Base; + template + class NumberStream : public NumberStream { + typedef NumberStream Base; public: - NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is) {} + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s) {} RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); } }; template void ParseNumber(InputStream& is, Handler& handler) { + typedef typename internal::SelectIf, typename TargetEncoding::Ch, char>::Type NumberCharacter; + internal::StreamLocalCopy copy(is); - NumberStream(s.Length()); - StringStream srcStream(s.Pop()); + GenericStringStream > srcStream(s.Pop()); StackStream dstStream(stack_); while (numCharsToCopy--) { - Transcoder, TargetEncoding>::Transcode(srcStream, dstStream); + Transcoder, TargetEncoding>::Transcode(srcStream, dstStream); } dstStream.Put('\0'); const typename TargetEncoding::Ch* str = dstStream.Pop(); @@ -1705,7 +1707,7 @@ private: } else { size_t length = s.Length(); - const char* decimal = s.Pop(); // Pop stack no matter if it will be used or not. + const NumberCharacter* decimal = s.Pop(); // Pop stack no matter if it will be used or not. if (useDouble) { int p = exp + expFrac; diff --git a/contrib/rapidjson/include/rapidjson/schema.h b/contrib/rapidjson/include/rapidjson/schema.h index 11f716096..02a6d0f9e 100644 --- a/contrib/rapidjson/include/rapidjson/schema.h +++ b/contrib/rapidjson/include/rapidjson/schema.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available-> -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip-> All rights reserved-> // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource->org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied-> See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied-> See the License for the // specific language governing permissions and limitations under the License-> #ifndef RAPIDJSON_SCHEMA_H_ @@ -19,17 +19,14 @@ #include "pointer.h" #include "stringbuffer.h" #include "error/en.h" +#include "uri.h" #include // abs, floor #if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX) #define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1 -#else -#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0 #endif -#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) -#define RAPIDJSON_SCHEMA_USE_STDREGEX 1 -#else +#if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) || !(__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) #define RAPIDJSON_SCHEMA_USE_STDREGEX 0 #endif @@ -49,10 +46,6 @@ #define RAPIDJSON_SCHEMA_VERBOSE 0 #endif -#if RAPIDJSON_SCHEMA_VERBOSE -#include "stringbuffer.h" -#endif - RAPIDJSON_DIAG_PUSH #if defined(__GNUC__) @@ -77,48 +70,94 @@ RAPIDJSON_NAMESPACE_BEGIN namespace internal { -inline void PrintInvalidKeyword(const char* keyword) { - printf("Fail keyword: %s\n", keyword); +inline void PrintInvalidKeywordData(const char* keyword) { + printf(" Fail keyword: '%s'\n", keyword); } -inline void PrintInvalidKeyword(const wchar_t* keyword) { - wprintf(L"Fail keyword: %ls\n", keyword); +inline void PrintInvalidKeywordData(const wchar_t* keyword) { + wprintf(L" Fail keyword: '%ls'\n", keyword); } -inline void PrintInvalidDocument(const char* document) { - printf("Fail document: %s\n\n", document); +inline void PrintInvalidDocumentData(const char* document) { + printf(" Fail document: '%s'\n", document); } -inline void PrintInvalidDocument(const wchar_t* document) { - wprintf(L"Fail document: %ls\n\n", document); +inline void PrintInvalidDocumentData(const wchar_t* document) { + wprintf(L" Fail document: '%ls'\n", document); } -inline void PrintValidatorPointers(unsigned depth, const char* s, const char* d) { - printf("S: %*s%s\nD: %*s%s\n\n", depth * 4, " ", s, depth * 4, " ", d); +inline void PrintValidatorPointersData(const char* s, const char* d, unsigned depth) { + printf(" Sch: %*s'%s'\n Doc: %*s'%s'\n", depth * 4, " ", s, depth * 4, " ", d); } -inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar_t* d) { - wprintf(L"S: %*ls%ls\nD: %*ls%ls\n\n", depth * 4, L" ", s, depth * 4, L" ", d); +inline void PrintValidatorPointersData(const wchar_t* s, const wchar_t* d, unsigned depth) { + wprintf(L" Sch: %*ls'%ls'\n Doc: %*ls'%ls'\n", depth * 4, L" ", s, depth * 4, L" ", d); +} + +inline void PrintSchemaIdsData(const char* base, const char* local, const char* resolved) { + printf(" Resolving id: Base: '%s', Local: '%s', Resolved: '%s'\n", base, local, resolved); +} + +inline void PrintSchemaIdsData(const wchar_t* base, const wchar_t* local, const wchar_t* resolved) { + wprintf(L" Resolving id: Base: '%ls', Local: '%ls', Resolved: '%ls'\n", base, local, resolved); +} + +inline void PrintMethodData(const char* method) { + printf("%s\n", method); +} + +inline void PrintMethodData(const char* method, bool b) { + printf("%s, Data: '%s'\n", method, b ? "true" : "false"); +} + +inline void PrintMethodData(const char* method, int64_t i) { + printf("%s, Data: '%" PRId64 "'\n", method, i); +} + +inline void PrintMethodData(const char* method, uint64_t u) { + printf("%s, Data: '%" PRIu64 "'\n", method, u); +} + +inline void PrintMethodData(const char* method, double d) { + printf("%s, Data: '%lf'\n", method, d); +} + +inline void PrintMethodData(const char* method, const char* s) { + printf("%s, Data: '%s'\n", method, s); +} + +inline void PrintMethodData(const char* method, const wchar_t* s) { + wprintf(L"%hs, Data: '%ls'\n", method, s); +} + +inline void PrintMethodData(const char* method, const char* s1, const char* s2) { + printf("%s, Data: '%s', '%s'\n", method, s1, s2); +} + +inline void PrintMethodData(const char* method, const wchar_t* s1, const wchar_t* s2) { + wprintf(L"%hs, Data: '%ls', '%ls'\n", method, s1, s2); } } // namespace internal #endif // RAPIDJSON_SCHEMA_VERBOSE +#ifndef RAPIDJSON_SCHEMA_PRINT +#if RAPIDJSON_SCHEMA_VERBOSE +#define RAPIDJSON_SCHEMA_PRINT(name, ...) internal::Print##name##Data(__VA_ARGS__) +#else +#define RAPIDJSON_SCHEMA_PRINT(name, ...) +#endif +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_INVALID_KEYWORD_RETURN -#if RAPIDJSON_SCHEMA_VERBOSE -#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) internal::PrintInvalidKeyword(keyword) -#else -#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) -#endif - #define RAPIDJSON_INVALID_KEYWORD_RETURN(code)\ RAPIDJSON_MULTILINEMACRO_BEGIN\ context.invalidCode = code;\ context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString();\ - RAPIDJSON_INVALID_KEYWORD_VERBOSE(context.invalidKeyword);\ + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, context.invalidKeyword);\ return false;\ RAPIDJSON_MULTILINEMACRO_END @@ -136,14 +175,56 @@ RAPIDJSON_MULTILINEMACRO_END #endif //! Combination of validate flags -/*! \see - */ enum ValidateFlag { kValidateNoFlags = 0, //!< No flags are set. kValidateContinueOnErrorFlag = 1, //!< Don't stop after first validation error. + kValidateReadFlag = 2, //!< Validation is for a read semantic. + kValidateWriteFlag = 4, //!< Validation is for a write semantic. kValidateDefaultFlags = RAPIDJSON_VALIDATE_DEFAULT_FLAGS //!< Default validate flags. Can be customized by defining RAPIDJSON_VALIDATE_DEFAULT_FLAGS }; +/////////////////////////////////////////////////////////////////////////////// +// Specification +enum SchemaDraft { + kDraftUnknown = -1, + kDraftNone = 0, + kDraft03 = 3, + kDraftMin = 4, //!< Current minimum supported draft + kDraft04 = 4, + kDraft05 = 5, + kDraftMax = 5, //!< Current maximum supported draft + kDraft06 = 6, + kDraft07 = 7, + kDraft2019_09 = 8, + kDraft2020_12 = 9 +}; + +enum OpenApiVersion { + kVersionUnknown = -1, + kVersionNone = 0, + kVersionMin = 2, //!< Current minimum supported version + kVersion20 = 2, + kVersion30 = 3, + kVersionMax = 3, //!< Current maximum supported version + kVersion31 = 4, +}; + +struct Specification { + Specification(SchemaDraft d) : draft(d), oapi(kVersionNone) {} + Specification(OpenApiVersion o) : oapi(o) { + if (oapi == kVersion20) draft = kDraft04; + else if (oapi == kVersion30) draft = kDraft05; + else if (oapi == kVersion31) draft = kDraft2020_12; + else draft = kDraft04; + } + ~Specification() {} + bool IsSupported() const { + return ((draft >= kDraftMin && draft <= kDraftMax) && ((oapi == kVersionNone) || (oapi >= kVersionMin && oapi <= kVersionMax))); + } + SchemaDraft draft; + OpenApiVersion oapi; +}; + /////////////////////////////////////////////////////////////////////////////// // Forward declarations @@ -233,8 +314,11 @@ public: virtual void EndDisallowedType(const typename SchemaType::ValueType& actualType) = 0; virtual void NotAllOf(ISchemaValidator** subvalidators, SizeType count) = 0; virtual void NoneOf(ISchemaValidator** subvalidators, SizeType count) = 0; - virtual void NotOneOf(ISchemaValidator** subvalidators, SizeType count, bool matched) = 0; + virtual void NotOneOf(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void MultipleOneOf(SizeType index1, SizeType index2) = 0; virtual void Disallowed() = 0; + virtual void DisallowedWhenWriting() = 0; + virtual void DisallowedWhenReading() = 0; }; @@ -255,10 +339,10 @@ public: bool Uint(unsigned u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } bool Int64(int64_t i) { Number n; n.u.i = i; n.d = static_cast(i); return WriteNumber(n); } bool Uint64(uint64_t u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } - bool Double(double d) { - Number n; + bool Double(double d) { + Number n; if (d < 0) n.u.i = static_cast(d); - else n.u.u = static_cast(d); + else n.u.u = static_cast(d); n.d = d; return WriteNumber(n); } @@ -279,7 +363,9 @@ public: uint64_t h = Hash(0, kObjectType); uint64_t* kv = stack_.template Pop(memberCount * 2); for (SizeType i = 0; i < memberCount; i++) - h ^= Hash(kv[i * 2], kv[i * 2 + 1]); // Use xor to achieve member order insensitive + // Issue #2205 + // Hasing the key to avoid key=value cases with bug-prone zero-value hash + h ^= Hash(Hash(0, kv[i * 2]), kv[i * 2 + 1]); // Use xor to achieve member order insensitive *stack_.template Push() = h; return true; } @@ -317,7 +403,7 @@ private: bool WriteBuffer(Type type, const void* data, size_t len) { // FNV-1a from http://isthe.com/chongo/tech/comp/fnv/ - uint64_t h = Hash(RAPIDJSON_UINT64_C2(0x84222325, 0xcbf29ce4), type); + uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type); const unsigned char* d = static_cast(data); for (size_t i = 0; i < len; i++) h = Hash(h, d[i]); @@ -352,10 +438,11 @@ struct SchemaValidationContext { kPatternValidatorWithAdditionalProperty }; - SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s) : + SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s, unsigned fl = 0) : factory(f), error_handler(eh), schema(s), + flags(fl), valueSchema(), invalidKeyword(), invalidCode(), @@ -379,13 +466,19 @@ struct SchemaValidationContext { if (hasher) factory.DestroryHasher(hasher); if (validators) { - for (SizeType i = 0; i < validatorCount; i++) - factory.DestroySchemaValidator(validators[i]); + for (SizeType i = 0; i < validatorCount; i++) { + if (validators[i]) { + factory.DestroySchemaValidator(validators[i]); + } + } factory.FreeState(validators); } if (patternPropertiesValidators) { - for (SizeType i = 0; i < patternPropertiesValidatorCount; i++) - factory.DestroySchemaValidator(patternPropertiesValidators[i]); + for (SizeType i = 0; i < patternPropertiesValidatorCount; i++) { + if (patternPropertiesValidators[i]) { + factory.DestroySchemaValidator(patternPropertiesValidators[i]); + } + } factory.FreeState(patternPropertiesValidators); } if (patternPropertiesSchemas) @@ -397,6 +490,7 @@ struct SchemaValidationContext { SchemaValidatorFactoryType& factory; ErrorHandlerType& error_handler; const SchemaType* schema; + unsigned flags; const SchemaType* valueSchema; const Ch* invalidKeyword; ValidateErrorCode invalidCode; @@ -432,11 +526,14 @@ public: typedef Schema SchemaType; typedef GenericValue SValue; typedef IValidationErrorHandler ErrorHandler; + typedef GenericUri UriType; friend class GenericSchemaDocument; - Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) : + Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator, const UriType& id = UriType()) : allocator_(allocator), uri_(schemaDocument->GetURI(), *allocator), + id_(id, allocator), + spec_(schemaDocument->GetSpecification()), pointer_(p, allocator), typeless_(schemaDocument->GetTypeless()), enum_(), @@ -469,14 +566,43 @@ public: maxLength_(~SizeType(0)), exclusiveMinimum_(false), exclusiveMaximum_(false), - defaultValueLength_(0) + defaultValueLength_(0), + readOnly_(false), + writeOnly_(false), + nullable_(false) { + GenericStringBuffer sb; + p.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Schema", sb.GetString(), id.GetString()); + typedef typename ValueType::ConstValueIterator ConstValueIterator; typedef typename ValueType::ConstMemberIterator ConstMemberIterator; + // PR #1393 + // Early add this Schema and its $ref(s) in schemaDocument's map to avoid infinite + // recursion (with recursive schemas), since schemaDocument->getSchema() is always + // checked before creating a new one. Don't cache typeless_, though. + if (this != typeless_) { + typedef typename SchemaDocumentType::SchemaEntry SchemaEntry; + SchemaEntry *entry = schemaDocument->schemaMap_.template Push(); + new (entry) SchemaEntry(pointer_, this, true, allocator_); + schemaDocument->AddSchemaRefs(this); + } + if (!value.IsObject()) return; + // If we have an id property, resolve it with the in-scope id + // Not supported for open api 2.0 or 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (const ValueType* v = GetMember(value, GetIdString())) { + if (v->IsString()) { + UriType local(*v, allocator); + id_ = local.Resolve(id_, allocator); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), v->GetString(), id_.GetString()); + } + } + if (const ValueType* v = GetMember(value, GetTypeString())) { type_ = 0; if (v->IsString()) @@ -490,9 +616,9 @@ public: if (v->IsArray() && v->Size() > 0) { enum_ = static_cast(allocator_->Malloc(sizeof(uint64_t) * v->Size())); for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) { - typedef Hasher > EnumHasherType; + typedef Hasher > EnumHasherType; char buffer[256u + 24]; - MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer)); + MemoryPoolAllocator hasherAllocator(buffer, sizeof(buffer)); EnumHasherType h(&hasherAllocator, 256); itr->Accept(h); enum_[enumCount_++] = h.GetHashCode(); @@ -500,16 +626,19 @@ public: } } - if (schemaDocument) { + if (schemaDocument) AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document); + + // AnyOf, OneOf, Not not supported for open api 2.0 + if (schemaDocument && spec_.oapi != kVersion20) { AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document); AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document); - } - if (const ValueType* v = GetMember(value, GetNotString())) { - schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document); - notValidatorIndex_ = validatorCount_; - validatorCount_++; + if (const ValueType* v = GetMember(value, GetNotString())) { + schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document, id_); + notValidatorIndex_ = validatorCount_; + validatorCount_++; + } } // Object @@ -524,12 +653,14 @@ public: if (properties && properties->IsObject()) for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) AddUniqueElement(allProperties, itr->name); - + if (required && required->IsArray()) for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr) if (itr->IsString()) AddUniqueElement(allProperties, *itr); + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (dependencies && dependencies->IsObject()) for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) { AddUniqueElement(allProperties, itr->name); @@ -555,10 +686,12 @@ public: for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) { SizeType index; if (FindPropertyIndex(itr->name, &index)) - schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document); + schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document, id_); } } + // PatternProperties not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (const ValueType* v = GetMember(value, GetPatternPropertiesString())) { PointerType q = p.Append(GetPatternPropertiesString(), allocator_); patternProperties_ = static_cast(allocator_->Malloc(sizeof(PatternProperty) * v->MemberCount())); @@ -566,8 +699,9 @@ public: for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) { new (&patternProperties_[patternPropertyCount_]) PatternProperty(); - patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name); - schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, q.Append(itr->name, allocator_), itr->value, document); + PointerType r = q.Append(itr->name, allocator_); + patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name, schemaDocument, r); + schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, r, itr->value, document, id_); patternPropertyCount_++; } } @@ -582,6 +716,8 @@ public: } } + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (dependencies && dependencies->IsObject()) { PointerType q = p.Append(GetDependenciesString(), allocator_); hasDependencies_ = true; @@ -599,7 +735,7 @@ public: } else if (itr->value.IsObject()) { hasSchemaDependencies_ = true; - schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document); + schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document, id_); properties_[sourceIndex].dependenciesValidatorIndex = validatorCount_; validatorCount_++; } @@ -611,7 +747,7 @@ public: if (v->IsBool()) additionalProperties_ = v->GetBool(); else if (v->IsObject()) - schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document); + schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document, id_); } AssignIfExist(minProperties_, value, GetMinPropertiesString()); @@ -621,23 +757,25 @@ public: if (const ValueType* v = GetMember(value, GetItemsString())) { PointerType q = p.Append(GetItemsString(), allocator_); if (v->IsObject()) // List validation - schemaDocument->CreateSchema(&itemsList_, q, *v, document); + schemaDocument->CreateSchema(&itemsList_, q, *v, document, id_); else if (v->IsArray()) { // Tuple validation itemsTuple_ = static_cast(allocator_->Malloc(sizeof(const Schema*) * v->Size())); SizeType index = 0; for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr, index++) - schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document); + schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document, id_); } } AssignIfExist(minItems_, value, GetMinItemsString()); AssignIfExist(maxItems_, value, GetMaxItemsString()); + // AdditionalItems not supported for openapi 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (const ValueType* v = GetMember(value, GetAdditionalItemsString())) { if (v->IsBool()) additionalItems_ = v->GetBool(); else if (v->IsObject()) - schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document); + schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document, id_); } AssignIfExist(uniqueItems_, value, GetUniqueItemsString()); @@ -647,7 +785,7 @@ public: AssignIfExist(maxLength_, value, GetMaxLengthString()); if (const ValueType* v = GetMember(value, GetPatternString())) - pattern_ = CreatePattern(*v); + pattern_ = CreatePattern(*v, schemaDocument, p.Append(GetPatternString(), allocator_)); // Number if (const ValueType* v = GetMember(value, GetMinimumString())) @@ -670,6 +808,23 @@ public: if (v->IsString()) defaultValueLength_ = v->GetStringLength(); + // ReadOnly - open api only (until draft 7 supported) + // WriteOnly - open api 3 only (until draft 7 supported) + // Both can't be true + if (spec_.oapi != kVersionNone) + AssignIfExist(readOnly_, value, GetReadOnlyString()); + if (spec_.oapi >= kVersion30) + AssignIfExist(writeOnly_, value, GetWriteOnlyString()); + if (readOnly_ && writeOnly_) + schemaDocument->SchemaError(kSchemaErrorReadOnlyAndWriteOnly, p); + + // Nullable - open api 3 only + // If true add 'null' as allowable type + if (spec_.oapi >= kVersion30) { + AssignIfExist(nullable_, value, GetNullableString()); + if (nullable_) + AddType(GetNullString()); + } } ~Schema() { @@ -697,11 +852,20 @@ public: return uri_; } + const UriType& GetId() const { + return id_; + } + + const Specification& GetSpecification() const { + return spec_; + } + const PointerType& GetPointer() const { return pointer_; } bool BeginValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::BeginValue"); if (context.inArray) { if (uniqueItems_) context.valueUniqueness = true; @@ -733,6 +897,8 @@ public: } RAPIDJSON_FORCEINLINE bool EndValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndValue"); + // Only check pattern properties if we have validators if (context.patternPropertiesValidatorCount > 0) { bool otherValid = false; SizeType count = context.patternPropertiesValidatorCount; @@ -775,87 +941,98 @@ public: foundEnum:; } - if (allOf_.schemas) - for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++) - if (!context.validators[i]->IsValid()) { - context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAllOf); - } - - if (anyOf_.schemas) { - for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++) - if (context.validators[i]->IsValid()) - goto foundAny; - context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAnyOf); - foundAny:; - } + // Only check allOf etc if we have validators + if (context.validatorCount > 0) { + if (allOf_.schemas) + for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++) + if (!context.validators[i]->IsValid()) { + context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAllOf); + } - if (oneOf_.schemas) { - bool oneValid = false; - for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++) - if (context.validators[i]->IsValid()) { - if (oneValid) { - context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count, true); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOfMatch); - } else - oneValid = true; - } - if (!oneValid) { - context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count, false); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOf); + if (anyOf_.schemas) { + for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++) + if (context.validators[i]->IsValid()) + goto foundAny; + context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAnyOf); + foundAny:; } - } - if (not_ && context.validators[notValidatorIndex_]->IsValid()) { - context.error_handler.Disallowed(); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorNot); + if (oneOf_.schemas) { + bool oneValid = false; + SizeType firstMatch = 0; + for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++) + if (context.validators[i]->IsValid()) { + if (oneValid) { + context.error_handler.MultipleOneOf(firstMatch, i - oneOf_.begin); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOfMatch); + } else { + oneValid = true; + firstMatch = i - oneOf_.begin; + } + } + if (!oneValid) { + context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOf); + } + } + + if (not_ && context.validators[notValidatorIndex_]->IsValid()) { + context.error_handler.Disallowed(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorNot); + } } return true; } bool Null(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Null"); if (!(type_ & (1 << kNullSchemaType))) { DisallowedType(context, GetNullString()); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } return CreateParallelValidator(context); } - - bool Bool(Context& context, bool) const { - if (!(type_ & (1 << kBooleanSchemaType))) { - DisallowedType(context, GetBooleanString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); - } + + bool Bool(Context& context, bool b) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Bool", b); + if (!CheckBool(context, b)) + return false; return CreateParallelValidator(context); } bool Int(Context& context, int i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int", (int64_t)i); if (!CheckInt(context, i)) return false; return CreateParallelValidator(context); } bool Uint(Context& context, unsigned u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint", (uint64_t)u); if (!CheckUint(context, u)) return false; return CreateParallelValidator(context); } bool Int64(Context& context, int64_t i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int64", i); if (!CheckInt(context, i)) return false; return CreateParallelValidator(context); } bool Uint64(Context& context, uint64_t u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint64", u); if (!CheckUint(context, u)) return false; return CreateParallelValidator(context); } bool Double(Context& context, double d) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Double", d); if (!(type_ & (1 << kNumberSchemaType))) { DisallowedType(context, GetNumberString()); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); @@ -866,14 +1043,15 @@ public: if (!maximum_.IsNull() && !CheckDoubleMaximum(context, d)) return false; - + if (!multipleOf_.IsNull() && !CheckDoubleMultipleOf(context, d)) return false; - + return CreateParallelValidator(context); } - + bool String(Context& context, const Ch* str, SizeType length, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::String", str); if (!(type_ & (1 << kStringSchemaType))) { DisallowedType(context, GetStringString()); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); @@ -902,6 +1080,7 @@ public: } bool StartObject(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartObject"); if (!(type_ & (1 << kObjectSchemaType))) { DisallowedType(context, GetObjectString()); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); @@ -921,8 +1100,10 @@ public: return CreateParallelValidator(context); } - + bool Key(Context& context, const Ch* str, SizeType len, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Key", str); + if (patternProperties_) { context.patternPropertiesSchemaCount = 0; for (SizeType i = 0; i < patternPropertyCount_; i++) @@ -949,7 +1130,7 @@ public: } if (additionalPropertiesSchema_) { - if (additionalPropertiesSchema_ && context.patternPropertiesSchemaCount > 0) { + if (context.patternPropertiesSchemaCount > 0) { context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = additionalPropertiesSchema_; context.valueSchema = typeless_; context.valuePatternValidatorType = Context::kPatternValidatorWithAdditionalProperty; @@ -974,6 +1155,7 @@ public: } bool EndObject(Context& context, SizeType memberCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndObject"); if (hasRequired_) { context.error_handler.StartMissingProperties(); for (SizeType index = 0; index < propertyCount_; index++) @@ -1014,13 +1196,14 @@ public: } } if (context.error_handler.EndDependencyErrors()) - RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorDependencies); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorDependencies); } return true; } bool StartArray(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartArray"); context.arrayElementIndex = 0; context.inArray = true; // Ensure we note that we are in an array @@ -1033,13 +1216,14 @@ public: } bool EndArray(Context& context, SizeType elementCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndArray"); context.inArray = false; - + if (elementCount < minItems_) { context.error_handler.TooFewItems(elementCount, minItems_); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinItems); } - + if (elementCount > maxItems_) { context.error_handler.TooManyItems(elementCount, maxItems_); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxItems); @@ -1081,6 +1265,9 @@ public: case kValidateErrorAnyOf: return GetAnyOfString(); case kValidateErrorNot: return GetNotString(); + case kValidateErrorReadOnly: return GetReadOnlyString(); + case kValidateErrorWriteOnly: return GetWriteOnlyString(); + default: return GetNullString(); } } @@ -1128,6 +1315,14 @@ public: RAPIDJSON_STRING_(ExclusiveMaximum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'a', 'x', 'i', 'm', 'u', 'm') RAPIDJSON_STRING_(MultipleOf, 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'O', 'f') RAPIDJSON_STRING_(DefaultValue, 'd', 'e', 'f', 'a', 'u', 'l', 't') + RAPIDJSON_STRING_(Schema, '$', 's', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(Ref, '$', 'r', 'e', 'f') + RAPIDJSON_STRING_(Id, 'i', 'd') + RAPIDJSON_STRING_(Swagger, 's', 'w', 'a', 'g', 'g', 'e', 'r') + RAPIDJSON_STRING_(OpenApi, 'o', 'p', 'e', 'n', 'a', 'p', 'i') + RAPIDJSON_STRING_(ReadOnly, 'r', 'e', 'a', 'd', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(WriteOnly, 'w', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(Nullable, 'n', 'u', 'l', 'l', 'a', 'b', 'l', 'e') #undef RAPIDJSON_STRING_ @@ -1193,7 +1388,7 @@ private: out.schemas = static_cast(allocator_->Malloc(out.count * sizeof(const Schema*))); memset(out.schemas, 0, sizeof(Schema*)* out.count); for (SizeType i = 0; i < out.count; i++) - schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document); + schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document, id_); out.begin = validatorCount_; validatorCount_ += out.count; } @@ -1202,10 +1397,11 @@ private: #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX template - RegexType* CreatePattern(const ValueType& value) { + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { if (value.IsString()) { RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), allocator_); if (!r->IsValid()) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); r->~RegexType(); AllocatorType::Free(r); r = 0; @@ -1221,13 +1417,14 @@ private: } #elif RAPIDJSON_SCHEMA_USE_STDREGEX template - RegexType* CreatePattern(const ValueType& value) { + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { if (value.IsString()) { RegexType *r = static_cast(allocator_->Malloc(sizeof(RegexType))); try { return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); } - catch (const std::regex_error&) { + catch (const std::regex_error& e) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); AllocatorType::Free(r); } } @@ -1240,7 +1437,9 @@ private: } #else template - RegexType* CreatePattern(const ValueType&) { return 0; } + RegexType* CreatePattern(const ValueType&) { + return 0; + } static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; } #endif // RAPIDJSON_SCHEMA_USE_STDREGEX @@ -1255,6 +1454,9 @@ private: else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType); } + // Creates parallel validators for allOf, anyOf, oneOf, not and schema dependencies, if required. + // Also creates a hasher for enums and array uniqueness, if required. + // Also a useful place to add type-independent error checks. bool CreateParallelValidator(Context& context) const { if (enum_ || context.arrayUniqueness) context.hasher = context.factory.CreateHasher(); @@ -1262,6 +1464,7 @@ private: if (validatorCount_) { RAPIDJSON_ASSERT(context.validators == 0); context.validators = static_cast(context.factory.MallocState(sizeof(ISchemaValidator*) * validatorCount_)); + std::memset(context.validators, 0, sizeof(ISchemaValidator*) * validatorCount_); context.validatorCount = validatorCount_; // Always return after first failure for these sub-validators @@ -1270,10 +1473,10 @@ private: if (anyOf_.schemas) CreateSchemaValidators(context, anyOf_, false); - + if (oneOf_.schemas) CreateSchemaValidators(context, oneOf_, false); - + if (not_) context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_, false); @@ -1284,6 +1487,16 @@ private: } } + // Add any other type-independent checks here + if (readOnly_ && (context.flags & kValidateWriteFlag)) { + context.error_handler.DisallowedWhenWriting(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorReadOnly); + } + if (writeOnly_ && (context.flags & kValidateReadFlag)) { + context.error_handler.DisallowedWhenReading(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorWriteOnly); + } + return true; } @@ -1297,7 +1510,7 @@ private: SizeType len = name.GetStringLength(); const Ch* str = name.GetString(); for (SizeType index = 0; index < propertyCount_; index++) - if (properties_[index].name.GetStringLength() == len && + if (properties_[index].name.GetStringLength() == len && (std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0)) { *outIndex = index; @@ -1306,6 +1519,14 @@ private: return false; } + bool CheckBool(Context& context, bool) const { + if (!(type_ & (1 << kBooleanSchemaType))) { + DisallowedType(context, GetBooleanString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + return true; + } + bool CheckInt(Context& context, int64_t i) const { if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) { DisallowedType(context, GetIntegerString()); @@ -1420,9 +1641,13 @@ private: bool CheckDoubleMultipleOf(Context& context, double d) const { double a = std::abs(d), b = std::abs(multipleOf_.GetDouble()); - double q = std::floor(a / b); - double r = a - q * b; - if (r > 0.0) { + double q = a / b; + double qRounded = std::floor(q + 0.5); + double scaledEpsilon = (q + qRounded) * std::numeric_limits::epsilon(); + double difference = std::abs(qRounded - q); + bool isMultiple = (difference <= scaledEpsilon) + || (difference < std::numeric_limits::min()); + if (!isMultiple) { context.error_handler.NotMultipleOf(d, multipleOf_); RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); } @@ -1458,7 +1683,7 @@ private: struct PatternProperty { PatternProperty() : schema(), pattern() {} - ~PatternProperty() { + ~PatternProperty() { if (pattern) { pattern->~RegexType(); AllocatorType::Free(pattern); @@ -1470,6 +1695,8 @@ private: AllocatorType* allocator_; SValue uri_; + UriType id_; + Specification spec_; PointerType pointer_; const SchemaType* typeless_; uint64_t* enum_; @@ -1512,8 +1739,12 @@ private: SValue multipleOf_; bool exclusiveMinimum_; bool exclusiveMaximum_; - + SizeType defaultValueLength_; + + bool readOnly_; + bool writeOnly_; + bool nullable_; }; template @@ -1555,9 +1786,18 @@ template class IGenericRemoteSchemaDocumentProvider { public: typedef typename SchemaDocumentType::Ch Ch; + typedef typename SchemaDocumentType::ValueType ValueType; + typedef typename SchemaDocumentType::AllocatorType AllocatorType; virtual ~IGenericRemoteSchemaDocumentProvider() {} virtual const SchemaDocumentType* GetRemoteDocument(const Ch* uri, SizeType length) = 0; + virtual const SchemaDocumentType* GetRemoteDocument(const GenericUri uri, Specification& spec) { + // Default implementation just calls through for compatibility + // Following line suppresses unused parameter warning + (void)spec; + // printf("GetRemoteDocument: %d %d\n", spec.draft, spec.oapi); + return GetRemoteDocument(uri.GetBaseString(), uri.GetBaseStringLength()); + } }; /////////////////////////////////////////////////////////////////////////////// @@ -1582,7 +1822,9 @@ public: typedef typename EncodingType::Ch Ch; typedef internal::Schema SchemaType; typedef GenericPointer PointerType; - typedef GenericValue URIType; + typedef GenericValue GValue; + typedef GenericUri UriType; + typedef GenericStringRef StringRefType; friend class internal::Schema; template friend class GenericSchemaValidator; @@ -1596,46 +1838,53 @@ public: \param uriLength Length of \c name, in code points. \param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null. \param allocator An optional allocator instance for allocating memory. Can be null. + \param pointer An optional JSON pointer to the start of the schema document + \param spec Optional schema draft or OpenAPI version. Used if no specification in document. Defaults to draft-04. */ explicit GenericSchemaDocument(const ValueType& document, const Ch* uri = 0, SizeType uriLength = 0, - IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) : + IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0, + const PointerType& pointer = PointerType(), // PR #1393 + const Specification& spec = Specification(kDraft04)) : remoteProvider_(remoteProvider), allocator_(allocator), ownAllocator_(), root_(), typeless_(), schemaMap_(allocator, kInitialSchemaMapSize), - schemaRef_(allocator, kInitialSchemaRefSize) + schemaRef_(allocator, kInitialSchemaRefSize), + spec_(spec), + error_(kObjectType), + currentError_() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::GenericSchemaDocument"); if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); Ch noUri[1] = {0}; uri_.SetString(uri ? uri : noUri, uriLength, *allocator_); + docId_ = UriType(uri_, allocator_); typeless_ = static_cast(allocator_->Malloc(sizeof(SchemaType))); - new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_); + new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_, docId_); + + // Establish the schema draft or open api version. + // We only ever look for '$schema' or 'swagger' or 'openapi' at the root of the document. + SetSchemaSpecification(document); // Generate root schema, it will call CreateSchema() to create sub-schemas, - // And call AddRefSchema() if there are $ref. - CreateSchemaRecursive(&root_, PointerType(), document, document); - - // Resolve $ref - while (!schemaRef_.Empty()) { - SchemaRefEntry* refEntry = schemaRef_.template Pop(1); - if (const SchemaType* s = GetSchema(refEntry->target)) { - if (refEntry->schema) - *refEntry->schema = s; - - // Create entry in map if not exist - if (!GetSchema(refEntry->source)) { - new (schemaMap_.template Push()) SchemaEntry(refEntry->source, const_cast(s), false, allocator_); - } - } - else if (refEntry->schema) - *refEntry->schema = typeless_; - - refEntry->~SchemaRefEntry(); + // And call HandleRefSchema() if there are $ref. + // PR #1393 use input pointer if supplied + root_ = typeless_; + if (pointer.GetTokenCount() == 0) { + CreateSchemaRecursive(&root_, pointer, document, document, docId_); + } + else if (const ValueType* v = pointer.Get(document)) { + CreateSchema(&root_, pointer, *v, document, docId_); + } + else { + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + SchemaErrorValue(kSchemaErrorStartUnknown, PointerType(), sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch))); } RAPIDJSON_ASSERT(root_ != 0); @@ -1653,7 +1902,11 @@ public: typeless_(rhs.typeless_), schemaMap_(std::move(rhs.schemaMap_)), schemaRef_(std::move(rhs.schemaRef_)), - uri_(std::move(rhs.uri_)) + uri_(std::move(rhs.uri_)), + docId_(std::move(rhs.docId_)), + spec_(rhs.spec_), + error_(std::move(rhs.error_)), + currentError_(std::move(rhs.currentError_)) { rhs.remoteProvider_ = 0; rhs.allocator_ = 0; @@ -1672,26 +1925,87 @@ public: Allocator::Free(typeless_); } + // these may contain some allocator data so clear before deleting ownAllocator_ + uri_.SetNull(); + error_.SetNull(); + currentError_.SetNull(); + RAPIDJSON_DELETE(ownAllocator_); } - const URIType& GetURI() const { return uri_; } + const GValue& GetURI() const { return uri_; } + + const Specification& GetSpecification() const { return spec_; } + bool IsSupportedSpecification() const { return spec_.IsSupported(); } + + //! Static method to get the specification of any schema document + // Returns kDraftNone if document is silent + static const Specification GetSpecification(const ValueType& document) { + SchemaDraft draft = GetSchemaDraft(document); + if (draft != kDraftNone) + return Specification(draft); + else { + OpenApiVersion oapi = GetOpenApiVersion(document); + if (oapi != kVersionNone) + return Specification(oapi); + } + return Specification(kDraftNone); + } //! Get the root schema. const SchemaType& GetRoot() const { return *root_; } -private: + //! Gets the error object. + GValue& GetError() { return error_; } + const GValue& GetError() const { return error_; } + + static const StringRefType& GetSchemaErrorKeyword(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorStartUnknown: return GetStartUnknownString(); + case kSchemaErrorRefPlainName: return GetRefPlainNameString(); + case kSchemaErrorRefInvalid: return GetRefInvalidString(); + case kSchemaErrorRefPointerInvalid: return GetRefPointerInvalidString(); + case kSchemaErrorRefUnknown: return GetRefUnknownString(); + case kSchemaErrorRefCyclical: return GetRefCyclicalString(); + case kSchemaErrorRefNoRemoteProvider: return GetRefNoRemoteProviderString(); + case kSchemaErrorRefNoRemoteSchema: return GetRefNoRemoteSchemaString(); + case kSchemaErrorRegexInvalid: return GetRegexInvalidString(); + case kSchemaErrorSpecUnknown: return GetSpecUnknownString(); + case kSchemaErrorSpecUnsupported: return GetSpecUnsupportedString(); + case kSchemaErrorSpecIllegal: return GetSpecIllegalString(); + case kSchemaErrorReadOnlyAndWriteOnly: return GetReadOnlyAndWriteOnlyString(); + default: return GetNullString(); + } + } + + //! Default error method + void SchemaError(const SchemaErrorCode code, const PointerType& location) { + currentError_ = GValue(kObjectType); + AddCurrentError(code, location); + } + + //! Method for error with single string value insert + void SchemaErrorValue(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + AddCurrentError(code, location); + } + + //! Method for error with invalid pointer + void SchemaErrorPointer(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length, const PointerType& pointer) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + currentError_.AddMember(GetOffsetString(), static_cast(pointer.GetParseErrorOffset() / sizeof(Ch)), *allocator_); + AddCurrentError(code, location); + } + + private: //! Prohibit copying GenericSchemaDocument(const GenericSchemaDocument&); //! Prohibit assignment GenericSchemaDocument& operator=(const GenericSchemaDocument&); - struct SchemaRefEntry { - SchemaRefEntry(const PointerType& s, const PointerType& t, const SchemaType** outSchema, Allocator *allocator) : source(s, allocator), target(t, allocator), schema(outSchema) {} - PointerType source; - PointerType target; - const SchemaType** schema; - }; + typedef const PointerType* SchemaRefPtr; // PR #1393 struct SchemaEntry { SchemaEntry(const PointerType& p, SchemaType* s, bool o, Allocator* allocator) : pointer(p, allocator), schema(s), owned(o) {} @@ -1706,79 +2020,361 @@ private: bool owned; }; - void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) { - if (schema) - *schema = typeless_; + void AddErrorInstanceLocation(GValue& result, const PointerType& location) { + GenericStringBuffer sb; + location.StringifyUriFragment(sb); + GValue instanceRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), *allocator_); + result.AddMember(GetInstanceRefString(), instanceRef, *allocator_); + } + void AddError(GValue& keyword, GValue& error) { + typename GValue::MemberIterator member = error_.FindMember(keyword); + if (member == error_.MemberEnd()) + error_.AddMember(keyword, error, *allocator_); + else { + if (member->value.IsObject()) { + GValue errors(kArrayType); + errors.PushBack(member->value, *allocator_); + member->value = errors; + } + member->value.PushBack(error, *allocator_); + } + } + + void AddCurrentError(const SchemaErrorCode code, const PointerType& location) { + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, GetSchemaErrorKeyword(code)); + currentError_.AddMember(GetErrorCodeString(), code, *allocator_); + AddErrorInstanceLocation(currentError_, location); + AddError(GValue(GetSchemaErrorKeyword(code)).Move(), currentError_); + } + +#define RAPIDJSON_STRING_(name, ...) \ + static const StringRefType& Get##name##String() {\ + static const Ch s[] = { __VA_ARGS__, '\0' };\ + static const StringRefType v(s, static_cast(sizeof(s) / sizeof(Ch) - 1)); \ + return v;\ + } + + RAPIDJSON_STRING_(InstanceRef, 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 'R', 'e', 'f') + RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') + RAPIDJSON_STRING_(Value, 'v', 'a', 'l', 'u', 'e') + RAPIDJSON_STRING_(Offset, 'o', 'f', 'f', 's', 'e', 't') + + RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l') + RAPIDJSON_STRING_(SpecUnknown, 'S', 'p', 'e', 'c', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(SpecUnsupported, 'S', 'p', 'e', 'c', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd') + RAPIDJSON_STRING_(SpecIllegal, 'S', 'p', 'e', 'c', 'I', 'l', 'l', 'e', 'g', 'a', 'l') + RAPIDJSON_STRING_(StartUnknown, 'S', 't', 'a', 'r', 't', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefPlainName, 'R', 'e', 'f', 'P', 'l', 'a', 'i', 'n', 'N', 'a', 'm', 'e') + RAPIDJSON_STRING_(RefInvalid, 'R', 'e', 'f', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefPointerInvalid, 'R', 'e', 'f', 'P', 'o', 'i', 'n', 't', 'e', 'r', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefUnknown, 'R', 'e', 'f', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefCyclical, 'R', 'e', 'f', 'C', 'y', 'c', 'l', 'i', 'c', 'a', 'l') + RAPIDJSON_STRING_(RefNoRemoteProvider, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'P', 'r', 'o', 'v', 'i', 'd', 'e', 'r') + RAPIDJSON_STRING_(RefNoRemoteSchema, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'S', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(ReadOnlyAndWriteOnly, 'R', 'e', 'a', 'd', 'O', 'n', 'l', 'y', 'A', 'n', 'd', 'W', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(RegexInvalid, 'R', 'e', 'g', 'e', 'x', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + +#undef RAPIDJSON_STRING_ + + // Static method to get schema draft of any schema document + static SchemaDraft GetSchemaDraft(const ValueType& document) { + static const Ch kDraft03String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '3', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft04String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '4', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft05String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '5', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft06String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '6', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft07String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '7', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft2019_09String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '1', '9', '-', '0', '9', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + static const Ch kDraft2020_12String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '2', '0', '-', '1', '2', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + + if (!document.IsObject()) { + return kDraftNone; + } + + // Get the schema draft from the $schema keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSchemaString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kDraftUnknown; + const UriType draftUri(itr->value); + // Check base uri for match + if (draftUri.Match(UriType(kDraft04String), false)) return kDraft04; + if (draftUri.Match(UriType(kDraft05String), false)) return kDraft05; + if (draftUri.Match(UriType(kDraft06String), false)) return kDraft06; + if (draftUri.Match(UriType(kDraft07String), false)) return kDraft07; + if (draftUri.Match(UriType(kDraft03String), false)) return kDraft03; + if (draftUri.Match(UriType(kDraft2019_09String), false)) return kDraft2019_09; + if (draftUri.Match(UriType(kDraft2020_12String), false)) return kDraft2020_12; + return kDraftUnknown; + } + // $schema not found + return kDraftNone; + } + + + // Get open api version of any schema document + static OpenApiVersion GetOpenApiVersion(const ValueType& document) { + static const Ch kVersion20String[] = { '2', '.', '0', '\0' }; + static const Ch kVersion30String[] = { '3', '.', '0', '.', '\0' }; // ignore patch level + static const Ch kVersion31String[] = { '3', '.', '1', '.', '\0' }; // ignore patch level + static SizeType len = internal::StrLen(kVersion30String); + + if (!document.IsObject()) { + return kVersionNone; + } + + // Get the open api version from the swagger / openapi keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSwaggerString()); + if (itr == document.MemberEnd()) itr = document.FindMember(SchemaType::GetOpenApiString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kVersionUnknown; + const ValueType kVersion20Value(kVersion20String); + if (kVersion20Value == itr->value) return kVersion20; // must match 2.0 exactly + const ValueType kVersion30Value(kVersion30String); + if (itr->value.GetStringLength() > len && kVersion30Value == ValueType(itr->value.GetString(), len)) return kVersion30; // must match 3.0.x + const ValueType kVersion31Value(kVersion31String); + if (itr->value.GetStringLength() > len && kVersion31Value == ValueType(itr->value.GetString(), len)) return kVersion31; // must match 3.1.x + return kVersionUnknown; + } + // swagger or openapi not found + return kVersionNone; + } + + // Get the draft of the schema or the open api version (which implies the draft). + // Report an error if schema draft or open api version not supported or not recognized, or both in document, and carry on. + void SetSchemaSpecification(const ValueType& document) { + // Look for '$schema', 'swagger' or 'openapi' keyword at document root + SchemaDraft docDraft = GetSchemaDraft(document); + OpenApiVersion docOapi = GetOpenApiVersion(document); + // Error if both in document + if (docDraft != kDraftNone && docOapi != kVersionNone) + SchemaError(kSchemaErrorSpecIllegal, PointerType()); + // Use document draft or open api version if present or use spec from constructor + if (docDraft != kDraftNone) + spec_ = Specification(docDraft); + else if (docOapi != kVersionNone) + spec_ = Specification(docOapi); + // Error if draft or version unknown + if (spec_.draft == kDraftUnknown || spec_.oapi == kVersionUnknown) + SchemaError(kSchemaErrorSpecUnknown, PointerType()); + else if (!spec_.IsSupported()) + SchemaError(kSchemaErrorSpecUnsupported, PointerType()); + } + + // Changed by PR #1393 + void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { if (v.GetType() == kObjectType) { - const SchemaType* s = GetSchema(pointer); - if (!s) - CreateSchema(schema, pointer, v, document); + UriType newid = UriType(CreateSchema(schema, pointer, v, document, id), allocator_); for (typename ValueType::ConstMemberIterator itr = v.MemberBegin(); itr != v.MemberEnd(); ++itr) - CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document); + CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document, newid); } else if (v.GetType() == kArrayType) for (SizeType i = 0; i < v.Size(); i++) - CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document); + CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document, id); } - void CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) { + // Changed by PR #1393 + const UriType& CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { RAPIDJSON_ASSERT(pointer.IsValid()); + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::CreateSchema", sb.GetString(), id.GetString()); if (v.IsObject()) { - if (!HandleRefSchema(pointer, schema, v, document)) { - SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_); - new (schemaMap_.template Push()) SchemaEntry(pointer, s, true, allocator_); + if (const SchemaType* sc = GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + } + else if (!HandleRefSchema(pointer, schema, v, document, id)) { + // The new schema constructor adds itself and its $ref(s) to schemaMap_ + SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_, id); if (schema) *schema = s; + return s->GetId(); } } + else { + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + } + return id; } - bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document) { - static const Ch kRefString[] = { '$', 'r', 'e', 'f', '\0' }; - static const ValueType kRefValue(kRefString, 4); - - typename ValueType::ConstMemberIterator itr = v.FindMember(kRefValue); + // Changed by PR #1393 + // TODO should this return a UriType& ? + bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document, const UriType& id) { + typename ValueType::ConstMemberIterator itr = v.FindMember(SchemaType::GetRefString()); if (itr == v.MemberEnd()) return false; + GenericStringBuffer sb; + source.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::HandleRefSchema", sb.GetString(), id.GetString()); + // Resolve the source pointer to the $ref'ed schema (finally) + new (schemaRef_.template Push()) SchemaRefPtr(&source); + if (itr->value.IsString()) { SizeType len = itr->value.GetStringLength(); - if (len > 0) { - const Ch* s = itr->value.GetString(); - SizeType i = 0; - while (i < len && s[i] != '#') // Find the first # - i++; - - if (i > 0) { // Remote reference, resolve immediately - if (remoteProvider_) { - if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(s, i)) { - PointerType pointer(&s[i], len - i, allocator_); - if (pointer.IsValid()) { - if (const SchemaType* sc = remoteDocument->GetSchema(pointer)) { - if (schema) - *schema = sc; - new (schemaMap_.template Push()) SchemaEntry(source, const_cast(sc), false, allocator_); - return true; + if (len == 0) + SchemaError(kSchemaErrorRefInvalid, source); + else { + // First resolve $ref against the in-scope id + UriType scopeId = UriType(id, allocator_); + UriType ref = UriType(itr->value, allocator_).Resolve(scopeId, allocator_); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), itr->value.GetString(), ref.GetString()); + // See if the resolved $ref minus the fragment matches a resolved id in this document + // Search from the root. Returns the subschema in the document and its absolute JSON pointer. + PointerType basePointer = PointerType(); + const ValueType *base = FindId(document, ref, basePointer, docId_, false); + if (!base) { + // Remote reference - call the remote document provider + if (!remoteProvider_) + SchemaError(kSchemaErrorRefNoRemoteProvider, source); + else { + if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(ref, spec_)) { + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, absolute in the remote schema + const PointerType pointer(s, len, allocator_); + if (!pointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, pointer); + else { + // Get the subschema + if (const SchemaType *sc = remoteDocument->GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + return true; + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); } - } - } + } else + // Plain name fragment, not allowed in remote schema + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + } else + SchemaErrorValue(kSchemaErrorRefNoRemoteSchema, source, ref.GetString(), ref.GetStringLength()); } } - else if (s[i] == '#') { // Local reference, defer resolution - PointerType pointer(&s[i], len - i, allocator_); - if (pointer.IsValid()) { - if (const ValueType* nv = pointer.Get(document)) - if (HandleRefSchema(source, schema, *nv, document)) + else { // Local reference + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, relative to the resolved URI + const PointerType relPointer(s, len, allocator_); + if (!relPointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, relPointer); + else { + // Get the subschema + if (const ValueType *pv = relPointer.Get(*base)) { + // Now get the absolute JSON pointer by adding relative to base + PointerType pointer(basePointer, allocator_); + for (SizeType i = 0; i < relPointer.GetTokenCount(); i++) + pointer = pointer.Append(relPointer.GetTokens()[i], allocator_); + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); + return true; + } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); + } + } else { + // Plain name fragment, relative to the resolved URI + // Not supported in open api 2.0 and 3.0 + PointerType pointer(allocator_); + if (spec_.oapi == kVersion20 || spec_.oapi == kVersion30) + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + // See if the fragment matches an id in this document. + // Search from the base we just established. Returns the subschema in the document and its absolute JSON pointer. + else if (const ValueType *pv = FindId(*base, ref, pointer, UriType(ref.GetBaseString(), ref.GetBaseStringLength(), allocator_), true, basePointer)) { + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); return true; - - new (schemaRef_.template Push()) SchemaRefEntry(source, pointer, schema, allocator_); - return true; + } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); } } } } + + // Invalid/Unknown $ref + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + return true; + } + + //! Find the first subschema with a resolved 'id' that matches the specified URI. + // If full specified use all URI else ignore fragment. + // If found, return a pointer to the subschema and its JSON pointer. + // TODO cache pointer <-> id mapping + ValueType* FindId(const ValueType& doc, const UriType& finduri, PointerType& resptr, const UriType& baseuri, bool full, const PointerType& here = PointerType()) const { + SizeType i = 0; + ValueType* resval = 0; + UriType tempuri = UriType(finduri, allocator_); + UriType localuri = UriType(baseuri, allocator_); + if (doc.GetType() == kObjectType) { + // Establish the base URI of this object + typename ValueType::ConstMemberIterator m = doc.FindMember(SchemaType::GetIdString()); + if (m != doc.MemberEnd() && m->value.GetType() == kStringType) { + localuri = UriType(m->value, allocator_).Resolve(baseuri, allocator_); + } + // See if it matches + if (localuri.Match(finduri, full)) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::FindId (match)", full ? localuri.GetString() : localuri.GetBaseString()); + resval = const_cast(&doc); + resptr = here; + return resval; + } + // No match, continue looking + for (m = doc.MemberBegin(); m != doc.MemberEnd(); ++m) { + if (m->value.GetType() == kObjectType || m->value.GetType() == kArrayType) { + resval = FindId(m->value, finduri, resptr, localuri, full, here.Append(m->name.GetString(), m->name.GetStringLength(), allocator_)); + } + if (resval) break; + } + } else if (doc.GetType() == kArrayType) { + // Continue looking + for (typename ValueType::ConstValueIterator v = doc.Begin(); v != doc.End(); ++v) { + if (v->GetType() == kObjectType || v->GetType() == kArrayType) { + resval = FindId(*v, finduri, resptr, localuri, full, here.Append(i, allocator_)); + } + if (resval) break; + i++; + } + } + return resval; + } + + // Added by PR #1393 + void AddSchemaRefs(SchemaType* schema) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::AddSchemaRefs"); + while (!schemaRef_.Empty()) { + SchemaRefPtr *ref = schemaRef_.template Pop(1); + SchemaEntry *entry = schemaMap_.template Push(); + new (entry) SchemaEntry(**ref, schema, false, allocator_); + } + } + + // Added by PR #1393 + bool IsCyclicRef(const PointerType& pointer) const { + for (const SchemaRefPtr* ref = schemaRef_.template Bottom(); ref != schemaRef_.template End(); ++ref) + if (pointer == **ref) + return true; return false; } @@ -1807,8 +2403,12 @@ private: const SchemaType* root_; //!< Root schema. SchemaType* typeless_; internal::Stack schemaMap_; // Stores created Pointer -> Schemas - internal::Stack schemaRef_; // Stores Pointer from $ref and schema which holds the $ref - URIType uri_; + internal::Stack schemaRef_; // Stores Pointer(s) from $ref(s) until resolved + GValue uri_; // Schema document URI + UriType docId_; + Specification spec_; + GValue error_; + GValue currentError_; }; //! GenericSchemaDocument using Value type. @@ -1872,11 +2472,10 @@ public: currentError_(), missingDependents_(), valid_(true), - flags_(kValidateDefaultFlags) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(0) -#endif + flags_(kValidateDefaultFlags), + depth_(0) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator"); } //! Constructor with output handler. @@ -1904,11 +2503,10 @@ public: currentError_(), missingDependents_(), valid_(true), - flags_(kValidateDefaultFlags) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(0) -#endif + flags_(kValidateDefaultFlags), + depth_(0) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (output handler)"); } //! Destructor. @@ -1941,13 +2539,12 @@ public: return flags_; } - //! Checks whether the current state is valid. - // Implementation of ISchemaValidator virtual bool IsValid() const { if (!valid_) return false; if (GetContinueOnErrors() && !error_.ObjectEmpty()) return false; return true; } + //! End of Implementation of ISchemaValidator //! Gets the error object. ValueType& GetError() { return error_; } @@ -1963,7 +2560,7 @@ public: // If reporting all errors, the stack will be empty, so return "errors". const Ch* GetInvalidSchemaKeyword() const { if (!schemaStack_.Empty()) return CurrentContext().invalidKeyword; - if (GetContinueOnErrors() && !error_.ObjectEmpty()) return (const Ch*)GetErrorsString(); + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return static_cast(GetErrorsString()); return 0; } @@ -2155,13 +2752,29 @@ public: void NoneOf(ISchemaValidator** subvalidators, SizeType count) { AddErrorArray(kValidateErrorAnyOf, subvalidators, count); } - void NotOneOf(ISchemaValidator** subvalidators, SizeType count, bool matched = false) { - AddErrorArray(matched ? kValidateErrorOneOfMatch : kValidateErrorOneOf, subvalidators, count); + void NotOneOf(ISchemaValidator** subvalidators, SizeType count) { + AddErrorArray(kValidateErrorOneOf, subvalidators, count); + } + void MultipleOneOf(SizeType index1, SizeType index2) { + ValueType matches(kArrayType); + matches.PushBack(index1, GetStateAllocator()); + matches.PushBack(index2, GetStateAllocator()); + currentError_.SetObject(); + currentError_.AddMember(GetMatchesString(), matches, GetStateAllocator()); + AddCurrentError(kValidateErrorOneOfMatch); } void Disallowed() { currentError_.SetObject(); AddCurrentError(kValidateErrorNot); } + void DisallowedWhenWriting() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorReadOnly); + } + void DisallowedWhenReading() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorWriteOnly); + } #define RAPIDJSON_STRING_(name, ...) \ static const StringRefType& Get##name##String() {\ @@ -2180,25 +2793,18 @@ public: RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') RAPIDJSON_STRING_(ErrorMessage, 'e', 'r', 'r', 'o', 'r', 'M', 'e', 's', 's', 'a', 'g', 'e') RAPIDJSON_STRING_(Duplicates, 'd', 'u', 'p', 'l', 'i', 'c', 'a', 't', 'e', 's') + RAPIDJSON_STRING_(Matches, 'm', 'a', 't', 'c', 'h', 'e', 's') #undef RAPIDJSON_STRING_ -#if RAPIDJSON_SCHEMA_VERBOSE -#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() \ -RAPIDJSON_MULTILINEMACRO_BEGIN\ - *documentStack_.template Push() = '\0';\ - documentStack_.template Pop(1);\ - internal::PrintInvalidDocument(documentStack_.template Bottom());\ -RAPIDJSON_MULTILINEMACRO_END -#else -#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() -#endif - #define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\ if (!valid_) return false; \ if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {\ - RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\ - return valid_ = false;\ + *documentStack_.template Push() = '\0';\ + documentStack_.template Pop(1);\ + RAPIDJSON_SCHEMA_PRINT(InvalidDocument, documentStack_.template Bottom());\ + valid_ = false;\ + return valid_;\ } #define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\ @@ -2235,52 +2841,68 @@ RAPIDJSON_MULTILINEMACRO_END { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); } bool StartObject() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartObject"); RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext())); RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartObject, ()); - return valid_ = !outputHandler_ || outputHandler_->StartObject(); + valid_ = !outputHandler_ || outputHandler_->StartObject(); + return valid_; } bool Key(const Ch* str, SizeType len, bool copy) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::Key", str); if (!valid_) return false; AppendToken(str, len); - if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) return valid_ = false; + if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(Key, (str, len, copy)); - return valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy); + valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy); + return valid_; } bool EndObject(SizeType memberCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndObject"); if (!valid_) return false; RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndObject, (memberCount)); - if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) return valid_ = false; + if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_END_(EndObject, (memberCount)); } bool StartArray() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartArray"); RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartArray, (CurrentContext())); RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartArray, ()); - return valid_ = !outputHandler_ || outputHandler_->StartArray(); + valid_ = !outputHandler_ || outputHandler_->StartArray(); + return valid_; } bool EndArray(SizeType elementCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndArray"); if (!valid_) return false; RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndArray, (elementCount)); - if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) return valid_ = false; + if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_END_(EndArray, (elementCount)); } -#undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_ #undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_ #undef RAPIDJSON_SCHEMA_HANDLE_PARALLEL_ #undef RAPIDJSON_SCHEMA_HANDLE_VALUE_ // Implementation of ISchemaStateFactory virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root, const bool inheritContinueOnErrors) { + *documentStack_.template Push() = '\0'; + documentStack_.template Pop(1); ISchemaValidator* sv = new (GetStateAllocator().Malloc(sizeof(GenericSchemaValidator))) GenericSchemaValidator(*schemaDocument_, root, documentStack_.template Bottom(), documentStack_.GetSize(), -#if RAPIDJSON_SCHEMA_VERBOSE depth_ + 1, -#endif &GetStateAllocator()); - sv->SetValidateFlags(inheritContinueOnErrors ? GetValidateFlags() : GetValidateFlags() & ~(unsigned)kValidateContinueOnErrorFlag); + sv->SetValidateFlags(inheritContinueOnErrors ? GetValidateFlags() : GetValidateFlags() & ~static_cast(kValidateContinueOnErrorFlag)); return sv; } @@ -2311,6 +2933,7 @@ RAPIDJSON_MULTILINEMACRO_END virtual void FreeState(void* p) { StateAllocator::Free(p); } + // End of implementation of ISchemaStateFactory private: typedef typename SchemaType::Context Context; @@ -2321,9 +2944,7 @@ private: const SchemaDocumentType& schemaDocument, const SchemaType& root, const char* basePath, size_t basePathSize, -#if RAPIDJSON_SCHEMA_VERBOSE unsigned depth, -#endif StateAllocator* allocator = 0, size_t schemaStackCapacity = kDefaultSchemaStackCapacity, size_t documentStackCapacity = kDefaultDocumentStackCapacity) @@ -2339,11 +2960,10 @@ private: currentError_(), missingDependents_(), valid_(true), - flags_(kValidateDefaultFlags) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(depth) -#endif + flags_(kValidateDefaultFlags), + depth_(depth) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (internal)", basePath && basePathSize ? basePath : ""); if (basePath && basePathSize) memcpy(documentStack_.template Push(basePathSize), basePath, basePathSize); } @@ -2359,6 +2979,7 @@ private: } bool BeginValue() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::BeginValue"); if (schemaStack_.Empty()) PushSchema(root_); else { @@ -2380,6 +3001,7 @@ private: ISchemaValidator**& va = CurrentContext().patternPropertiesValidators; SizeType& validatorCount = CurrentContext().patternPropertiesValidatorCount; va = static_cast(MallocState(sizeof(ISchemaValidator*) * count)); + std::memset(va, 0, sizeof(ISchemaValidator*) * count); for (SizeType i = 0; i < count; i++) va[validatorCount++] = CreateSchemaValidator(*sa[i], true); // Inherit continueOnError } @@ -2390,17 +3012,15 @@ private: } bool EndValue() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndValue"); if (!CurrentSchema().EndValue(CurrentContext()) && !GetContinueOnErrors()) return false; -#if RAPIDJSON_SCHEMA_VERBOSE GenericStringBuffer sb; - schemaDocument_->GetPointer(&CurrentSchema()).Stringify(sb); - + schemaDocument_->GetPointer(&CurrentSchema()).StringifyUriFragment(sb); *documentStack_.template Push() = '\0'; documentStack_.template Pop(1); - internal::PrintValidatorPointers(depth_, sb.GetString(), documentStack_.template Bottom()); -#endif + RAPIDJSON_SCHEMA_PRINT(ValidatorPointers, sb.GetString(), documentStack_.template Bottom(), depth_); void* hasher = CurrentContext().hasher; uint64_t h = hasher && CurrentContext().arrayUniqueness ? static_cast(hasher)->GetHashCode() : 0; @@ -2451,7 +3071,7 @@ private: } } - RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push()) Context(*this, *this, &schema); } + RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push()) Context(*this, *this, &schema, flags_); } RAPIDJSON_FORCEINLINE void PopSchema() { Context* c = schemaStack_.template Pop(1); @@ -2553,9 +3173,7 @@ private: ValueType missingDependents_; bool valid_; unsigned flags_; -#if RAPIDJSON_SCHEMA_VERBOSE unsigned depth_; -#endif }; typedef GenericSchemaValidator SchemaValidator; diff --git a/contrib/rapidjson/include/rapidjson/uri.h b/contrib/rapidjson/include/rapidjson/uri.h new file mode 100644 index 000000000..f93e508a4 --- /dev/null +++ b/contrib/rapidjson/include/rapidjson/uri.h @@ -0,0 +1,481 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// (C) Copyright IBM Corporation 2021 +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_URI_H_ +#define RAPIDJSON_URI_H_ + +#include "internal/strfunc.h" + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// GenericUri + +template +class GenericUri { +public: + typedef typename ValueType::Ch Ch; +#if RAPIDJSON_HAS_STDSTRING + typedef std::basic_string String; +#endif + + //! Constructors + GenericUri(Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + } + + GenericUri(const Ch* uri, SizeType len, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, len); + } + + GenericUri(const Ch* uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, internal::StrLen(uri)); + } + + // Use with specializations of GenericValue + template GenericUri(const T& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + const Ch* u = uri.template Get(); // TypeHelper from document.h + Parse(u, internal::StrLen(u)); + } + +#if RAPIDJSON_HAS_STDSTRING + GenericUri(const String& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri.c_str(), internal::StrLen(uri.c_str())); + } +#endif + + //! Copy constructor + GenericUri(const GenericUri& rhs) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(), ownAllocator_() { + *this = rhs; + } + + //! Copy constructor + GenericUri(const GenericUri& rhs, Allocator* allocator) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + *this = rhs; + } + + //! Destructor. + ~GenericUri() { + Free(); + RAPIDJSON_DELETE(ownAllocator_); + } + + //! Assignment operator + GenericUri& operator=(const GenericUri& rhs) { + if (this != &rhs) { + // Do not delete ownAllocator + Free(); + Allocate(rhs.GetStringLength()); + auth_ = CopyPart(scheme_, rhs.scheme_, rhs.GetSchemeStringLength()); + path_ = CopyPart(auth_, rhs.auth_, rhs.GetAuthStringLength()); + query_ = CopyPart(path_, rhs.path_, rhs.GetPathStringLength()); + frag_ = CopyPart(query_, rhs.query_, rhs.GetQueryStringLength()); + base_ = CopyPart(frag_, rhs.frag_, rhs.GetFragStringLength()); + uri_ = CopyPart(base_, rhs.base_, rhs.GetBaseStringLength()); + CopyPart(uri_, rhs.uri_, rhs.GetStringLength()); + } + return *this; + } + + //! Getters + // Use with specializations of GenericValue + template void Get(T& uri, Allocator& allocator) { + uri.template Set(this->GetString(), allocator); // TypeHelper from document.h + } + + const Ch* GetString() const { return uri_; } + SizeType GetStringLength() const { return uri_ == 0 ? 0 : internal::StrLen(uri_); } + const Ch* GetBaseString() const { return base_; } + SizeType GetBaseStringLength() const { return base_ == 0 ? 0 : internal::StrLen(base_); } + const Ch* GetSchemeString() const { return scheme_; } + SizeType GetSchemeStringLength() const { return scheme_ == 0 ? 0 : internal::StrLen(scheme_); } + const Ch* GetAuthString() const { return auth_; } + SizeType GetAuthStringLength() const { return auth_ == 0 ? 0 : internal::StrLen(auth_); } + const Ch* GetPathString() const { return path_; } + SizeType GetPathStringLength() const { return path_ == 0 ? 0 : internal::StrLen(path_); } + const Ch* GetQueryString() const { return query_; } + SizeType GetQueryStringLength() const { return query_ == 0 ? 0 : internal::StrLen(query_); } + const Ch* GetFragString() const { return frag_; } + SizeType GetFragStringLength() const { return frag_ == 0 ? 0 : internal::StrLen(frag_); } + +#if RAPIDJSON_HAS_STDSTRING + static String Get(const GenericUri& uri) { return String(uri.GetString(), uri.GetStringLength()); } + static String GetBase(const GenericUri& uri) { return String(uri.GetBaseString(), uri.GetBaseStringLength()); } + static String GetScheme(const GenericUri& uri) { return String(uri.GetSchemeString(), uri.GetSchemeStringLength()); } + static String GetAuth(const GenericUri& uri) { return String(uri.GetAuthString(), uri.GetAuthStringLength()); } + static String GetPath(const GenericUri& uri) { return String(uri.GetPathString(), uri.GetPathStringLength()); } + static String GetQuery(const GenericUri& uri) { return String(uri.GetQueryString(), uri.GetQueryStringLength()); } + static String GetFrag(const GenericUri& uri) { return String(uri.GetFragString(), uri.GetFragStringLength()); } +#endif + + //! Equality operators + bool operator==(const GenericUri& rhs) const { + return Match(rhs, true); + } + + bool operator!=(const GenericUri& rhs) const { + return !Match(rhs, true); + } + + bool Match(const GenericUri& uri, bool full = true) const { + Ch* s1; + Ch* s2; + if (full) { + s1 = uri_; + s2 = uri.uri_; + } else { + s1 = base_; + s2 = uri.base_; + } + if (s1 == s2) return true; + if (s1 == 0 || s2 == 0) return false; + return internal::StrCmp(s1, s2) == 0; + } + + //! Resolve this URI against another (base) URI in accordance with URI resolution rules. + // See https://tools.ietf.org/html/rfc3986 + // Use for resolving an id or $ref with an in-scope id. + // Returns a new GenericUri for the resolved URI. + GenericUri Resolve(const GenericUri& baseuri, Allocator* allocator = 0) { + GenericUri resuri; + resuri.allocator_ = allocator; + // Ensure enough space for combining paths + resuri.Allocate(GetStringLength() + baseuri.GetStringLength() + 1); // + 1 for joining slash + + if (!(GetSchemeStringLength() == 0)) { + // Use all of this URI + resuri.auth_ = CopyPart(resuri.scheme_, scheme_, GetSchemeStringLength()); + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base scheme + resuri.auth_ = CopyPart(resuri.scheme_, baseuri.scheme_, baseuri.GetSchemeStringLength()); + if (!(GetAuthStringLength() == 0)) { + // Use this auth, path, query + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base auth + resuri.path_ = CopyPart(resuri.auth_, baseuri.auth_, baseuri.GetAuthStringLength()); + if (GetPathStringLength() == 0) { + // Use the base path + resuri.query_ = CopyPart(resuri.path_, baseuri.path_, baseuri.GetPathStringLength()); + if (GetQueryStringLength() == 0) { + // Use the base query + resuri.frag_ = CopyPart(resuri.query_, baseuri.query_, baseuri.GetQueryStringLength()); + } else { + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } else { + if (path_[0] == '/') { + // Absolute path - use all of this path + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } else { + // Relative path - append this path to base path after base path's last slash + size_t pos = 0; + if (!(baseuri.GetAuthStringLength() == 0) && baseuri.GetPathStringLength() == 0) { + resuri.path_[pos] = '/'; + pos++; + } + size_t lastslashpos = baseuri.GetPathStringLength(); + while (lastslashpos > 0) { + if (baseuri.path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + std::memcpy(&resuri.path_[pos], baseuri.path_, lastslashpos * sizeof(Ch)); + pos += lastslashpos; + resuri.query_ = CopyPart(&resuri.path_[pos], path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } + } + // Always use this frag + resuri.base_ = CopyPart(resuri.frag_, frag_, GetFragStringLength()); + + // Re-constitute base_ and uri_ + resuri.SetBase(); + resuri.uri_ = resuri.base_ + resuri.GetBaseStringLength() + 1; + resuri.SetUri(); + return resuri; + } + + //! Get the allocator of this GenericUri. + Allocator& GetAllocator() { return *allocator_; } + +private: + // Allocate memory for a URI + // Returns total amount allocated + std::size_t Allocate(std::size_t len) { + // Create own allocator if user did not supply. + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + // Allocate one block containing each part of the URI (5) plus base plus full URI, all null terminated. + // Order: scheme, auth, path, query, frag, base, uri + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + size_t total = (3 * len + 7) * sizeof(Ch); + scheme_ = static_cast(allocator_->Malloc(total)); + *scheme_ = '\0'; + auth_ = scheme_; + auth_++; + *auth_ = '\0'; + path_ = auth_; + path_++; + *path_ = '\0'; + query_ = path_; + query_++; + *query_ = '\0'; + frag_ = query_; + frag_++; + *frag_ = '\0'; + base_ = frag_; + base_++; + *base_ = '\0'; + uri_ = base_; + uri_++; + *uri_ = '\0'; + return total; + } + + // Free memory for a URI + void Free() { + if (scheme_) { + Allocator::Free(scheme_); + scheme_ = 0; + } + } + + // Parse a URI into constituent scheme, authority, path, query, & fragment parts + // Supports URIs that match regex ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? as per + // https://tools.ietf.org/html/rfc3986 + void Parse(const Ch* uri, std::size_t len) { + std::size_t start = 0, pos1 = 0, pos2 = 0; + Allocate(len); + + // Look for scheme ([^:/?#]+):)? + if (start < len) { + while (pos1 < len) { + if (uri[pos1] == ':') break; + pos1++; + } + if (pos1 != len) { + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (pos1 < pos2) { + pos1++; + std::memcpy(scheme_, &uri[start], pos1 * sizeof(Ch)); + scheme_[pos1] = '\0'; + start = pos1; + } + } + } + // Look for auth (//([^/?#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + auth_ = scheme_ + GetSchemeStringLength(); + auth_++; + *auth_ = '\0'; + if (start < len - 1 && uri[start] == '/' && uri[start + 1] == '/') { + pos2 = start + 2; + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + std::memcpy(auth_, &uri[start], (pos2 - start) * sizeof(Ch)); + auth_[pos2 - start] = '\0'; + start = pos2; + } + // Look for path ([^?#]*) + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + path_ = auth_ + GetAuthStringLength(); + path_++; + *path_ = '\0'; + if (start < len) { + pos2 = start; + while (pos2 < len) { + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(path_, &uri[start], (pos2 - start) * sizeof(Ch)); + path_[pos2 - start] = '\0'; + if (path_[0] == '/') + RemoveDotSegments(); // absolute path - normalize + start = pos2; + } + } + // Look for query (\?([^#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + query_ = path_ + GetPathStringLength(); + query_++; + *query_ = '\0'; + if (start < len && uri[start] == '?') { + pos2 = start + 1; + while (pos2 < len) { + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(query_, &uri[start], (pos2 - start) * sizeof(Ch)); + query_[pos2 - start] = '\0'; + start = pos2; + } + } + // Look for fragment (#(.*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + frag_ = query_ + GetQueryStringLength(); + frag_++; + *frag_ = '\0'; + if (start < len && uri[start] == '#') { + std::memcpy(frag_, &uri[start], (len - start) * sizeof(Ch)); + frag_[len - start] = '\0'; + } + + // Re-constitute base_ and uri_ + base_ = frag_ + GetFragStringLength() + 1; + SetBase(); + uri_ = base_ + GetBaseStringLength() + 1; + SetUri(); + } + + // Reconstitute base + void SetBase() { + Ch* next = base_; + std::memcpy(next, scheme_, GetSchemeStringLength() * sizeof(Ch)); + next+= GetSchemeStringLength(); + std::memcpy(next, auth_, GetAuthStringLength() * sizeof(Ch)); + next+= GetAuthStringLength(); + std::memcpy(next, path_, GetPathStringLength() * sizeof(Ch)); + next+= GetPathStringLength(); + std::memcpy(next, query_, GetQueryStringLength() * sizeof(Ch)); + next+= GetQueryStringLength(); + *next = '\0'; + } + + // Reconstitute uri + void SetUri() { + Ch* next = uri_; + std::memcpy(next, base_, GetBaseStringLength() * sizeof(Ch)); + next+= GetBaseStringLength(); + std::memcpy(next, frag_, GetFragStringLength() * sizeof(Ch)); + next+= GetFragStringLength(); + *next = '\0'; + } + + // Copy a part from one GenericUri to another + // Return the pointer to the next part to be copied to + Ch* CopyPart(Ch* to, Ch* from, std::size_t len) { + RAPIDJSON_ASSERT(to != 0); + RAPIDJSON_ASSERT(from != 0); + std::memcpy(to, from, len * sizeof(Ch)); + to[len] = '\0'; + Ch* next = to + len + 1; + return next; + } + + // Remove . and .. segments from the path_ member. + // https://tools.ietf.org/html/rfc3986 + // This is done in place as we are only removing segments. + void RemoveDotSegments() { + std::size_t pathlen = GetPathStringLength(); + std::size_t pathpos = 0; // Position in path_ + std::size_t newpos = 0; // Position in new path_ + + // Loop through each segment in original path_ + while (pathpos < pathlen) { + // Get next segment, bounded by '/' or end + size_t slashpos = 0; + while ((pathpos + slashpos) < pathlen) { + if (path_[pathpos + slashpos] == '/') break; + slashpos++; + } + // Check for .. and . segments + if (slashpos == 2 && path_[pathpos] == '.' && path_[pathpos + 1] == '.') { + // Backup a .. segment in the new path_ + // We expect to find a previously added slash at the end or nothing + RAPIDJSON_ASSERT(newpos == 0 || path_[newpos - 1] == '/'); + size_t lastslashpos = newpos; + // Make sure we don't go beyond the start segment + if (lastslashpos > 1) { + // Find the next to last slash and back up to it + lastslashpos--; + while (lastslashpos > 0) { + if (path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + // Set the new path_ position + newpos = lastslashpos; + } + } else if (slashpos == 1 && path_[pathpos] == '.') { + // Discard . segment, leaves new path_ unchanged + } else { + // Move any other kind of segment to the new path_ + RAPIDJSON_ASSERT(newpos <= pathpos); + std::memmove(&path_[newpos], &path_[pathpos], slashpos * sizeof(Ch)); + newpos += slashpos; + // Add slash if not at end + if ((pathpos + slashpos) < pathlen) { + path_[newpos] = '/'; + newpos++; + } + } + // Move to next segment + pathpos += slashpos + 1; + } + path_[newpos] = '\0'; + } + + Ch* uri_; // Everything + Ch* base_; // Everything except fragment + Ch* scheme_; // Includes the : + Ch* auth_; // Includes the // + Ch* path_; // Absolute if starts with / + Ch* query_; // Includes the ? + Ch* frag_; // Includes the # + + Allocator* allocator_; //!< The current allocator. It is either user-supplied or equal to ownAllocator_. + Allocator* ownAllocator_; //!< Allocator owned by this Uri. +}; + +//! GenericUri for Value (UTF-8, default allocator). +typedef GenericUri Uri; + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_URI_H_ diff --git a/contrib/rapidjson/include/rapidjson/writer.h b/contrib/rapidjson/include/rapidjson/writer.h index 8b389219a..632e02ce7 100644 --- a/contrib/rapidjson/include/rapidjson/writer.h +++ b/contrib/rapidjson/include/rapidjson/writer.h @@ -67,6 +67,7 @@ enum WriteFlag { kWriteNoFlags = 0, //!< No flags are set. kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings. kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN. + kWriteNanAndInfNullFlag = 4, //!< Allow writing of Infinity, -Infinity and NaN as null. kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS }; @@ -348,8 +349,13 @@ protected: bool WriteDouble(double d) { if (internal::Double(d).IsNanOrInf()) { - if (!(writeFlags & kWriteNanAndInfFlag)) + if (!(writeFlags & kWriteNanAndInfFlag) && !(writeFlags & kWriteNanAndInfNullFlag)) return false; + if (writeFlags & kWriteNanAndInfNullFlag) { + PutReserve(*os_, 4); + PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); + return true; + } if (internal::Double(d).IsNan()) { PutReserve(*os_, 3); PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N'); @@ -548,6 +554,11 @@ inline bool Writer::WriteDouble(double d) { // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag). if (!(kWriteDefaultFlags & kWriteNanAndInfFlag)) return false; + if (kWriteDefaultFlags & kWriteNanAndInfNullFlag) { + PutReserve(*os_, 4); + PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); + return true; + } if (internal::Double(d).IsNan()) { PutReserve(*os_, 3); PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N'); diff --git a/contrib/rapidjson/readme.md b/contrib/rapidjson/readme.md index b833a98e8..ac683b051 100644 --- a/contrib/rapidjson/readme.md +++ b/contrib/rapidjson/readme.md @@ -6,7 +6,7 @@ Tencent is pleased to support the open source community by making RapidJSON available. -Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. * [RapidJSON GitHub](https://github.com/Tencent/rapidjson/) * RapidJSON Documentation @@ -43,7 +43,7 @@ RapidJSON is a JSON parser and generator for C++. It was inspired by [RapidXml]( More features can be read [here](doc/features.md). -JSON(JavaScript Object Notation) is a light-weight data exchange format. RapidJSON should be in fully compliance with RFC7159/ECMA-404, with optional support of relaxed syntax. More information about JSON can be obtained at +JSON(JavaScript Object Notation) is a light-weight data exchange format. RapidJSON should be in full compliance with RFC7159/ECMA-404, with optional support of relaxed syntax. More information about JSON can be obtained at * [Introducing JSON](http://json.org/) * [RFC7159: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc7159) * [Standard ECMA-404: The JSON Data Interchange Format](https://www.ecma-international.org/publications/standards/Ecma-404.htm) @@ -72,6 +72,9 @@ Users can build and run the unit tests on their platform/compiler. RapidJSON is a header-only C++ library. Just copy the `include/rapidjson` folder to system or project's include path. +Alternatively, if you are using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager you can download and install rapidjson with CMake integration in a single command: +* vcpkg install rapidjson + RapidJSON uses following software as its dependencies: * [CMake](https://cmake.org/) as a general build tool * (optional) [Doxygen](http://www.doxygen.org) to build documentation @@ -158,3 +161,50 @@ More [examples](https://github.com/Tencent/rapidjson/tree/master/example) are av * [parsebyparts](https://github.com/Tencent/rapidjson/blob/master/example/parsebyparts/parsebyparts.cpp): Implements an `AsyncDocumentParser` which can parse JSON in parts, using C++11 thread. * [filterkey](https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp): A command line tool to remove all values with user-specified key. * [filterkeydom](https://github.com/Tencent/rapidjson/blob/master/example/filterkeydom/filterkeydom.cpp): Same tool as above, but it demonstrates how to use a generator to populate a `Document`. + +## Contributing + +RapidJSON welcomes contributions. When contributing, please follow the code below. + +### Issues + +Feel free to submit issues and enhancement requests. + +Please help us by providing **minimal reproducible examples**, because source code is easier to let other people understand what happens. +For crash problems on certain platforms, please bring stack dump content with the detail of the OS, compiler, etc. + +Please try breakpoint debugging first, tell us what you found, see if we can start exploring based on more information been prepared. + +### Workflow + +In general, we follow the "fork-and-pull" Git workflow. + + 1. **Fork** the repo on GitHub + 2. **Clone** the project to your own machine + 3. **Checkout** a new branch on your fork, start developing on the branch + 4. **Test** the change before commit, Make sure the changes pass all the tests, including `unittest` and `preftest`, please add test case for each new feature or bug-fix if needed. + 5. **Commit** changes to your own branch + 6. **Push** your work back up to your fork + 7. Submit a **Pull request** so that we can review your changes + +NOTE: Be sure to merge the latest from "upstream" before making a pull request! + +### Copyright and Licensing + +You can copy and paste the license summary from below. + +``` +Tencent is pleased to support the open source community by making RapidJSON available. + +Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. + +Licensed under the MIT License (the "License"); you may not use this file except +in compliance with the License. You may obtain a copy of the License at + +http://opensource.org/licenses/MIT + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +``` diff --git a/contrib/stb/stb_image.h b/contrib/stb/stb_image.h index 5e807a0a6..a632d5435 100644 --- a/contrib/stb/stb_image.h +++ b/contrib/stb/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.28 - public domain image loader - http://nothings.org/stb +/* stb_image - v2.29 - public domain image loader - http://nothings.org/stb no warranty implied; use at your own risk Do this: @@ -48,6 +48,7 @@ LICENSE RECENT REVISION HISTORY: + 2.29 (2023-05-xx) optimizations 2.28 (2023-01-29) many error fixes, security errors, just tons of stuff 2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes 2.26 (2020-07-13) many minor fixes @@ -1072,8 +1073,8 @@ static int stbi__addints_valid(int a, int b) return a <= INT_MAX - b; } -// returns 1 if the product of two signed shorts is valid, 0 on overflow. -static int stbi__mul2shorts_valid(short a, short b) +// returns 1 if the product of two ints fits in a signed short, 0 on overflow. +static int stbi__mul2shorts_valid(int a, int b) { if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid @@ -3384,13 +3385,13 @@ static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) return 1; } -static int stbi__skip_jpeg_junk_at_end(stbi__jpeg *j) +static stbi_uc stbi__skip_jpeg_junk_at_end(stbi__jpeg *j) { // some JPEGs have junk at end, skip over it but if we find what looks // like a valid marker, resume there while (!stbi__at_eof(j->s)) { - int x = stbi__get8(j->s); - while (x == 255) { // might be a marker + stbi_uc x = stbi__get8(j->s); + while (x == 0xff) { // might be a marker if (stbi__at_eof(j->s)) return STBI__MARKER_none; x = stbi__get8(j->s); if (x != 0x00 && x != 0xff) { @@ -4176,6 +4177,7 @@ typedef struct { stbi_uc *zbuffer, *zbuffer_end; int num_bits; + int hit_zeof_once; stbi__uint32 code_buffer; char *zout; @@ -4242,9 +4244,20 @@ stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) int b,s; if (a->num_bits < 16) { if (stbi__zeof(a)) { - return -1; /* report error for unexpected end of data. */ + if (!a->hit_zeof_once) { + // This is the first time we hit eof, insert 16 extra padding btis + // to allow us to keep going; if we actually consume any of them + // though, that is invalid data. This is caught later. + a->hit_zeof_once = 1; + a->num_bits += 16; // add 16 implicit zero bits + } else { + // We already inserted our extra 16 padding bits and are again + // out, this stream is actually prematurely terminated. + return -1; + } + } else { + stbi__fill_bits(a); } - stbi__fill_bits(a); } b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; if (b) { @@ -4309,6 +4322,13 @@ static int stbi__parse_huffman_block(stbi__zbuf *a) int len,dist; if (z == 256) { a->zout = zout; + if (a->hit_zeof_once && a->num_bits < 16) { + // The first time we hit zeof, we inserted 16 extra zero bits into our bit + // buffer so the decoder can just do its speculative decoding. But if we + // actually consumed any of those bits (which is the case when num_bits < 16), + // the stream actually read past the end so it is malformed. + return stbi__err("unexpected end","Corrupt PNG"); + } return 1; } if (z >= 286) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data @@ -4320,7 +4340,7 @@ static int stbi__parse_huffman_block(stbi__zbuf *a) dist = stbi__zdist_base[z]; if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG"); - if (zout + len > a->zout_end) { + if (len > a->zout_end - zout) { if (!stbi__zexpand(a, zout, len)) return 0; zout = a->zout; } @@ -4464,6 +4484,7 @@ static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) if (!stbi__parse_zlib_header(a)) return 0; a->num_bits = 0; a->code_buffer = 0; + a->hit_zeof_once = 0; do { final = stbi__zreceive(a,1); type = stbi__zreceive(a,2); @@ -4619,9 +4640,8 @@ enum { STBI__F_up=2, STBI__F_avg=3, STBI__F_paeth=4, - // synthetic filters used for first scanline to avoid needing a dummy row of 0s - STBI__F_avg_first, - STBI__F_paeth_first + // synthetic filter used for first scanline to avoid needing a dummy row of 0s + STBI__F_avg_first }; static stbi_uc first_row_filter[5] = @@ -4630,29 +4650,56 @@ static stbi_uc first_row_filter[5] = STBI__F_sub, STBI__F_none, STBI__F_avg_first, - STBI__F_paeth_first + STBI__F_sub // Paeth with b=c=0 turns out to be equivalent to sub }; static int stbi__paeth(int a, int b, int c) { - int p = a + b - c; - int pa = abs(p-a); - int pb = abs(p-b); - int pc = abs(p-c); - if (pa <= pb && pa <= pc) return a; - if (pb <= pc) return b; - return c; + // This formulation looks very different from the reference in the PNG spec, but is + // actually equivalent and has favorable data dependencies and admits straightforward + // generation of branch-free code, which helps performance significantly. + int thresh = c*3 - (a + b); + int lo = a < b ? a : b; + int hi = a < b ? b : a; + int t0 = (hi <= thresh) ? lo : c; + int t1 = (thresh <= lo) ? hi : t0; + return t1; } static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 }; +// adds an extra all-255 alpha channel +// dest == src is legal +// img_n must be 1 or 3 +static void stbi__create_png_alpha_expand8(stbi_uc *dest, stbi_uc *src, stbi__uint32 x, int img_n) +{ + int i; + // must process data backwards since we allow dest==src + if (img_n == 1) { + for (i=x-1; i >= 0; --i) { + dest[i*2+1] = 255; + dest[i*2+0] = src[i]; + } + } else { + STBI_ASSERT(img_n == 3); + for (i=x-1; i >= 0; --i) { + dest[i*4+3] = 255; + dest[i*4+2] = src[i*3+2]; + dest[i*4+1] = src[i*3+1]; + dest[i*4+0] = src[i*3+0]; + } + } +} + // create the png data from post-deflated data static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) { - int bytes = (depth == 16? 2 : 1); + int bytes = (depth == 16 ? 2 : 1); stbi__context *s = a->s; stbi__uint32 i,j,stride = x*out_n*bytes; stbi__uint32 img_len, img_width_bytes; + stbi_uc *filter_buf; + int all_ok = 1; int k; int img_n = s->img_n; // copy it into a local for later @@ -4664,8 +4711,11 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into if (!a->out) return stbi__err("outofmem", "Out of memory"); + // note: error exits here don't need to clean up a->out individually, + // stbi__do_png always does on error. if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG"); img_width_bytes = (((img_n * x * depth) + 7) >> 3); + if (!stbi__mad2sizes_valid(img_width_bytes, y, img_width_bytes)) return stbi__err("too large", "Corrupt PNG"); img_len = (img_width_bytes + 1) * y; // we used to check for exact match between raw_len and img_len on non-interlaced PNGs, @@ -4673,189 +4723,137 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r // so just check for raw_len < img_len always. if (raw_len < img_len) return stbi__err("not enough pixels","Corrupt PNG"); + // Allocate two scan lines worth of filter workspace buffer. + filter_buf = (stbi_uc *) stbi__malloc_mad2(img_width_bytes, 2, 0); + if (!filter_buf) return stbi__err("outofmem", "Out of memory"); + + // Filtering for low-bit-depth images + if (depth < 8) { + filter_bytes = 1; + width = img_width_bytes; + } + for (j=0; j < y; ++j) { - stbi_uc *cur = a->out + stride*j; - stbi_uc *prior; + // cur/prior filter buffers alternate + stbi_uc *cur = filter_buf + (j & 1)*img_width_bytes; + stbi_uc *prior = filter_buf + (~j & 1)*img_width_bytes; + stbi_uc *dest = a->out + stride*j; + int nk = width * filter_bytes; int filter = *raw++; - if (filter > 4) - return stbi__err("invalid filter","Corrupt PNG"); - - if (depth < 8) { - if (img_width_bytes > x) return stbi__err("invalid width","Corrupt PNG"); - cur += x*out_n - img_width_bytes; // store output to the rightmost img_len bytes, so we can decode in place - filter_bytes = 1; - width = img_width_bytes; + // check filter type + if (filter > 4) { + all_ok = stbi__err("invalid filter","Corrupt PNG"); + break; } - prior = cur - stride; // bugfix: need to compute this after 'cur +=' computation above // if first row, use special filter that doesn't sample previous row if (j == 0) filter = first_row_filter[filter]; - // handle first byte explicitly - for (k=0; k < filter_bytes; ++k) { - switch (filter) { - case STBI__F_none : cur[k] = raw[k]; break; - case STBI__F_sub : cur[k] = raw[k]; break; - case STBI__F_up : cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; - case STBI__F_avg : cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); break; - case STBI__F_paeth : cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(0,prior[k],0)); break; - case STBI__F_avg_first : cur[k] = raw[k]; break; - case STBI__F_paeth_first: cur[k] = raw[k]; break; - } + // perform actual filtering + switch (filter) { + case STBI__F_none: + memcpy(cur, raw, nk); + break; + case STBI__F_sub: + memcpy(cur, raw, filter_bytes); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); + break; + case STBI__F_up: + for (k = 0; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + prior[k]); + break; + case STBI__F_avg: + for (k = 0; k < filter_bytes; ++k) + cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); + break; + case STBI__F_paeth: + for (k = 0; k < filter_bytes; ++k) + cur[k] = STBI__BYTECAST(raw[k] + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0) + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes], prior[k], prior[k-filter_bytes])); + break; + case STBI__F_avg_first: + memcpy(cur, raw, filter_bytes); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); + break; } - if (depth == 8) { - if (img_n != out_n) - cur[img_n] = 255; // first pixel - raw += img_n; - cur += out_n; - prior += out_n; - } else if (depth == 16) { - if (img_n != out_n) { - cur[filter_bytes] = 255; // first pixel top byte - cur[filter_bytes+1] = 255; // first pixel bottom byte - } - raw += filter_bytes; - cur += output_bytes; - prior += output_bytes; - } else { - raw += 1; - cur += 1; - prior += 1; - } + raw += nk; - // this is a little gross, so that we don't switch per-pixel or per-component - if (depth < 8 || img_n == out_n) { - int nk = (width - 1)*filter_bytes; - #define STBI__CASE(f) \ - case f: \ - for (k=0; k < nk; ++k) - switch (filter) { - // "none" filter turns into a memcpy here; make that explicit. - case STBI__F_none: memcpy(cur, raw, nk); break; - STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); } break; - STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; - STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); } break; - STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); } break; - STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); } break; - STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],0,0)); } break; - } - #undef STBI__CASE - raw += nk; - } else { - STBI_ASSERT(img_n+1 == out_n); - #define STBI__CASE(f) \ - case f: \ - for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \ - for (k=0; k < filter_bytes; ++k) - switch (filter) { - STBI__CASE(STBI__F_none) { cur[k] = raw[k]; } break; - STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); } break; - STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; - STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); } break; - STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); } break; - STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); } break; - STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],0,0)); } break; - } - #undef STBI__CASE - - // the loop above sets the high byte of the pixels' alpha, but for - // 16 bit png files we also need the low byte set. we'll do that here. - if (depth == 16) { - cur = a->out + stride*j; // start at the beginning of the row again - for (i=0; i < x; ++i,cur+=output_bytes) { - cur[filter_bytes+1] = 255; - } - } - } - } - - // we make a separate pass to expand bits to pixels; for performance, - // this could run two scanlines behind the above code, so it won't - // intefere with filtering but will still be in the cache. - if (depth < 8) { - for (j=0; j < y; ++j) { - stbi_uc *cur = a->out + stride*j; - stbi_uc *in = a->out + stride*j + x*out_n - img_width_bytes; - // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit - // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop + // expand decoded bits in cur to dest, also adding an extra alpha channel if desired + if (depth < 8) { stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range + stbi_uc *in = cur; + stbi_uc *out = dest; + stbi_uc inb = 0; + stbi__uint32 nsmp = x*img_n; - // note that the final byte might overshoot and write more data than desired. - // we can allocate enough data that this never writes out of memory, but it - // could also overwrite the next scanline. can it overwrite non-empty data - // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel. - // so we need to explicitly clamp the final ones - + // expand bits to bytes first if (depth == 4) { - for (k=x*img_n; k >= 2; k-=2, ++in) { - *cur++ = scale * ((*in >> 4) ); - *cur++ = scale * ((*in ) & 0x0f); + for (i=0; i < nsmp; ++i) { + if ((i & 1) == 0) inb = *in++; + *out++ = scale * (inb >> 4); + inb <<= 4; } - if (k > 0) *cur++ = scale * ((*in >> 4) ); } else if (depth == 2) { - for (k=x*img_n; k >= 4; k-=4, ++in) { - *cur++ = scale * ((*in >> 6) ); - *cur++ = scale * ((*in >> 4) & 0x03); - *cur++ = scale * ((*in >> 2) & 0x03); - *cur++ = scale * ((*in ) & 0x03); + for (i=0; i < nsmp; ++i) { + if ((i & 3) == 0) inb = *in++; + *out++ = scale * (inb >> 6); + inb <<= 2; } - if (k > 0) *cur++ = scale * ((*in >> 6) ); - if (k > 1) *cur++ = scale * ((*in >> 4) & 0x03); - if (k > 2) *cur++ = scale * ((*in >> 2) & 0x03); - } else if (depth == 1) { - for (k=x*img_n; k >= 8; k-=8, ++in) { - *cur++ = scale * ((*in >> 7) ); - *cur++ = scale * ((*in >> 6) & 0x01); - *cur++ = scale * ((*in >> 5) & 0x01); - *cur++ = scale * ((*in >> 4) & 0x01); - *cur++ = scale * ((*in >> 3) & 0x01); - *cur++ = scale * ((*in >> 2) & 0x01); - *cur++ = scale * ((*in >> 1) & 0x01); - *cur++ = scale * ((*in ) & 0x01); + } else { + STBI_ASSERT(depth == 1); + for (i=0; i < nsmp; ++i) { + if ((i & 7) == 0) inb = *in++; + *out++ = scale * (inb >> 7); + inb <<= 1; } - if (k > 0) *cur++ = scale * ((*in >> 7) ); - if (k > 1) *cur++ = scale * ((*in >> 6) & 0x01); - if (k > 2) *cur++ = scale * ((*in >> 5) & 0x01); - if (k > 3) *cur++ = scale * ((*in >> 4) & 0x01); - if (k > 4) *cur++ = scale * ((*in >> 3) & 0x01); - if (k > 5) *cur++ = scale * ((*in >> 2) & 0x01); - if (k > 6) *cur++ = scale * ((*in >> 1) & 0x01); } - if (img_n != out_n) { - int q; - // insert alpha = 255 - cur = a->out + stride*j; + + // insert alpha=255 values if desired + if (img_n != out_n) + stbi__create_png_alpha_expand8(dest, dest, x, img_n); + } else if (depth == 8) { + if (img_n == out_n) + memcpy(dest, cur, x*img_n); + else + stbi__create_png_alpha_expand8(dest, cur, x, img_n); + } else if (depth == 16) { + // convert the image data from big-endian to platform-native + stbi__uint16 *dest16 = (stbi__uint16*)dest; + stbi__uint32 nsmp = x*img_n; + + if (img_n == out_n) { + for (i = 0; i < nsmp; ++i, ++dest16, cur += 2) + *dest16 = (cur[0] << 8) | cur[1]; + } else { + STBI_ASSERT(img_n+1 == out_n); if (img_n == 1) { - for (q=x-1; q >= 0; --q) { - cur[q*2+1] = 255; - cur[q*2+0] = cur[q]; + for (i = 0; i < x; ++i, dest16 += 2, cur += 2) { + dest16[0] = (cur[0] << 8) | cur[1]; + dest16[1] = 0xffff; } } else { STBI_ASSERT(img_n == 3); - for (q=x-1; q >= 0; --q) { - cur[q*4+3] = 255; - cur[q*4+2] = cur[q*3+2]; - cur[q*4+1] = cur[q*3+1]; - cur[q*4+0] = cur[q*3+0]; + for (i = 0; i < x; ++i, dest16 += 4, cur += 6) { + dest16[0] = (cur[0] << 8) | cur[1]; + dest16[1] = (cur[2] << 8) | cur[3]; + dest16[2] = (cur[4] << 8) | cur[5]; + dest16[3] = 0xffff; } } } } - } else if (depth == 16) { - // force the image data from big-endian to platform-native. - // this is done in a separate pass due to the decoding relying - // on the data being untouched, but could probably be done - // per-line during decode if care is taken. - stbi_uc *cur = a->out; - stbi__uint16 *cur16 = (stbi__uint16*)cur; - - for(i=0; i < x*y*out_n; ++i,cur16++,cur+=2) { - *cur16 = (cur[0] << 8) | cur[1]; - } } + STBI_FREE(filter_buf); + if (!all_ok) return 0; + return 1; } diff --git a/contrib/unzip/crypt.h b/contrib/unzip/crypt.h index 1cc41f19d..f4b93b78d 100644 --- a/contrib/unzip/crypt.h +++ b/contrib/unzip/crypt.h @@ -32,8 +32,7 @@ /*********************************************************************** * Return the next byte in the pseudo-random sequence */ -static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) -{ +static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) { unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an * unpredictable manner on 16-bit systems; not a problem * with any known compiler so far, though */ @@ -46,8 +45,7 @@ static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) /*********************************************************************** * Update the encryption keys with the next byte of plain text */ -static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) -{ +static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) { (*(pkeys+0)) = CRC32((*(pkeys+0)), c); (*(pkeys+1)) += (*(pkeys+0)) & 0xff; (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; @@ -63,8 +61,7 @@ static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) * Initialize the encryption keys and the random header according to * the given password. */ -static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab) -{ +static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) { *(pkeys+0) = 305419896L; *(pkeys+1) = 591751049L; *(pkeys+2) = 878082192L; @@ -93,8 +90,7 @@ static unsigned crypthead(const char* passwd, /* password string */ int bufSize, unsigned long* pkeys, const z_crc_t* pcrc_32_tab, - unsigned long crcForCrypting) -{ + unsigned long crcForCrypting) { unsigned n; /* index in random header */ int t; /* temporary */ int c; /* random byte */ diff --git a/contrib/unzip/ioapi.c b/contrib/unzip/ioapi.c index 0ca29db6a..782d32469 100644 --- a/contrib/unzip/ioapi.c +++ b/contrib/unzip/ioapi.c @@ -14,7 +14,7 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#if defined(__APPLE__) || defined(IOAPI_NO_64) +#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions #define FOPEN_FUNC(filename, mode) fopen(filename, mode) #define FTELLO_FUNC(stream) ftello(stream) @@ -28,8 +28,7 @@ #include "ioapi.h" -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) { if (pfilefunc->zfile_func64.zopen64_file != NULL) return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); else @@ -38,8 +37,7 @@ voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename } } -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) { if (pfilefunc->zfile_func64.zseek64_file != NULL) return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); else @@ -52,8 +50,7 @@ long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZP } } -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) { if (pfilefunc->zfile_func64.zseek64_file != NULL) return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); else @@ -66,11 +63,9 @@ ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream } } -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) { p_filefunc64_32->zfile_func64.zopen64_file = NULL; p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; p_filefunc64_32->zfile_func64.ztell64_file = NULL; @@ -84,16 +79,7 @@ void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ +static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) { FILE* file = NULL; const char* mode_fopen = NULL; (void)opaque; @@ -111,8 +97,7 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in return file; } -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ +static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) { FILE* file = NULL; const char* mode_fopen = NULL; (void)opaque; @@ -131,24 +116,21 @@ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, } -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ +static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) { uLong ret; (void)opaque; ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); return ret; } -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ +static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) { uLong ret; (void)opaque; ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); return ret; } -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ +static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) { long ret; (void)opaque; ret = ftell((FILE *)stream); @@ -156,16 +138,14 @@ static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) } -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ +static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) { ZPOS64_T ret; (void)opaque; ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream); return ret; } -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ +static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) { int fseek_origin=0; long ret; (void)opaque; @@ -188,8 +168,7 @@ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs return ret; } -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ +static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { int fseek_origin=0; long ret; (void)opaque; @@ -208,31 +187,28 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T } ret = 0; - if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0) + if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0) ret = -1; return ret; } -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ +static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) { int ret; (void)opaque; ret = fclose((FILE *)stream); return ret; } -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ +static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) { int ret; (void)opaque; ret = ferror((FILE *)stream); return ret; } -void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def) -{ +void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen_file = fopen_file_func; pzlib_filefunc_def->zread_file = fread_file_func; pzlib_filefunc_def->zwrite_file = fwrite_file_func; @@ -243,8 +219,7 @@ void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def) pzlib_filefunc_def->opaque = NULL; } -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ +void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) { pzlib_filefunc_def->zopen64_file = fopen64_file_func; pzlib_filefunc_def->zread_file = fread_file_func; pzlib_filefunc_def->zwrite_file = fwrite_file_func; diff --git a/contrib/unzip/ioapi.h b/contrib/unzip/ioapi.h index 548dafb5e..a2d2e6e60 100644 --- a/contrib/unzip/ioapi.h +++ b/contrib/unzip/ioapi.h @@ -50,7 +50,7 @@ #define ftello64 ftell #define fseeko64 fseek #else -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) #define fopen64 fopen #define ftello64 ftello #define fseeko64 fseeko @@ -82,7 +82,7 @@ #include "mz64conf.h" #endif -/* a type choosen by DEFINE */ +/* a type chosen by DEFINE */ #ifdef HAVE_64BIT_INT_CUSTOM typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; #else @@ -134,17 +134,17 @@ extern "C" { -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); +typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode); +typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size); +typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size); +typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream); +typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream); -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); +typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream); +typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin); -/* here is the "old" 32 bits structure structure */ +/* here is the "old" 32 bits structure */ typedef struct zlib_filefunc_def_s { open_file_func zopen_file; @@ -157,9 +157,9 @@ typedef struct zlib_filefunc_def_s voidpf opaque; } zlib_filefunc_def; -typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream); +typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin); +typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void* filename, int mode); typedef struct zlib_filefunc64_def_s { @@ -173,8 +173,8 @@ typedef struct zlib_filefunc64_def_s voidpf opaque; } zlib_filefunc64_def; -void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); +void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def); +void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def); /* now internal definition, only for zip.c and unzip.h */ typedef struct zlib_filefunc64_32_def_s @@ -193,11 +193,11 @@ typedef struct zlib_filefunc64_32_def_s #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) -voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); -long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); -ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); +voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode); +long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin); +ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream); -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) diff --git a/contrib/unzip/unzip.c b/contrib/unzip/unzip.c index e703549d2..ea05b7d62 100644 --- a/contrib/unzip/unzip.c +++ b/contrib/unzip/unzip.c @@ -49,12 +49,12 @@ Copyright (C) 2007-2008 Even Rouault - Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G should only read the compressed/uncompressed size from the Zip64 format if the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required) Patch created by Daniel Borca Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer @@ -77,8 +77,6 @@ #ifdef STDC # include -# include -# include #endif #ifdef NO_ERRNO_H extern int errno; @@ -111,9 +109,6 @@ #ifndef ALLOC # define ALLOC(size) (malloc(size)) #endif -#ifndef TRYFREE -# define TRYFREE(p) { free(p);} -#endif #define SIZECENTRALDIRITEM (0x2e) #define SIZEZIPLOCALHEADER (0x1e) @@ -122,7 +117,7 @@ const char unz_copyright[] = " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; -/* unz_file_info_interntal contain internal info about a file in zipfile*/ +/* unz_file_info64_internal contain internal info about a file in zipfile*/ typedef struct unz_file_info64_internal_s { ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ @@ -153,7 +148,7 @@ typedef struct ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ uLong compression_method; /* compression method (0==store) */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ int raw; @@ -166,7 +161,7 @@ typedef struct { zlib_filefunc64_32_def z_filefunc; int is64bitOpenFunction; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ unz_global_info64 gi; /* public global information */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ ZPOS64_T num_file; /* number of the current file in the zipfile*/ @@ -197,29 +192,44 @@ typedef struct #include "crypt.h" #endif + /* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been successfully opened for reading. + Reads a long in LSB order from the given gz_stream. Sets */ - -local int unz64local_getByte OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) +local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) { + unsigned char c[2]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2); + if (err==2) { - *pi = (int)c; + *pX = c[0] | ((uLong)c[1] << 8); return UNZ_OK; } else { + *pX = 0; + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + +local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) { + unsigned char c[4]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4); + if (err==4) + { + *pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24); + return UNZ_OK; + } + else + { + *pX = 0; if (ZERROR64(*pzlib_filefunc_def,filestream)) return UNZ_ERRNO; else @@ -228,126 +238,29 @@ local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, v } -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unz64local_getShort OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; +local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX) { + unsigned char c[8]; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8); + if (err==8) + { + *pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24) + | ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56); + return UNZ_OK; + } else + { *pX = 0; - return err; -} - -local int unz64local_getLong OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX)); - - -local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX) -{ - ZPOS64_T x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<24; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<32; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<40; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<48; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<56; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } } /* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) -{ +local int strcmpcasenosensitive_internal(const char* fileName1, const char* fileName2) { for (;;) { char c1=*(fileName1++); @@ -379,19 +292,17 @@ local int strcmpcasenosensitive_internal (const char* fileName1, const char* fil #endif /* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + Compare two filenames (fileName1,fileName2). + If iCaseSensitivity = 1, comparison is case sensitive (like strcmp) + If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSensitivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, - const char* fileName2, - int iCaseSensitivity) - -{ + const char* fileName2, + int iCaseSensitivity) { if (iCaseSensitivity==0) iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; @@ -405,21 +316,23 @@ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, #define BUFREADCOMMENT (0x400) #endif +#ifndef CENTRALDIRINVALID +#define CENTRALDIRINVALID ((ZPOS64_T)(-1)) +#endif + /* Locate the Central directory of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) { unsigned char* buf; ZPOS64_T uSizeFile; ZPOS64_T uBackRead; ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; + ZPOS64_T uPosFound=CENTRALDIRINVALID; if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; + return CENTRALDIRINVALID; uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); @@ -429,7 +342,7 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); if (buf==NULL) - return 0; + return CENTRALDIRINVALID; uBackRead = 4; while (uBackReadz_filefunc, s->filestream); - TRYFREE(s); + free(s); return UNZ_OK; } @@ -825,8 +727,7 @@ extern int ZEXPORT unzClose (unzFile file) Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) -{ +extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info) { unz64_s* s; if (file==NULL) return UNZ_PARAMERROR; @@ -835,8 +736,7 @@ extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_ return UNZ_OK; } -extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) -{ +extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) { unz64_s* s; if (file==NULL) return UNZ_PARAMERROR; @@ -847,10 +747,9 @@ extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info return UNZ_OK; } /* - Translate date/time from Dos format to tm_unz (readable more easilty) + Translate date/time from Dos format to tm_unz (readable more easily) */ -local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) -{ +local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz* ptm) { ZPOS64_T uDate; uDate = (ZPOS64_T)(ulDosDate>>16); ptm->tm_mday = (int)(uDate&0x1f) ; @@ -865,28 +764,16 @@ local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) /* Get Info about the current file in the zipfile, with internal only info */ -local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unz64local_GetCurrentFileInfoInternal (unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize) -{ +local int unz64local_GetCurrentFileInfoInternal(unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) { unz64_s* s; unz_file_info64 file_info; unz_file_info64_internal file_info_internal; @@ -1038,33 +925,31 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file, /* ZIP64 extra fields */ if (headerId == 0x0001) { - uLong uL1; + if(file_info.uncompressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info.uncompressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.compressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info.compressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info_internal.offset_curfile == MAXU32) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info_internal.offset_curfile == MAXU32) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.disk_num_start == MAXU32) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL1) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.disk_num_start == 0xffff) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + } } else @@ -1121,24 +1006,22 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file, No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, - unz_file_info64 * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ +extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, + unz_file_info64 * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) { return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); } -extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, - unz_file_info * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ +extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, + unz_file_info * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) { int err; unz_file_info64 file_info64; err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, @@ -1162,7 +1045,7 @@ extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, pfile_info->internal_fa = file_info64.internal_fa; pfile_info->external_fa = file_info64.external_fa; - pfile_info->tmu_date = file_info64.tmu_date, + pfile_info->tmu_date = file_info64.tmu_date; pfile_info->compressed_size = (uLong)file_info64.compressed_size; @@ -1175,8 +1058,7 @@ extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, Set the current file of the zipfile to the first file. return UNZ_OK if there is no problem */ -extern int ZEXPORT unzGoToFirstFile (unzFile file) -{ +extern int ZEXPORT unzGoToFirstFile(unzFile file) { int err=UNZ_OK; unz64_s* s; if (file==NULL) @@ -1196,8 +1078,7 @@ extern int ZEXPORT unzGoToFirstFile (unzFile file) return UNZ_OK if there is no problem return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. */ -extern int ZEXPORT unzGoToNextFile (unzFile file) -{ +extern int ZEXPORT unzGoToNextFile(unzFile file) { unz64_s* s; int err; @@ -1229,8 +1110,7 @@ extern int ZEXPORT unzGoToNextFile (unzFile file) UNZ_OK if the file is found. It becomes the current file. UNZ_END_OF_LIST_OF_FILE if the file is not found */ -extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) -{ +extern int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) { unz64_s* s; int err; @@ -1305,8 +1185,7 @@ typedef struct unz_file_pos_s } unz_file_pos; */ -extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) -{ +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) { unz64_s* s; if (file==NULL || file_pos==NULL) @@ -1321,10 +1200,7 @@ extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) return UNZ_OK; } -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos) -{ +extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos) { unz64_file_pos file_pos64; int err = unzGetFilePos64(file,&file_pos64); if (err==UNZ_OK) @@ -1335,8 +1211,7 @@ extern int ZEXPORT unzGetFilePos( return err; } -extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) -{ +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) { unz64_s* s; int err; @@ -1357,10 +1232,7 @@ extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos return err; } -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos) -{ +extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos) { unz64_file_pos file_pos64; if (file_pos == NULL) return UNZ_PARAMERROR; @@ -1382,10 +1254,9 @@ extern int ZEXPORT unzGoToFilePos( store in *piSizeVar the size of extra info in local header (filename and size of extra field data) */ -local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, - ZPOS64_T * poffset_local_extrafield, - uInt * psize_local_extrafield) -{ +local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar, + ZPOS64_T * poffset_local_extrafield, + uInt * psize_local_extrafield) { uLong uMagic,uData,uFlags; uLong size_filename; uLong size_extra_field; @@ -1469,9 +1340,8 @@ local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVa Open for reading data the current file in the zipfile. If there is no error and the file is opened, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, - int* level, int raw, const char* password) -{ +extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, + int* level, int raw, const char* password) { int err=UNZ_OK; uInt iSizeVar; unz64_s* s; @@ -1509,7 +1379,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, if (pfile_in_zip_read_info->read_buffer==NULL) { - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info); return UNZ_INTERNALERROR; } @@ -1566,8 +1436,8 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; else { - TRYFREE(pfile_in_zip_read_info->read_buffer); - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info); return err; } #else @@ -1587,8 +1457,8 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; else { - TRYFREE(pfile_in_zip_read_info->read_buffer); - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info); return err; } /* windowBits is passed < 0 to tell that there is no zlib header. @@ -1640,25 +1510,21 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, return UNZ_OK; } -extern int ZEXPORT unzOpenCurrentFile (unzFile file) -{ +extern int ZEXPORT unzOpenCurrentFile(unzFile file) { return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); } -extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) -{ +extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password) { return unzOpenCurrentFile3(file, NULL, NULL, 0, password); } -extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) -{ +extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw) { return unzOpenCurrentFile3(file, method, level, raw, NULL); } /** Addition for GDAL : START */ -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) -{ +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; s=(unz64_s*)file; @@ -1678,13 +1544,12 @@ extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ -extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) -{ +extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { int err=UNZ_OK; uInt iRead = 0; unz64_s* s; @@ -1891,8 +1756,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) /* Give the current position in uncompressed data */ -extern z_off_t ZEXPORT unztell (unzFile file) -{ +extern z_off_t ZEXPORT unztell(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; if (file==NULL) @@ -1906,8 +1770,7 @@ extern z_off_t ZEXPORT unztell (unzFile file) return (z_off_t)pfile_in_zip_read_info->stream.total_out; } -extern ZPOS64_T ZEXPORT unztell64 (unzFile file) -{ +extern ZPOS64_T ZEXPORT unztell64(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; @@ -1926,8 +1789,7 @@ extern ZPOS64_T ZEXPORT unztell64 (unzFile file) /* return 1 if the end of file was reached, 0 elsewhere */ -extern int ZEXPORT unzeof (unzFile file) -{ +extern int ZEXPORT unzeof(unzFile file) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; if (file==NULL) @@ -1958,8 +1820,7 @@ more info in the local-header version than in the central-header) the return value is the number of bytes copied in buf, or (if <0) the error code */ -extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) -{ +extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) { unz64_s* s; file_in_zip64_read_info_s* pfile_in_zip_read_info; uInt read_now; @@ -2006,8 +1867,7 @@ extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) Close the file in zip opened with unzOpenCurrentFile Return UNZ_CRCERROR if all the file was read but the CRC is not good */ -extern int ZEXPORT unzCloseCurrentFile (unzFile file) -{ +extern int ZEXPORT unzCloseCurrentFile(unzFile file) { int err=UNZ_OK; unz64_s* s; @@ -2029,7 +1889,7 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file) } - TRYFREE(pfile_in_zip_read_info->read_buffer); + free(pfile_in_zip_read_info->read_buffer); pfile_in_zip_read_info->read_buffer = NULL; if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) inflateEnd(&pfile_in_zip_read_info->stream); @@ -2040,7 +1900,7 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file) pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info); s->pfile_in_zip_read=NULL; @@ -2053,8 +1913,7 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file) uSizeBuf is the size of the szComment buffer. return the number of byte copied or an error code <0 */ -extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) -{ +extern int ZEXPORT unzGetGlobalComment(unzFile file, char * szComment, uLong uSizeBuf) { unz64_s* s; uLong uReadThis ; if (file==NULL) @@ -2081,8 +1940,7 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uS } /* Additions by RX '2004 */ -extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) -{ +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) { unz64_s* s; if (file==NULL) @@ -2096,8 +1954,7 @@ extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) return s->pos_in_central_dir; } -extern uLong ZEXPORT unzGetOffset (unzFile file) -{ +extern uLong ZEXPORT unzGetOffset(unzFile file) { ZPOS64_T offset64; if (file==NULL) @@ -2106,8 +1963,7 @@ extern uLong ZEXPORT unzGetOffset (unzFile file) return (uLong)offset64; } -extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) -{ +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) { unz64_s* s; int err; @@ -2124,7 +1980,6 @@ extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) return err; } -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) -{ +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) { return unzSetOffset64(file,pos); } diff --git a/contrib/unzip/unzip.h b/contrib/unzip/unzip.h index 6f95e94d7..5cfc9c627 100644 --- a/contrib/unzip/unzip.h +++ b/contrib/unzip/unzip.h @@ -150,21 +150,21 @@ typedef struct unz_file_info_s tm_unz tmu_date; } unz_file_info; -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); +extern int ZEXPORT unzStringFileNameCompare(const char* fileName1, + const char* fileName2, + int iCaseSensitivity); /* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + Compare two filenames (fileName1,fileName2). + If iCaseSensitivity = 1, comparison is case sensitive (like strcmp) + If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSensitivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ -extern unzFile ZEXPORT unzOpen OF((const char *path)); -extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +extern unzFile ZEXPORT unzOpen(const char *path); +extern unzFile ZEXPORT unzOpen64(const void *path); /* Open a Zip file. path contain the full pathname (by example, on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer @@ -181,41 +181,41 @@ extern unzFile ZEXPORT unzOpen64 OF((const void *path)); */ -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); +extern unzFile ZEXPORT unzOpen2(const char *path, + zlib_filefunc_def* pzlib_filefunc_def); /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write the zip file (see ioapi.h) */ -extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); +extern unzFile ZEXPORT unzOpen2_64(const void *path, + zlib_filefunc64_def* pzlib_filefunc_def); /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write the zip file (see ioapi.h) */ -extern int ZEXPORT unzClose OF((unzFile file)); +extern int ZEXPORT unzClose(unzFile file); /* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile (see later), these files MUST be closed with unzCloseCurrentFile before call unzClose. return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); +extern int ZEXPORT unzGetGlobalInfo(unzFile file, + unz_global_info *pglobal_info); -extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); +extern int ZEXPORT unzGetGlobalInfo64(unzFile file, + unz_global_info64 *pglobal_info); /* Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); +extern int ZEXPORT unzGetGlobalComment(unzFile file, + char *szComment, + uLong uSizeBuf); /* Get the global comment string of the ZipFile, in the szComment buffer. uSizeBuf is the size of the szComment buffer. @@ -226,22 +226,22 @@ extern int ZEXPORT unzGetGlobalComment OF((unzFile file, /***************************************************************************/ /* Unzip package allow you browse the directory of the zipfile */ -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +extern int ZEXPORT unzGoToFirstFile(unzFile file); /* Set the current file of the zipfile to the first file. return UNZ_OK if there is no problem */ -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +extern int ZEXPORT unzGoToNextFile(unzFile file); /* Set the current file of the zipfile to the next file. return UNZ_OK if there is no problem return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. */ -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); +extern int ZEXPORT unzLocateFile(unzFile file, + const char *szFileName, + int iCaseSensitivity); /* Try locate the file szFileName in the zipfile. For the iCaseSensitivity signification, see unzStringFileNameCompare @@ -285,28 +285,28 @@ extern int ZEXPORT unzGoToFilePos64( /* ****************************************** */ -extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); +extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize); -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); +extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize); /* Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about + if pfile_info!=NULL, the *pfile_info structure will contain some info about the current file - if szFileName!=NULL, the filemane string will be copied in szFileName + if szFileName!=NULL, the filename string will be copied in szFileName (fileNameBufferSize is the size of the buffer) if extraField!=NULL, the extra field information will be copied in extraField (extraFieldBufferSize is the size of the buffer). @@ -318,7 +318,7 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, /** Addition for GDAL : START */ -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file); /** Addition for GDAL : END */ @@ -328,24 +328,24 @@ extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); from it, and close it (you can close it before reading all the file) */ -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +extern int ZEXPORT unzOpenCurrentFile(unzFile file); /* Open for reading data the current file in the zipfile. If there is no error, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); +extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, + const char* password); /* Open for reading data the current file in the zipfile. password is a crypting password If there is no error, the return value is UNZ_OK. */ -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); +extern int ZEXPORT unzOpenCurrentFile2(unzFile file, + int* method, + int* level, + int raw); /* Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) if raw==1 @@ -355,11 +355,11 @@ extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, but you CANNOT set method parameter as NULL */ -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); +extern int ZEXPORT unzOpenCurrentFile3(unzFile file, + int* method, + int* level, + int raw, + const char* password); /* Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) if raw==1 @@ -370,41 +370,41 @@ extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, */ -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +extern int ZEXPORT unzCloseCurrentFile(unzFile file); /* Close the file in zip opened with unzOpenCurrentFile Return UNZ_CRCERROR if all the file was read but the CRC is not good */ -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); +extern int ZEXPORT unzReadCurrentFile(unzFile file, + voidp buf, + unsigned len); /* Read bytes from the current file (opened by unzOpenCurrentFile) buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ -extern z_off_t ZEXPORT unztell OF((unzFile file)); +extern z_off_t ZEXPORT unztell(unzFile file); -extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +extern ZPOS64_T ZEXPORT unztell64(unzFile file); /* Give the current position in uncompressed data */ -extern int ZEXPORT unzeof OF((unzFile file)); +extern int ZEXPORT unzeof(unzFile file); /* return 1 if the end of file was reached, 0 elsewhere */ -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); +extern int ZEXPORT unzGetLocalExtrafield(unzFile file, + voidp buf, + unsigned len); /* Read extra field from the current file (opened by unzOpenCurrentFile) This is the local-header version of the extra field (sometimes, there is diff --git a/contrib/zlib/CMakeLists.txt b/contrib/zlib/CMakeLists.txt index e7897d6a1..0e4906cea 100644 --- a/contrib/zlib/CMakeLists.txt +++ b/contrib/zlib/CMakeLists.txt @@ -198,9 +198,11 @@ endif(MINGW) add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -INSTALL( TARGETS zlibstatic - EXPORT "${TARGETS_EXPORT_NAME}" - LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} - COMPONENT ${LIBASSIMP_COMPONENT}) +IF(ASSIMP_INSTALL) + INSTALL( TARGETS zlibstatic + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} + COMPONENT ${LIBASSIMP_COMPONENT}) +ENDIF() diff --git a/doc/Fileformats.md b/doc/Fileformats.md index 118d798f2..6fc0fe34c 100644 --- a/doc/Fileformats.md +++ b/doc/Fileformats.md @@ -12,7 +12,6 @@ __Importers__: - ASE - ASK - B3D -- [BLEND](https://en.wikipedia.org/wiki/.blend_(file_format)) - [BVH](https://en.wikipedia.org/wiki/Biovision_Hierarchy) - CSM - COB @@ -29,6 +28,7 @@ __Importers__: + KHR_texture_transform ( 5.1 under test ) - HMB - IFC-STEP +- IQM - IRR / IRRMESH - [LWO](https://en.wikipedia.org/wiki/LightWave_3D) - LWS @@ -66,6 +66,9 @@ __Importers__: - XGL - ZGL +Note: support for [BLEND](https://en.wikipedia.org/wiki/.blend_(file_format)) is deprecated. +It is too time-consuming to maintain an undocumented format which contains so much more than we need. + Additionally, some formats are supported by dependency on non-free code or external SDKs (not built by default): - [C4D](https://en.wikipedia.org/wiki/Cinema_4D) (https://github.com/assimp/assimp/wiki/Cinema4D-&-Melange) IMporting geometry + node hierarchy are currently supported diff --git a/doc/dox.h b/doc/dox.h index 1d5f59aa4..2fb127a2b 100644 --- a/doc/dox.h +++ b/doc/dox.h @@ -1545,7 +1545,7 @@ Don't trust the input data! Check all offsets! Mixed stuff for internal use by loaders, mostly documented (most of them are already included by AssimpPCH.h):
  • ByteSwapper (ByteSwapper.h) - manual byte swapping stuff for binary loaders.
  • -
  • StreamReader (StreamReader.h) - safe, endianess-correct, binary reading.
  • +
  • StreamReader (StreamReader.h) - safe, endianness-correct, binary reading.
  • IrrXML (irrXMLWrapper.h) - for XML-parsing (SAX.
  • CommentRemover (RemoveComments.h) - remove single-line and multi-line comments from a text file.
  • fast_atof, strtoul10, strtoul16, SkipSpaceAndLineEnd, SkipToNextToken .. large family of low-level diff --git a/fuzz/assimp_fuzzer.cc b/fuzz/assimp_fuzzer.cc index e347f59cb..8178674e8 100644 --- a/fuzz/assimp_fuzzer.cc +++ b/fuzz/assimp_fuzzer.cc @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Base64.hpp b/include/assimp/Base64.hpp index 10288713c..6a3551307 100644 --- a/include/assimp/Base64.hpp +++ b/include/assimp/Base64.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index f9df32b32..447784e75 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -95,7 +95,7 @@ public: BaseImporter() AI_NO_EXCEPT; /** Destructor, private as well */ - virtual ~BaseImporter(); + virtual ~BaseImporter() = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/include/assimp/Bitmap.h b/include/assimp/Bitmap.h index 2678b5f64..5145a6cd5 100644 --- a/include/assimp/Bitmap.h +++ b/include/assimp/Bitmap.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/BlobIOSystem.h b/include/assimp/BlobIOSystem.h index 7e8d46a53..eb23f9e92 100644 --- a/include/assimp/BlobIOSystem.h +++ b/include/assimp/BlobIOSystem.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/ByteSwapper.h b/include/assimp/ByteSwapper.h index 488f7a51d..73c115b8a 100644 --- a/include/assimp/ByteSwapper.h +++ b/include/assimp/ByteSwapper.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -66,10 +65,10 @@ namespace Assimp { * and vice versa. Direct use of this class is DEPRECATED. Use #StreamReader instead. */ // -------------------------------------------------------------------------------------- class ByteSwap { - ByteSwap() AI_NO_EXCEPT {} + ByteSwap() AI_NO_EXCEPT = default; + ~ByteSwap() = default; public: - // ---------------------------------------------------------------------- /** Swap two bytes of data * @param[inout] _szOut A void* to save the reintcasts for the caller. */ @@ -89,8 +88,7 @@ public: // ---------------------------------------------------------------------- /** Swap four bytes of data * @param[inout] _szOut A void* to save the reintcasts for the caller. */ - static inline void Swap4(void* _szOut) - { + static inline void Swap4(void* _szOut) { ai_assert(_szOut); #if _MSC_VER >= 1400 @@ -263,7 +261,7 @@ struct ByteSwapper { }; // -------------------------------------------------------------------------------------------- -template +template struct Getter { void operator() (T* inout, bool le) { #ifdef AI_BUILD_BIG_ENDIAN @@ -278,12 +276,12 @@ struct Getter { } }; -template -struct Getter { +template +struct Getter { void operator() (T* inout, bool /*le*/) { // static branch - ByteSwapper1)> () (inout); + ByteSwapper1)> () (inout); } }; } // end Intern diff --git a/include/assimp/ColladaMetaData.h b/include/assimp/ColladaMetaData.h index 52eb3c508..9973d16a5 100644 --- a/include/assimp/ColladaMetaData.h +++ b/include/assimp/ColladaMetaData.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/CreateAnimMesh.h b/include/assimp/CreateAnimMesh.h index e5211f504..6e14ac747 100644 --- a/include/assimp/CreateAnimMesh.h +++ b/include/assimp/CreateAnimMesh.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/DefaultIOStream.h b/include/assimp/DefaultIOStream.h index 67cba3c5c..c39d9a8e1 100644 --- a/include/assimp/DefaultIOStream.h +++ b/include/assimp/DefaultIOStream.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/DefaultIOSystem.h b/include/assimp/DefaultIOSystem.h index 8545e75cf..0aeef9eb8 100644 --- a/include/assimp/DefaultIOSystem.h +++ b/include/assimp/DefaultIOSystem.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/DefaultLogger.hpp b/include/assimp/DefaultLogger.hpp index 723097ff2..b43eebb70 100644 --- a/include/assimp/DefaultLogger.hpp +++ b/include/assimp/DefaultLogger.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Exceptional.h b/include/assimp/Exceptional.h index ec3d38c5a..b4b51863f 100644 --- a/include/assimp/Exceptional.h +++ b/include/assimp/Exceptional.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 09a459442..bdec20b97 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/GenericProperty.h b/include/assimp/GenericProperty.h index 073d53312..a35ebf23d 100644 --- a/include/assimp/GenericProperty.h +++ b/include/assimp/GenericProperty.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/GltfMaterial.h b/include/assimp/GltfMaterial.h index 86ca8897c..5e63b9132 100644 --- a/include/assimp/GltfMaterial.h +++ b/include/assimp/GltfMaterial.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Hash.h b/include/assimp/Hash.h index cf889362c..9dec87408 100644 --- a/include/assimp/Hash.h +++ b/include/assimp/Hash.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/IOStream.hpp b/include/assimp/IOStream.hpp index 12beb0dbb..1866a3d72 100644 --- a/include/assimp/IOStream.hpp +++ b/include/assimp/IOStream.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -73,14 +73,14 @@ class ASSIMP_API IOStream { protected: /** Constructor protected, use IOSystem::Open() to create an instance. */ - IOStream() AI_NO_EXCEPT; + IOStream() AI_NO_EXCEPT = default; public: // ------------------------------------------------------------------- /** @brief Destructor. Deleting the object closes the underlying file, * alternatively you may use IOSystem::Close() to release the file. */ - virtual ~IOStream(); + virtual ~IOStream() = default; // ------------------------------------------------------------------- /** @brief Read from the file @@ -126,15 +126,6 @@ public: virtual void Flush() = 0; }; //! class IOStream -// ---------------------------------------------------------------------------------- -AI_FORCE_INLINE -IOStream::IOStream() AI_NO_EXCEPT = default; - -// ---------------------------------------------------------------------------------- -AI_FORCE_INLINE -IOStream::~IOStream() = default; -// ---------------------------------------------------------------------------------- - } //!namespace Assimp #endif //!!AI_IOSTREAM_H_INC diff --git a/include/assimp/IOStreamBuffer.h b/include/assimp/IOStreamBuffer.h index 47db35a95..5a6924a09 100644 --- a/include/assimp/IOStreamBuffer.h +++ b/include/assimp/IOStreamBuffer.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -66,7 +66,7 @@ public: IOStreamBuffer(size_t cache = 4096 * 4096); /// @brief The class destructor. - ~IOStreamBuffer(); + ~IOStreamBuffer() = default; /// @brief Will open the cached access for a given stream. /// @param stream The stream to cache. @@ -140,9 +140,6 @@ AI_FORCE_INLINE IOStreamBuffer::IOStreamBuffer(size_t cache) : std::fill(m_cache.begin(), m_cache.end(), '\n'); } -template -AI_FORCE_INLINE IOStreamBuffer::~IOStreamBuffer() = default; - template AI_FORCE_INLINE bool IOStreamBuffer::open(IOStream *stream) { // file still opened! diff --git a/include/assimp/IOSystem.hpp b/include/assimp/IOSystem.hpp index 30f48b81c..b345151d5 100644 --- a/include/assimp/IOSystem.hpp +++ b/include/assimp/IOSystem.hpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -97,7 +97,7 @@ public: * Create an instance of your derived class and assign it to an * #Assimp::Importer instance by calling Importer::SetIOHandler(). */ - IOSystem() AI_NO_EXCEPT; + IOSystem() AI_NO_EXCEPT = default; // ------------------------------------------------------------------- /** @brief Virtual destructor. @@ -105,7 +105,7 @@ public: * It is safe to be called from within DLL Assimp, we're constructed * on Assimp's heap. */ - virtual ~IOSystem(); + virtual ~IOSystem() = default; // ------------------------------------------------------------------- /** @brief For backward compatibility @@ -236,12 +236,6 @@ private: std::vector m_pathStack; }; -// ---------------------------------------------------------------------------- -AI_FORCE_INLINE IOSystem::IOSystem() AI_NO_EXCEPT = default; - -// ---------------------------------------------------------------------------- -AI_FORCE_INLINE IOSystem::~IOSystem() = default; - // ---------------------------------------------------------------------------- // For compatibility, the interface of some functions taking a std::string was // changed to const char* to avoid crashes between binary incompatible STL diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index 418643f1f..a3a0d9eae 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/LineSplitter.h b/include/assimp/LineSplitter.h index 379821f03..635349dc0 100644 --- a/include/assimp/LineSplitter.h +++ b/include/assimp/LineSplitter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -86,7 +86,7 @@ public: */ LineSplitter(StreamReaderLE& stream, bool skip_empty_lines = true, bool trim = true); - ~LineSplitter(); + ~LineSplitter() = default; // ----------------------------------------- /** pseudo-iterator increment */ @@ -110,6 +110,8 @@ public: std::string operator* () const; + const char *getEnd() const; + // ----------------------------------------- /** boolean context */ operator bool() const; @@ -139,23 +141,25 @@ public: private: line_idx mIdx; std::string mCur; + const char *mEnd; StreamReaderLE& mStream; bool mSwallow, mSkip_empty_lines, mTrim; }; AI_FORCE_INLINE LineSplitter::LineSplitter(StreamReaderLE& stream, bool skip_empty_lines, bool trim ) : mIdx(0), + mCur(), + mEnd(nullptr), mStream(stream), mSwallow(), mSkip_empty_lines(skip_empty_lines), mTrim(trim) { mCur.reserve(1024); + mEnd = mCur.c_str() + 1024; operator++(); mIdx = 0; } -AI_FORCE_INLINE LineSplitter::~LineSplitter() = default; - AI_FORCE_INLINE LineSplitter& LineSplitter::operator++() { if (mSwallow) { mSwallow = false; @@ -203,14 +207,14 @@ AI_FORCE_INLINE LineSplitter &LineSplitter::operator++(int) { AI_FORCE_INLINE const char *LineSplitter::operator[] (size_t idx) const { const char* s = operator->()->c_str(); - SkipSpaces(&s); + SkipSpaces(&s, mEnd); for (size_t i = 0; i < idx; ++i) { for (; !IsSpace(*s); ++s) { if (IsLineEnd(*s)) { throw std::range_error("Token index out of range, EOL reached"); } } - SkipSpaces(&s); + SkipSpaces(&s, mEnd); } return s; } @@ -219,7 +223,7 @@ template AI_FORCE_INLINE void LineSplitter::get_tokens(const char* (&tokens)[N]) const { const char* s = operator->()->c_str(); - SkipSpaces(&s); + SkipSpaces(&s, mEnd); for (size_t i = 0; i < N; ++i) { if (IsLineEnd(*s)) { throw std::range_error("Token count out of range, EOL reached"); @@ -227,7 +231,7 @@ AI_FORCE_INLINE void LineSplitter::get_tokens(const char* (&tokens)[N]) const { tokens[i] = s; for (; *s && !IsSpace(*s); ++s); - SkipSpaces(&s); + SkipSpaces(&s, mEnd); } } @@ -239,6 +243,10 @@ AI_FORCE_INLINE std::string LineSplitter::operator* () const { return mCur; } +AI_FORCE_INLINE const char* LineSplitter::getEnd() const { + return mEnd; +} + AI_FORCE_INLINE LineSplitter::operator bool() const { return mStream.GetRemainingSize() > 0; } diff --git a/include/assimp/LogAux.h b/include/assimp/LogAux.h index a8cb8f24c..20a7564b8 100644 --- a/include/assimp/LogAux.h +++ b/include/assimp/LogAux.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/LogStream.hpp b/include/assimp/LogStream.hpp index 3b17b200a..2d9f1d350 100644 --- a/include/assimp/LogStream.hpp +++ b/include/assimp/LogStream.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index e8df64dd8..0051153e2 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/MathFunctions.h b/include/assimp/MathFunctions.h index f2a7ccdf6..eaa8b4ac4 100644 --- a/include/assimp/MathFunctions.h +++ b/include/assimp/MathFunctions.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/MemoryIOWrapper.h b/include/assimp/MemoryIOWrapper.h index 4023f7529..ef06af273 100644 --- a/include/assimp/MemoryIOWrapper.h +++ b/include/assimp/MemoryIOWrapper.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/NullLogger.hpp b/include/assimp/NullLogger.hpp index 1b594ea28..552bcf66a 100644 --- a/include/assimp/NullLogger.hpp +++ b/include/assimp/NullLogger.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/ObjMaterial.h b/include/assimp/ObjMaterial.h index 9c511916a..21087ebcb 100644 --- a/include/assimp/ObjMaterial.h +++ b/include/assimp/ObjMaterial.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/ParsingUtils.h b/include/assimp/ParsingUtils.h index 7e7fb161c..e0ee2d77c 100644 --- a/include/assimp/ParsingUtils.h +++ b/include/assimp/ParsingUtils.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -102,8 +102,8 @@ AI_FORCE_INLINE bool IsSpaceOrNewLine(char_t in) { // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out) { - while (*in == (char_t)' ' || *in == (char_t)'\t') { +AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out, const char_t *end) { + while ((*in == (char_t)' ' || *in == (char_t)'\t') && in != end) { ++in; } *out = in; @@ -112,19 +112,19 @@ AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out) { // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpaces(const char_t **inout) { - return SkipSpaces(*inout, inout); +AI_FORCE_INLINE bool SkipSpaces(const char_t **inout, const char_t *end) { + return SkipSpaces(*inout, inout, end); } // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out) { - while (*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0') { +AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out, const char_t *end) { + while ((*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0') && in != end) { ++in; } // files are opened in binary mode. Ergo there are both NL and CR - while (*in == (char_t)'\r' || *in == (char_t)'\n') { + while ((*in == (char_t)'\r' || *in == (char_t)'\n') && in != end) { ++in; } *out = in; @@ -133,14 +133,14 @@ AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out) { // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipLine(const char_t **inout) { - return SkipLine(*inout, inout); +AI_FORCE_INLINE bool SkipLine(const char_t **inout, const char_t *end) { + return SkipLine(*inout, inout, end); } // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out) { - while (*in == (char_t)' ' || *in == (char_t)'\t' || *in == (char_t)'\r' || *in == (char_t)'\n') { +AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out, const char_t *end) { + while ((*in == (char_t)' ' || *in == (char_t)'\t' || *in == (char_t)'\r' || *in == (char_t)'\n') && in != end) { ++in; } *out = in; @@ -149,8 +149,8 @@ AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out) // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t **inout) { - return SkipSpacesAndLineEnd(*inout, inout); +AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t **inout, const char_t *end) { + return SkipSpacesAndLineEnd(*inout, inout, end); } // --------------------------------------------------------------------------------- @@ -210,16 +210,16 @@ AI_FORCE_INLINE bool TokenMatchI(const char *&in, const char *token, unsigned in } // --------------------------------------------------------------------------------- -AI_FORCE_INLINE void SkipToken(const char *&in) { - SkipSpaces(&in); +AI_FORCE_INLINE void SkipToken(const char *&in, const char *end) { + SkipSpaces(&in, end); while (!IsSpaceOrNewLine(*in)) { ++in; } } // --------------------------------------------------------------------------------- -AI_FORCE_INLINE std::string GetNextToken(const char *&in) { - SkipSpacesAndLineEnd(&in); +AI_FORCE_INLINE std::string GetNextToken(const char *&in, const char *end) { + SkipSpacesAndLineEnd(&in, end); const char *cur = in; while (!IsSpaceOrNewLine(*in)) { ++in; diff --git a/include/assimp/Profiler.h b/include/assimp/Profiler.h index 3b9263b40..ff4f590c3 100644 --- a/include/assimp/Profiler.h +++ b/include/assimp/Profiler.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index 93d881659..2a1ab309c 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/RemoveComments.h b/include/assimp/RemoveComments.h index c2defff63..a7a9a2381 100644 --- a/include/assimp/RemoveComments.h +++ b/include/assimp/RemoveComments.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SGSpatialSort.h b/include/assimp/SGSpatialSort.h index 96feefabb..13a214d44 100644 --- a/include/assimp/SGSpatialSort.h +++ b/include/assimp/SGSpatialSort.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -63,10 +62,8 @@ namespace Assimp { * implementation to handle all details of its file format correctly. */ // ---------------------------------------------------------------------------------- -class ASSIMP_API SGSpatialSort -{ +class ASSIMP_API SGSpatialSort { public: - SGSpatialSort(); // ------------------------------------------------------------------- @@ -90,7 +87,7 @@ public: void Prepare(); /** Destructor */ - ~SGSpatialSort(); + ~SGSpatialSort() = default; // ------------------------------------------------------------------- /** Returns an iterator for all positions close to the given position. diff --git a/include/assimp/SceneCombiner.h b/include/assimp/SceneCombiner.h index d6096900c..790a18c2d 100644 --- a/include/assimp/SceneCombiner.h +++ b/include/assimp/SceneCombiner.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SkeletonMeshBuilder.h b/include/assimp/SkeletonMeshBuilder.h index 2929aaa61..620748632 100644 --- a/include/assimp/SkeletonMeshBuilder.h +++ b/include/assimp/SkeletonMeshBuilder.h @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h index 60ad26411..8e8e2db5f 100644 --- a/include/assimp/SmallVector.h +++ b/include/assimp/SmallVector.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SmoothingGroups.h b/include/assimp/SmoothingGroups.h index 4625a2916..e77a8b2d9 100644 --- a/include/assimp/SmoothingGroups.h +++ b/include/assimp/SmoothingGroups.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SmoothingGroups.inl b/include/assimp/SmoothingGroups.inl index d5fff5bf7..6de5ee997 100644 --- a/include/assimp/SmoothingGroups.inl +++ b/include/assimp/SmoothingGroups.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/SpatialSort.h b/include/assimp/SpatialSort.h index cd055450e..e527b15a2 100644 --- a/include/assimp/SpatialSort.h +++ b/include/assimp/SpatialSort.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/StandardShapes.h b/include/assimp/StandardShapes.h index 77880cf9e..aad2ce395 100644 --- a/include/assimp/StandardShapes.h +++ b/include/assimp/StandardShapes.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/StreamReader.h b/include/assimp/StreamReader.h index 44b24a33b..cc74bd652 100644 --- a/include/assimp/StreamReader.h +++ b/include/assimp/StreamReader.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -68,7 +68,7 @@ namespace Assimp { * * XXX switch from unsigned int for size types to size_t? or ptrdiff_t?*/ // -------------------------------------------------------------------------------------------- -template +template class StreamReader { public: using diff = size_t; @@ -84,7 +84,7 @@ public: * reads from the current position to the end of the stream. * @param le If @c RuntimeSwitch is true: specifies whether the * stream is in little endian byte order. Otherwise the - * endianness information is contained in the @c SwapEndianess + * endianness information is contained in the @c SwapEndianness * template parameter and this parameter is meaningless. */ StreamReader(std::shared_ptr stream, bool le = false) : mStream(stream), @@ -291,7 +291,7 @@ public: T f; ::memcpy(&f, mCurrent, sizeof(T)); - Intern::Getter()(&f, mLe); + Intern::Getter()(&f, mLe); mCurrent += sizeof(T); return f; diff --git a/include/assimp/StreamWriter.h b/include/assimp/StreamWriter.h index 50e28447c..32da6911b 100644 --- a/include/assimp/StreamWriter.h +++ b/include/assimp/StreamWriter.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -65,7 +65,7 @@ namespace Assimp { * stream is to be determined at runtime. */ // -------------------------------------------------------------------------------------------- -template +template class StreamWriter { enum { INITIAL_CAPACITY = 1024 @@ -82,7 +82,7 @@ public: continues at the current position of the stream cursor. * @param le If @c RuntimeSwitch is true: specifies whether the * stream is in little endian byte order. Otherwise the - * endianness information is defined by the @c SwapEndianess + * endianness information is defined by the @c SwapEndianness * template parameter and this parameter is meaningless. */ StreamWriter(std::shared_ptr stream, bool le = false) : stream(stream) @@ -260,7 +260,7 @@ public: /** Generic write method. ByteSwap::Swap(T*) *must* be defined */ template void Put(T f) { - Intern :: Getter() (&f, le); + Intern :: Getter() (&f, le); if (cursor + sizeof(T) >= buffer.size()) { buffer.resize(cursor + sizeof(T)); diff --git a/include/assimp/StringComparison.h b/include/assimp/StringComparison.h index 0518d426d..283d8ba6b 100644 --- a/include/assimp/StringComparison.h +++ b/include/assimp/StringComparison.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index cd8726785..0af923902 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Subdivision.h b/include/assimp/Subdivision.h index 114120368..75f44cbb5 100644 --- a/include/assimp/Subdivision.h +++ b/include/assimp/Subdivision.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/TinyFormatter.h b/include/assimp/TinyFormatter.h index df2a32eca..387fc86b6 100644 --- a/include/assimp/TinyFormatter.h +++ b/include/assimp/TinyFormatter.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/Vertex.h b/include/assimp/Vertex.h index 3fc974504..62a531ce2 100644 --- a/include/assimp/Vertex.h +++ b/include/assimp/Vertex.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/XMLTools.h b/include/assimp/XMLTools.h index b2766f19b..fa27af134 100644 --- a/include/assimp/XMLTools.h +++ b/include/assimp/XMLTools.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 4ab42ba2a..4c19098a4 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/ZipArchiveIOSystem.h b/include/assimp/ZipArchiveIOSystem.h index 9f3a4783b..8145e98f8 100644 --- a/include/assimp/ZipArchiveIOSystem.h +++ b/include/assimp/ZipArchiveIOSystem.h @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -55,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include namespace Assimp { diff --git a/include/assimp/aabb.h b/include/assimp/aabb.h index b38aa1697..bd78e67a6 100644 --- a/include/assimp/aabb.h +++ b/include/assimp/aabb.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -59,18 +59,12 @@ struct aiAABB { #ifdef __cplusplus /// @brief The default class constructor. - aiAABB() : - mMin(), mMax() { - // empty - } + aiAABB() = default; /// @brief The class constructor with the minimum and maximum. /// @param min The minimum dimension. /// @param max The maximum dimension. - aiAABB(const aiVector3D &min, const aiVector3D &max) : - mMin(min), mMax(max) { - // empty - } + aiAABB(const aiVector3D &min, const aiVector3D &max) : mMin(min), mMax(max) {} /// @brief The class destructor. ~aiAABB() = default; diff --git a/include/assimp/ai_assert.h b/include/assimp/ai_assert.h index e49a482dd..e4d43f31c 100644 --- a/include/assimp/ai_assert.h +++ b/include/assimp/ai_assert.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/anim.h b/include/assimp/anim.h index 49f0d5014..4e29fa0c0 100644 --- a/include/assimp/anim.h +++ b/include/assimp/anim.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -90,6 +90,7 @@ struct aiVectorKey { bool operator==(const aiVectorKey &rhs) const { return rhs.mValue == this->mValue; } + bool operator!=(const aiVectorKey &rhs) const { return rhs.mValue != this->mValue; } diff --git a/include/assimp/camera.h b/include/assimp/camera.h index 09255fa05..b8ea59927 100644 --- a/include/assimp/camera.h +++ b/include/assimp/camera.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/cexport.h b/include/assimp/cexport.h index a45ece39b..175fe5ea4 100644 --- a/include/assimp/cexport.h +++ b/include/assimp/cexport.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/cfileio.h b/include/assimp/cfileio.h index fc1b95ad1..bd971957c 100644 --- a/include/assimp/cfileio.h +++ b/include/assimp/cfileio.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index 935ed18bd..b0b4e038a 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/color4.h b/include/assimp/color4.h index e1e354939..cdd61e451 100644 --- a/include/assimp/color4.h +++ b/include/assimp/color4.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/color4.inl b/include/assimp/color4.inl index aed3de6f1..7fd067758 100644 --- a/include/assimp/color4.inl +++ b/include/assimp/color4.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/commonMetaData.h b/include/assimp/commonMetaData.h index ccded585b..53d2f37aa 100644 --- a/include/assimp/commonMetaData.h +++ b/include/assimp/commonMetaData.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index cb46d8057..897eecb19 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -225,6 +225,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_CONFIG_PP_PTV_ROOT_TRANSFORMATION \ "PP_PTV_ROOT_TRANSFORMATION" +// --------------------------------------------------------------------------- +/** @brief Set epsilon to check the identity of the matrix 4x4. + * + * This is used by aiMatrix4x4t::IsIdentity(const TReal epsilon). + * @note The default value is 10e-3f for backward compatibility of legacy code. + * Property type: Float. + */ +#define AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON \ + "CHECK_IDENTITY_MATRIX_EPSILON" + +// default value for AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON +#if (!defined AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT) +# define AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT 10e-3f +#endif + // --------------------------------------------------------------------------- /** @brief Configures the #aiProcess_FindDegenerates step to * remove degenerated primitives from the import - immediately. @@ -1098,6 +1113,16 @@ enum aiComponent #define AI_CONFIG_EXPORT_GLTF_UNLIMITED_SKINNING_BONES_PER_VERTEX \ "USE_UNLIMITED_BONES_PER VERTEX" +/** @brief Specifies whether to write the value referenced to opacity in TransparencyFactor of each material. + * + * When this flag is not defined, the TransparencyFactor value of each meterial is 1.0. + * By enabling this flag, the value is 1.0 - opacity; + + * Property type: Bool. Default value: false. + */ +#define AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY \ + "EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY" + /** * @brief Specifies the blob name, assimp uses for exporting. * diff --git a/include/assimp/defs.h b/include/assimp/defs.h index e1aaafd44..6a971928d 100644 --- a/include/assimp/defs.h +++ b/include/assimp/defs.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/importerdesc.h b/include/assimp/importerdesc.h index d08bd1781..e26751049 100644 --- a/include/assimp/importerdesc.h +++ b/include/assimp/importerdesc.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/light.h b/include/assimp/light.h index 3331997a9..3233cec70 100644 --- a/include/assimp/light.h +++ b/include/assimp/light.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/material.h b/include/assimp/material.h index 80551e53d..30db265e8 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/material.inl b/include/assimp/material.inl index b7222f9c7..fdf837db4 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/matrix3x3.h b/include/assimp/matrix3x3.h index 74382e263..a49394ea4 100644 --- a/include/assimp/matrix3x3.h +++ b/include/assimp/matrix3x3.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/matrix3x3.inl b/include/assimp/matrix3x3.inl index 99d9197e3..c41a5a076 100644 --- a/include/assimp/matrix3x3.inl +++ b/include/assimp/matrix3x3.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/matrix4x4.h b/include/assimp/matrix4x4.h index 67e0e356e..861a7acef 100644 --- a/include/assimp/matrix4x4.h +++ b/include/assimp/matrix4x4.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef __cplusplus @@ -136,9 +137,13 @@ public: // ------------------------------------------------------------------- /** @brief Returns true of the matrix is the identity matrix. + * @param epsilon Value of epsilon. Default value is 10e-3 for backward + * compatibility with legacy code. + * @return Returns true of the matrix is the identity matrix. * The check is performed against a not so small epsilon. */ - inline bool IsIdentity() const; + inline bool IsIdentity(const TReal + epsilon = AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT) const; // ------------------------------------------------------------------- /** @brief Decompose a trafo matrix into its original components diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index 54d176d18..56f7296e5 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -242,7 +242,7 @@ aiMatrix4x4t& aiMatrix4x4t::Inverse() { const TReal det = Determinant(); if(det == static_cast(0.0)) { - // Matrix not invertible. Setting all elements to nan is not really + // Matrix is not invertible. Setting all elements to nan is not really // correct in a mathematical sense but it is easy to debug for the // programmer. const TReal nan = std::numeric_limits::quiet_NaN(); @@ -545,10 +545,7 @@ aiMatrix4x4t& aiMatrix4x4t::FromEulerAnglesXYZ(TReal x, TReal y, T // ---------------------------------------------------------------------------------------- template AI_FORCE_INLINE -bool aiMatrix4x4t::IsIdentity() const { - // Use a small epsilon to solve floating-point inaccuracies - const static TReal epsilon = 10e-3f; - +bool aiMatrix4x4t::IsIdentity(const TReal epsilon) const { return (a2 <= epsilon && a2 >= -epsilon && a3 <= epsilon && a3 >= -epsilon && a4 <= epsilon && a4 >= -epsilon && @@ -657,7 +654,7 @@ aiMatrix4x4t& aiMatrix4x4t::Scaling( const aiVector3t& v, a /** A function for creating a rotation matrix that rotates a vector called * "from" into another vector called "to". * Input : from[3], to[3] which both must be *normalized* non-zero vectors - * Output: mtx[3][3] -- a 3x3 matrix in colum-major form + * Output: mtx[3][3] -- a 3x3 matrix in column-major form * Authors: Tomas Möller, John Hughes * "Efficiently Building a Matrix to Rotate One Vector to Another" * Journal of Graphics Tools, 4(4):1-4, 1999 diff --git a/include/assimp/mesh.h b/include/assimp/mesh.h index 45f50d5a5..ed9a8faf9 100644 --- a/include/assimp/mesh.h +++ b/include/assimp/mesh.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index c766d0ae2..8d387ca00 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/pbrmaterial.h b/include/assimp/pbrmaterial.h index 3bdf151a3..172d2b8cb 100644 --- a/include/assimp/pbrmaterial.h +++ b/include/assimp/pbrmaterial.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/postprocess.h b/include/assimp/postprocess.h index a905a8be0..962d500f8 100644 --- a/include/assimp/postprocess.h +++ b/include/assimp/postprocess.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/qnan.h b/include/assimp/qnan.h index c64cabaad..2c071320f 100644 --- a/include/assimp/qnan.h +++ b/include/assimp/qnan.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index 7ab3ad6f8..457c650aa 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -45,14 +45,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_QUATERNION_H_INC #define AI_QUATERNION_H_INC +#include + #ifdef __cplusplus #ifdef __GNUC__ # pragma GCC system_header #endif -#include - // Forward declarations template class aiVector3t; template class aiMatrix3x3t; diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index 2cb24653c..d3e391331 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/include/assimp/scene.h b/include/assimp/scene.h index 1b830a5b0..86ab9bf60 100644 --- a/include/assimp/scene.h +++ b/include/assimp/scene.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/texture.h b/include/assimp/texture.h index 576fa7711..53837fc86 100644 --- a/include/assimp/texture.h +++ b/include/assimp/texture.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/types.h b/include/assimp/types.h index 42aa0f9eb..ea72dd996 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -523,6 +523,23 @@ struct aiMemoryInfo { unsigned int total; }; // !struct aiMemoryInfo +/** + * @brief Type to store a in-memory data buffer. + */ +struct aiBuffer { + const char *data; ///< Begin poiner + const char *end; ///< End pointer + +#ifdef __cplusplus + /// @brief The class constructor. + aiBuffer() : + data(nullptr), end(nullptr) {} + + /// @brief The class destructor. + ~aiBuffer() = default; +#endif //! __cplusplus +}; + #ifdef __cplusplus } #endif //! __cplusplus diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index f06e9441d..a8bfddba2 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 245eb3190..a5592ea31 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index eb940e7f9..c09fe9b08 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index 28ca2be07..c42e4cf32 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/include/assimp/version.h b/include/assimp/version.h index 812be551c..f7bcf5bbf 100644 --- a/include/assimp/version.h +++ b/include/assimp/version.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/packaging/windows-mkzip/bin_readme.txt b/packaging/windows-mkzip/bin_readme.txt deleted file mode 100644 index f4402d6bf..000000000 --- a/packaging/windows-mkzip/bin_readme.txt +++ /dev/null @@ -1,29 +0,0 @@ - ------------------------------------------------------------------------------------- -Open Asset Import Library (Assimp) Tools/Binaries for Windows -Release Notes ------------------------------------------------------------------------------------- - - -Known Bugs & Limitations -======================== - -Viewer - -- For files more than one embedded texture, only the first is loaded. -- Normals appear flipped from time to time when either of the normals-related menu items was hit. -- Alpha-sorting is implemented, but still causes artifacts when models are moved quickly. -- Several important texture file formats (such as GIF) are not supported. -- HUD is blurred on the right side. ATI/AMD hardware only. - -Troubleshooting -=============== - -1. Missing d3dx9_42.dll? -Install the latest DirectX runtime or grab the file from somewhere (that's evil but mostly fine). - -2. Application configuration not correct / missing msv*** DLLs? -(Re)install Microsoft Visual C++ 2005 SP1 Redistributable (x86 or x64, depending on your system) - -3. Crashes immediately -You CPU lacks SSE2 support. Build Assimp from scratch to suit your CPU, sorry. diff --git a/packaging/windows-mkzip/mkfinal.bat b/packaging/windows-mkzip/mkfinal.bat deleted file mode 100644 index b626514c0..000000000 --- a/packaging/windows-mkzip/mkfinal.bat +++ /dev/null @@ -1,169 +0,0 @@ - -rem ----------------------------------------------------- -rem Batch file to build zipped redist packages -rem Two different packages are built: -rem -rem assimp---bin.zip -rem Binaries for x86 and x64 -rem Command line reference -rem -rem assimp---sdk.zip -rem Binaries for x86 and x64, Debug & Release -rem Libs for DLL build, x86 & 64, Debug & Release -rem Full SVN checkout exluding mkutil & port -rem -rem -rem PREREQUISITES: -rem -7za.exe (7zip standalone) -rem Download from http://www.7-zip.org/download.html -rem -rem -svnversion.exe (Subversion revision getter) -rem Download any command line SVN package -rem -rem -doxygen.exe (Doxygen client) -rem Download from www.doxygen.com -rem -rem -svn client -rem -rem NOTES: -rem ./bin must not have any local modifications -rem -rem ----------------------------------------------------- - -@echo off -color 4e -cls - -rem ----------------------------------------------------- -rem Setup file revision for build -rem ----------------------------------------------------- -call mkrev.bat - -rem ----------------------------------------------------- -rem Build output file names -rem ----------------------------------------------------- - -cd ..\..\bin -svnversion > tmpfile.txt -SET /p REVISIONBASE= < tmpfile.txt -DEL /q tmpfile.txt -cd ..\packaging\windows-mkzip - -SET VERSIONBASE=2.0.%REVISIONBASE% - -SET OUT_SDK=assimp--%VERSIONBASE%-sdk -SET OUT_BIN=assimp--%VERSIONBASE%-bin - -SET BINCFG_x86=release-dll_win32 -SET BINCFG_x64=release-dll_x64 - -SET BINCFG_x86_DEBUG=debug-dll_win32 -SET BINCFG_x64_DEBUG=debug-dll_x64 - -rem ----------------------------------------------------- -rem Delete previous output directories -rem ----------------------------------------------------- -RD /S /q final\ - -rem ----------------------------------------------------- -rem Create output directories -rem ----------------------------------------------------- - -mkdir final\%OUT_BIN%\x86 -mkdir final\%OUT_BIN%\x64 - -rem ----------------------------------------------------- -rem Copy all executables to 'final-bin' -rem ----------------------------------------------------- - -copy /Y ..\..\bin\assimpview_%BINCFG_x86%\assimp_view.exe "final\%OUT_BIN%\x86\assimp_view.exe" -copy /Y ..\..\bin\assimpview_%BINCFG_x64%\assimp_view.exe "final\%OUT_BIN%\x64\assimp_view.exe" - -copy /Y ..\..\bin\assimpcmd_%BINCFG_x86%\assimp.exe "final\%OUT_BIN%\x86\assimp.exe" -copy /Y ..\..\bin\assimpcmd_%BINCFG_x64%\assimp.exe "final\%OUT_BIN%\x64\assimp.exe" - -copy /Y ..\..\bin\assimp_%BINCFG_x86%\Assimp32.dll "final\%OUT_BIN%\x86\Assimp32.dll" -copy /Y ..\..\bin\assimp_%BINCFG_x64%\Assimp64.dll "final\%OUT_BIN%\x64\Assimp64.dll" - -copy ..\..\LICENSE final\%OUT_BIN%\LICENSE -copy ..\..\CREDITS final\%OUT_BIN%\CREDITS -copy bin_readme.txt final\%OUT_BIN%\README -copy bin_readme.txt final\%OUT_BIN%\README - -copy ..\..\doc\AssimpCmdDoc_Html\AssimpCmdDoc.chm final\%OUT_BIN%\CommandLine.chm - -rem ----------------------------------------------------- -rem Do a clean export of the repository and build SDK -rem -rem We take the current revision and remove some stuff -rem that is nto yet ready to be published. -rem ----------------------------------------------------- - -svn export .\..\..\ .\final\%OUT_SDK% - -mkdir final\%OUT_SDK%\doc\assimp_html -mkdir final\%OUT_SDK%\doc\assimpcmd_html -copy .\..\..\doc\AssimpDoc_Html\* final\%OUT_SDK%\doc\assimp_html -copy .\..\..\doc\AssimpCmdDoc_Html\* final\%OUT_SDK%\doc\assimpcmd_html -del final\%OUT_SDK%\doc\assimpcmd_html\AssimpCmdDoc.chm -del final\%OUT_SDK%\doc\assimp_html\AssimpDoc.chm - -rem Copy doc to a suitable place -move final\%OUT_SDK%\doc\AssimpDoc_Html\AssimpDoc.chm final\%OUT_SDK%\Documentation.chm -move final\%OUT_SDK%\doc\AssimpCmdDoc_Html\AssimpCmdDoc.chm final\%OUT_SDK%\CommandLine.chm - -rem Cleanup ./doc folder -del /q final\%OUT_SDK%\doc\Preamble.txt -RD /s /q final\%OUT_SDK%\doc\AssimpDoc_Html -RD /s /q final\%OUT_SDK%\doc\AssimpCmdDoc_Html - -rem Insert 'dummy' files into empty folders -echo. > final\%OUT_SDK%\lib\dummy -echo. > final\%OUT_SDK%\obj\dummy - - -RD /s /q final\%OUT_SDK%\port\swig - -rem Also, repackaging is not a must-have feature -RD /s /q final\%OUT_SDK%\packaging - -rem Copy prebuilt libs -mkdir "final\%OUT_SDK%\lib\assimp_%BINCFG_x86%" -mkdir "final\%OUT_SDK%\lib\assimp_%BINCFG_x64%" -mkdir "final\%OUT_SDK%\lib\assimp_%BINCFG_x86_DEBUG%" -mkdir "final\%OUT_SDK%\lib\assimp_%BINCFG_x64_DEBUG%" - -copy /Y ..\..\lib\assimp_%BINCFG_x86%\assimp.lib "final\%OUT_SDK%\lib\assimp_%BINCFG_x86%" -copy /Y ..\..\lib\assimp_%BINCFG_x64%\assimp.lib "final\%OUT_SDK%\lib\assimp_%BINCFG_x64%\" -copy /Y ..\..\lib\assimp_%BINCFG_x86_DEBUG%\assimp.lib "final\%OUT_SDK%\lib\assimp_%BINCFG_x86_DEBUG%\" -copy /Y ..\..\lib\assimp_%BINCFG_x64_DEBUG%\assimp.lib "final\%OUT_SDK%\lib\assimp_%BINCFG_x64_DEBUG%\" - -rem Copy prebuilt DLLs -mkdir "final\%OUT_SDK%\bin\assimp_%BINCFG_x86%" -mkdir "final\%OUT_SDK%\bin\assimp_%BINCFG_x64%" -mkdir "final\%OUT_SDK%\bin\assimp_%BINCFG_x86_DEBUG%" -mkdir "final\%OUT_SDK%\bin\assimp_%BINCFG_x64_DEBUG%" - - -copy /Y ..\..\bin\assimp_%BINCFG_x86%\Assimp32.dll "final\%OUT_SDK%\bin\assimp_%BINCFG_x86%\" -copy /Y ..\..\bin\assimp_%BINCFG_x64%\Assimp64.dll "final\%OUT_SDK%\bin\assimp_%BINCFG_x64%\" -copy /Y ..\..\bin\assimp_%BINCFG_x86_DEBUG%\Assimp32d.dll "final\%OUT_SDK%\bin\assimp_%BINCFG_x86_DEBUG%\" -copy /Y ..\..\bin\assimp_%BINCFG_x64_DEBUG%\Assimp64d.dll "final\%OUT_SDK%\bin\assimp_%BINCFG_x64_DEBUG%\" - - -rem ----------------------------------------------------- -rem Make final-bin.zip and final-sdk.zip -rem ----------------------------------------------------- - -IF NOT EXIST 7za.exe ( - cls - echo You need to have 7zip standalone installed to - echo build ZIP archives. Download: http://www.7-zip.org/download.html - pause -) else ( -7za.exe a -tzip "final\%OUT_BIN%.zip" ".\final\%OUT_BIN%" -7za.exe a -tzip "final\%OUT_SDK%.zip" ".\final\%OUT_SDK%" -) - -rem OK. We should have the release packages now. - diff --git a/packaging/windows-mkzip/mkrev.bat b/packaging/windows-mkzip/mkrev.bat deleted file mode 100644 index 9d8eec120..000000000 --- a/packaging/windows-mkzip/mkrev.bat +++ /dev/null @@ -1,27 +0,0 @@ -@echo off - -rem ----------------------------------------------------- -rem Tiny batch script to build the input file revision.h -rem revision.h contains the revision number of the wc. -rem It is included by assimp.rc. -rem ----------------------------------------------------- - -rem This is not very elegant, but it works. -rem ./bin shouldn't have any local modifications - -svnversion > tmpfile.txt -set /p addtext= < tmpfile.txt -del /q tmpfile.txt - -echo #define SVNRevision > tmpfile.txt - -if exist ..\..\revision.h del /q ..\..\revision.h -for /f "delims=" %%l in (tmpfile.txt) Do ( - for /f "delims=M:" %%r in ("%addtext%") Do ( - echo %%l %%r >> ..\..\revision.h - ) -) -del /q tmpfile.txt - - - diff --git a/port/PyAssimp/LICENSE b/port/PyAssimp/LICENSE new file mode 100644 index 000000000..91cf88d72 --- /dev/null +++ b/port/PyAssimp/LICENSE @@ -0,0 +1,17 @@ +ISC License + +Copyright 2024, pyassimp contributors + +Permission to use, copy, modify, and/or distribute this software +for any purpose with or without fee is hereby granted, provided +that the above copyright notice and this permission notice appear +in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/port/PyAssimp/pyassimp/helper.py b/port/PyAssimp/pyassimp/helper.py index 7c14f6097..0ae7cbdff 100644 --- a/port/PyAssimp/pyassimp/helper.py +++ b/port/PyAssimp/pyassimp/helper.py @@ -5,13 +5,17 @@ Some fancy helper functions. """ import os +import platform import ctypes import operator -from distutils.sysconfig import get_python_lib import re import sys +have_distutils = sys.version_info[0] < 3 and sys.version_info[1] < 12 +if have_distutils: + from distutils.sysconfig import get_python_lib + try: import numpy except ImportError: numpy = None @@ -32,10 +36,14 @@ if os.name=='posix': if 'LD_LIBRARY_PATH' in os.environ: additional_dirs.extend([item for item in os.environ['LD_LIBRARY_PATH'].split(':') if item]) + + if platform.system() == 'Darwin': + if 'DYLD_LIBRARY_PATH' in os.environ: + additional_dirs.extend([item for item in os.environ['DYLD_LIBRARY_PATH'].split(':') if item]) # check if running from anaconda. anaconda_keywords = ("conda", "continuum") - if any(k in sys.version.lower() for k in anaconda_keywords): + if have_distutils and any(k in sys.version.lower() for k in anaconda_keywords): cur_path = get_python_lib() pattern = re.compile('.*\/lib\/') conda_lib = pattern.match(cur_path).group() diff --git a/port/PyAssimp/scripts/3d_viewer.py b/port/PyAssimp/scripts/3d_viewer.py index 08a62660b..3bf790e05 100755 --- a/port/PyAssimp/scripts/3d_viewer.py +++ b/port/PyAssimp/scripts/3d_viewer.py @@ -466,8 +466,8 @@ class PyAssimp3DViewer: try: self.set_shaders_v130() self.prepare_shaders() - except RuntimeError, message: - sys.stderr.write("%s\n" % message) + except RuntimeError as e: + sys.stderr.write("%s\n" % e.message) sys.stdout.write("Could not compile shaders in version 1.30, trying version 1.20\n") if not shader_compilation_succeeded: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afe487411..a59cafbbc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- -# Copyright (c) 2006-2022, assimp team +# Copyright (c) 2006-2024, assimp team # # All rights reserved. # @@ -165,6 +165,7 @@ SET( IMPORTERS unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp unit/ImportExport/RAW/utRAWImportExport.cpp unit/ImportExport/Terragen/utTerragenImportExport.cpp + unit/ImportExport/Pbrt/utPbrtImportExport.cpp ) SET( MATERIAL diff --git a/test/models/AC/SphereWithLight.acc b/test/models/AC/SphereWithLight.acc new file mode 100644 index 000000000..42096672a --- /dev/null +++ b/test/models/AC/SphereWithLight.acc @@ -0,0 +1,535 @@ +AC3Db +MATERIAL "ac3dmat1" rgb 1.00 1.00 1.00 amb 0.20 0.20 0.20 emis 0.00 0.00 0.00 spec 0.20 0.20 0.20 shi 128 trans 0 +OBJECT world +kids 2 +OBJECT light +name "light" +loc 0.000424567 -0.0127304 0 +kids 0 +OBJECT poly +name "sphere" +texture "earthSpherical.jpg" base +texture empty_texture_no_mapping tiled +texture empty_texture_no_mapping skids +texture empty_texture_no_mapping shad +numvert 167 +-0.051576 -0.062833 0.063067 0.224114 -0.961969 0.156168 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.049587 -0.062833 0.055841 0.270337 -0.962554 0.020215 +-0.057009 -0.062833 0.068357 0.117917 -0.961035 0.250013 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.064432 -0.062833 0.070294 -0.019618 -0.960685 0.276946 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.071854 -0.062833 0.068357 -0.151973 -0.961267 0.229935 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.077288 -0.062833 0.063067 -0.243865 -0.962202 0.121235 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.079277 -0.062833 0.055841 -0.270337 -0.962554 -0.020215 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.077288 -0.062833 0.048614 -0.224114 -0.961969 -0.156168 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.071854 -0.062833 0.043324 -0.117917 -0.961035 -0.250013 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.064432 -0.062833 0.041388 0.019618 -0.960685 -0.276946 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.057009 -0.062833 0.043324 0.151973 -0.961267 -0.229935 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.049587 0.042114 0.055841 0.270334 0.962554 -0.020215 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.051576 0.042114 0.063067 0.243863 0.962202 0.121233 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.057009 0.042114 0.068357 0.151972 0.961268 0.229933 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.064432 0.042114 0.070294 0.019618 0.960686 0.276944 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.071854 0.042114 0.068357 -0.117915 0.961036 0.250011 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.077288 0.042114 0.063067 -0.224112 0.961970 0.156167 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.079277 0.042114 0.055841 -0.270334 0.962554 0.020215 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.077288 0.042114 0.048614 -0.243863 0.962202 -0.121233 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.071854 0.042114 0.043324 -0.151972 0.961268 -0.229933 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.064432 0.042114 0.041388 -0.019618 0.960686 -0.276944 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.057009 0.042114 0.043324 0.117916 0.961036 -0.250011 +-0.035753 -0.057406 0.055841 0.479979 -0.877222 0.010123 +-0.049587 -0.062833 0.055841 0.270337 -0.962554 0.020215 +-0.051576 -0.062833 0.048614 0.243865 -0.962202 -0.121234 +-0.039596 -0.057406 0.041881 0.420061 -0.875943 -0.237219 +-0.023874 -0.048773 0.055841 0.687850 -0.725803 0.008451 +-0.029308 -0.048773 0.036098 0.598218 -0.723534 -0.344433 +-0.014759 -0.037522 0.055841 0.853991 -0.520251 0.006112 +-0.021414 -0.037522 0.031661 0.739473 -0.517639 -0.430382 +-0.009029 -0.024420 0.055841 0.962274 -0.272063 0.003217 +-0.016452 -0.024420 0.028872 0.830450 -0.270187 -0.487187 +-0.007075 -0.010360 0.055841 1.000000 -0.000000 0.000000 +-0.014759 -0.010360 0.027920 0.860926 0.000265 -0.508731 +-0.009029 0.003701 0.055841 0.962274 0.272063 -0.003217 +-0.016452 0.003701 0.028872 0.827147 0.270625 -0.492534 +-0.014759 0.016803 0.055841 0.853991 0.520251 -0.006112 +-0.021414 0.016803 0.031661 0.733264 0.517855 -0.440625 +-0.023874 0.028054 0.055841 0.687850 0.725803 -0.008451 +-0.029308 0.028054 0.036098 0.589753 0.723523 -0.358756 +-0.035753 0.036687 0.055841 0.479979 0.877222 -0.010123 +-0.039596 0.036687 0.041881 0.410061 0.875812 -0.254565 +-0.049587 0.042114 0.055841 0.270334 0.962554 -0.020215 +-0.051576 0.042114 0.048614 0.224112 0.961970 -0.156167 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +-0.039596 -0.057406 0.069801 0.410061 -0.875812 0.254565 +-0.035753 -0.057406 0.055841 0.479979 -0.877222 0.010123 +-0.050092 -0.057406 0.080021 0.230454 -0.873143 0.429549 +-0.064432 -0.057406 0.083761 -0.009683 -0.871880 0.489625 +-0.078771 -0.057406 0.080021 -0.247407 -0.873270 0.419748 +-0.089268 -0.057406 0.069801 -0.420061 -0.875942 0.237220 +-0.093110 -0.057406 0.055841 -0.479980 -0.877221 -0.010124 +-0.089268 -0.057406 0.041881 -0.410062 -0.875812 -0.254565 +-0.078771 -0.057406 0.031661 -0.230453 -0.873143 -0.429549 +-0.064432 -0.057406 0.027920 0.009684 -0.871880 -0.489625 +-0.050092 -0.057406 0.031661 0.247407 -0.873271 -0.419748 +-0.029308 -0.048773 0.075583 0.589753 -0.723523 0.358757 +-0.023874 -0.048773 0.055841 0.687850 -0.725803 0.008451 +-0.044153 -0.048773 0.090036 0.333957 -0.719029 0.609483 +-0.064432 -0.048773 0.095326 -0.007940 -0.716811 0.697222 +-0.084710 -0.048773 0.090036 -0.348006 -0.719035 0.601564 +-0.099555 -0.048773 0.075583 -0.598218 -0.723534 0.344434 +-0.104989 -0.048773 0.055841 -0.687850 -0.725804 -0.008451 +-0.099555 -0.048773 0.036098 -0.589753 -0.723523 -0.358757 +-0.084710 -0.048773 0.021645 -0.333958 -0.719029 -0.609483 +-0.064432 -0.048773 0.016355 0.007940 -0.716811 -0.697222 +-0.044153 -0.048773 0.021645 0.348006 -0.719035 -0.601565 +-0.021414 -0.037522 0.080021 0.733263 -0.517855 0.440625 +-0.014759 -0.037522 0.055841 0.853991 -0.520251 0.006112 +-0.039596 -0.037522 0.097721 0.416448 -0.512938 0.750643 +-0.064432 -0.037522 0.104200 -0.005639 -0.510417 0.859908 +-0.089268 -0.037522 0.097721 -0.426533 -0.512723 0.745107 +-0.107449 -0.037522 0.080021 -0.739473 -0.517640 0.430382 +-0.114104 -0.037522 0.055841 -0.853991 -0.520252 -0.006112 +-0.107449 -0.037522 0.031661 -0.733262 -0.517857 -0.440626 +-0.089268 -0.037522 0.013960 -0.416448 -0.512938 -0.750643 +-0.064432 -0.037522 0.007481 0.005639 -0.510417 -0.859908 +-0.039595 -0.037522 0.013960 0.426534 -0.512723 -0.745107 +-0.016452 -0.024420 0.082810 0.827147 -0.270625 0.492534 +-0.009029 -0.024420 0.055841 0.962274 -0.272063 0.003217 +-0.036730 -0.024420 0.102553 0.470709 -0.267377 0.840799 +-0.064432 -0.024420 0.109779 -0.002929 -0.265584 0.964083 +-0.092133 -0.024420 0.102553 -0.475987 -0.266955 0.837957 +-0.112412 -0.024420 0.082810 -0.830450 -0.270188 0.487187 +-0.119834 -0.024420 0.055841 -0.962274 -0.272062 -0.003217 +-0.112412 -0.024420 0.028872 -0.827148 -0.270623 -0.492534 +-0.092133 -0.024420 0.009129 -0.470709 -0.267377 -0.840799 +-0.064432 -0.024420 0.001903 0.002929 -0.265584 -0.964083 +-0.036730 -0.024420 0.009129 0.475987 -0.266954 -0.837957 +-0.014759 -0.010360 0.083761 0.860926 -0.000266 0.508731 +-0.007075 -0.010360 0.055841 1.000000 -0.000000 0.000000 +-0.035753 -0.010360 0.104200 0.491288 -0.000257 0.870997 +-0.064432 -0.010360 0.111682 0.000000 -0.000000 1.000000 +-0.093110 -0.010360 0.104200 -0.491288 0.000257 0.870997 +-0.114104 -0.010360 0.083761 -0.860926 0.000265 0.508731 +-0.121788 -0.010360 0.055841 -1.000000 -0.000001 -0.000001 +-0.114104 -0.010360 0.027920 -0.860925 -0.000266 -0.508731 +-0.093110 -0.010360 0.007481 -0.491288 -0.000256 -0.870997 +-0.064432 -0.010360 0.000000 0.000000 -0.000000 -1.000000 +-0.035753 -0.010360 0.007481 0.491288 0.000257 -0.870997 +-0.016452 0.003701 0.082810 0.830450 0.270188 0.487187 +-0.009029 0.003701 0.055841 0.962274 0.272063 -0.003217 +-0.036730 0.003701 0.102553 0.475987 0.266955 0.837957 +-0.064432 0.003701 0.109779 0.002929 0.265584 0.964083 +-0.092133 0.003701 0.102553 -0.470709 0.267377 0.840799 +-0.112412 0.003701 0.082810 -0.827147 0.270625 0.492534 +-0.119834 0.003701 0.055841 -0.962274 0.272063 0.003217 +-0.112412 0.003701 0.028872 -0.830450 0.270186 -0.487188 +-0.092133 0.003701 0.009129 -0.475987 0.266954 -0.837957 +-0.064432 0.003701 0.001903 -0.002929 0.265583 -0.964083 +-0.036730 0.003701 0.009129 0.470710 0.267376 -0.840799 +-0.021414 0.016803 0.080021 0.739473 0.517639 0.430383 +-0.014759 0.016803 0.055841 0.853991 0.520251 -0.006112 +-0.039596 0.016803 0.097721 0.426533 0.512723 0.745107 +-0.064432 0.016803 0.104200 0.005639 0.510417 0.859908 +-0.089268 0.016803 0.097721 -0.416448 0.512938 0.750643 +-0.107449 0.016803 0.080021 -0.733262 0.517857 0.440626 +-0.114104 0.016803 0.055841 -0.853991 0.520252 0.006112 +-0.107449 0.016803 0.031661 -0.739473 0.517640 -0.430382 +-0.089268 0.016803 0.013960 -0.426533 0.512723 -0.745107 +-0.064432 0.016803 0.007481 -0.005640 0.510418 -0.859908 +-0.039595 0.016803 0.013960 0.416449 0.512938 -0.750643 +-0.029308 0.028054 0.075583 0.598218 0.723534 0.344433 +-0.023874 0.028054 0.055841 0.687850 0.725803 -0.008451 +-0.044153 0.028054 0.090036 0.348006 0.719035 0.601565 +-0.064432 0.028054 0.095326 0.007940 0.716811 0.697222 +-0.084710 0.028054 0.090036 -0.333958 0.719029 0.609483 +-0.099555 0.028054 0.075583 -0.589753 0.723523 0.358757 +-0.104989 0.028054 0.055841 -0.687850 0.725804 0.008451 +-0.099555 0.028054 0.036098 -0.598218 0.723534 -0.344434 +-0.084710 0.028054 0.021645 -0.348006 0.719035 -0.601564 +-0.064432 0.028054 0.016355 -0.007940 0.716811 -0.697222 +-0.044153 0.028054 0.021645 0.333956 0.719030 -0.609483 +-0.039596 0.036687 0.069801 0.420061 0.875943 0.237219 +-0.035753 0.036687 0.055841 0.479979 0.877222 -0.010123 +-0.050092 0.036687 0.080021 0.247407 0.873271 0.419748 +-0.064432 0.036687 0.083761 0.009684 0.871880 0.489625 +-0.078771 0.036687 0.080021 -0.230453 0.873143 0.429549 +-0.089268 0.036687 0.069801 -0.410062 0.875812 0.254565 +-0.093110 0.036687 0.055841 -0.479980 0.877221 0.010124 +-0.089268 0.036687 0.041881 -0.420061 0.875942 -0.237220 +-0.078771 0.036687 0.031661 -0.247407 0.873270 -0.419748 +-0.064432 0.036687 0.027920 -0.009683 0.871880 -0.489625 +-0.050092 0.036687 0.031661 0.230454 0.873143 -0.429549 +-0.064432 0.043965 0.055841 0.000000 1.000000 -0.000000 +-0.064432 -0.064684 0.055841 0.000000 -1.000000 -0.000000 +numsurf 13 +SURF 0x14 +mat 0 +refs 25 +166 0.12500 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +19 0.16667 0.08333 0.20078 0.00100 0.27261 -0.65958 0.06470 0.11207 +44 0.08333 0.08333 0.22774 0.00100 0.24337 -0.66338 0.11207 0.06470 +45 0.08333 0.16667 0.25662 0.00100 0.24258 -0.70570 0.21651 0.12500 +42 -0.00000 0.16667 0.29617 0.00100 0.18165 -0.65455 0.25000 0.00000 +45 0.08333 0.16667 0.25662 0.00100 0.24258 -0.70570 0.21651 0.12500 +46 -0.00000 0.25000 0.34675 0.00100 0.14154 -0.62617 0.35355 0.00000 +47 0.08333 0.25000 0.28254 0.00100 0.23215 -0.72379 0.30619 0.17678 +48 -0.00000 0.33333 0.39286 0.00100 0.09463 -0.54477 0.43301 0.00000 +49 0.08333 0.33333 0.30010 0.00100 0.20445 -0.70053 0.37500 0.21651 +50 -0.00000 0.41667 0.42672 0.00100 0.04684 -0.39635 0.48296 0.00000 +51 0.08333 0.41667 0.30053 0.00100 0.14994 -0.59217 0.41826 0.24148 +52 -0.00000 0.50000 0.43819 0.27990 0.01216 -0.18101 0.50000 0.00000 +53 0.08333 0.50000 0.27797 0.11146 0.07998 -0.31169 0.43301 0.25000 +54 -0.00000 0.58333 0.42036 0.71453 0.00746 0.06528 0.48296 0.00000 +55 0.08333 0.58333 0.25398 0.77247 0.06825 0.11068 0.41826 0.24148 +56 -0.00000 0.66667 0.37732 0.99900 0.03584 0.27934 0.43301 0.00000 +57 0.08333 0.66667 0.24356 0.99900 0.12085 0.40243 0.37500 0.21651 +58 -0.00000 0.75000 0.32156 0.99900 0.08264 0.41936 0.35355 0.00000 +59 0.08333 0.75000 0.23016 0.99900 0.16764 0.51660 0.30619 0.17678 +60 -0.00000 0.83333 0.26409 0.99900 0.13155 0.48413 0.25000 0.00000 +61 0.08333 0.83333 0.21022 0.99900 0.19350 0.53698 0.21651 0.12500 +62 -0.00000 0.91667 0.21082 0.99900 0.17434 0.49121 0.12941 0.00000 +63 0.08333 0.91667 0.18721 0.99900 0.20517 0.51082 0.11207 0.06470 +64 0.04167 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 4 +42 -0.00000 0.16667 0.29617 0.00100 0.18165 -0.65455 0.25000 0.00000 +43 -0.00000 0.08333 0.24596 0.00100 0.21392 -0.64381 0.12941 0.00000 +44 0.08333 0.08333 0.22774 0.00100 0.24337 -0.66338 0.11207 0.06470 +65 0.04167 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +41 0.16667 0.91667 0.15686 0.99900 0.23923 0.50697 0.06470 0.11207 +165 0.12500 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +41 0.16667 0.91667 0.15686 0.99900 0.23923 0.50697 0.06470 0.11207 +63 0.08333 0.91667 0.18721 0.99900 0.20517 0.51082 0.11207 0.06470 +164 0.16667 0.83333 0.14064 0.99900 0.27287 0.52638 0.12500 0.21651 +61 0.08333 0.83333 0.21022 0.99900 0.19350 0.53698 0.21651 0.12500 +153 0.16667 0.75000 0.11005 0.99900 0.30883 0.49554 0.17678 0.30619 +59 0.08333 0.75000 0.23016 0.99900 0.16764 0.51660 0.30619 0.17678 +142 0.16667 0.66667 0.06221 0.99900 0.34565 0.37156 0.21651 0.37500 +57 0.08333 0.66667 0.24356 0.99900 0.12085 0.40243 0.37500 0.21651 +131 0.16667 0.58333 0.01707 0.75383 0.37997 0.09731 0.24148 0.41826 +55 0.08333 0.58333 0.25398 0.77247 0.06825 0.11068 0.41826 0.24148 +120 0.16667 0.50000 0.02917 0.16155 0.40148 -0.27285 0.25000 0.43301 +53 0.08333 0.50000 0.27797 0.11146 0.07998 -0.31169 0.43301 0.25000 +109 0.16667 0.41667 0.09227 0.00100 0.39866 -0.54216 0.24148 0.41826 +51 0.08333 0.41667 0.30053 0.00100 0.14994 -0.59217 0.41826 0.24148 +98 0.16667 0.33333 0.14840 0.00100 0.37604 -0.66637 0.21651 0.37500 +49 0.08333 0.33333 0.30010 0.00100 0.20445 -0.70053 0.37500 0.21651 +87 0.16667 0.25000 0.18125 0.00100 0.34374 -0.70421 0.17678 0.30619 +47 0.08333 0.25000 0.28254 0.00100 0.23215 -0.72379 0.30619 0.17678 +76 0.16667 0.16667 0.19643 0.00100 0.30813 -0.69579 0.12500 0.21651 +45 0.08333 0.16667 0.25662 0.00100 0.24258 -0.70570 0.21651 0.12500 +76 0.16667 0.16667 0.19643 0.00100 0.30813 -0.69579 0.12500 0.21651 +19 0.16667 0.08333 0.20078 0.00100 0.27261 -0.65958 0.06470 0.11207 +17 0.25000 0.08333 0.17478 0.00100 0.29109 -0.63431 0.00000 0.12941 +20 0.20833 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +39 0.25000 0.91667 0.13138 0.99900 0.26321 0.48188 0.00000 0.12941 +40 0.20833 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +39 0.25000 0.91667 0.13138 0.99900 0.26321 0.48188 0.00000 0.12941 +41 0.16667 0.91667 0.15686 0.99900 0.23923 0.50697 0.06470 0.11207 +163 0.25000 0.83333 0.09337 0.99900 0.32380 0.46306 0.00000 0.25000 +164 0.16667 0.83333 0.14064 0.99900 0.27287 0.52638 0.12500 0.21651 +152 0.25000 0.75000 0.05350 0.99900 0.38666 0.38881 0.00000 0.35355 +153 0.16667 0.75000 0.11005 0.99900 0.30883 0.49554 0.17678 0.30619 +141 0.25000 0.66667 0.01921 0.99900 0.44417 0.25077 0.00000 0.43301 +142 0.16667 0.66667 0.06221 0.99900 0.34565 0.37156 0.21651 0.37500 +130 0.25000 0.58333 0.00104 0.70147 0.48527 0.05732 0.00000 0.48296 +131 0.16667 0.58333 0.01707 0.75383 0.37997 0.09731 0.24148 0.41826 +119 0.25000 0.50000 0.00634 0.30861 0.50000 -0.15875 0.00000 0.50000 +120 0.16667 0.50000 0.02917 0.16155 0.40148 -0.27285 0.25000 0.43301 +108 0.25000 0.41667 0.03263 0.00100 0.48620 -0.35427 0.00000 0.48296 +109 0.16667 0.41667 0.09227 0.00100 0.39866 -0.54216 0.24148 0.41826 +97 0.25000 0.33333 0.07009 0.00100 0.45008 -0.50072 0.00000 0.43301 +98 0.16667 0.33333 0.14840 0.00100 0.37604 -0.66637 0.21651 0.37500 +86 0.25000 0.25000 0.10926 0.00100 0.40081 -0.59156 0.00000 0.35355 +87 0.16667 0.25000 0.18125 0.00100 0.34374 -0.70421 0.17678 0.30619 +75 0.25000 0.16667 0.14481 0.00100 0.34608 -0.63293 0.00000 0.25000 +76 0.16667 0.16667 0.19643 0.00100 0.30813 -0.69579 0.12500 0.21651 +75 0.25000 0.16667 0.14481 0.00100 0.34608 -0.63293 0.00000 0.25000 +17 0.25000 0.08333 0.17478 0.00100 0.29109 -0.63431 0.00000 0.12941 +15 0.33333 0.08333 0.15726 0.00100 0.29335 -0.59942 -0.06470 0.11207 +18 0.29167 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +37 0.33333 0.91667 0.11731 0.99900 0.26926 0.44859 -0.06470 0.11207 +38 0.29167 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +37 0.33333 0.91667 0.11731 0.99900 0.26926 0.44859 -0.06470 0.11207 +39 0.25000 0.91667 0.13138 0.99900 0.26321 0.48188 0.00000 0.12941 +162 0.33333 0.83333 0.07414 0.99900 0.32883 0.39669 -0.12500 0.21651 +163 0.25000 0.83333 0.09337 0.99900 0.32380 0.46306 0.00000 0.25000 +151 0.33333 0.75000 0.03873 0.99900 0.38213 0.30552 -0.17678 0.30619 +152 0.25000 0.75000 0.05350 0.99900 0.38666 0.38881 0.00000 0.35355 +140 0.33333 0.66667 0.01433 0.96962 0.42405 0.18283 -0.21651 0.37500 +141 0.25000 0.66667 0.01921 0.99900 0.44417 0.25077 0.00000 0.43301 +129 0.33333 0.58333 0.00283 0.67965 0.45074 0.03994 -0.24148 0.41826 +130 0.25000 0.58333 0.00104 0.70147 0.48527 0.05732 0.00000 0.48296 +118 0.33333 0.50000 0.00464 0.37108 0.46020 -0.11023 -0.25000 0.43301 +119 0.25000 0.50000 0.00634 0.30861 0.50000 -0.15875 0.00000 0.50000 +107 0.33333 0.41667 0.01889 0.06946 0.45233 -0.25504 -0.24148 0.41826 +108 0.25000 0.41667 0.03263 0.00100 0.48620 -0.35427 0.00000 0.48296 +96 0.33333 0.33333 0.04378 0.00100 0.42865 -0.38353 -0.21651 0.37500 +97 0.25000 0.33333 0.07009 0.00100 0.45008 -0.50072 0.00000 0.43301 +85 0.33333 0.25000 0.07694 0.00100 0.39190 -0.48717 -0.17678 0.30619 +86 0.25000 0.25000 0.10926 0.00100 0.40081 -0.59156 0.00000 0.35355 +74 0.33333 0.16667 0.11569 0.00100 0.34553 -0.56015 -0.12500 0.21651 +75 0.25000 0.16667 0.14481 0.00100 0.34608 -0.63293 0.00000 0.25000 +74 0.33333 0.16667 0.11569 0.00100 0.34553 -0.56015 -0.12500 0.21651 +15 0.33333 0.08333 0.15726 0.00100 0.29335 -0.59942 -0.06470 0.11207 +13 0.41667 0.08333 0.15134 0.00100 0.28069 -0.56690 -0.11207 0.06470 +16 0.37500 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +35 0.41667 0.91667 0.11568 0.99900 0.25826 0.41884 -0.11207 0.06470 +36 0.37500 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +35 0.41667 0.91667 0.11568 0.99900 0.25826 0.41884 -0.11207 0.06470 +37 0.33333 0.91667 0.11731 0.99900 0.26926 0.44859 -0.06470 0.11207 +161 0.41667 0.83333 0.07575 0.99900 0.30096 0.34871 -0.21651 0.12500 +162 0.33333 0.83333 0.07414 0.99900 0.32883 0.39669 -0.12500 0.21651 +150 0.41667 0.75000 0.04562 0.99900 0.33524 0.25608 -0.30619 0.17678 +151 0.33333 0.75000 0.03873 0.99900 0.38213 0.30552 -0.17678 0.30619 +139 0.41667 0.66667 0.02569 0.92724 0.36024 0.14834 -0.37500 0.21651 +140 0.33333 0.66667 0.01433 0.96962 0.42405 0.18283 -0.21651 0.37500 +128 0.41667 0.58333 0.01596 0.67063 0.37568 0.03187 -0.41826 0.24148 +129 0.33333 0.58333 0.00283 0.67965 0.45074 0.03994 -0.24148 0.41826 +117 0.41667 0.50000 0.01621 0.39994 0.38162 -0.08785 -0.43301 0.25000 +118 0.33333 0.50000 0.00464 0.37108 0.46020 -0.11023 -0.25000 0.43301 +106 0.41667 0.41667 0.02609 0.13144 0.37828 -0.20590 -0.41826 0.24148 +107 0.33333 0.41667 0.01889 0.06946 0.45233 -0.25504 -0.24148 0.41826 +95 0.41667 0.33333 0.04522 0.00100 0.36600 -0.31762 -0.37500 0.21651 +96 0.33333 0.33333 0.04378 0.00100 0.42865 -0.38353 -0.21651 0.37500 +84 0.41667 0.25000 0.07305 0.00100 0.34519 -0.41833 -0.30619 0.17678 +85 0.33333 0.25000 0.07694 0.00100 0.39190 -0.48717 -0.17678 0.30619 +73 0.41667 0.16667 0.10881 0.00100 0.31647 -0.50313 -0.21651 0.12500 +74 0.33333 0.16667 0.11569 0.00100 0.34553 -0.56015 -0.12500 0.21651 +73 0.41667 0.16667 0.10881 0.00100 0.31647 -0.50313 -0.21651 0.12500 +13 0.41667 0.08333 0.15134 0.00100 0.28069 -0.56690 -0.11207 0.06470 +11 0.50000 0.08333 0.15695 0.00100 0.25836 -0.54379 -0.12941 0.00000 +14 0.45833 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +33 0.50000 0.91667 0.12506 0.99900 0.23590 0.39836 -0.12941 0.00000 +34 0.45833 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +33 0.50000 0.91667 0.12506 0.99900 0.23590 0.39836 -0.12941 0.00000 +35 0.41667 0.91667 0.11568 0.99900 0.25826 0.41884 -0.11207 0.06470 +160 0.50000 0.83333 0.09377 0.99900 0.25637 0.32013 -0.25000 0.00000 +161 0.41667 0.83333 0.07575 0.99900 0.30096 0.34871 -0.21651 0.12500 +149 0.50000 0.75000 0.07035 0.99900 0.27148 0.22961 -0.35355 0.00000 +150 0.41667 0.75000 0.04562 0.99900 0.33524 0.25608 -0.30619 0.17678 +138 0.50000 0.66667 0.05477 0.90616 0.28211 0.13113 -0.43301 0.00000 +139 0.41667 0.66667 0.02569 0.92724 0.36024 0.14834 -0.37500 0.21651 +127 0.50000 0.58333 0.04697 0.66642 0.28889 0.02798 -0.48296 0.00000 +128 0.41667 0.58333 0.01596 0.67063 0.37568 0.03187 -0.41826 0.24148 +116 0.50000 0.50000 0.04685 0.41393 0.29223 -0.07709 -0.50000 0.00000 +117 0.41667 0.50000 0.01621 0.39994 0.38162 -0.08785 -0.43301 0.25000 +105 0.50000 0.41667 0.05433 0.16212 0.29232 -0.18164 -0.48296 0.00000 +106 0.41667 0.41667 0.02609 0.13144 0.37828 -0.20590 -0.41826 0.24148 +94 0.50000 0.33333 0.06929 0.00100 0.28922 -0.28327 -0.43301 0.00000 +95 0.41667 0.33333 0.04522 0.00100 0.36600 -0.31762 -0.37500 0.21651 +83 0.50000 0.25000 0.09157 0.00100 0.28277 -0.37947 -0.35355 0.00000 +84 0.41667 0.25000 0.07305 0.00100 0.34519 -0.41833 -0.30619 0.17678 +72 0.50000 0.16667 0.12093 0.00100 0.27266 -0.46743 -0.25000 0.00000 +73 0.41667 0.16667 0.10881 0.00100 0.31647 -0.50313 -0.21651 0.12500 +72 0.50000 0.16667 0.12093 0.00100 0.27266 -0.46743 -0.25000 0.00000 +11 0.50000 0.08333 0.15695 0.00100 0.25836 -0.54379 -0.12941 0.00000 +9 0.58333 0.08333 0.17221 0.00100 0.23253 -0.53297 -0.11207 -0.06470 +12 0.54167 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +31 0.58333 0.91667 0.14311 0.99900 0.20878 0.38894 -0.11207 -0.06470 +32 0.54167 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +31 0.58333 0.91667 0.14311 0.99900 0.20878 0.38894 -0.11207 -0.06470 +33 0.50000 0.91667 0.12506 0.99900 0.23590 0.39836 -0.12941 0.00000 +159 0.58333 0.83333 0.12527 0.99900 0.20699 0.30801 -0.21651 -0.12500 +160 0.50000 0.83333 0.09377 0.99900 0.25637 0.32013 -0.25000 0.00000 +148 0.58333 0.75000 0.11143 0.99900 0.20500 0.21899 -0.30619 -0.17678 +149 0.50000 0.75000 0.07035 0.99900 0.27148 0.22961 -0.35355 0.00000 +137 0.58333 0.66667 0.10210 0.89651 0.20368 0.12444 -0.37500 -0.21651 +138 0.50000 0.66667 0.05477 0.90616 0.28211 0.13113 -0.43301 0.00000 +126 0.58333 0.58333 0.09758 0.66389 0.20355 0.02650 -0.41826 -0.24148 +127 0.50000 0.58333 0.04697 0.66642 0.28889 0.02798 -0.48296 0.00000 +115 0.58333 0.50000 0.09802 0.41933 0.20491 -0.07299 -0.43301 -0.25000 +116 0.50000 0.50000 0.04685 0.41393 0.29223 -0.07709 -0.50000 0.00000 +104 0.58333 0.41667 0.10346 0.17498 0.20788 -0.17229 -0.41826 -0.24148 +105 0.50000 0.41667 0.05433 0.16212 0.29232 -0.18164 -0.48296 0.00000 +93 0.58333 0.33333 0.11385 0.00100 0.21242 -0.26969 -0.37500 -0.21651 +94 0.50000 0.33333 0.06929 0.00100 0.28922 -0.28327 -0.43301 0.00000 +82 0.58333 0.25000 0.12901 0.00100 0.21834 -0.36350 -0.30619 -0.17678 +83 0.50000 0.25000 0.09157 0.00100 0.28277 -0.37947 -0.35355 0.00000 +71 0.58333 0.16667 0.14863 0.00100 0.22526 -0.45191 -0.21651 -0.12500 +72 0.50000 0.16667 0.12093 0.00100 0.27266 -0.46743 -0.25000 0.00000 +71 0.58333 0.16667 0.14863 0.00100 0.22526 -0.45191 -0.21651 -0.12500 +9 0.58333 0.08333 0.17221 0.00100 0.23253 -0.53297 -0.11207 -0.06470 +7 0.66667 0.08333 0.19399 0.00100 0.20888 -0.53519 -0.06470 -0.11207 +10 0.62500 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +29 0.66667 0.91667 0.16656 0.99900 0.18279 0.39086 -0.06470 -0.11207 +30 0.62500 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +29 0.66667 0.91667 0.16656 0.99900 0.18279 0.39086 -0.06470 -0.11207 +31 0.58333 0.91667 0.14311 0.99900 0.20878 0.38894 -0.11207 -0.06470 +158 0.66667 0.83333 0.16659 0.99900 0.16130 0.31057 -0.12500 -0.21651 +159 0.58333 0.83333 0.12527 0.99900 0.20699 0.30801 -0.21651 -0.12500 +147 0.66667 0.75000 0.16588 0.99900 0.14487 0.22131 -0.17678 -0.30619 +148 0.58333 0.75000 0.11143 0.99900 0.20500 0.21899 -0.30619 -0.17678 +136 0.66667 0.66667 0.16546 0.89633 0.13378 0.12594 -0.21651 -0.37500 +137 0.58333 0.66667 0.10210 0.89651 0.20368 0.12444 -0.37500 -0.21651 +125 0.66667 0.58333 0.16597 0.66293 0.12819 0.02683 -0.24148 -0.41826 +126 0.58333 0.58333 0.09758 0.66389 0.20355 0.02650 -0.41826 -0.24148 +114 0.66667 0.50000 0.16776 0.41811 0.12818 -0.07393 -0.25000 -0.43301 +115 0.58333 0.50000 0.09802 0.41933 0.20491 -0.07299 -0.43301 -0.25000 +103 0.66667 0.41667 0.17097 0.17362 0.13376 -0.17442 -0.24148 -0.41826 +104 0.58333 0.41667 0.10346 0.17498 0.20788 -0.17229 -0.41826 -0.24148 +92 0.66667 0.33333 0.17556 0.00100 0.14484 -0.27274 -0.21651 -0.37500 +93 0.58333 0.33333 0.11385 0.00100 0.21242 -0.26969 -0.37500 -0.21651 +81 0.66667 0.25000 0.18129 0.00100 0.16125 -0.36700 -0.17678 -0.30619 +82 0.58333 0.25000 0.12901 0.00100 0.21834 -0.36350 -0.30619 -0.17678 +70 0.66667 0.16667 0.18769 0.00100 0.18273 -0.45521 -0.12500 -0.21651 +71 0.58333 0.16667 0.14863 0.00100 0.22526 -0.45191 -0.21651 -0.12500 +70 0.66667 0.16667 0.18769 0.00100 0.18273 -0.45521 -0.12500 -0.21651 +7 0.66667 0.08333 0.19399 0.00100 0.20888 -0.53519 -0.06470 -0.11207 +5 0.75000 0.08333 0.21789 0.00100 0.19222 -0.55023 0.00000 -0.12941 +8 0.70833 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +27 0.75000 0.91667 0.19095 0.99900 0.16283 0.40401 0.00000 -0.12941 +28 0.70833 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +27 0.75000 0.91667 0.19095 0.99900 0.16283 0.40401 0.00000 -0.12941 +29 0.66667 0.91667 0.16656 0.99900 0.18279 0.39086 -0.06470 -0.11207 +157 0.75000 0.83333 0.21201 0.99900 0.12561 0.32796 0.00000 -0.25000 +158 0.66667 0.83333 0.16659 0.99900 0.16130 0.31057 -0.12500 -0.21651 +146 0.75000 0.75000 0.22797 0.99900 0.09754 0.23688 0.00000 -0.35355 +147 0.66667 0.75000 0.16588 0.99900 0.14487 0.22131 -0.17678 -0.30619 +135 0.75000 0.66667 0.23948 0.90806 0.07868 0.13588 0.00000 -0.43301 +136 0.66667 0.66667 0.16546 0.89633 0.13378 0.12594 -0.21651 -0.37500 +124 0.75000 0.58333 0.24702 0.66503 0.06897 0.02906 0.00000 -0.48296 +125 0.66667 0.58333 0.16597 0.66293 0.12819 0.02683 -0.24148 -0.41826 +113 0.75000 0.50000 0.25094 0.41006 0.06830 -0.08009 0.00000 -0.50000 +114 0.66667 0.50000 0.16776 0.41811 0.12818 -0.07393 -0.25000 -0.43301 +102 0.75000 0.41667 0.25144 0.15617 0.07651 -0.18841 0.00000 -0.48296 +103 0.66667 0.41667 0.17097 0.17362 0.13376 -0.17442 -0.24148 -0.41826 +91 0.75000 0.33333 0.24857 0.00100 0.09338 -0.29285 0.00000 -0.43301 +92 0.66667 0.33333 0.17556 0.00100 0.14484 -0.27274 -0.21651 -0.37500 +80 0.75000 0.25000 0.24221 0.00100 0.11860 -0.39028 0.00000 -0.35355 +81 0.66667 0.25000 0.18129 0.00100 0.16125 -0.36700 -0.17678 -0.30619 +69 0.75000 0.16667 0.23212 0.00100 0.15175 -0.47734 0.00000 -0.25000 +70 0.66667 0.16667 0.18769 0.00100 0.18273 -0.45521 -0.12500 -0.21651 +69 0.75000 0.16667 0.23212 0.00100 0.15175 -0.47734 0.00000 -0.25000 +5 0.75000 0.08333 0.21789 0.00100 0.19222 -0.55023 0.00000 -0.12941 +3 0.83333 0.08333 0.23838 0.00100 0.18630 -0.57670 0.06470 -0.11207 +6 0.79167 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +25 0.83333 0.91667 0.21053 0.99900 0.15290 0.42768 0.06470 -0.11207 +26 0.79167 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +25 0.83333 0.91667 0.21053 0.99900 0.15290 0.42768 0.06470 -0.11207 +27 0.75000 0.91667 0.19095 0.99900 0.16283 0.40401 0.00000 -0.12941 +156 0.83333 0.83333 0.25271 0.99900 0.10497 0.36222 0.12500 -0.21651 +157 0.75000 0.83333 0.21201 0.99900 0.12561 0.32796 0.00000 -0.25000 +145 0.83333 0.75000 0.28799 0.99900 0.06767 0.26941 0.17678 -0.30619 +146 0.75000 0.75000 0.22797 0.99900 0.09754 0.23688 0.00000 -0.35355 +134 0.83333 0.66667 0.31457 0.93678 0.04237 0.15738 0.21651 -0.37500 +135 0.75000 0.66667 0.23948 0.90806 0.07868 0.13588 0.00000 -0.43301 +123 0.83333 0.58333 0.33150 0.67193 0.02955 0.03395 0.24148 -0.41826 +124 0.75000 0.58333 0.24702 0.66503 0.06897 0.02906 0.00000 -0.48296 +112 0.83333 0.50000 0.33844 0.39249 0.02914 -0.09363 0.25000 -0.43301 +113 0.75000 0.50000 0.25094 0.41006 0.06830 -0.08009 0.00000 -0.50000 +101 0.83333 0.41667 0.33549 0.11627 0.04068 -0.21875 0.24148 -0.41826 +102 0.75000 0.41667 0.25144 0.15617 0.07651 -0.18841 0.00000 -0.48296 +90 0.83333 0.33333 0.32310 0.00100 0.06342 -0.33527 0.21651 -0.37500 +91 0.75000 0.33333 0.24857 0.00100 0.09338 -0.29285 0.00000 -0.43301 +79 0.83333 0.25000 0.30202 0.00100 0.09629 -0.43738 0.17678 -0.30619 +80 0.75000 0.25000 0.24221 0.00100 0.11860 -0.39028 0.00000 -0.35355 +68 0.83333 0.16667 0.27332 0.00100 0.13788 -0.51956 0.12500 -0.21651 +69 0.75000 0.16667 0.23212 0.00100 0.15175 -0.47734 0.00000 -0.25000 +68 0.83333 0.16667 0.27332 0.00100 0.13788 -0.51956 0.12500 -0.21651 +3 0.83333 0.08333 0.23838 0.00100 0.18630 -0.57670 0.06470 -0.11207 +0 0.91667 0.08333 0.24936 0.00100 0.19351 -0.61071 0.11207 -0.06470 +4 0.87500 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 26 +23 0.91667 0.91667 0.21882 0.99900 0.15617 0.45920 0.11207 -0.06470 +24 0.87500 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +23 0.91667 0.91667 0.21882 0.99900 0.15617 0.45920 0.11207 -0.06470 +25 0.83333 0.91667 0.21053 0.99900 0.15290 0.42768 0.06470 -0.11207 +154 0.91667 0.83333 0.27563 0.99900 0.10447 0.41577 0.21651 -0.12500 +156 0.83333 0.83333 0.25271 0.99900 0.10497 0.36222 0.12500 -0.21651 +143 0.91667 0.75000 0.32918 0.99900 0.05945 0.32703 0.30619 -0.17678 +145 0.83333 0.75000 0.28799 0.99900 0.06767 0.26941 0.17678 -0.30619 +132 0.91667 0.66667 0.37332 0.99232 0.02664 0.19879 0.37500 -0.21651 +134 0.83333 0.66667 0.31457 0.93678 0.04237 0.15738 0.21651 -0.37500 +121 0.91667 0.58333 0.40266 0.68601 0.01006 0.04379 0.41826 -0.24148 +123 0.83333 0.58333 0.33150 0.67193 0.02955 0.03395 0.24148 -0.41826 +110 0.91667 0.50000 0.41387 0.35730 0.01120 -0.12091 0.43301 -0.25000 +112 0.83333 0.50000 0.33844 0.39249 0.02914 -0.09363 0.25000 -0.43301 +99 0.91667 0.41667 0.40641 0.03864 0.02889 -0.27785 0.41826 -0.24148 +101 0.83333 0.41667 0.33549 0.11627 0.04068 -0.21875 0.24148 -0.41826 +88 0.91667 0.33333 0.38226 0.00100 0.06003 -0.41261 0.37500 -0.21651 +90 0.83333 0.33333 0.32310 0.00100 0.06342 -0.33527 0.21651 -0.37500 +77 0.91667 0.25000 0.34511 0.00100 0.10054 -0.51553 0.30619 -0.17678 +79 0.83333 0.25000 0.30202 0.00100 0.09629 -0.43738 0.17678 -0.30619 +66 0.91667 0.16667 0.29935 0.00100 0.14628 -0.58181 0.21651 -0.12500 +68 0.83333 0.16667 0.27332 0.00100 0.13788 -0.51956 0.12500 -0.21651 +66 0.91667 0.16667 0.29935 0.00100 0.14628 -0.58181 0.21651 -0.12500 +0 0.91667 0.08333 0.24936 0.00100 0.19351 -0.61071 0.11207 -0.06470 +2 1.00000 0.08333 0.24596 0.00100 0.21392 -0.64381 0.12941 0.00000 +1 0.95833 0.00000 0.19898 0.00100 0.23912 -0.60440 0.00000 0.00000 +SURF 0x14 +mat 0 +refs 23 +66 0.91667 0.16667 0.29935 0.00100 0.14628 -0.58181 0.21651 -0.12500 +2 1.00000 0.08333 0.24596 0.00100 0.21392 -0.64381 0.12941 0.00000 +66 0.91667 0.16667 0.29935 0.00100 0.14628 -0.58181 0.21651 -0.12500 +67 1.00000 0.16667 0.29617 0.00100 0.18165 -0.65455 0.25000 0.00000 +77 0.91667 0.25000 0.34511 0.00100 0.10054 -0.51553 0.30619 -0.17678 +78 1.00000 0.25000 0.34675 0.00100 0.14154 -0.62617 0.35355 0.00000 +88 0.91667 0.33333 0.38226 0.00100 0.06003 -0.41261 0.37500 -0.21651 +89 1.00000 0.33333 0.39286 0.00100 0.09463 -0.54477 0.43301 0.00000 +99 0.91667 0.41667 0.40641 0.03864 0.02889 -0.27785 0.41826 -0.24148 +100 1.00000 0.41667 0.42672 0.00100 0.04684 -0.39635 0.48296 0.00000 +110 0.91667 0.50000 0.41387 0.35730 0.01120 -0.12091 0.43301 -0.25000 +111 1.00000 0.50000 0.43819 0.27990 0.01216 -0.18101 0.50000 0.00000 +121 0.91667 0.58333 0.40266 0.68601 0.01006 0.04379 0.41826 -0.24148 +122 1.00000 0.58333 0.42036 0.71453 0.00746 0.06528 0.48296 0.00000 +132 0.91667 0.66667 0.37332 0.99232 0.02664 0.19879 0.37500 -0.21651 +133 1.00000 0.66667 0.37732 0.99900 0.03584 0.27934 0.43301 0.00000 +143 0.91667 0.75000 0.32918 0.99900 0.05945 0.32703 0.30619 -0.17678 +144 1.00000 0.75000 0.32156 0.99900 0.08264 0.41936 0.35355 0.00000 +154 0.91667 0.83333 0.27563 0.99900 0.10447 0.41577 0.21651 -0.12500 +155 1.00000 0.83333 0.26409 0.99900 0.13155 0.48413 0.25000 0.00000 +23 0.91667 0.91667 0.21882 0.99900 0.15617 0.45920 0.11207 -0.06470 +21 1.00000 0.91667 0.21082 0.99900 0.17434 0.49121 0.12941 0.00000 +22 0.95833 1.00000 0.16417 0.99900 0.20895 0.45830 0.00000 0.00000 +kids 0 diff --git a/test/models/IRR/EpisodeII_TheDwarfesStrikeBack.irr b/test/models/IRR/EpisodeII_TheDwarfesStrikeBack.irr index a317ac61e..761ea0ad4 100644 --- a/test/models/IRR/EpisodeII_TheDwarfesStrikeBack.irr +++ b/test/models/IRR/EpisodeII_TheDwarfesStrikeBack.irr @@ -32,7 +32,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -206,7 +206,7 @@ - + @@ -245,7 +245,7 @@ - + @@ -284,7 +284,7 @@ - + @@ -329,7 +329,7 @@ - + @@ -345,7 +345,7 @@ - + @@ -384,7 +384,7 @@ - + @@ -468,7 +468,7 @@ - + @@ -484,7 +484,7 @@ - + @@ -523,7 +523,7 @@ - + @@ -620,7 +620,7 @@ - + @@ -678,7 +678,7 @@ - + @@ -723,7 +723,7 @@ - + @@ -739,7 +739,7 @@ - + @@ -778,7 +778,7 @@ - + @@ -875,7 +875,7 @@ - + @@ -920,7 +920,7 @@ - + @@ -936,7 +936,7 @@ - + @@ -975,7 +975,7 @@ - + diff --git a/test/models/IRR/EpisodeII_TheDwarfesStrikeBack_UTF16LE.irr b/test/models/IRR/EpisodeII_TheDwarfesStrikeBack_UTF16LE.irr index 9321cf93f..d109c67cc 100644 Binary files a/test/models/IRR/EpisodeII_TheDwarfesStrikeBack_UTF16LE.irr and b/test/models/IRR/EpisodeII_TheDwarfesStrikeBack_UTF16LE.irr differ diff --git a/test/models/IRR/EpisodeI_ANewDwarf.irr b/test/models/IRR/EpisodeI_ANewDwarf.irr index 65f65ad4b..c84073553 100644 --- a/test/models/IRR/EpisodeI_ANewDwarf.irr +++ b/test/models/IRR/EpisodeI_ANewDwarf.irr @@ -33,8 +33,8 @@ - - + + @@ -72,8 +72,8 @@ - - + + @@ -117,7 +117,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -170,7 +170,7 @@ - + @@ -254,7 +254,7 @@ - + @@ -268,7 +268,7 @@ - + @@ -307,7 +307,7 @@ - + @@ -391,7 +391,7 @@ - + @@ -405,7 +405,7 @@ - + @@ -444,7 +444,7 @@ - + @@ -528,7 +528,7 @@ - + @@ -542,7 +542,7 @@ - + @@ -581,7 +581,7 @@ - + @@ -665,7 +665,7 @@ - + @@ -679,7 +679,7 @@ - + @@ -718,7 +718,7 @@ - + diff --git a/test/models/IRR/EpisodeI_ANewDwarf_UTF16LE.irr b/test/models/IRR/EpisodeI_ANewDwarf_UTF16LE.irr index 5e5a68f2d..551a5ac9a 100644 Binary files a/test/models/IRR/EpisodeI_ANewDwarf_UTF16LE.irr and b/test/models/IRR/EpisodeI_ANewDwarf_UTF16LE.irr differ diff --git a/test/models/IRR/animMesh.irr b/test/models/IRR/animMesh.irr index 0e246bacf..5cd109d77 100644 --- a/test/models/IRR/animMesh.irr +++ b/test/models/IRR/animMesh.irr @@ -19,7 +19,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -73,7 +73,7 @@ - + diff --git a/test/models/IRR/animMesh_UTF16LE.irr b/test/models/IRR/animMesh_UTF16LE.irr index c041565ea..70f6374fa 100644 Binary files a/test/models/IRR/animMesh_UTF16LE.irr and b/test/models/IRR/animMesh_UTF16LE.irr differ diff --git a/test/models/IRR/1.png b/test/models/IRR/assets/1.png similarity index 100% rename from test/models/IRR/1.png rename to test/models/IRR/assets/1.png diff --git a/test/models/IRR/SpiderTex.jpg b/test/models/IRR/assets/SpiderTex.jpg similarity index 100% rename from test/models/IRR/SpiderTex.jpg rename to test/models/IRR/assets/SpiderTex.jpg diff --git a/test/models/IRR/UVTransformTestImg.png b/test/models/IRR/assets/UVTransformTestImg.png similarity index 100% rename from test/models/IRR/UVTransformTestImg.png rename to test/models/IRR/assets/UVTransformTestImg.png diff --git a/test/models/IRR/axe.jpg b/test/models/IRR/assets/axe.jpg similarity index 100% rename from test/models/IRR/axe.jpg rename to test/models/IRR/assets/axe.jpg diff --git a/test/models/IRR/brownground_1-1.jpg b/test/models/IRR/assets/brownground_1-1.jpg similarity index 100% rename from test/models/IRR/brownground_1-1.jpg rename to test/models/IRR/assets/brownground_1-1.jpg diff --git a/test/models/IRR/crackedground_1-6.jpg b/test/models/IRR/assets/crackedground_1-6.jpg similarity index 100% rename from test/models/IRR/crackedground_1-6.jpg rename to test/models/IRR/assets/crackedground_1-6.jpg diff --git a/test/models/IRR/assets/default.png b/test/models/IRR/assets/default.png new file mode 100644 index 000000000..fe9926e41 Binary files /dev/null and b/test/models/IRR/assets/default.png differ diff --git a/test/models/IRR/assets/default_texture.png b/test/models/IRR/assets/default_texture.png new file mode 100644 index 000000000..a1ad5979b Binary files /dev/null and b/test/models/IRR/assets/default_texture.png differ diff --git a/test/models/IRR/drkwood2.jpg b/test/models/IRR/assets/drkwood2.jpg similarity index 100% rename from test/models/IRR/drkwood2.jpg rename to test/models/IRR/assets/drkwood2.jpg diff --git a/test/models/IRR/dwarf.jpg b/test/models/IRR/assets/dwarf.jpg similarity index 100% rename from test/models/IRR/dwarf.jpg rename to test/models/IRR/assets/dwarf.jpg diff --git a/test/models/IRR/dwarf.x b/test/models/IRR/assets/dwarf.x similarity index 100% rename from test/models/IRR/dwarf.x rename to test/models/IRR/assets/dwarf.x diff --git a/test/models/IRR/earthSpherical.jpg b/test/models/IRR/assets/earthSpherical.jpg similarity index 100% rename from test/models/IRR/earthSpherical.jpg rename to test/models/IRR/assets/earthSpherical.jpg diff --git a/test/models/IRR/engineflare1.jpg b/test/models/IRR/assets/engineflare1.jpg similarity index 100% rename from test/models/IRR/engineflare1.jpg rename to test/models/IRR/assets/engineflare1.jpg diff --git a/test/models/IRR/assets/skybox/credits.txt b/test/models/IRR/assets/skybox/credits.txt new file mode 100644 index 000000000..b2b601392 --- /dev/null +++ b/test/models/IRR/assets/skybox/credits.txt @@ -0,0 +1,11 @@ +This skybox is basing on a skydome texture from + +http://mikepan.homeip.net/earth + +Downloaded November 22th, 08 +Distribution note: +"These royalty-free skydome textures work best when applied to a sphere or hemisphere" + + + +Thanks for your great work! diff --git a/test/models/IRR/assets/skybox/default_skybox0.jpg b/test/models/IRR/assets/skybox/default_skybox0.jpg new file mode 100644 index 000000000..0fe4d0890 Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skybox0.jpg differ diff --git a/test/models/IRR/assets/skybox/default_skybox1.jpg b/test/models/IRR/assets/skybox/default_skybox1.jpg new file mode 100644 index 000000000..c4c286bff Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skybox1.jpg differ diff --git a/test/models/IRR/assets/skybox/default_skybox2.jpg b/test/models/IRR/assets/skybox/default_skybox2.jpg new file mode 100644 index 000000000..935f72579 Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skybox2.jpg differ diff --git a/test/models/IRR/assets/skybox/default_skybox3.jpg b/test/models/IRR/assets/skybox/default_skybox3.jpg new file mode 100644 index 000000000..e8107ff99 Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skybox3.jpg differ diff --git a/test/models/IRR/assets/skybox/default_skyboxdn.jpg b/test/models/IRR/assets/skybox/default_skyboxdn.jpg new file mode 100644 index 000000000..af66a6176 Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skyboxdn.jpg differ diff --git a/test/models/IRR/assets/skybox/default_skyboxup.jpg b/test/models/IRR/assets/skybox/default_skyboxup.jpg new file mode 100644 index 000000000..7959709fa Binary files /dev/null and b/test/models/IRR/assets/skybox/default_skyboxup.jpg differ diff --git a/test/models/IRR/spider.mtl b/test/models/IRR/assets/spider.mtl similarity index 100% rename from test/models/IRR/spider.mtl rename to test/models/IRR/assets/spider.mtl diff --git a/test/models/IRR/wal67ar_small.jpg b/test/models/IRR/assets/wal67ar_small.jpg similarity index 100% rename from test/models/IRR/wal67ar_small.jpg rename to test/models/IRR/assets/wal67ar_small.jpg diff --git a/test/models/IRR/wal69ar_small.jpg b/test/models/IRR/assets/wal69ar_small.jpg similarity index 100% rename from test/models/IRR/wal69ar_small.jpg rename to test/models/IRR/assets/wal69ar_small.jpg diff --git a/test/models/IRR/box.irr b/test/models/IRR/box.irr index 8a094ded6..2af68ab44 100644 --- a/test/models/IRR/box.irr +++ b/test/models/IRR/box.irr @@ -32,7 +32,7 @@ - + diff --git a/test/models/IRR/box_UTF16LE.irr b/test/models/IRR/box_UTF16LE.irr index efc165d93..655517195 100644 Binary files a/test/models/IRR/box_UTF16LE.irr and b/test/models/IRR/box_UTF16LE.irr differ diff --git a/test/models/IRR/cellar.irrmesh b/test/models/IRR/cellar.irrmesh index 0278c9239..ee787463a 100644 --- a/test/models/IRR/cellar.irrmesh +++ b/test/models/IRR/cellar.irrmesh @@ -13,8 +13,8 @@ - - + + @@ -870,8 +870,8 @@ - - + + diff --git a/test/models/IRR/dawfInCellar_ChildOfCellar.irr b/test/models/IRR/dawfInCellar_ChildOfCellar.irr index b9fa20c6a..0b57fc158 100644 --- a/test/models/IRR/dawfInCellar_ChildOfCellar.irr +++ b/test/models/IRR/dawfInCellar_ChildOfCellar.irr @@ -33,8 +33,8 @@ - - + + @@ -71,8 +71,8 @@ - - + + @@ -113,7 +113,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -165,7 +165,7 @@ - + diff --git a/test/models/IRR/dawfInCellar_ChildOfCellar_UTF16LE.irr b/test/models/IRR/dawfInCellar_ChildOfCellar_UTF16LE.irr index aba42e94d..cd7ba9752 100644 Binary files a/test/models/IRR/dawfInCellar_ChildOfCellar_UTF16LE.irr and b/test/models/IRR/dawfInCellar_ChildOfCellar_UTF16LE.irr differ diff --git a/test/models/IRR/dawfInCellar_SameHierarchy.irr b/test/models/IRR/dawfInCellar_SameHierarchy.irr index 424b42df8..5f6d01fe5 100644 --- a/test/models/IRR/dawfInCellar_SameHierarchy.irr +++ b/test/models/IRR/dawfInCellar_SameHierarchy.irr @@ -33,8 +33,8 @@ - - + + @@ -71,8 +71,8 @@ - - + + @@ -115,7 +115,7 @@ - + @@ -129,7 +129,7 @@ - + @@ -167,7 +167,7 @@ - + diff --git a/test/models/IRR/dawfInCellar_SameHierarchy_UTF16LE.irr b/test/models/IRR/dawfInCellar_SameHierarchy_UTF16LE.irr index a4e7cc951..5cc3dda87 100644 Binary files a/test/models/IRR/dawfInCellar_SameHierarchy_UTF16LE.irr and b/test/models/IRR/dawfInCellar_SameHierarchy_UTF16LE.irr differ diff --git a/test/models/IRR/instancing.irr b/test/models/IRR/instancing.irr index ba0e710da..18b86f6e7 100644 --- a/test/models/IRR/instancing.irr +++ b/test/models/IRR/instancing.irr @@ -33,7 +33,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -153,7 +153,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -205,7 +205,7 @@ - + @@ -287,7 +287,7 @@ - + @@ -301,7 +301,7 @@ - + @@ -339,7 +339,7 @@ - + @@ -421,7 +421,7 @@ - + @@ -435,7 +435,7 @@ - + @@ -473,7 +473,7 @@ - + @@ -555,7 +555,7 @@ - + @@ -569,7 +569,7 @@ - + @@ -607,7 +607,7 @@ - + @@ -689,7 +689,7 @@ - + @@ -703,7 +703,7 @@ - + @@ -741,7 +741,7 @@ - + diff --git a/test/models/IRR/scenegraphAnim.irr b/test/models/IRR/scenegraphAnim.irr index 2300ea18f..dedc1c2cf 100644 --- a/test/models/IRR/scenegraphAnim.irr +++ b/test/models/IRR/scenegraphAnim.irr @@ -126,7 +126,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -213,7 +213,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -347,8 +347,8 @@ - - + + @@ -385,8 +385,8 @@ - - + + @@ -442,7 +442,7 @@ - + @@ -512,7 +512,7 @@ - + diff --git a/test/models/IRR/scenegraphAnimMod.irr b/test/models/IRR/scenegraphAnimMod.irr index 21408b245..9f82efcb0 100644 --- a/test/models/IRR/scenegraphAnimMod.irr +++ b/test/models/IRR/scenegraphAnimMod.irr @@ -126,7 +126,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -213,7 +213,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -347,8 +347,8 @@ - - + + @@ -385,8 +385,8 @@ - - + + @@ -442,7 +442,7 @@ - + @@ -512,7 +512,7 @@ - + diff --git a/test/models/IRR/scenegraphAnimMod_UTF16LE.irr b/test/models/IRR/scenegraphAnimMod_UTF16LE.irr index 7384ae29a..a8cab1a12 100644 Binary files a/test/models/IRR/scenegraphAnimMod_UTF16LE.irr and b/test/models/IRR/scenegraphAnimMod_UTF16LE.irr differ diff --git a/test/models/IRR/scenegraphAnim_UTF16LE.irr b/test/models/IRR/scenegraphAnim_UTF16LE.irr index f6794351f..4b6a2a6f7 100644 Binary files a/test/models/IRR/scenegraphAnim_UTF16LE.irr and b/test/models/IRR/scenegraphAnim_UTF16LE.irr differ diff --git a/test/models/IRR/sphere.irr b/test/models/IRR/sphere.irr index 1e548fee5..1b1896e2a 100644 --- a/test/models/IRR/sphere.irr +++ b/test/models/IRR/sphere.irr @@ -34,7 +34,7 @@ - + diff --git a/test/models/IRR/sphere_UTF16LE.irr b/test/models/IRR/sphere_UTF16LE.irr index d0f99a018..7974a4c70 100644 Binary files a/test/models/IRR/sphere_UTF16LE.irr and b/test/models/IRR/sphere_UTF16LE.irr differ diff --git a/test/models/IRRMesh/1.png b/test/models/IRRMesh/assets/1.png similarity index 100% rename from test/models/IRRMesh/1.png rename to test/models/IRRMesh/assets/1.png diff --git a/test/models/IRRMesh/SpiderTex.jpg b/test/models/IRRMesh/assets/SpiderTex.jpg similarity index 100% rename from test/models/IRRMesh/SpiderTex.jpg rename to test/models/IRRMesh/assets/SpiderTex.jpg diff --git a/test/models/IRRMesh/assets/UVTransformTestImg.png b/test/models/IRRMesh/assets/UVTransformTestImg.png new file mode 100644 index 000000000..b8f6f54f1 Binary files /dev/null and b/test/models/IRRMesh/assets/UVTransformTestImg.png differ diff --git a/test/models/IRRMesh/assets/UVTransform_OffsetUV0.5-mirrorUV.png b/test/models/IRRMesh/assets/UVTransform_OffsetUV0.5-mirrorUV.png new file mode 100644 index 000000000..447d30c32 Binary files /dev/null and b/test/models/IRRMesh/assets/UVTransform_OffsetUV0.5-mirrorUV.png differ diff --git a/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72.png b/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72.png new file mode 100644 index 000000000..4645a5668 Binary files /dev/null and b/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72.png differ diff --git a/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72_mirrorU.png b/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72_mirrorU.png new file mode 100644 index 000000000..9fdc6daab Binary files /dev/null and b/test/models/IRRMesh/assets/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72_mirrorU.png differ diff --git a/test/models/IRRMesh/assets/UVTransform_ScaleUV2x_Rotate45.png b/test/models/IRRMesh/assets/UVTransform_ScaleUV2x_Rotate45.png new file mode 100644 index 000000000..ac15908c3 Binary files /dev/null and b/test/models/IRRMesh/assets/UVTransform_ScaleUV2x_Rotate45.png differ diff --git a/test/models/IRRMesh/brownground_1-1.jpg b/test/models/IRRMesh/assets/brownground_1-1.jpg similarity index 100% rename from test/models/IRRMesh/brownground_1-1.jpg rename to test/models/IRRMesh/assets/brownground_1-1.jpg diff --git a/test/models/IRRMesh/crackedground_1-6.jpg b/test/models/IRRMesh/assets/crackedground_1-6.jpg similarity index 100% rename from test/models/IRRMesh/crackedground_1-6.jpg rename to test/models/IRRMesh/assets/crackedground_1-6.jpg diff --git a/test/models/IRRMesh/drkwood2.jpg b/test/models/IRRMesh/assets/drkwood2.jpg similarity index 100% rename from test/models/IRRMesh/drkwood2.jpg rename to test/models/IRRMesh/assets/drkwood2.jpg diff --git a/test/models/IRRMesh/engineflare1.jpg b/test/models/IRRMesh/assets/engineflare1.jpg similarity index 100% rename from test/models/IRRMesh/engineflare1.jpg rename to test/models/IRRMesh/assets/engineflare1.jpg diff --git a/test/models/IRRMesh/wal67ar_small.jpg b/test/models/IRRMesh/assets/wal67ar_small.jpg similarity index 100% rename from test/models/IRRMesh/wal67ar_small.jpg rename to test/models/IRRMesh/assets/wal67ar_small.jpg diff --git a/test/models/IRRMesh/wal69ar_small.jpg b/test/models/IRRMesh/assets/wal69ar_small.jpg similarity index 100% rename from test/models/IRRMesh/wal69ar_small.jpg rename to test/models/IRRMesh/assets/wal69ar_small.jpg diff --git a/test/models/IRRMesh/cellar.irrmesh b/test/models/IRRMesh/cellar.irrmesh index 0278c9239..ee787463a 100644 --- a/test/models/IRRMesh/cellar.irrmesh +++ b/test/models/IRRMesh/cellar.irrmesh @@ -13,8 +13,8 @@ - - + + @@ -870,8 +870,8 @@ - - + + diff --git a/test/models/IRRMesh/cellar_UTF16LE.irrmesh b/test/models/IRRMesh/cellar_UTF16LE.irrmesh index d8d3a661b..38ef1847c 100644 Binary files a/test/models/IRRMesh/cellar_UTF16LE.irrmesh and b/test/models/IRRMesh/cellar_UTF16LE.irrmesh differ diff --git a/test/models/IRRMesh/spider.irrmesh b/test/models/IRRMesh/spider.irrmesh index e446a9ec2..e94901156 100644 --- a/test/models/IRRMesh/spider.irrmesh +++ b/test/models/IRRMesh/spider.irrmesh @@ -13,7 +13,7 @@ - + @@ -354,7 +354,7 @@ - + @@ -485,7 +485,7 @@ - + @@ -1609,7 +1609,7 @@ - + diff --git a/test/models/IRRMesh/spider_UTF16LE.irrmesh b/test/models/IRRMesh/spider_UTF16LE.irrmesh index 25fda7c27..4a3509d5b 100644 Binary files a/test/models/IRRMesh/spider_UTF16LE.irrmesh and b/test/models/IRRMesh/spider_UTF16LE.irrmesh differ diff --git a/test/models/IRRMesh/testFormatDetection.xml b/test/models/IRRMesh/testFormatDetection.xml index 0986eaf61..fd2e34f65 100644 --- a/test/models/IRRMesh/testFormatDetection.xml +++ b/test/models/IRRMesh/testFormatDetection.xml @@ -13,7 +13,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -179,7 +179,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -345,7 +345,7 @@ - + diff --git a/test/models/IRRMesh/testFormatDetection_UTF16LE.xml b/test/models/IRRMesh/testFormatDetection_UTF16LE.xml index aa73560d4..64891be9f 100644 Binary files a/test/models/IRRMesh/testFormatDetection_UTF16LE.xml and b/test/models/IRRMesh/testFormatDetection_UTF16LE.xml differ diff --git a/test/models/X3D/IndexedLineSet.x3d b/test/models/X3D/IndexedLineSet.x3d new file mode 100644 index 000000000..ed865ebb7 --- /dev/null +++ b/test/models/X3D/IndexedLineSet.x3d @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/test/models/invalid/box_nested_animation_4286.dae b/test/models/invalid/box_nested_animation_4286.dae new file mode 100644 index 000000000..2def61d20 --- /dev/null +++ b/test/models/invalid/box_nested_animation_4286.dae @@ -0,0 +1,196 @@ + + + + + Blender User + Blender 2.80.40 commit date:2019-01-07, commit time:23:37, hash:91a155833e59 + + 2019-01-08T17:44:11 + 2019-01-08T17:44:11 + + Z_UP + + + + + + + + 0.8 0.8 0.8 1 + + + 0 0.5 0 1 + + + + + + + + + + + + + + + + + 1 1 1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 + + + + + + + + + + 0 0 1 0 -1 0 -1 0 0 0 0 -1 1 0 0 0 1 0 + + + + + + + + + + 0.625 0 0.375 0.25 0.375 0 0.625 0.25 0.375 0.5 0.375 0.25 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.75 0.375 1 0.375 0.75 0.375 0.5 0.125 0.75 0.125 0.5 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.5 0.375 0.5 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.75 0.625 1 0.375 1 0.375 0.5 0.375 0.75 0.125 0.75 0.875 0.5 0.875 0.75 0.625 0.75 + + + + + + + + + + + + + + + 3 3 3 3 3 3 3 3 3 3 3 3 +

    4 0 0 2 0 1 0 0 2 2 1 3 7 1 4 3 1 5 6 2 6 5 2 7 7 2 8 1 3 9 7 3 10 5 3 11 0 4 12 3 4 13 1 4 14 4 5 15 1 5 16 5 5 17 4 0 18 6 0 19 2 0 20 2 1 21 6 1 22 7 1 23 6 2 24 4 2 25 5 2 26 1 3 27 3 3 28 7 3 29 0 4 30 2 4 31 3 4 32 4 5 33 0 5 34 1 5 35

    +
    +
    +
    +
    + + + + 1 0 0 -1 0 1 0 1 0 0 1 1 0 0 0 1 + + Bone + + + + + + + + 0.7886752 0.2113248 0.5773504 -0.5773504 -0.5773503 0.5773503 0.5773503 1.154701 -0.2113249 -0.7886752 0.5773503 -0.5773502 0 0 0 1 + + + + + + + + 1 1 1 1 1 1 1 1 + + + + + + + + + + + + + + 1 1 1 1 1 1 1 1 + 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 + + + + + + + + + 0.04166662 0.08333331 0.125 0.1666666 0.2083333 0.25 0.2916666 0.3333333 0.375 0.4166666 0.4583333 0.5 0.5416667 0.5833333 0.625 0.6666667 0.7083333 0.75 0.7916667 0.8333333 0.875 0.9166667 0.9583333 1 1.041667 1.083333 1.125 1.166667 1.208333 1.25 1.291667 1.333333 1.375 1.416667 1.458333 1.5 1.541667 1.583333 1.625 1.666667 + + + + + + + + 1 0 0 1 0 1 0 -1 0 0 1 0 0 0 0 1 0.9999878 3.10816e-5 0.004935208 1 0 0.9999802 -0.006297799 -1 -0.004935306 0.006297722 0.999968 0 0 0 0 1 0.999819 4.61727e-4 0.01901668 1 0 0.9997054 -0.02427293 -1 -0.01902229 0.02426853 0.9995245 0 0 0 0 1 0.9991519 0.002163141 0.04111904 1 0 0.9986191 -0.05253414 -1 -0.04117589 0.05248959 0.9977722 0 0 0 0 1 0.9975264 0.006301912 0.07000974 1 0 0.9959731 -0.08965231 -1 -0.0702928 0.08943056 0.9935095 0 0 0 0 1 0.9944467 0.01411698 0.1042901 1 0 0.9909625 -0.1341392 -1 -0.1052413 0.1333943 0.9854594 0 0 0 0 1 0.9894527 0.02671701 0.1423712 1 0 0.9828442 -0.184438 -1 -0.1448563 0.1824927 0.9724778 0 0 0 0 1 0.9821799 0.04490547 0.1825 1 0 0.9710366 -0.2389307 -1 -0.1879434 0.234673 0.9537326 0 0 0 0 1 0.9724072 0.06904543 0.2228386 1 0 0.9551992 -0.2959637 -1 -0.2332902 0.2877972 0.9288425 0 0 0 0 1 0.9600915 0.09897761 0.261587 1 0 0.9352878 -0.3538882 -1 -0.2796861 0.339765 0.8979618 0 0 0 0 1 0.9453882 0.1340003 0.2971281 1 0 0.9115852 -0.4111113 -1 -0.3259466 0.3886598 0.8618018 0 0 0 0 1 0.9286572 0.1729132 0.328172 1 0 0.8847058 -0.4661497 -1 -0.3709391 0.4328933 0.8215885 0 0 0 0 1 0.9104556 0.2141147 0.3538722 1 0 0.8555763 -0.5176768 -1 -0.4136069 0.4713217 0.7789642 0 0 0 0 1 0.8915175 0.2557371 0.3738919 1 0 0.8253933 -0.5645581 -1 -0.4529863 0.5033134 0.7358525 0 0 0 0 1 0.8727233 0.2957927 0.388408 1 0 0.7955672 -0.6058654 -1 -0.4882152 0.5287529 0.6943099 0 0 0 0 1 0.8550603 0.332307 0.3980502 1 0 0.7676533 -0.6408653 -1 -0.5185286 0.5479785 0.6563899 0 0 0 0 1 0.8395769 0.3634188 0.4037789 1 0 0.7432778 -0.6689829 -1 -0.5432408 0.5616626 0.6240388 0 0 0 0 1 0.8273312 0.3874339 0.4067161 1 0 0.7240622 -0.6897347 -1 -0.5617144 0.5706391 0.5990393 0 0 0 0 1 0.8193359 0.4028329 0.4079393 1 0 0.7115462 -0.7026393 -1 -0.5733138 0.5756976 0.5829953 0 0 0 0 1 0.8164964 0.4082482 0.4082486 1 7.75722e-8 0.707107 -0.7071065 -1 -0.5773504 0.57735 0.5773503 0 0 0 0 1 0.8190646 0.4033515 0.4079717 1 7.78161e-8 0.7111219 -0.7030687 -1 -0.5737014 0.5758587 0.5824547 0 0 0 0 1 0.8263245 0.3893851 0.4068995 1 7.85059e-8 0.7224849 -0.6913868 -1 -0.5631944 0.5713098 0.5970069 0 0 0 0 1 0.8375081 0.3675125 0.4043696 1 7.95684e-8 0.7400277 -0.6725764 -1 -0.5464249 0.5632883 0.6197791 0 0 0 0 1 0.8517552 0.3390183 0.3994742 1 8.0922e-8 0.7624427 -0.6470557 -1 -0.5239399 0.5511332 0.6494145 0 0 0 0 1 0.8681612 0.3053284 0.3912425 1 8.24806e-8 0.7883466 -0.6152314 -1 -0.4962822 0.5341201 0.6844119 0 0 0 0 1 0.8858209 0.2680094 0.3788038 1 8.41584e-8 0.8163394 -0.5775725 -1 -0.4640273 0.5116258 0.7231305 0 0 0 0 1 0.9038687 0.2287352 0.3615268 1 8.58731e-8 0.8450637 -0.5346656 -1 -0.42781 0.4832675 0.7638266 0 0 0 0 1 0.9215156 0.1892192 0.339124 1 8.75496e-8 0.8732626 -0.4872499 -1 -0.3883413 0.4490085 0.8047251 0 0 0 0 1 0.9380813 0.1511175 0.3117163 1 8.91235e-8 0.899834 -0.4362323 -1 -0.3464153 0.4092214 0.8441175 0 0 0 0 1 0.9530206 0.1159168 0.2798482 1 9.05428e-8 0.9238796 -0.3826832 -1 -0.3029055 0.3647051 0.8804763 0 0 0 0 1 0.965943 0.08482374 0.2444564 1 9.17705e-8 0.9447417 -0.3278156 -1 -0.2587547 0.3166512 0.9125667 0 0 0 0 1 0.9766233 0.05867312 0.2067956 1 9.27852e-8 0.9620277 -0.2729518 -1 -0.2149581 0.2665711 0.9395387 0 0 0 0 1 0.9850019 0.03787052 0.1683363 1 9.35812e-8 0.975616 -0.2194843 -1 -0.1725436 0.2161924 0.9609836 0 0 0 0 1 0.991176 0.02237916 0.1306496 1 9.41678e-8 0.9856446 -0.1688333 -1 -0.1325524 0.1673435 0.9769473 0 0 0 0 1 0.9953793 0.01175384 0.09529842 1 9.45671e-8 0.9924796 -0.1224106 -1 -0.09602053 0.121845 0.9878936 0 0 0 0 1 0.997952 0.005218936 0.06375288 1 9.48115e-8 0.996666 -0.08159051 -1 -0.06396614 0.08142342 0.9946249 0 0 0 0 1 0.9993011 0.001782816 0.03733916 1 9.49397e-8 0.998862 -0.04769476 -1 -0.0373817 0.04766143 0.9981638 0 0 0 0 1 0.9998515 3.78837e-4 0.01722835 1 9.4992e-8 0.9997582 -0.02198936 -1 -0.01723252 0.0219861 0.9996098 0 0 0 0 1 0.99999 2.53135e-5 0.004462156 1 9.50052e-8 0.9999838 -0.00569412 -1 -0.004462227 0.005694063 0.9999738 0 0 0 0 1 1 0 0 2 0 1 0 -1 0 0 1 0 0 0 0 1 + + + + + + + + LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR LINEAR + + + + + + + + + + + + + + + + + + + 1 0 0 1 0 1 0 -1 0 0 1 0 0 0 0 1 + + 0.7886751 -0.5773503 -0.211325 0 0.2113248 0.5773503 -0.7886751 0 0.5773503 0.5773503 0.5773502 0 0 0 0 1 + + + 0 + -0.5235989 + -2 + 2 + 2 + + + + + 0 0 0 + 0 0 1 0 + 0 1 0 0 + 1 0 0 0 + 1 1 1 + + #Armature_Bone + + + + + + + + + + + + + + + +
    diff --git a/test/models/invalid/readme.txt b/test/models/invalid/readme.txt index 6ad8b4380..ad144ca36 100644 --- a/test/models/invalid/readme.txt +++ b/test/models/invalid/readme.txt @@ -18,6 +18,9 @@ crash. FILES ********************************************************* +box_nested_animation_4286.dae - This was reported as GH#4286. + The "count" parameter in "Cube-mesh-positions-array" is too small. + OutOfMemory.off - the number of faces is invalid. There won't be enough memory so std::vector::reserve() will most likely fail. The exception should be caught in Importer.cpp. diff --git a/test/unit/AbstractImportExportBase.cpp b/test/unit/AbstractImportExportBase.cpp index 077a4d1f2..80e53500d 100644 --- a/test/unit/AbstractImportExportBase.cpp +++ b/test/unit/AbstractImportExportBase.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/AssimpAPITest.cpp b/test/unit/AssimpAPITest.cpp index b8739b039..effe940b1 100644 --- a/test/unit/AssimpAPITest.cpp +++ b/test/unit/AssimpAPITest.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/AssimpAPITest_aiMatrix3x3.cpp b/test/unit/AssimpAPITest_aiMatrix3x3.cpp index 90976ba6e..7b4532dce 100644 --- a/test/unit/AssimpAPITest_aiMatrix3x3.cpp +++ b/test/unit/AssimpAPITest_aiMatrix3x3.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/AssimpAPITest_aiMatrix4x4.cpp b/test/unit/AssimpAPITest_aiMatrix4x4.cpp index 9372bd9c4..2f17ea2ad 100644 --- a/test/unit/AssimpAPITest_aiMatrix4x4.cpp +++ b/test/unit/AssimpAPITest_aiMatrix4x4.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -47,7 +45,7 @@ using namespace Assimp; class AssimpAPITest_aiMatrix4x4 : public AssimpMathTest { protected: - virtual void SetUp() { + void SetUp() override { result_c = result_cpp = aiMatrix4x4(); } @@ -64,6 +62,11 @@ protected: aiMatrix4x4 result_c, result_cpp; }; +TEST_F(AssimpAPITest_aiMatrix4x4, isIdendityTest) { + aiMatrix4x4 m = aiMatrix4x4(1.001f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + EXPECT_TRUE(m.IsIdentity(1e-3f)); +} + TEST_F(AssimpAPITest_aiMatrix4x4, aiIdentityMatrix4Test) { // Force a non-identity matrix. result_c = aiMatrix4x4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); diff --git a/test/unit/AssimpAPITest_aiQuaternion.cpp b/test/unit/AssimpAPITest_aiQuaternion.cpp index 68daeefec..fe28bc9d0 100644 --- a/test/unit/AssimpAPITest_aiQuaternion.cpp +++ b/test/unit/AssimpAPITest_aiQuaternion.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/AssimpAPITest_aiVector2D.cpp b/test/unit/AssimpAPITest_aiVector2D.cpp index 44bb34aec..8831016cd 100644 --- a/test/unit/AssimpAPITest_aiVector2D.cpp +++ b/test/unit/AssimpAPITest_aiVector2D.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/AssimpAPITest_aiVector3D.cpp b/test/unit/AssimpAPITest_aiVector3D.cpp index c7521163d..67ad11bb6 100644 --- a/test/unit/AssimpAPITest_aiVector3D.cpp +++ b/test/unit/AssimpAPITest_aiVector3D.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/Common/uiScene.cpp b/test/unit/Common/uiScene.cpp index 509bf71b1..5002b5dd8 100644 --- a/test/unit/Common/uiScene.cpp +++ b/test/unit/Common/uiScene.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utAssertHandler.cpp b/test/unit/Common/utAssertHandler.cpp index 039ba8345..53bf5c929 100644 --- a/test/unit/Common/utAssertHandler.cpp +++ b/test/unit/Common/utAssertHandler.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utBase64.cpp b/test/unit/Common/utBase64.cpp index ec927b980..910a908cb 100644 --- a/test/unit/Common/utBase64.cpp +++ b/test/unit/Common/utBase64.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utBaseProcess.cpp b/test/unit/Common/utBaseProcess.cpp index 359042315..f70dae07b 100644 --- a/test/unit/Common/utBaseProcess.cpp +++ b/test/unit/Common/utBaseProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utHash.cpp b/test/unit/Common/utHash.cpp index 97e2d91c1..912aca11d 100644 --- a/test/unit/Common/utHash.cpp +++ b/test/unit/Common/utHash.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utLineSplitter.cpp b/test/unit/Common/utLineSplitter.cpp index 0a97f72d9..f62a00c74 100644 --- a/test/unit/Common/utLineSplitter.cpp +++ b/test/unit/Common/utLineSplitter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/Common/utMaybe.cpp b/test/unit/Common/utMaybe.cpp index 9de300290..c66b8f603 100644 --- a/test/unit/Common/utMaybe.cpp +++ b/test/unit/Common/utMaybe.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utMesh.cpp b/test/unit/Common/utMesh.cpp index 77a711394..7baaa92a0 100644 --- a/test/unit/Common/utMesh.cpp +++ b/test/unit/Common/utMesh.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utSpatialSort.cpp b/test/unit/Common/utSpatialSort.cpp index 6b05ac65e..a75daebce 100644 --- a/test/unit/Common/utSpatialSort.cpp +++ b/test/unit/Common/utSpatialSort.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Common/utStandardShapes.cpp b/test/unit/Common/utStandardShapes.cpp index d7e6d21d7..e1843d6c5 100644 --- a/test/unit/Common/utStandardShapes.cpp +++ b/test/unit/Common/utStandardShapes.cpp @@ -1,7 +1,7 @@ /* Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the diff --git a/test/unit/Common/utXmlParser.cpp b/test/unit/Common/utXmlParser.cpp index 2db78e30d..b566aa381 100644 --- a/test/unit/Common/utXmlParser.cpp +++ b/test/unit/Common/utXmlParser.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/Geometry/utGeometryUtils.cpp b/test/unit/Geometry/utGeometryUtils.cpp index 2e764860d..345946132 100644 --- a/test/unit/Geometry/utGeometryUtils.cpp +++ b/test/unit/Geometry/utGeometryUtils.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/MDL/MDLHL1TestFiles.h b/test/unit/ImportExport/MDL/MDLHL1TestFiles.h index 3c0630f63..0fff3411e 100644 --- a/test/unit/ImportExport/MDL/MDLHL1TestFiles.h +++ b/test/unit/ImportExport/MDL/MDLHL1TestFiles.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp index d50c2b35a..f6e03cb09 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp index f733893ca..d0345e3e4 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp index 49ae8a16c..1029a6138 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/Pbrt/utPbrtImportExport.cpp b/test/unit/ImportExport/Pbrt/utPbrtImportExport.cpp new file mode 100644 index 000000000..c7807205a --- /dev/null +++ b/test/unit/ImportExport/Pbrt/utPbrtImportExport.cpp @@ -0,0 +1,70 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above +copyright notice, this list of conditions and the +following disclaimer. + +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other +materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its +contributors may be used to endorse or promote products +derived from this software without specific prior +written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ +#include "AbstractImportExportBase.h" +#include "UnitTestPCH.h" +#include +#include +#include +#include + +using namespace Assimp; + +class utPbrtImportExport : public AbstractImportExportBase { +public: +#ifndef ASSIMP_BUILD_NO_EXPORT + bool exporterTest() override { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure); + EXPECT_NE(scene, nullptr ); + + ::Assimp::Exporter exporter; + return AI_SUCCESS == exporter.Export(scene, "pbrt", ASSIMP_TEST_MODELS_DIR "/OBJ/spider_out.pbrt"); + } +#endif +}; + +#ifndef ASSIMP_BUILD_NO_EXPORT + +TEST_F(utPbrtImportExport, exportTest_Success) { + EXPECT_TRUE(exporterTest()); +} + +#endif // ASSIMP_BUILD_NO_EXPORT diff --git a/test/unit/ImportExport/RAW/utRAWImportExport.cpp b/test/unit/ImportExport/RAW/utRAWImportExport.cpp index bdd7f8533..9981ed2f7 100644 --- a/test/unit/ImportExport/RAW/utRAWImportExport.cpp +++ b/test/unit/ImportExport/RAW/utRAWImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/Terragen/utTerragenImportExport.cpp b/test/unit/ImportExport/Terragen/utTerragenImportExport.cpp index 8ec20e0c0..1ddde44a6 100644 --- a/test/unit/ImportExport/Terragen/utTerragenImportExport.cpp +++ b/test/unit/ImportExport/Terragen/utTerragenImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utAssjsonImportExport.cpp b/test/unit/ImportExport/utAssjsonImportExport.cpp index 3470874b5..c32b0f160 100644 --- a/test/unit/ImportExport/utAssjsonImportExport.cpp +++ b/test/unit/ImportExport/utAssjsonImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utCOBImportExport.cpp b/test/unit/ImportExport/utCOBImportExport.cpp index 187f16ede..705cda38d 100644 --- a/test/unit/ImportExport/utCOBImportExport.cpp +++ b/test/unit/ImportExport/utCOBImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utExporter.cpp b/test/unit/ImportExport/utExporter.cpp index 096a5c49d..d94f179ed 100644 --- a/test/unit/ImportExport/utExporter.cpp +++ b/test/unit/ImportExport/utExporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utMD2Importer.cpp b/test/unit/ImportExport/utMD2Importer.cpp index 0fcf76bfc..975b8f641 100644 --- a/test/unit/ImportExport/utMD2Importer.cpp +++ b/test/unit/ImportExport/utMD2Importer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utMD5Importer.cpp b/test/unit/ImportExport/utMD5Importer.cpp index 082121937..6fe558565 100644 --- a/test/unit/ImportExport/utMD5Importer.cpp +++ b/test/unit/ImportExport/utMD5Importer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utMDLImporter.cpp b/test/unit/ImportExport/utMDLImporter.cpp index c8960601d..43cdf9a1d 100644 --- a/test/unit/ImportExport/utMDLImporter.cpp +++ b/test/unit/ImportExport/utMDLImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utNFFImportExport.cpp b/test/unit/ImportExport/utNFFImportExport.cpp index 621324a85..b989578f5 100644 --- a/test/unit/ImportExport/utNFFImportExport.cpp +++ b/test/unit/ImportExport/utNFFImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utOFFImportExport.cpp b/test/unit/ImportExport/utOFFImportExport.cpp index 78ae4acc4..abd1fe154 100644 --- a/test/unit/ImportExport/utOFFImportExport.cpp +++ b/test/unit/ImportExport/utOFFImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utOgreImportExport.cpp b/test/unit/ImportExport/utOgreImportExport.cpp index 7312d6b58..d3234c036 100644 --- a/test/unit/ImportExport/utOgreImportExport.cpp +++ b/test/unit/ImportExport/utOgreImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utQ3BSPFileImportExport.cpp b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp index f5694d2ee..d8738eff7 100644 --- a/test/unit/ImportExport/utQ3BSPFileImportExport.cpp +++ b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ImportExport/utXGLImportExport.cpp b/test/unit/ImportExport/utXGLImportExport.cpp index 8199806cc..080290e1d 100644 --- a/test/unit/ImportExport/utXGLImportExport.cpp +++ b/test/unit/ImportExport/utXGLImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/MathTest.cpp b/test/unit/MathTest.cpp index 86a5d7e0f..6069df22e 100644 --- a/test/unit/MathTest.cpp +++ b/test/unit/MathTest.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/MathTest.h b/test/unit/MathTest.h index 08411e82f..a09024370 100644 --- a/test/unit/MathTest.h +++ b/test/unit/MathTest.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/RandomNumberGeneration.h b/test/unit/RandomNumberGeneration.h index 95ba5b43b..0383332e4 100644 --- a/test/unit/RandomNumberGeneration.h +++ b/test/unit/RandomNumberGeneration.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/SceneDiffer.cpp b/test/unit/SceneDiffer.cpp index a7132496a..6cbc33dde 100644 --- a/test/unit/SceneDiffer.cpp +++ b/test/unit/SceneDiffer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/SceneDiffer.h b/test/unit/SceneDiffer.h index 2ac429b76..06065bd5f 100644 --- a/test/unit/SceneDiffer.h +++ b/test/unit/SceneDiffer.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/TestIOSystem.h b/test/unit/TestIOSystem.h index fe2455e52..8791f9b92 100644 --- a/test/unit/TestIOSystem.h +++ b/test/unit/TestIOSystem.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/TestModelFactory.h b/test/unit/TestModelFactory.h index c938af0fd..2ddf37e3e 100644 --- a/test/unit/TestModelFactory.h +++ b/test/unit/TestModelFactory.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/UTLogStream.h b/test/unit/UTLogStream.h index 6e5d75762..d35de8bdc 100644 --- a/test/unit/UTLogStream.h +++ b/test/unit/UTLogStream.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/UnitTestFileGenerator.h b/test/unit/UnitTestFileGenerator.h index 2166c6939..93007bad9 100644 --- a/test/unit/UnitTestFileGenerator.h +++ b/test/unit/UnitTestFileGenerator.h @@ -44,9 +44,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__) +#define TMP_PATH "./" +#elif defined(__GNUC__) || defined(__clang__) +#define TMP_PATH "/tmp/" +#endif + #if defined(_MSC_VER) #include -#define TMP_PATH "./" inline FILE* MakeTmpFile(char* tmplate) { auto pathtemplate = _mktemp(tmplate); @@ -60,7 +65,6 @@ inline FILE* MakeTmpFile(char* tmplate) return fs; } #elif defined(__GNUC__) || defined(__clang__) -#define TMP_PATH "/tmp/" inline FILE* MakeTmpFile(char* tmplate) { auto fd = mkstemp(tmplate); diff --git a/test/unit/ut3DImportExport.cpp b/test/unit/ut3DImportExport.cpp index 32b77ddf8..4cd538c46 100644 --- a/test/unit/ut3DImportExport.cpp +++ b/test/unit/ut3DImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/ut3DSImportExport.cpp b/test/unit/ut3DSImportExport.cpp index 7279227fc..a2da3607c 100644 --- a/test/unit/ut3DSImportExport.cpp +++ b/test/unit/ut3DSImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utACImportExport.cpp b/test/unit/utACImportExport.cpp index c844603cf..4fdb68651 100644 --- a/test/unit/utACImportExport.cpp +++ b/test/unit/utACImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -99,6 +99,12 @@ TEST(utACImportExport, importSphereWithLight) { ASSERT_NE(nullptr, scene); } +TEST(utACImportExport, importSphereWithLightACC) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/AC/SphereWithLight.acc", aiProcess_ValidateDataStructure); + ASSERT_NE(nullptr, scene); +} + TEST(utACImportExport, importSphereWithLightUTF16) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/AC/SphereWithLight_UTF16LE.ac", aiProcess_ValidateDataStructure); diff --git a/test/unit/utAMFImportExport.cpp b/test/unit/utAMFImportExport.cpp index 7319320cf..996614572 100644 --- a/test/unit/utAMFImportExport.cpp +++ b/test/unit/utAMFImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utASEImportExport.cpp b/test/unit/utASEImportExport.cpp index af05a2fe5..e2d1bfa59 100644 --- a/test/unit/utASEImportExport.cpp +++ b/test/unit/utASEImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utAnim.cpp b/test/unit/utAnim.cpp index 956810d74..613f7f03b 100644 --- a/test/unit/utAnim.cpp +++ b/test/unit/utAnim.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utArmaturePopulate.cpp b/test/unit/utArmaturePopulate.cpp index 0acea7b50..9f4545c6a 100644 --- a/test/unit/utArmaturePopulate.cpp +++ b/test/unit/utArmaturePopulate.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utAssbinImportExport.cpp b/test/unit/utAssbinImportExport.cpp index 437a0a5fe..5eb2f56bd 100644 --- a/test/unit/utAssbinImportExport.cpp +++ b/test/unit/utAssbinImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utB3DImportExport.cpp b/test/unit/utB3DImportExport.cpp index 9672aa01b..76017f66c 100644 --- a/test/unit/utB3DImportExport.cpp +++ b/test/unit/utB3DImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utBVHImportExport.cpp b/test/unit/utBVHImportExport.cpp index 5a0ff1e10..94636c7bf 100644 --- a/test/unit/utBVHImportExport.cpp +++ b/test/unit/utBVHImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utBatchLoader.cpp b/test/unit/utBatchLoader.cpp index df6aa7995..be1ac30ad 100644 --- a/test/unit/utBatchLoader.cpp +++ b/test/unit/utBatchLoader.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utBlendImportAreaLight.cpp b/test/unit/utBlendImportAreaLight.cpp index 470d80737..cc6e1e1a0 100644 --- a/test/unit/utBlendImportAreaLight.cpp +++ b/test/unit/utBlendImportAreaLight.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utBlendImportMaterials.cpp b/test/unit/utBlendImportMaterials.cpp index 11499cc18..416fb3236 100644 --- a/test/unit/utBlendImportMaterials.cpp +++ b/test/unit/utBlendImportMaterials.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utBlenderImportExport.cpp b/test/unit/utBlenderImportExport.cpp index 26fa36d14..36dc5563c 100644 --- a/test/unit/utBlenderImportExport.cpp +++ b/test/unit/utBlenderImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utBlenderIntermediate.cpp b/test/unit/utBlenderIntermediate.cpp index c2cc51e8d..b76c48b44 100644 --- a/test/unit/utBlenderIntermediate.cpp +++ b/test/unit/utBlenderIntermediate.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utBlenderWork.cpp b/test/unit/utBlenderWork.cpp index 977877250..2ba6329ca 100644 --- a/test/unit/utBlenderWork.cpp +++ b/test/unit/utBlenderWork.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utCSMImportExport.cpp b/test/unit/utCSMImportExport.cpp index 13bfd52bc..8ef14e282 100644 --- a/test/unit/utCSMImportExport.cpp +++ b/test/unit/utCSMImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utColladaExport.cpp b/test/unit/utColladaExport.cpp index 0df9312f2..e0a62b338 100644 --- a/test/unit/utColladaExport.cpp +++ b/test/unit/utColladaExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utColladaImportExport.cpp b/test/unit/utColladaImportExport.cpp index e2842732e..4e92c6930 100644 --- a/test/unit/utColladaImportExport.cpp +++ b/test/unit/utColladaImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -357,6 +357,14 @@ TEST_F(utColladaImportExport, exporterUniqueIdsTest) { ImportAsNames(outFileNamed, scene); } +// This file is invalid, we just want to ensure that the importer is not crashing +// This was reported as GH#4286. The "count" parameter in "Cube-mesh-positions-array" is too small. +TEST_F(utColladaImportExport, parseInvalid4286) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/invalid/box_nested_animation_4286.dae", 0); + EXPECT_EQ(nullptr, scene); +} + #endif class utColladaZaeImportExport : public AbstractImportExportBase { diff --git a/test/unit/utD3MFImportExport.cpp b/test/unit/utD3MFImportExport.cpp index ed290e876..f25b2dcf7 100644 --- a/test/unit/utD3MFImportExport.cpp +++ b/test/unit/utD3MFImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utDXFImporterExporter.cpp b/test/unit/utDXFImporterExporter.cpp index 53c5328e4..ee0c57db6 100644 --- a/test/unit/utDXFImporterExporter.cpp +++ b/test/unit/utDXFImporterExporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utDefaultIOStream.cpp b/test/unit/utDefaultIOStream.cpp index 803c6f6f6..2a2d7a894 100644 --- a/test/unit/utDefaultIOStream.cpp +++ b/test/unit/utDefaultIOStream.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utExport.cpp b/test/unit/utExport.cpp index cb7826bfc..ebb664fa4 100644 --- a/test/unit/utExport.cpp +++ b/test/unit/utExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utFBXImporterExporter.cpp b/test/unit/utFBXImporterExporter.cpp index 9fa293aaf..5cc40d216 100644 --- a/test/unit/utFBXImporterExporter.cpp +++ b/test/unit/utFBXImporterExporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utFastAtof.cpp b/test/unit/utFastAtof.cpp index cc25482d2..50c26ca03 100644 --- a/test/unit/utFastAtof.cpp +++ b/test/unit/utFastAtof.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utFindDegenerates.cpp b/test/unit/utFindDegenerates.cpp index 5eadc032c..04f554716 100644 --- a/test/unit/utFindDegenerates.cpp +++ b/test/unit/utFindDegenerates.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utFindInvalidData.cpp b/test/unit/utFindInvalidData.cpp index b995b951b..ab845b35e 100644 --- a/test/unit/utFindInvalidData.cpp +++ b/test/unit/utFindInvalidData.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utFixInfacingNormals.cpp b/test/unit/utFixInfacingNormals.cpp index 8f75dd2f0..54fef7b59 100644 --- a/test/unit/utFixInfacingNormals.cpp +++ b/test/unit/utFixInfacingNormals.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utGenBoundingBoxesProcess.cpp b/test/unit/utGenBoundingBoxesProcess.cpp index c512e7f80..18b15c31e 100644 --- a/test/unit/utGenBoundingBoxesProcess.cpp +++ b/test/unit/utGenBoundingBoxesProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utGenNormals.cpp b/test/unit/utGenNormals.cpp index 92d477dbf..4a1db0216 100644 --- a/test/unit/utGenNormals.cpp +++ b/test/unit/utGenNormals.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utHMPImportExport.cpp b/test/unit/utHMPImportExport.cpp index 83e7ba09d..8171bb26a 100644 --- a/test/unit/utHMPImportExport.cpp +++ b/test/unit/utHMPImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utIFCImportExport.cpp b/test/unit/utIFCImportExport.cpp index 49c7446c7..06009be2b 100644 --- a/test/unit/utIFCImportExport.cpp +++ b/test/unit/utIFCImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index 7565014c1..381716040 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utIOSystem.cpp b/test/unit/utIOSystem.cpp index d69e645fe..5bc9996b0 100644 --- a/test/unit/utIOSystem.cpp +++ b/test/unit/utIOSystem.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utImporter.cpp b/test/unit/utImporter.cpp index 5ecc45e34..2470283c0 100644 --- a/test/unit/utImporter.cpp +++ b/test/unit/utImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utImproveCacheLocality.cpp b/test/unit/utImproveCacheLocality.cpp index 0e97eb0c7..269721eda 100644 --- a/test/unit/utImproveCacheLocality.cpp +++ b/test/unit/utImproveCacheLocality.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utIssues.cpp b/test/unit/utIssues.cpp index 546c36ad0..4a3fa1585 100644 --- a/test/unit/utIssues.cpp +++ b/test/unit/utIssues.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utJoinVertices.cpp b/test/unit/utJoinVertices.cpp index b0700900c..9dbe87536 100644 --- a/test/unit/utJoinVertices.cpp +++ b/test/unit/utJoinVertices.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utLWOImportExport.cpp b/test/unit/utLWOImportExport.cpp index 2ab1c4722..78572a7db 100644 --- a/test/unit/utLWOImportExport.cpp +++ b/test/unit/utLWOImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utLWSImportExport.cpp b/test/unit/utLWSImportExport.cpp index 730911ec2..3f9c62361 100644 --- a/test/unit/utLWSImportExport.cpp +++ b/test/unit/utLWSImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utLimitBoneWeights.cpp b/test/unit/utLimitBoneWeights.cpp index bf3ea93f5..5a543aa2b 100644 --- a/test/unit/utLimitBoneWeights.cpp +++ b/test/unit/utLimitBoneWeights.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utMDCImportExport.cpp b/test/unit/utMDCImportExport.cpp index 29b9ed56c..d5b8dee0b 100644 --- a/test/unit/utMDCImportExport.cpp +++ b/test/unit/utMDCImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utMaterialSystem.cpp b/test/unit/utMaterialSystem.cpp index a84ae8333..8b1691b3f 100644 --- a/test/unit/utMaterialSystem.cpp +++ b/test/unit/utMaterialSystem.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utMatrix3x3.cpp b/test/unit/utMatrix3x3.cpp index ae722a811..54bbece7d 100644 --- a/test/unit/utMatrix3x3.cpp +++ b/test/unit/utMatrix3x3.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utMatrix4x4.cpp b/test/unit/utMatrix4x4.cpp index 795971afc..510900e82 100644 --- a/test/unit/utMatrix4x4.cpp +++ b/test/unit/utMatrix4x4.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -90,3 +90,17 @@ TEST_F(utMatrix4x4, indexOperatorTest) { ai_real *a15 = a12 + 3; EXPECT_FLOAT_EQ(1.0, *a15); } + +TEST_F(utMatrix4x4, identityMatrixTest) { + aiMatrix4x4 m1 = aiMatrix4x4(1.f,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0, 1); + EXPECT_TRUE(m1.IsIdentity()); + aiMatrix4x4 m2 = aiMatrix4x4(1.02f,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0, 1); + EXPECT_FALSE(m2.IsIdentity()); + aiMatrix4x4 m3 = aiMatrix4x4(1.009f,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0, 1); + EXPECT_TRUE(m3.IsIdentity()); + + EXPECT_TRUE(m1.IsIdentity(1e-3f)); + EXPECT_FALSE(m2.IsIdentity(1e-3f)); + EXPECT_TRUE(m2.IsIdentity(1e-1f)); + EXPECT_FALSE(m3.IsIdentity(1e-3f)); +} diff --git a/test/unit/utMetadata.cpp b/test/unit/utMetadata.cpp index 676404c3c..e7cd239aa 100644 --- a/test/unit/utMetadata.cpp +++ b/test/unit/utMetadata.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index ce778a950..8e9b4e633 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utObjTools.cpp b/test/unit/utObjTools.cpp index f2e5304ad..f1437ff32 100644 --- a/test/unit/utObjTools.cpp +++ b/test/unit/utObjTools.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utOpenGEXImportExport.cpp b/test/unit/utOpenGEXImportExport.cpp index ed22a6fb7..51da9e237 100644 --- a/test/unit/utOpenGEXImportExport.cpp +++ b/test/unit/utOpenGEXImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 13c90fc47..e748a40cf 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utPMXImporter.cpp b/test/unit/utPMXImporter.cpp index 167fb234a..a5aba923b 100644 --- a/test/unit/utPMXImporter.cpp +++ b/test/unit/utPMXImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utPretransformVertices.cpp b/test/unit/utPretransformVertices.cpp index b3ae818bc..9652ec611 100644 --- a/test/unit/utPretransformVertices.cpp +++ b/test/unit/utPretransformVertices.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utProfiler.cpp b/test/unit/utProfiler.cpp index 6738d568e..a9a54a934 100644 --- a/test/unit/utProfiler.cpp +++ b/test/unit/utProfiler.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utQ3DImportExport.cpp b/test/unit/utQ3DImportExport.cpp index e5396a680..4fb71bb69 100644 --- a/test/unit/utQ3DImportExport.cpp +++ b/test/unit/utQ3DImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utRemoveComments.cpp b/test/unit/utRemoveComments.cpp index 44fb56ef8..f101b7d9e 100644 --- a/test/unit/utRemoveComments.cpp +++ b/test/unit/utRemoveComments.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utRemoveComponent.cpp b/test/unit/utRemoveComponent.cpp index dd9e4f9cb..5fbfe612c 100644 --- a/test/unit/utRemoveComponent.cpp +++ b/test/unit/utRemoveComponent.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utRemoveRedundantMaterials.cpp b/test/unit/utRemoveRedundantMaterials.cpp index 99b91aa5f..5c9983859 100644 --- a/test/unit/utRemoveRedundantMaterials.cpp +++ b/test/unit/utRemoveRedundantMaterials.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utRemoveVCProcess.cpp b/test/unit/utRemoveVCProcess.cpp index b555b0c86..fdb4049b9 100644 --- a/test/unit/utRemoveVCProcess.cpp +++ b/test/unit/utRemoveVCProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSIBImporter.cpp b/test/unit/utSIBImporter.cpp index b36e0883f..e2deb85c2 100644 --- a/test/unit/utSIBImporter.cpp +++ b/test/unit/utSIBImporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSMDImportExport.cpp b/test/unit/utSMDImportExport.cpp index 08683d554..6e2bc08e7 100644 --- a/test/unit/utSMDImportExport.cpp +++ b/test/unit/utSMDImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSTLImportExport.cpp b/test/unit/utSTLImportExport.cpp index 4bf374a1b..7e2c29168 100644 --- a/test/unit/utSTLImportExport.cpp +++ b/test/unit/utSTLImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utScaleProcess.cpp b/test/unit/utScaleProcess.cpp index baa13ab52..5772d4883 100644 --- a/test/unit/utScaleProcess.cpp +++ b/test/unit/utScaleProcess.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSceneCombiner.cpp b/test/unit/utSceneCombiner.cpp index d837e4dce..055b54f5b 100644 --- a/test/unit/utSceneCombiner.cpp +++ b/test/unit/utSceneCombiner.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utScenePreprocessor.cpp b/test/unit/utScenePreprocessor.cpp index 45d8a36ee..5e3dd95ce 100644 --- a/test/unit/utScenePreprocessor.cpp +++ b/test/unit/utScenePreprocessor.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSharedPPData.cpp b/test/unit/utSharedPPData.cpp index 16ee9c75f..f70d352ff 100644 --- a/test/unit/utSharedPPData.cpp +++ b/test/unit/utSharedPPData.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utSimd.cpp b/test/unit/utSimd.cpp index 720d657b6..3f073b475 100644 --- a/test/unit/utSimd.cpp +++ b/test/unit/utSimd.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSortByPType.cpp b/test/unit/utSortByPType.cpp index 5fd360fcc..ff8b717ef 100644 --- a/test/unit/utSortByPType.cpp +++ b/test/unit/utSortByPType.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utSplitLargeMeshes.cpp b/test/unit/utSplitLargeMeshes.cpp index 160831baa..b8bab7193 100644 --- a/test/unit/utSplitLargeMeshes.cpp +++ b/test/unit/utSplitLargeMeshes.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utStringUtils.cpp b/test/unit/utStringUtils.cpp index 9c5ab31f5..7cb11797d 100644 --- a/test/unit/utStringUtils.cpp +++ b/test/unit/utStringUtils.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utTargetAnimation.cpp b/test/unit/utTargetAnimation.cpp index 9cbb45309..2711e895c 100644 --- a/test/unit/utTargetAnimation.cpp +++ b/test/unit/utTargetAnimation.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utTextureTransform.cpp b/test/unit/utTextureTransform.cpp index 9cbb45309..2711e895c 100644 --- a/test/unit/utTextureTransform.cpp +++ b/test/unit/utTextureTransform.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utTriangulate.cpp b/test/unit/utTriangulate.cpp index f51daea63..2df0ce6cd 100644 --- a/test/unit/utTriangulate.cpp +++ b/test/unit/utTriangulate.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utTypes.cpp b/test/unit/utTypes.cpp index 33d2b4f76..45a4b5517 100644 --- a/test/unit/utTypes.cpp +++ b/test/unit/utTypes.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/test/unit/utVector3.cpp b/test/unit/utVector3.cpp index 2602c287c..f13521894 100644 --- a/test/unit/utVector3.cpp +++ b/test/unit/utVector3.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utVersion.cpp b/test/unit/utVersion.cpp index e4378e9f6..838d2dd7f 100644 --- a/test/unit/utVersion.cpp +++ b/test/unit/utVersion.cpp @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -48,18 +48,18 @@ TEST_F( utVersion, aiGetLegalStringTest ) { EXPECT_NE( lv, nullptr ); std::string text( lv ); - size_t pos = text.find(std::string("2023")); + size_t pos = text.find(std::string("2024")); EXPECT_NE(pos, std::string::npos); } -TEST_F( utVersion, aiGetVersionMinorTest ) { - EXPECT_EQ(aiGetVersionMinor(), 3U); -} - TEST_F( utVersion, aiGetVersionMajorTest ) { EXPECT_EQ( aiGetVersionMajor(), 5U ); } +TEST_F( utVersion, aiGetVersionMinorTest ) { + EXPECT_EQ(aiGetVersionMinor(), 4U); +} + TEST_F( utVersion, aiGetVersionPatchTest ) { EXPECT_EQ(aiGetVersionPatch(), 0U ); } diff --git a/test/unit/utVertexTriangleAdjacency.cpp b/test/unit/utVertexTriangleAdjacency.cpp index 8c8d9db04..f5ad492ef 100644 --- a/test/unit/utVertexTriangleAdjacency.cpp +++ b/test/unit/utVertexTriangleAdjacency.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utX3DImportExport.cpp b/test/unit/utX3DImportExport.cpp index f2df81ac2..b0b6802b9 100644 --- a/test/unit/utX3DImportExport.cpp +++ b/test/unit/utX3DImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include using namespace Assimp; @@ -59,3 +60,16 @@ public: TEST_F(utX3DImportExport, importX3DFromFileTest) { EXPECT_TRUE(importerTest()); } + +TEST_F(utX3DImportExport, importX3DIndexedLineSet) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/X3D/IndexedLineSet.x3d", aiProcess_ValidateDataStructure); + ASSERT_NE(nullptr, scene); + ASSERT_EQ(scene->mNumMeshes, 1u); + ASSERT_EQ(scene->mMeshes[0]->mNumFaces, 4u); + ASSERT_EQ(scene->mMeshes[0]->mPrimitiveTypes, aiPrimitiveType_LINE); + ASSERT_EQ(scene->mMeshes[0]->mNumVertices, 4u); + for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; i++) { + ASSERT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2u); + } +} diff --git a/test/unit/utXImporterExporter.cpp b/test/unit/utXImporterExporter.cpp index 4d247cc6f..807e3ca83 100644 --- a/test/unit/utXImporterExporter.cpp +++ b/test/unit/utXImporterExporter.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 6778e2679..c29d17d33 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -988,3 +988,27 @@ TEST_F(utglTF2ImportExport, noSchemaFound) { EXPECT_NE(scene, nullptr); EXPECT_STREQ(importer.GetErrorString(), ""); } + +// ------------------------------------------------------------------------------------------------ +TEST_F(utglTF2ImportExport, testSetIdentityMatrixEpsilon) { +// Assimp::Exporter exporter; + Assimp::ExportProperties properties = Assimp::ExportProperties(); + EXPECT_EQ(AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT, + properties.GetPropertyFloat("CHECK_IDENTITY_MATRIX_EPSILON", + AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT)); + aiMatrix4x4 m; + m = aiMatrix4x4(1.02f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + EXPECT_FALSE(m.IsIdentity()); + m = aiMatrix4x4(1.001f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + EXPECT_TRUE(m.IsIdentity()); + + bool b = properties.SetPropertyFloat("CHECK_IDENTITY_MATRIX_EPSILON", 0.0001f); + EXPECT_TRUE(!b); + ai_real epsilon = properties.GetPropertyFloat("CHECK_IDENTITY_MATRIX_EPSILON", 0.01f); + EXPECT_EQ(0.0001f, epsilon); + m = aiMatrix4x4(1.0002f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + EXPECT_FALSE(m.IsIdentity(epsilon)); + m = aiMatrix4x4(1.00009f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + EXPECT_TRUE(m.IsIdentity(epsilon)); +} + diff --git a/test/unit/utglTFImportExport.cpp b/test/unit/utglTFImportExport.cpp index cb20c1519..9d1cebc54 100644 --- a/test/unit/utglTFImportExport.cpp +++ b/test/unit/utglTFImportExport.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/CMakeLists.txt b/tools/assimp_cmd/CMakeLists.txt index 5b80ee77b..2f4486723 100644 --- a/tools/assimp_cmd/CMakeLists.txt +++ b/tools/assimp_cmd/CMakeLists.txt @@ -1,7 +1,7 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- # -# Copyright (c) 2006-2022, assimp team +# Copyright (c) 2006-2024, assimp team # All rights reserved. # # Redistribution and use of this software in source and binary forms, diff --git a/tools/assimp_cmd/CompareDump.cpp b/tools/assimp_cmd/CompareDump.cpp index 3cf22bb28..5ea162cae 100644 --- a/tools/assimp_cmd/CompareDump.cpp +++ b/tools/assimp_cmd/CompareDump.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team diff --git a/tools/assimp_cmd/Export.cpp b/tools/assimp_cmd/Export.cpp index b78db157b..2961bad2c 100644 --- a/tools/assimp_cmd/Export.cpp +++ b/tools/assimp_cmd/Export.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/ImageExtractor.cpp b/tools/assimp_cmd/ImageExtractor.cpp index 49edf9790..6469db42b 100644 --- a/tools/assimp_cmd/ImageExtractor.cpp +++ b/tools/assimp_cmd/ImageExtractor.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/Info.cpp b/tools/assimp_cmd/Info.cpp index d67974269..18cf1a1c1 100644 --- a/tools/assimp_cmd/Info.cpp +++ b/tools/assimp_cmd/Info.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/Main.cpp b/tools/assimp_cmd/Main.cpp index 06c44f029..aa7a137de 100644 --- a/tools/assimp_cmd/Main.cpp +++ b/tools/assimp_cmd/Main.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/Main.h b/tools/assimp_cmd/Main.h index a95bc96f6..a3329dd0b 100644 --- a/tools/assimp_cmd/Main.h +++ b/tools/assimp_cmd/Main.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_cmd/WriteDump.cpp b/tools/assimp_cmd/WriteDump.cpp index 4ada408fd..d922d7947 100644 --- a/tools/assimp_cmd/WriteDump.cpp +++ b/tools/assimp_cmd/WriteDump.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/AnimEvaluator.cpp b/tools/assimp_view/AnimEvaluator.cpp index 4f8d1bda8..206afb284 100644 --- a/tools/assimp_view/AnimEvaluator.cpp +++ b/tools/assimp_view/AnimEvaluator.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/AnimEvaluator.h b/tools/assimp_view/AnimEvaluator.h index aa44ab211..854b232dd 100644 --- a/tools/assimp_view/AnimEvaluator.h +++ b/tools/assimp_view/AnimEvaluator.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/AssetHelper.h b/tools/assimp_view/AssetHelper.h index 8661d875f..16648f9c7 100644 --- a/tools/assimp_view/AssetHelper.h +++ b/tools/assimp_view/AssetHelper.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/Background.cpp b/tools/assimp_view/Background.cpp index e49630204..6943115df 100644 --- a/tools/assimp_view/Background.cpp +++ b/tools/assimp_view/Background.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/CMakeLists.txt b/tools/assimp_view/CMakeLists.txt index a5a9eed35..e8c354fc8 100644 --- a/tools/assimp_view/CMakeLists.txt +++ b/tools/assimp_view/CMakeLists.txt @@ -1,7 +1,7 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- # -# Copyright (c) 2006-2022, assimp team +# Copyright (c) 2006-2024, assimp team # All rights reserved. diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 95ed41615..5020d65ca 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. @@ -518,20 +518,19 @@ int CDisplay::AddTextureToDisplayList(unsigned int iType, return 1; } //------------------------------------------------------------------------------- -int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, - unsigned int iIndex) -{ +int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, unsigned int iIndex) { ai_assert(nullptr != hRoot); aiMaterial* pcMat = g_pcAsset->pcScene->mMaterials[iIndex]; + if (g_pcAsset->pcScene->mNumMeshes == 0) { + return -1; + } // find the first mesh using this material index unsigned int iMesh = 0; - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { - if (iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex) - { + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) { + if (iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex) { iMesh = i; break; } @@ -540,12 +539,9 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, // use the name of the material, if possible char chTemp[512]; aiString szOut; - if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut)) - { + if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut)) { ai_snprintf(chTemp,512,"Material %i",iIndex+1); - } - else - { + } else { ai_snprintf(chTemp,512,"%s (%i)",szOut.data,iIndex+1); } TVITEMEXW tvi; @@ -577,17 +573,15 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, aiTextureOp eOp; aiString szPath; bool bNoOpacity = true; - for (unsigned int i = 0; i <= AI_TEXTURE_TYPE_MAX;++i) - { + for (unsigned int i = 0; i <= AI_TEXTURE_TYPE_MAX;++i) { unsigned int iNum = 0; - while (true) - { - if (AI_SUCCESS != aiGetMaterialTexture(pcMat,(aiTextureType)i,iNum, - &szPath,nullptr, &iUV,&fBlend,&eOp)) - { + while (true) { + if (AI_SUCCESS != aiGetMaterialTexture(pcMat,(aiTextureType)i,iNum, &szPath,nullptr, &iUV,&fBlend,&eOp)) { break; } - if (aiTextureType_OPACITY == i)bNoOpacity = false; + if (aiTextureType_OPACITY == i) { + bNoOpacity = false; + } AddTextureToDisplayList(i,iNum,&szPath,hTexture,iUV,fBlend,eOp,iMesh); ++iNum; } @@ -595,8 +589,7 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, AssetHelper::MeshHelper* pcMesh = g_pcAsset->apcMeshes[iMesh]; - if (pcMesh->piDiffuseTexture && pcMesh->piDiffuseTexture == pcMesh->piOpacityTexture && bNoOpacity) - { + if (pcMesh->piDiffuseTexture && pcMesh->piDiffuseTexture == pcMesh->piOpacityTexture && bNoOpacity) { // check whether the diffuse texture is not a default texture // {9785DA94-1D96-426b-B3CB-BADC36347F5E} @@ -606,9 +599,7 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, uint32_t iData = 0; DWORD dwSize = 4; - if(FAILED( pcMesh->piDiffuseTexture->GetPrivateData(guidPrivateData,&iData,&dwSize) || - 0xffffffff == iData)) - { + if(FAILED( pcMesh->piDiffuseTexture->GetPrivateData(guidPrivateData,&iData,&dwSize) || 0xffffffff == iData)) { // seems the diffuse texture contains alpha, therefore it has been // added to the opacity channel, too. Add a special value ... AddTextureToDisplayList(aiTextureType_OPACITY | 0x40000000, @@ -625,33 +616,26 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, this->AddMaterial(info); return 1; } + //------------------------------------------------------------------------------- // Expand all elements in the tree-view -int CDisplay::ExpandTree() -{ +int CDisplay::ExpandTree() { // expand all materials - for (std::vector< MaterialInfo >::iterator - i = m_asMaterials.begin(); - i != m_asMaterials.end();++i) - { + for (std::vector< MaterialInfo >::iterator i = m_asMaterials.begin(); i != m_asMaterials.end();++i) { TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),(*i).hTreeItem,TVE_EXPAND); } // expand all nodes - for (std::vector< NodeInfo >::iterator - i = m_asNodes.begin(); - i != m_asNodes.end();++i) - { + for (std::vector< NodeInfo >::iterator i = m_asNodes.begin(); i != m_asNodes.end();++i) { TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),(*i).hTreeItem,TVE_EXPAND); } TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),m_hRoot,TVE_EXPAND); return 1; } + //------------------------------------------------------------------------------- // Get image list for tree view -int CDisplay::LoadImageList(void) -{ - if (!m_hImageList) - { +int CDisplay::LoadImageList() { + if (!m_hImageList) { // First, create the image list we will need. // FIX: Need RGB888 color space to display all colors correctly HIMAGELIST hIml = ImageList_Create( 16,16,ILC_COLOR24, 5, 0 ); @@ -682,12 +666,13 @@ int CDisplay::LoadImageList(void) m_hImageList = hIml; } + return 1; } + //------------------------------------------------------------------------------- // Fill tree view -int CDisplay::FillDisplayList(void) -{ +int CDisplay::FillDisplayList(void) { LoadImageList(); // Initialize the tree view window. @@ -713,11 +698,11 @@ int CDisplay::FillDisplayList(void) (LPARAM)(LPTVINSERTSTRUCT)&sNew); // add each loaded material to the tree - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMaterials;++i) + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMaterials; ++i) AddMaterialToDisplayList(m_hRoot,i); // add each mesh to the tree - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes; ++i) AddMeshToDisplayList(i,m_hRoot); // now add all loaded nodes recursively @@ -729,8 +714,10 @@ int CDisplay::FillDisplayList(void) // everything reacts a little bit slowly if D3D is rendering, // so give GDI a small hint to leave the couch and work ;-) UpdateWindow(g_hDlg); + return 1; } + //------------------------------------------------------------------------------- // Main render loop int CDisplay::OnRender() diff --git a/tools/assimp_view/HelpDialog.cpp b/tools/assimp_view/HelpDialog.cpp index fde4e1caf..700619a6c 100644 --- a/tools/assimp_view/HelpDialog.cpp +++ b/tools/assimp_view/HelpDialog.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/Input.cpp b/tools/assimp_view/Input.cpp index b8572d792..f9bda0451 100644 --- a/tools/assimp_view/Input.cpp +++ b/tools/assimp_view/Input.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/LogDisplay.cpp b/tools/assimp_view/LogDisplay.cpp index 1bd650c08..41777856f 100644 --- a/tools/assimp_view/LogDisplay.cpp +++ b/tools/assimp_view/LogDisplay.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/LogWindow.cpp b/tools/assimp_view/LogWindow.cpp index 8e80bf564..24a359f19 100644 --- a/tools/assimp_view/LogWindow.cpp +++ b/tools/assimp_view/LogWindow.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index c28231332..2337f13fa 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/MaterialManager.h b/tools/assimp_view/MaterialManager.h index b708fb337..577f81a6b 100644 --- a/tools/assimp_view/MaterialManager.h +++ b/tools/assimp_view/MaterialManager.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/MeshRenderer.cpp b/tools/assimp_view/MeshRenderer.cpp index 655e99d0b..710ce1cce 100644 --- a/tools/assimp_view/MeshRenderer.cpp +++ b/tools/assimp_view/MeshRenderer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/MessageProc.cpp b/tools/assimp_view/MessageProc.cpp index aea65a8d5..5acdafb68 100644 --- a/tools/assimp_view/MessageProc.cpp +++ b/tools/assimp_view/MessageProc.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/Normals.cpp b/tools/assimp_view/Normals.cpp index b76408939..32c5a486a 100644 --- a/tools/assimp_view/Normals.cpp +++ b/tools/assimp_view/Normals.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/SceneAnimator.cpp b/tools/assimp_view/SceneAnimator.cpp index c8b20229e..f24f2018f 100644 --- a/tools/assimp_view/SceneAnimator.cpp +++ b/tools/assimp_view/SceneAnimator.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/SceneAnimator.h b/tools/assimp_view/SceneAnimator.h index 454357f30..444f71014 100644 --- a/tools/assimp_view/SceneAnimator.h +++ b/tools/assimp_view/SceneAnimator.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/Shaders.cpp b/tools/assimp_view/Shaders.cpp index 9fd05ca8d..10e89e696 100644 --- a/tools/assimp_view/Shaders.cpp +++ b/tools/assimp_view/Shaders.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index 8f2d131d2..c2c8bfd4a 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/assimp_view/assimp_view.h b/tools/assimp_view/assimp_view.h index e67cc9fd0..f5c08559d 100644 --- a/tools/assimp_view/assimp_view.h +++ b/tools/assimp_view/assimp_view.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team +Copyright (c) 2006-2024, assimp team All rights reserved. diff --git a/tools/make/build_env_win32.bat b/tools/make/build_env_win32.bat deleted file mode 100644 index 4b8b4674b..000000000 --- a/tools/make/build_env_win32.bat +++ /dev/null @@ -1,57 +0,0 @@ -@echo off -set "initialdir=%cd%" -goto:main - -:exitsucc -cd /d "%initialdir%" -set initialdir= - -set MSBUILD_15="C:\Program Files (x86)\Microsoft Visual Studio\2018\Professional\MSBuild\15.0\Bin\msbuild.exe" -set MSBUILD_14="C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" - -if not "%VS150%"=="" set MSBUILD_15="%VS150%\MSBuild\15.0\Bin\msbuild.exe" - -if /i %VS_VERSION%==2017 ( - set MS_BUILD_EXE=%MSBUILD_15% - set PLATFORM_VER=v141 -) else ( - set MS_BUILD_EXE=%MSBUILD_14% - set PLATFORM_VER=v140 -) - -set MSBUILD=%MS_BUILD_EXE% - -exit /b 0 - -:main -if not defined PLATFORM set "PLATFORM=x64" - -::my work here is done? - -set PATH_VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\ -REM set PATH_STUDIO="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\" - -for /f "usebackq tokens=*" %%i in (`"%PATH_VSWHERE%vswhere" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set InstallDir=%%i -) - -IF EXIST "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" set VS150=%InstallDir%\ - -set "CMAKE_GENERATOR=Visual Studio 15 2017 Win64" -if not "%VS150%"=="" call "%VS150%\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM% && echo found VS 2o17 && set PLATFORM_VER=v141 && set VS_VERSION=2017 && goto:exitsucc - -set "CMAKE_GENERATOR=Visual Studio 14 2015 Win64" -if defined VS140COMNTOOLS call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %PLATFORM% && echo found VS 2o15 && set PLATFORM_VER=v140 && set VS_VERSION=2015 && goto:exitsucc - -if defined VS130COMNTOOLS echo call ghostbusters... found lost VS version - -set "CMAKE_GENERATOR=Visual Studio 12 2013 Win64" -if defined VS120COMNTOOLS call "%VS120COMNTOOLS%..\..\VC\vcvarsall.bat" %PLATFORM% && echo found VS 2o13 && set PLATFORM_VER=v120 && set VS_VERSION=2013 && goto:exitsucc - -set "CMAKE_GENERATOR=Visual Studio 11 2012 Win64" -if defined VS110COMNTOOLS call "%VS110COMNTOOLS%..\..\VC\vcvarsall.bat" %PLATFORM% && echo found VS 2o12 && set PLATFORM_VER=v110 && set VS_VERSION=2012 && goto:exitsucc - -set "CMAKE_GENERATOR=Visual Studio 10 2010 Win64" -if defined VS100COMNTOOLS call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %PLATFORM% && echo found VS 2o1o && set PLATFORM_VER=v100 && set VS_VERSION=2010 && goto:exitsucc - -goto:exitsucc \ No newline at end of file diff --git a/tools/make/make_all_win32_x64.bat b/tools/make/make_all_win32_x64.bat deleted file mode 100644 index 4a1e663e6..000000000 --- a/tools/make/make_all_win32_x64.bat +++ /dev/null @@ -1,18 +0,0 @@ -rem @echo off -setlocal -call build_env_win32.bat - -set BUILD_CONFIG=release -set PLATFORM_CONFIG=x64 -set MAX_CPU_CONFIG=4 - -set CONFIG_PARAMETER=/p:Configuration="%BUILD_CONFIG%" -set PLATFORM_PARAMETER=/p:Platform="%PLATFORM_CONFIG%" -set CPU_PARAMETER=/maxcpucount:%MAX_CPU_CONFIG% -set PLATFORM_TOOLSET=/p:PlatformToolset=%PLATFORM_VER% - -pushd ..\..\ -cmake CMakeLists.txt -G "Visual Studio 15 2017 Win64" -%MSBUILD% assimp.sln %CONFIG_PARAMETER% %PLATFORM_PARAMETER% %CPU_PARAMETER% %PLATFORM_TOOLSET% -popd -endlocal