diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 2c5ca438b..1c533aa80 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter, windows-msvc-hunter] + name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++] # For Windows msvc, for Linux and macOS let's use the clang compiler, use gcc for Linux. include: - name: windows-latest-cl.exe @@ -35,15 +35,6 @@ jobs: os: ubuntu-latest cxx: g++ cc: gcc - - name: ubuntu-gcc-hunter - os: ubuntu-latest - toolchain: ninja-gcc-cxx17-fpic - - name: macos-clang-hunter - os: macos-latest - toolchain: ninja-clang-cxx17-fpic - - name: windows-msvc-hunter - os: windows-latest - toolchain: ninja-vs-win64-cxx17 steps: - uses: actions/checkout@v4 @@ -55,25 +46,11 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1 - name: Set Compiler Environment - if: "!endsWith(matrix.name, 'hunter')" uses: lukka/set-shell-env@v1 with: CXX: ${{ matrix.cxx }} CC: ${{ matrix.cc }} - - name: Set Compiler Environment for Hunter on Windows - if: startsWith(matrix.name, 'windows') && endsWith(matrix.name, 'hunter') - uses: lukka/set-shell-env@v1 - with: - VS160COMNTOOLS: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools - - - name: Checkout Hunter toolchains - if: endsWith(matrix.name, 'hunter') - uses: actions/checkout@v4 - with: - repository: cpp-pm/polly - path: cmake/polly - - name: Cache DX SDK id: dxcache if: contains(matrix.name, 'windows') @@ -121,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/Build.md b/Build.md index 957031b5f..9440a0073 100644 --- a/Build.md +++ b/Build.md @@ -43,6 +43,7 @@ cd assimp cmake CMakeLists.txt cmake --build . ``` +Note that by default this builds a shared library into the `bin` directory. If you want to build it as a static library see the build options at the bottom of this file. ### Build instructions for Windows with Visual-Studio diff --git a/CMakeLists.txt b/CMakeLists.txt index 88f69174a..868282ef2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ IF (WIN32) ELSE() OPTION( ASSIMP_BUILD_ZLIB "Build your own zlib" - ON + OFF ) ENDIF() @@ -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() 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 9a8ac7c33..a1f707a95 100644 --- a/Readme.md +++ b/Readme.md @@ -6,25 +6,19 @@ Open Asset Import Library is a library to load various 3d file formats into a sh ### Current project status ### [![Financial Contributors on Open Collective](https://opencollective.com/assimp/all/badge.svg?label=financial+contributors)](https://opencollective.com/assimp) ![C/C++ CI](https://github.com/assimp/assimp/workflows/C/C++%20CI/badge.svg) - - Coverity Scan Build Status - [![Codacy Badge](https://app.codacy.com/project/badge/Grade/9973693b7bdd4543b07084d5d9cf4745)](https://www.codacy.com/gh/assimp/assimp/dashboard?utm_source=github.com&utm_medium=referral&utm_content=assimp/assimp&utm_campaign=Badge_Grade) - -[![Coverage Status](https://coveralls.io/repos/github/assimp/assimp/badge.svg?branch=master)](https://coveralls.io/github/assimp/assimp?branch=master) [![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) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/assimp/assimp.svg)](http://isitmaintained.com/project/assimp/assimp "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/assimp/assimp.svg)](http://isitmaintained.com/project/assimp/assimp "Percentage of issues still open")
APIs are provided for C and C++. There are various bindings to other languages (C#, Java, Python, Delphi, D). Assimp also runs on Android and iOS. -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. +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. -### Latest Doc's ### +### Documentation ### Please check the latest documents at [Asset-Importer-Lib-Doc](https://assimp-docs.readthedocs.io/en/latest/). -### Prebuild binaries ### +### Pre-built binaries ### Please check 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 @@ -41,7 +35,7 @@ And we also have a Gitter-channel:Gitter [![Join the chat at https://gitter.im/a You can find the complete list of supported file-formats [here](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md) ### Building ### -Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file. 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. +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. ### Ports ### * [Android](port/AndroidJNI/README.md) @@ -58,20 +52,21 @@ Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file. ### Other tools ### [open3mod](https://github.com/acgessler/open3mod) is a powerful 3D model viewer based on Assimp's import and export abilities. +[Assimp-Viewer](https://github.com/assimp/assimp_view) is an experimental implementation for an Asset-Viewer based on ImGUI and Assimp (experimental). #### Repository structure #### -Open Asset Import Library is implemented in C++. The directory structure looks like: +Open Asset Import Library is implemented in C++. The directory structure looks like this: /code Source code /contrib Third-party libraries /doc Documentation (doxysource and pre-compiled docs) - /fuzz Contains the test-code for the Google-Fuzzer project + /fuzz Contains the test code for the Google Fuzzer project /include Public header C and C++ header files - /scripts Scripts used to generate the loading code for some formats + /scripts Scripts are used to generate the loading code for some formats /port Ports to other languages and scripts to maintain those. /test Unit- and regression tests, test suite of models /tools Tools (old assimp viewer, command line `assimp`) - /samples A small number of samples to illustrate possible use-cases for Assimp + /samples A small number of samples to illustrate possible use cases for Assimp The source code is organized in the following way: @@ -79,9 +74,9 @@ The source code is organized in the following way: code/CApi Special implementations which are only used for the C-API code/Geometry A collection of geometry tools code/Material The material system - code/PBR An exporter for physical based models + code/PBR An exporter for physical-based models code/PostProcessing The post-processing steps - code/AssetLib/ Implementation for import and export for the format + code/AssetLib/ Implementation for import and export of the format ### Contributing ### Contributions to assimp are highly appreciated. The easiest way to get involved is to submit @@ -118,4 +113,4 @@ and don't sue us if our code doesn't work. Note that, unlike LGPLed code, you ma For the legal details, see the `LICENSE` file. ### Why this name ### -Sorry, we're germans :-), no english native speakers ... +Sorry, we're germans :-), no English native speakers ... diff --git a/code/AssetLib/3DS/3DSConverter.cpp b/code/AssetLib/3DS/3DSConverter.cpp index b4f625b76..6d3f09cb7 100644 --- a/code/AssetLib/3DS/3DSConverter.cpp +++ b/code/AssetLib/3DS/3DSConverter.cpp @@ -52,9 +52,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const unsigned int NotSet = 0xcdcdcdcd; +static constexpr unsigned int NotSet = 0xcdcdcdcd; // ------------------------------------------------------------------------------------------------ // Setup final material indices, generae a default material if necessary @@ -68,7 +68,7 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() { unsigned int idx(NotSet); for (unsigned int i = 0; i < mScene->mMaterials.size(); ++i) { std::string s = mScene->mMaterials[i].mName; - for (char & it : s) { + for (char &it : s) { it = static_cast(::tolower(static_cast(it))); } @@ -262,7 +262,7 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat, unsigned int iWire = 1; mat.AddProperty((int *)&iWire, 1, AI_MATKEY_ENABLE_WIREFRAME); } - [[fallthrough]]; + [[fallthrough]]; case D3DS::Discreet3DS::Gouraud: eShading = aiShadingMode_Gouraud; @@ -593,7 +593,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut, // Cameras or lights define their transformation in their parent node and in the // corresponding light or camera chunks. However, we read and process the latter - // to to be able to return valid cameras/lights even if no scenegraph is given. + // to be able to return valid cameras/lights even if no scenegraph is given. for (unsigned int n = 0; n < pcSOut->mNumCameras; ++n) { if (pcSOut->mCameras[n]->mName == pcOut->mName) { pcSOut->mCameras[n]->mLookAt = aiVector3D(0.f, 0.f, 1.f); @@ -805,4 +805,6 @@ void Discreet3DSImporter::ConvertScene(aiScene *pcOut) { } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_3DS_IMPORTER diff --git a/code/AssetLib/3DS/3DSExporter.h b/code/AssetLib/3DS/3DSExporter.h index 82ec3512f..66e91e10d 100644 --- a/code/AssetLib/3DS/3DSExporter.h +++ b/code/AssetLib/3DS/3DSExporter.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -57,8 +56,7 @@ struct aiNode; struct aiMaterial; struct aiMesh; -namespace Assimp -{ +namespace Assimp { // ------------------------------------------------------------------------------------------------ /** @@ -88,7 +86,7 @@ private: std::map trafos; - typedef std::multimap MeshesByNodeMap; + using MeshesByNodeMap = std::multimap; MeshesByNodeMap meshes; }; diff --git a/code/AssetLib/3DS/3DSLoader.cpp b/code/AssetLib/3DS/3DSLoader.cpp index aa29956df..a406ea1d2 100644 --- a/code/AssetLib/3DS/3DSLoader.cpp +++ b/code/AssetLib/3DS/3DSLoader.cpp @@ -54,9 +54,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Discreet 3DS Importer", "", "", @@ -103,10 +103,6 @@ Discreet3DSImporter::Discreet3DSImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -Discreet3DSImporter::~Discreet3DSImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool Discreet3DSImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -369,7 +365,7 @@ void Discreet3DSImporter::ParseChunk(const char *name, unsigned int num) { // IMPLEMENTATION NOTE; // Cameras or lights define their transformation in their parent node and in the // corresponding light or camera chunks. However, we read and process the latter - // to to be able to return valid cameras/lights even if no scenegraph is given. + // to be able to return valid cameras/lights even if no scenegraph is given. // get chunk type switch (chunk.Flag) { @@ -1339,4 +1335,6 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D *out, bool acceptPercent) { (void)bGamma; } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_3DS_IMPORTER diff --git a/code/AssetLib/3DS/3DSLoader.h b/code/AssetLib/3DS/3DSLoader.h index 6bd73f412..c579507e0 100644 --- a/code/AssetLib/3DS/3DSLoader.h +++ b/code/AssetLib/3DS/3DSLoader.h @@ -59,7 +59,6 @@ struct aiNode; namespace Assimp { - using namespace D3DS; // --------------------------------------------------------------------------------- @@ -68,7 +67,7 @@ using namespace D3DS; class Discreet3DSImporter : public BaseImporter { public: Discreet3DSImporter(); - ~Discreet3DSImporter() override; + ~Discreet3DSImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/3MF/D3MFImporter.cpp b/code/AssetLib/3MF/D3MFImporter.cpp index 5d9644fa5..9a5081db9 100644 --- a/code/AssetLib/3MF/D3MFImporter.cpp +++ b/code/AssetLib/3MF/D3MFImporter.cpp @@ -68,7 +68,7 @@ namespace Assimp { using namespace D3MF; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "3mf Importer", "", "", @@ -81,16 +81,17 @@ static const aiImporterDesc desc = { "3mf" }; -D3MFImporter::D3MFImporter() = default; - -D3MFImporter::~D3MFImporter() = default; - -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 a39ae790f..9ae68acb0 100644 --- a/code/AssetLib/3MF/D3MFImporter.h +++ b/code/AssetLib/3MF/D3MFImporter.h @@ -56,10 +56,10 @@ namespace Assimp { class D3MFImporter : public BaseImporter { public: /// @brief The default class constructor. - D3MFImporter(); + D3MFImporter() = default; /// @brief The class destructor. - ~D3MFImporter() override; + ~D3MFImporter() override = default; /// @brief Performs the data format detection. /// @param pFile The filename to check. diff --git a/code/AssetLib/3MF/D3MFOpcPackage.cpp b/code/AssetLib/3MF/D3MFOpcPackage.cpp index 934305d49..e772d8b7e 100644 --- a/code/AssetLib/3MF/D3MFOpcPackage.cpp +++ b/code/AssetLib/3MF/D3MFOpcPackage.cpp @@ -68,7 +68,7 @@ using OpcPackageRelationshipPtr = std::shared_ptr; class OpcPackageRelationshipReader { public: OpcPackageRelationshipReader(XmlParser &parser) : - m_relationShips() { + mRelations() { XmlNode root = parser.getRootNode(); ParseRootNode(root); } @@ -108,13 +108,13 @@ public: relPtr->type = currentNode.attribute(XmlTag::RELS_ATTRIB_TYPE).as_string(); relPtr->target = currentNode.attribute(XmlTag::RELS_ATTRIB_TARGET).as_string(); if (validateRels(relPtr)) { - m_relationShips.push_back(relPtr); + mRelations.push_back(relPtr); } } } } - std::vector m_relationShips; + std::vector mRelations; }; static bool IsEmbeddedTexture( const std::string &filename ) { @@ -186,9 +186,6 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) : D3MFOpcPackage::~D3MFOpcPackage() { mZipArchive->Close(mRootStream); delete mZipArchive; - for (auto tex : mEmbeddedTextures) { - delete tex; - } } IOStream *D3MFOpcPackage::RootStream() const { @@ -217,11 +214,11 @@ std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) { OpcPackageRelationshipReader reader(xmlParser); - auto itr = std::find_if(reader.m_relationShips.begin(), reader.m_relationShips.end(), [](const OpcPackageRelationshipPtr &rel) { + auto itr = std::find_if(reader.mRelations.begin(), reader.mRelations.end(), [](const OpcPackageRelationshipPtr &rel) { return rel->type == XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE; }); - if (itr == reader.m_relationShips.end()) { + if (itr == reader.mRelations.end()) { throw DeadlyImportError("Cannot find ", XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE); } diff --git a/code/AssetLib/3MF/XmlSerializer.cpp b/code/AssetLib/3MF/XmlSerializer.cpp index c77111728..5fcdc0ccc 100644 --- a/code/AssetLib/3MF/XmlSerializer.cpp +++ b/code/AssetLib/3MF/XmlSerializer.cpp @@ -49,12 +49,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { namespace D3MF { -static const int IdNotSet = -1; +static constexpr int IdNotSet = -1; namespace { -static const size_t ColRGBA_Len = 9; -static const size_t ColRGB_Len = 7; +static constexpr size_t ColRGBA_Len = 9; +static constexpr size_t ColRGB_Len = 7; // format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1) bool validateColorString(const char *color) { diff --git a/code/AssetLib/AC/ACLoader.cpp b/code/AssetLib/AC/ACLoader.cpp index e93fba5f0..f98a4d105 100644 --- a/code/AssetLib/AC/ACLoader.cpp +++ b/code/AssetLib/AC/ACLoader.cpp @@ -60,9 +60,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "AC3D Importer", "", "", @@ -170,9 +170,9 @@ bool AC3DImporter::GetNextLine() { // ------------------------------------------------------------------------------------------------ // Parse an object section in an AC file -void AC3DImporter::LoadObjectSection(std::vector &objects) { +bool AC3DImporter::LoadObjectSection(std::vector &objects) { if (!TokenMatch(buffer, "OBJECT", 6)) - return; + return false; SkipSpaces(&buffer); @@ -212,10 +212,14 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { 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; + return true; } else if (TokenMatch(buffer, "name", 4)) { SkipSpaces(&buffer); buffer = AcGetString(buffer, obj.name); @@ -227,9 +231,16 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { } } else if (TokenMatch(buffer, "texture", 7)) { SkipSpaces(&buffer); - std::string texture; - buffer = AcGetString(buffer, texture); - obj.textures.push_back(texture); + // skip empty acc texture + if (*buffer != '\"') { + if (!TokenMatch(buffer, "empty_texture_no_mapping", 24)) { + ASSIMP_LOG_ERROR("AC3D: Unquoted texture string"); + } + } else { + std::string texture; + buffer = AcGetString(buffer, texture); + obj.textures.push_back(texture); + } } else if (TokenMatch(buffer, "texrep", 6)) { SkipSpaces(&buffer); buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &obj.texRepeat); @@ -340,6 +351,7 @@ void AC3DImporter::LoadObjectSection(std::vector &objects) { } } ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: \'kids\' line was expected"); + return false; } // ------------------------------------------------------------------------------------------------ @@ -445,7 +457,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 @@ -574,15 +586,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]; @@ -804,8 +807,9 @@ void AC3DImporter::InternReadFile(const std::string &pFile, buffer = TAcCheckedLoadFloatArray(buffer, "spec", 4, 3, &mat.spec); buffer = TAcCheckedLoadFloatArray(buffer, "shi", 3, 1, &mat.shin); buffer = TAcCheckedLoadFloatArray(buffer, "trans", 5, 1, &mat.trans); + } else { + LoadObjectSection(rootObjects); } - LoadObjectSection(rootObjects); } if (rootObjects.empty() || !mNumMeshes) { @@ -862,4 +866,6 @@ void AC3DImporter::InternReadFile(const std::string &pFile, } } +} // namespace Assimp + #endif //!defined ASSIMP_BUILD_NO_AC_IMPORTER diff --git a/code/AssetLib/AC/ACLoader.h b/code/AssetLib/AC/ACLoader.h index 7f8dfd03c..3b5be4b6e 100644 --- a/code/AssetLib/AC/ACLoader.h +++ b/code/AssetLib/AC/ACLoader.h @@ -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. diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index ff581b492..eabdb35e1 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -const aiImporterDesc AMFImporter::Description = { +static constexpr aiImporterDesc Description = { "Additive manufacturing file format(AMF) Importer", "smalcom", "", diff --git a/code/AssetLib/AMF/AMFImporter.hpp b/code/AssetLib/AMF/AMFImporter.hpp index 27f733043..fbaf4fc6d 100644 --- a/code/AssetLib/AMF/AMFImporter.hpp +++ b/code/AssetLib/AMF/AMFImporter.hpp @@ -98,8 +98,12 @@ namespace Assimp { /// old - and children , , , , , /// class AMFImporter : public BaseImporter { -private: - struct SPP_Material; // forward declaration + using AMFMetaDataArray = std::vector; + using MeshArray = std::vector; + using NodeArray = std::vector; + +public: + struct SPP_Material; /// Data type for post-processing step. More suitable container for part of material's composition. struct SPP_Composite { @@ -107,22 +111,6 @@ private: std::string Formula; ///< Formula for calculating ratio of \ref Material. }; - /// \struct SPP_Material - /// Data type for post-processing step. More suitable container for material. - struct SPP_Material { - std::string ID; ///< Material ID. - std::list Metadata; ///< Metadata of material. - AMFColor *Color; ///< Color of material. - std::list Composition; ///< List of child materials if current material is composition of few another. - - /// Return color calculated for specified coordinate. - /// \param [in] pX - "x" coordinate. - /// \param [in] pY - "y" coordinate. - /// \param [in] pZ - "z" coordinate. - /// \return calculated color. - aiColor4D GetColor(const float pX, const float pY, const float pZ) const; - }; - /// Data type for post-processing step. More suitable container for texture. struct SPP_Texture { std::string ID; @@ -139,10 +127,52 @@ private: const AMFTexMap *TexMap; ///< Face texture mapping data. Equal to nullptr if texture mapping is not set for the face. }; - using AMFMetaDataArray = std::vector; - using MeshArray = std::vector; - using NodeArray = std::vector; + /// Data type for post-processing step. More suitable container for material. + struct SPP_Material { + std::string ID; ///< Material ID. + std::list Metadata; ///< Metadata of material. + AMFColor *Color; ///< Color of material. + std::list Composition; ///< List of child materials if current material is composition of few another. + /// Return color calculated for specified coordinate. + /// \param [in] pX - "x" coordinate. + /// \param [in] pY - "y" coordinate. + /// \param [in] pZ - "z" coordinate. + /// \return calculated color. + aiColor4D GetColor(const float pX, const float pY, const float pZ) const; + }; + + /// Default constructor. + AMFImporter() AI_NO_EXCEPT; + + /// Default destructor. + ~AMFImporter() override; + + /// Parse AMF file and fill scene graph. The function has no return value. Result can be found by analyzing the generated graph. + /// Also exception can be thrown if trouble will found. + /// \param [in] pFile - name of file to be parsed. + /// \param [in] pIOHandler - pointer to IO helper object. + void ParseFile(const std::string &pFile, IOSystem *pIOHandler); + void ParseHelper_Node_Enter(AMFNodeElementBase *child); + void ParseHelper_Node_Exit(); + bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const override; + void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override; + const aiImporterDesc *GetInfo() const override; + bool Find_NodeElement(const std::string &pID, const AMFNodeElementBase::EType pType, AMFNodeElementBase **pNodeElement) const; + bool Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const; + bool Find_ConvertedMaterial(const std::string &pID, const SPP_Material **pConvertedMaterial) const; + AI_WONT_RETURN void Throw_CloseNotFound(const std::string &nodeName) AI_WONT_RETURN_SUFFIX; + AI_WONT_RETURN void Throw_IncorrectAttr(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX; + AI_WONT_RETURN void Throw_IncorrectAttrValue(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX; + AI_WONT_RETURN void Throw_MoreThanOnceDefined(const std::string &nodeName, const std::string &pNodeType, const std::string &pDescription) AI_WONT_RETURN_SUFFIX; + AI_WONT_RETURN void Throw_ID_NotFound(const std::string &pID) const AI_WONT_RETURN_SUFFIX; + void XML_CheckNode_MustHaveChildren(pugi::xml_node &node); + bool XML_SearchNode(const std::string &nodeName); + void ParseHelper_FixTruncatedFloatString(const char *pInStr, std::string &pOutString); + AMFImporter(const AMFImporter &pScene) = delete; + AMFImporter &operator=(const AMFImporter &pScene) = delete; + +private: /// Clear all temporary data. void Clear(); @@ -262,40 +292,9 @@ private: /// \param [in] pUseOldName - if true then use old name of node(and children) - , instead of new name - . void ParseNode_TexMap(XmlNode &node, const bool pUseOldName = false); -public: - /// Default constructor. - AMFImporter() AI_NO_EXCEPT; - /// Default destructor. - ~AMFImporter() override; - - /// Parse AMF file and fill scene graph. The function has no return value. Result can be found by analyzing the generated graph. - /// Also exception can be thrown if trouble will found. - /// \param [in] pFile - name of file to be parsed. - /// \param [in] pIOHandler - pointer to IO helper object. - void ParseFile(const std::string &pFile, IOSystem *pIOHandler); - void ParseHelper_Node_Enter(AMFNodeElementBase *child); - void ParseHelper_Node_Exit(); - bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const override; - void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override; - const aiImporterDesc *GetInfo() const override; - bool Find_NodeElement(const std::string &pID, const AMFNodeElementBase::EType pType, AMFNodeElementBase **pNodeElement) const; - bool Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const; - bool Find_ConvertedMaterial(const std::string &pID, const SPP_Material **pConvertedMaterial) const; - AI_WONT_RETURN void Throw_CloseNotFound(const std::string &nodeName) AI_WONT_RETURN_SUFFIX; - AI_WONT_RETURN void Throw_IncorrectAttr(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX; - AI_WONT_RETURN void Throw_IncorrectAttrValue(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX; - AI_WONT_RETURN void Throw_MoreThanOnceDefined(const std::string &nodeName, const std::string &pNodeType, const std::string &pDescription) AI_WONT_RETURN_SUFFIX; - AI_WONT_RETURN void Throw_ID_NotFound(const std::string &pID) const AI_WONT_RETURN_SUFFIX; - void XML_CheckNode_MustHaveChildren(pugi::xml_node &node); - bool XML_SearchNode(const std::string &nodeName); - void ParseHelper_FixTruncatedFloatString(const char *pInStr, std::string &pOutString); - AMFImporter(const AMFImporter &pScene) = delete; - AMFImporter &operator=(const AMFImporter &pScene) = delete; private: - static const aiImporterDesc Description; - AMFNodeElementBase *mNodeElement_Cur; ///< Current element. std::list mNodeElement_List; ///< All elements of scene graph. XmlParser *mXmlParser; diff --git a/code/AssetLib/ASE/ASELoader.cpp b/code/AssetLib/ASE/ASELoader.cpp index 4617c9ed4..f98316661 100644 --- a/code/AssetLib/ASE/ASELoader.cpp +++ b/code/AssetLib/ASE/ASELoader.cpp @@ -63,10 +63,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // utilities #include -using namespace Assimp; +namespace Assimp { using namespace Assimp::ASE; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "ASE Importer", "", "", @@ -904,7 +904,7 @@ void ASEImporter::ConvertMeshes(ASE::Mesh &mesh, std::vector &avOutMes ASSIMP_LOG_WARN("Material index is out of range"); } - // If the material the mesh is assigned to is consisting of submeshes, split it + // If the material the mesh is assigned to consists of submeshes, split it if (!mParser->m_vMaterials[mesh.iMaterialIndex].avSubMaterials.empty()) { std::vector vSubMaterials = mParser->m_vMaterials[mesh.iMaterialIndex].avSubMaterials; @@ -1262,6 +1262,8 @@ bool ASEImporter::GenerateNormals(ASE::Mesh &mesh) { return false; } +} + #endif // ASSIMP_BUILD_NO_3DS_IMPORTER #endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER diff --git a/code/AssetLib/ASE/ASEParser.cpp b/code/AssetLib/ASE/ASEParser.cpp index c43eb42ff..90f462598 100644 --- a/code/AssetLib/ASE/ASEParser.cpp +++ b/code/AssetLib/ASE/ASEParser.cpp @@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { using namespace Assimp::ASE; // ------------------------------------------------------------------------------------------------ @@ -1864,6 +1864,8 @@ void Parser::ParseLV4MeshLong(unsigned int &iOut) { iOut = strtoul10(filePtr, &filePtr); } +} + #endif // ASSIMP_BUILD_NO_3DS_IMPORTER #endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER diff --git a/code/AssetLib/Assbin/AssbinFileWriter.cpp b/code/AssetLib/Assbin/AssbinFileWriter.cpp index e9d857a84..782595bc1 100644 --- a/code/AssetLib/Assbin/AssbinFileWriter.cpp +++ b/code/AssetLib/Assbin/AssbinFileWriter.cpp @@ -50,11 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#ifdef ASSIMP_BUILD_NO_OWN_ZLIB -#include -#else -#include "../contrib/zlib/zlib.h" -#endif +#include "zlib.h" #include diff --git a/code/AssetLib/Assbin/AssbinLoader.cpp b/code/AssetLib/Assbin/AssbinLoader.cpp index f7b35636c..6995ea976 100644 --- a/code/AssetLib/Assbin/AssbinLoader.cpp +++ b/code/AssetLib/Assbin/AssbinLoader.cpp @@ -65,7 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Assimp Binary Importer", "Gargaj / Conspiracy", "", diff --git a/code/AssetLib/B3D/B3DImporter.cpp b/code/AssetLib/B3D/B3DImporter.cpp index bf8145798..670f3de53 100644 --- a/code/AssetLib/B3D/B3DImporter.cpp +++ b/code/AssetLib/B3D/B3DImporter.cpp @@ -59,10 +59,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -using namespace Assimp; +namespace Assimp { using namespace std; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "BlitzBasic 3D Importer", "", "", @@ -79,9 +79,9 @@ static const aiImporterDesc desc = { #pragma warning(disable : 4018) #endif -//#define DEBUG_B3D +// #define DEBUG_B3D -template +template void DeleteAllBarePointers(std::vector &x) { for (auto p : x) { delete p; @@ -329,7 +329,7 @@ void B3DImporter::ReadBRUS() { mat->AddProperty(&i, 1, AI_MATKEY_TWOSIDED); } - //Textures + // Textures for (int i = 0; i < n_texs; ++i) { int texid = ReadInt(); if (texid < -1 || (texid >= 0 && texid >= static_cast(_textures.size()))) { @@ -372,7 +372,7 @@ void B3DImporter::ReadVRTS() { } if (_vflags & 2) { - ReadQuat(); //skip v 4bytes... + ReadQuat(); // skip v 4bytes... } for (int j = 0; j < _tcsets; ++j) { @@ -704,22 +704,22 @@ void B3DImporter::ReadBB3D(aiScene *scene) { } } - //nodes + // nodes scene->mRootNode = _nodes[0]; _nodes.clear(); // node ownership now belongs to scene - //material + // material if (!_materials.size()) { _materials.emplace_back(std::unique_ptr(new aiMaterial)); } scene->mNumMaterials = static_cast(_materials.size()); scene->mMaterials = unique_to_array(_materials); - //meshes + // meshes scene->mNumMeshes = static_cast(_meshes.size()); scene->mMeshes = unique_to_array(_meshes); - //animations + // animations if (_animations.size() == 1 && _nodeAnims.size()) { aiAnimation *anim = _animations.back().get(); @@ -738,4 +738,6 @@ void B3DImporter::ReadBB3D(aiScene *scene) { flip.Execute(scene); } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_B3D_IMPORTER diff --git a/code/AssetLib/BVH/BVHLoader.cpp b/code/AssetLib/BVH/BVHLoader.cpp index d92887c9e..4d2cfde15 100644 --- a/code/AssetLib/BVH/BVHLoader.cpp +++ b/code/AssetLib/BVH/BVHLoader.cpp @@ -55,10 +55,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { + using namespace Assimp::Formatter; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "BVH Importer (MoCap)", "", "", @@ -73,8 +74,8 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Aborts the file reading with an exception -template -AI_WONT_RETURN void BVHLoader::ThrowException(T&&... args) { +template +AI_WONT_RETURN void BVHLoader::ThrowException(T &&...args) { throw DeadlyImportError(mFileName, ":", mLine, " - ", args...); } @@ -426,7 +427,7 @@ void BVHLoader::CreateAnimation(aiScene *pScene) { nodeAnim->mNodeName.Set(nodeName); std::map channelMap; - //Build map of channels + // Build map of channels for (unsigned int channel = 0; channel < node.mChannels.size(); ++channel) { channelMap[node.mChannels[channel]] = channel; } @@ -441,7 +442,7 @@ void BVHLoader::CreateAnimation(aiScene *pScene) { // Now compute all translations for (BVHLoader::ChannelType channel = Channel_PositionX; channel <= Channel_PositionZ; channel = (BVHLoader::ChannelType)(channel + 1)) { - //Find channel in node + // Find channel in node std::map::iterator mapIter = channelMap.find(channel); if (mapIter == channelMap.end()) @@ -485,30 +486,27 @@ void BVHLoader::CreateAnimation(aiScene *pScene) { for (unsigned int fr = 0; fr < mAnimNumFrames; ++fr) { aiMatrix4x4 temp; aiMatrix3x3 rotMatrix; - for (unsigned int channelIdx = 0; channelIdx < node.mChannels.size(); ++ channelIdx) { - switch (node.mChannels[channelIdx]) { - case Channel_RotationX: - { + for (unsigned int channelIdx = 0; channelIdx < node.mChannels.size(); ++channelIdx) { + switch (node.mChannels[channelIdx]) { + case Channel_RotationX: { const float angle = node.mChannelValues[fr * node.mChannels.size() + channelIdx] * float(AI_MATH_PI) / 180.0f; - aiMatrix4x4::RotationX( angle, temp); rotMatrix *= aiMatrix3x3( temp); - } - break; - case Channel_RotationY: - { + aiMatrix4x4::RotationX(angle, temp); + rotMatrix *= aiMatrix3x3(temp); + } break; + case Channel_RotationY: { const float angle = node.mChannelValues[fr * node.mChannels.size() + channelIdx] * float(AI_MATH_PI) / 180.0f; - aiMatrix4x4::RotationY( angle, temp); rotMatrix *= aiMatrix3x3( temp); - } - break; - case Channel_RotationZ: - { + aiMatrix4x4::RotationY(angle, temp); + rotMatrix *= aiMatrix3x3(temp); + } break; + case Channel_RotationZ: { const float angle = node.mChannelValues[fr * node.mChannels.size() + channelIdx] * float(AI_MATH_PI) / 180.0f; - aiMatrix4x4::RotationZ( angle, temp); rotMatrix *= aiMatrix3x3( temp); - } - break; + aiMatrix4x4::RotationZ(angle, temp); + rotMatrix *= aiMatrix3x3(temp); + } break; default: break; - } - } + } + } rotkey->mTime = double(fr); rotkey->mValue = aiQuaternion(rotMatrix); ++rotkey; @@ -525,4 +523,6 @@ void BVHLoader::CreateAnimation(aiScene *pScene) { } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_BVH_IMPORTER diff --git a/code/AssetLib/Blender/BlenderLoader.cpp b/code/AssetLib/Blender/BlenderLoader.cpp index 5c6e7bc5b..35b35f08d 100644 --- a/code/AssetLib/Blender/BlenderLoader.cpp +++ b/code/AssetLib/Blender/BlenderLoader.cpp @@ -69,11 +69,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // zlib is needed for compressed blend files #ifndef ASSIMP_BUILD_NO_COMPRESSED_BLEND #include "Common/Compression.h" -/* #ifdef ASSIMP_BUILD_NO_OWN_ZLIB -# include -# else -# include "../contrib/zlib/zlib.h" -# endif*/ #endif namespace Assimp { @@ -89,7 +84,7 @@ using namespace Assimp; using namespace Assimp::Blender; using namespace Assimp::Formatter; -static const aiImporterDesc blenderDesc = { +static constexpr aiImporterDesc blenderDesc = { "Blender 3D Importer (http://www.blender3d.org)", "", "", diff --git a/code/AssetLib/Blender/BlenderModifier.cpp b/code/AssetLib/Blender/BlenderModifier.cpp index 6cc11ec8e..f925de608 100644 --- a/code/AssetLib/Blender/BlenderModifier.cpp +++ b/code/AssetLib/Blender/BlenderModifier.cpp @@ -283,6 +283,11 @@ void BlenderModifier_Subdivision ::DoIt(aiNode &out, ConversionData &conv_data, if (conv_data.meshes->empty()) { return; } + const size_t meshIndex = conv_data.meshes->size() - out.mNumMeshes; + if (meshIndex >= conv_data.meshes->size()) { + ASSIMP_LOG_ERROR("Invalid index detected."); + return; + } aiMesh **const meshes = &conv_data.meshes[conv_data.meshes->size() - out.mNumMeshes]; std::unique_ptr tempmeshes(new aiMesh *[out.mNumMeshes]()); diff --git a/code/AssetLib/Blender/BlenderScene.cpp b/code/AssetLib/Blender/BlenderScene.cpp index a2e4c30f2..e25dc450b 100644 --- a/code/AssetLib/Blender/BlenderScene.cpp +++ b/code/AssetLib/Blender/BlenderScene.cpp @@ -297,7 +297,7 @@ void Structure ::Convert( const FileDatabase &db) const { // note: as per https://github.com/assimp/assimp/issues/128, // reading the Object linked list recursively is prone to stack overflow. - // This structure converter is therefore an hand-written exception that + // This structure converter is therefore a hand-written exception that // does it iteratively. const int initial_pos = db.reader->GetCurrentPos(); diff --git a/code/AssetLib/COB/COBLoader.cpp b/code/AssetLib/COB/COBLoader.cpp index 20df53f75..9a6e32f6d 100644 --- a/code/AssetLib/COB/COBLoader.cpp +++ b/code/AssetLib/COB/COBLoader.cpp @@ -61,11 +61,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -using namespace Assimp; +namespace Assimp { using namespace Assimp::COB; using namespace Assimp::Formatter; -static const float units[] = { +static constexpr float units[] = { 1000.f, 100.f, 1.f, @@ -76,7 +76,7 @@ static const float units[] = { 1.f / 1609.344f }; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "TrueSpace Object Importer", "", "", @@ -89,14 +89,6 @@ static const aiImporterDesc desc = { "cob scn" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -COBImporter::COBImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -COBImporter::~COBImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool COBImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -1172,4 +1164,6 @@ void COBImporter::ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const ASSIMP_LOG_WARN("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist"); } +} + #endif // ASSIMP_BUILD_NO_COB_IMPORTER diff --git a/code/AssetLib/COB/COBLoader.h b/code/AssetLib/COB/COBLoader.h index e6eb96dc1..a9755f5d7 100644 --- a/code/AssetLib/COB/COBLoader.h +++ b/code/AssetLib/COB/COBLoader.h @@ -56,16 +56,16 @@ class LineSplitter; // TinyFormatter.h namespace Formatter { -template -class basic_formatter; -typedef class basic_formatter, std::allocator> format; + template + class basic_formatter; + typedef class basic_formatter, std::allocator> format; } // namespace Formatter // COBScene.h namespace COB { -struct ChunkInfo; -struct Node; -struct Scene; + struct ChunkInfo; + struct Node; + struct Scene; } // namespace COB // ------------------------------------------------------------------------------------------- @@ -75,8 +75,8 @@ struct Scene; // ------------------------------------------------------------------------------------------- class COBImporter : public BaseImporter { public: - COBImporter(); - ~COBImporter() override; + COBImporter() = default; + ~COBImporter() override = default; // -------------------- bool CanRead(const std::string &pFile, IOSystem *pIOHandler, diff --git a/code/AssetLib/CSM/CSMLoader.cpp b/code/AssetLib/CSM/CSMLoader.cpp index db152f453..20f2343f5 100644 --- a/code/AssetLib/CSM/CSMLoader.cpp +++ b/code/AssetLib/CSM/CSMLoader.cpp @@ -44,9 +44,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file CSMLoader.cpp * Implementation of the CSM importer class. */ - - - #ifndef ASSIMP_BUILD_NO_CSM_IMPORTER #include "CSMLoader.h" @@ -63,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "CharacterStudio Motion Importer (MoCap)", "", "", @@ -79,13 +76,9 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -CSMImporter::CSMImporter() -: noSkeletonMesh() -{} - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -CSMImporter::~CSMImporter() = default; +CSMImporter::CSMImporter() : noSkeletonMesh(){ + // empty +} // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/CSM/CSMLoader.h b/code/AssetLib/CSM/CSMLoader.h index e9c4cd5ee..fc9017d17 100644 --- a/code/AssetLib/CSM/CSMLoader.h +++ b/code/AssetLib/CSM/CSMLoader.h @@ -61,7 +61,7 @@ namespace Assimp { class CSMImporter : public BaseImporter { public: CSMImporter(); - ~CSMImporter() override; + ~CSMImporter() override = default; // ------------------------------------------------------------------- bool CanRead(const std::string &pFile, IOSystem *pIOHandler, @@ -81,9 +81,8 @@ protected: private: bool noSkeletonMesh; -}; // end of class CSMImporter +}; -} // end of namespace Assimp +} // namespace Assimp #endif // AI_AC3DIMPORTER_H_INC - diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index e1f19a5ed..41e529de0 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -64,7 +64,7 @@ namespace Assimp { using namespace Assimp::Formatter; using namespace Assimp::Collada; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Collada Importer", "", "", @@ -101,10 +101,6 @@ ColladaLoader::ColladaLoader() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -ColladaLoader::~ColladaLoader() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool ColladaLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/Collada/ColladaLoader.h b/code/AssetLib/Collada/ColladaLoader.h index 74b5c06b7..3cea7f531 100644 --- a/code/AssetLib/Collada/ColladaLoader.h +++ b/code/AssetLib/Collada/ColladaLoader.h @@ -86,7 +86,7 @@ public: ColladaLoader(); /// The class destructor. - ~ColladaLoader() override; + ~ColladaLoader() override = default; /// Returns whether the class can handle the format of the given file. /// @see BaseImporter::CanRead() for more details. diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index fcadd08a7..42a8d6052 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -814,38 +814,38 @@ void ColladaParser::ReadImage(XmlNode &node, Collada::Image &pImage) { if (!pImage.mFileName.length()) { pImage.mFileName = "unknown_texture"; } - } - } else if (mFormat == FV_1_5_n) { - std::string value; - XmlNode refChild = currentNode.child("ref"); - XmlNode hexChild = currentNode.child("hex"); - if (refChild) { - // element content is filename - hopefully - if (XmlParser::getValueAsString(refChild, value)) { - aiString filepath(value); - UriDecodePath(filepath); - pImage.mFileName = filepath.C_Str(); - } - } else if (hexChild && !pImage.mFileName.length()) { - // embedded image. get format - pImage.mEmbeddedFormat = hexChild.attribute("format").as_string(); - if (pImage.mEmbeddedFormat.empty()) { - ASSIMP_LOG_WARN("Collada: Unknown image file format"); - } + } else if (mFormat == FV_1_5_n) { + std::string value; + XmlNode refChild = currentNode.child("ref"); + XmlNode hexChild = currentNode.child("hex"); + if (refChild) { + // element content is filename - hopefully + if (XmlParser::getValueAsString(refChild, value)) { + aiString filepath(value); + UriDecodePath(filepath); + pImage.mFileName = filepath.C_Str(); + } + } else if (hexChild && !pImage.mFileName.length()) { + // embedded image. get format + pImage.mEmbeddedFormat = hexChild.attribute("format").as_string(); + if (pImage.mEmbeddedFormat.empty()) { + ASSIMP_LOG_WARN("Collada: Unknown image file format"); + } - XmlParser::getValueAsString(hexChild, value); - const char *data = value.c_str(); - // hexadecimal-encoded binary octets. First of all, find the - // required buffer size to reserve enough storage. - const char *cur = data; - while (!IsSpaceOrNewLine(*cur)) { - ++cur; - } + XmlParser::getValueAsString(hexChild, value); + const char *data = value.c_str(); + // hexadecimal-encoded binary octets. First of all, find the + // required buffer size to reserve enough storage. + const char *cur = data; + while (!IsSpaceOrNewLine(*cur)) { + ++cur; + } - const unsigned int size = (unsigned int)(cur - data) * 2; - pImage.mImageData.resize(size); - for (unsigned int i = 0; i < size; ++i) { - pImage.mImageData[i] = HexOctetToDecimal(data + (i << 1)); + const unsigned int size = (unsigned int)(cur - data) * 2; + pImage.mImageData.resize(size); + for (unsigned int i = 0; i < size; ++i) { + pImage.mImageData[i] = HexOctetToDecimal(data + (i << 1)); + } } } } @@ -1274,9 +1274,7 @@ void ColladaParser::ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam) return; } - XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode); - XmlNode currentNode; - while (xmlIt.getNext(currentNode)) { + for (XmlNode ¤tNode : node.children()) { const std::string ¤tName = currentNode.name(); if (currentName == "surface") { // image ID given inside tags @@ -1289,22 +1287,24 @@ void ColladaParser::ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam) } } else if (currentName == "sampler2D" && (FV_1_4_n == mFormat || FV_1_3_n == mFormat)) { // surface ID is given inside tags - const char *content = currentNode.value(); - pParam.mType = Param_Sampler; - pParam.mReference = content; + XmlNode source = currentNode.child("source"); + if (source) { + std::string v; + XmlParser::getValueAsString(source, v); + pParam.mType = Param_Sampler; + pParam.mReference = v.c_str(); + } } else if (currentName == "sampler2D") { // surface ID is given inside tags - std::string url; - XmlParser::getStdStrAttribute(currentNode, "url", url); - if (url[0] != '#') { - throw DeadlyImportError("Unsupported URL format in instance_image"); - } - pParam.mType = Param_Sampler; - pParam.mReference = url.c_str() + 1; - } else if (currentName == "source") { - const char *source = currentNode.child_value(); - if (nullptr != source) { - pParam.mReference = source; + XmlNode instance_image = currentNode.child("instance_image"); + if (instance_image) { + std::string url; + XmlParser::getStdStrAttribute(instance_image, "url", url); + if (url[0] != '#') { + throw DeadlyImportError("Unsupported URL format in instance_image"); + } + pParam.mType = Param_Sampler; + pParam.mReference = url.c_str() + 1; } } } @@ -1867,7 +1867,7 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vector and tags this function will create wrong uv coordinates. -///It's not clear from COLLADA documentation is this allowed or not. For now only exporter fixed to avoid such behavior +///It's not clear from COLLADA documentation whether this is allowed or not. For now only exporter fixed to avoid such behavior void ColladaParser::CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset, Mesh &pMesh, std::vector &pPerIndexChannels, size_t currentPrimitive, const std::vector &indices) { // calculate the base offset of the vertex whose attributes we ant to copy diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index dae665388..f69cdfce2 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -70,7 +70,7 @@ static const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f)); // color indices for DXF - 16 are supported, the table is // taken directly from the DXF spec. -static aiColor4D g_aclrDxfIndexColors[] = { +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 @@ -97,7 +97,7 @@ static const int GroupCode_XComp = 10; static const int GroupCode_YComp = 20; static const int GroupCode_ZComp = 30; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Drawing Interchange Format (DXF) Importer", "", "", diff --git a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp index 8d79e2339..55424a6a8 100644 --- a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp +++ b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp @@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXUtil.h" #include #include +#include #include #include #include diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index c02548fc2..cf6a29220 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -55,9 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include - #include #include #include @@ -577,16 +575,17 @@ void FBXConverter::GetRotationMatrix(Model::RotOrder mode, const aiVector3D &rot bool is_id[3] = { true, true, true }; aiMatrix4x4 temp[3]; - if (std::fabs(rotation.z) > angle_epsilon) { - aiMatrix4x4::RotationZ(AI_DEG_TO_RAD(rotation.z), temp[2]); + const auto rot = AI_DEG_TO_RAD(rotation); + if (std::fabs(rot.z) > angle_epsilon) { + aiMatrix4x4::RotationZ(rot.z, temp[2]); is_id[2] = false; } - if (std::fabs(rotation.y) > angle_epsilon) { - aiMatrix4x4::RotationY(AI_DEG_TO_RAD(rotation.y), temp[1]); + if (std::fabs(rot.y) > angle_epsilon) { + aiMatrix4x4::RotationY(rot.y, temp[1]); is_id[1] = false; } - if (std::fabs(rotation.x) > angle_epsilon) { - aiMatrix4x4::RotationX(AI_DEG_TO_RAD(rotation.x), temp[0]); + if (std::fabs(rot.x) > angle_epsilon) { + aiMatrix4x4::RotationX(rot.x, temp[0]); is_id[0] = false; } @@ -1205,7 +1204,7 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c const auto &curNormals = shapeGeometry->GetNormals(); const auto &curIndices = shapeGeometry->GetIndices(); //losing channel name if using shapeGeometry->Name() - // if blendShapeChannel Name is empty or don't have a ".", add geoMetryName; + // if blendShapeChannel Name is empty or doesn't have a ".", add geoMetryName; auto aniName = FixAnimMeshName(blendShapeChannel->Name()); auto geoMetryName = FixAnimMeshName(shapeGeometry->Name()); if (aniName.empty()) { @@ -1603,7 +1602,7 @@ void FBXConverter::ConvertWeights(aiMesh *out, const MeshGeometry &geo, const ai void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const Cluster *cluster, std::vector &out_indices, std::vector &index_out_indices, - std::vector &count_out_indices, const aiMatrix4x4 & /* absolute_transform*/, + std::vector &count_out_indices, const aiMatrix4x4 &absolute_transform, aiNode *) { ai_assert(cluster != nullptr); // make sure cluster valid @@ -1620,16 +1619,16 @@ void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const bone = new aiBone(); bone->mName = bone_name; - bone->mOffsetMatrix = cluster->Transform(); + //bone->mOffsetMatrix = cluster->Transform(); // store local transform link for post processing - /* + bone->mOffsetMatrix = cluster->TransformLink(); bone->mOffsetMatrix.Inverse(); - aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform; + const aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform; bone->mOffsetMatrix = bone->mOffsetMatrix * matrix; // * mesh_offset - */ + // // Now calculate the aiVertexWeights // @@ -3229,7 +3228,6 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, aiVector3D defTranslate = PropertyGet(props, "Lcl Translation", aiVector3D(0.f, 0.f, 0.f)); aiVector3D defRotation = PropertyGet(props, "Lcl Rotation", aiVector3D(0.f, 0.f, 0.f)); aiVector3D defScale = PropertyGet(props, "Lcl Scaling", aiVector3D(1.f, 1.f, 1.f)); - aiQuaternion defQuat = EulerToQuaternion(defRotation, rotOrder); aiVectorKey* outTranslations = new aiVectorKey[keyCount]; aiQuatKey* outRotations = new aiQuatKey[keyCount]; @@ -3245,8 +3243,9 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, } if (keyframeLists[TransformationComp_Rotation].size() > 0) { - InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder); + InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], AI_DEG_TO_RAD(defRotation), maxTime, minTime, rotOrder); } else { + aiQuaternion defQuat = EulerToQuaternion(AI_DEG_TO_RAD(defRotation), rotOrder); for (size_t i = 0; i < keyCount; ++i) { outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outRotations[i].mValue = defQuat; @@ -3268,7 +3267,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(preRotation, Model::RotOrder_EulerXYZ); + const aiQuaternion preQuat = EulerToQuaternion(AI_DEG_TO_RAD(preRotation), Model::RotOrder_EulerXYZ); for (size_t i = 0; i < keyCount; ++i) { outRotations[i].mValue = preQuat * outRotations[i].mValue; } @@ -3276,7 +3275,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(postRotation, Model::RotOrder_EulerXYZ); + const aiQuaternion postQuat = EulerToQuaternion(AI_DEG_TO_RAD(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/FBXDeformer.cpp b/code/AssetLib/FBX/FBXDeformer.cpp index 1aab55ea9..8f944527a 100644 --- a/code/AssetLib/FBX/FBXDeformer.cpp +++ b/code/AssetLib/FBX/FBXDeformer.cpp @@ -84,7 +84,7 @@ Cluster::Cluster(uint64_t id, const Element& element, const Document& doc, const transform = ReadMatrix(Transform); transformLink = ReadMatrix(TransformLink); - // it is actually possible that there be Deformer's with no weights + // it is actually possible that there are Deformer's with no weights if (!!Indexes != !!Weights) { DOMError("either Indexes or Weights are missing from Cluster",&element); } diff --git a/code/AssetLib/FBX/FBXDocument.cpp b/code/AssetLib/FBX/FBXDocument.cpp index 657f30f8c..ee4a6632b 100644 --- a/code/AssetLib/FBX/FBXDocument.cpp +++ b/code/AssetLib/FBX/FBXDocument.cpp @@ -390,7 +390,7 @@ void Document::ReadObjects() { const auto foundObject = objects.find(id); if(foundObject != objects.end()) { DOMWarning("encountered duplicate object id, ignoring first occurrence",el.second); - delete foundObject->second; + delete_LazyObject(foundObject->second); } objects[id] = new_LazyObject(id, *el.second, *this); diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index 9da713e5d..28299544a 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -74,8 +74,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // https://code.blender.org/2013/08/fbx-binary-file-format-specification/ // https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure -const ai_real DEG = ai_real( 57.29577951308232087679815481 ); // degrees per radian - using namespace Assimp; using namespace Assimp::FBX; @@ -1063,14 +1061,14 @@ aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene) return transform; } -int64_t to_ktime(double ticks, const aiAnimation* anim) { +inline int64_t to_ktime(double ticks, const aiAnimation* anim) { if (anim->mTicksPerSecond <= 0) { return static_cast(ticks) * FBX::SECOND; } - return (static_cast(ticks) / static_cast(anim->mTicksPerSecond)) * FBX::SECOND; + return (static_cast(ticks / anim->mTicksPerSecond)) * FBX::SECOND; } -int64_t to_ktime(double time) { +inline int64_t to_ktime(double time) { return (static_cast(time * FBX::SECOND)); } @@ -2415,7 +2413,7 @@ void FBXExporter::WriteObjects () // position/translation for (size_t ki = 0; ki < na->mNumPositionKeys; ++ki) { const aiVectorKey& k = na->mPositionKeys[ki]; - times.push_back(to_ktime(k.mTime)); + times.push_back(to_ktime(k.mTime, anim)); xval.push_back(k.mValue.x); yval.push_back(k.mValue.y); zval.push_back(k.mValue.z); @@ -2429,12 +2427,12 @@ void FBXExporter::WriteObjects () times.clear(); xval.clear(); yval.clear(); zval.clear(); for (size_t ki = 0; ki < na->mNumRotationKeys; ++ki) { const aiQuatKey& k = na->mRotationKeys[ki]; - times.push_back(to_ktime(k.mTime)); + times.push_back(to_ktime(k.mTime, anim)); // TODO: aiQuaternion method to convert to Euler... aiMatrix4x4 m(k.mValue.GetMatrix()); aiVector3D qs, qr, qt; m.Decompose(qs, qr, qt); - qr *= DEG; + qr = AI_RAD_TO_DEG(qr); xval.push_back(qr.x); yval.push_back(qr.y); zval.push_back(qr.z); @@ -2447,7 +2445,7 @@ void FBXExporter::WriteObjects () times.clear(); xval.clear(); yval.clear(); zval.clear(); for (size_t ki = 0; ki < na->mNumScalingKeys; ++ki) { const aiVectorKey& k = na->mScalingKeys[ki]; - times.push_back(to_ktime(k.mTime)); + times.push_back(to_ktime(k.mTime, anim)); xval.push_back(k.mValue.x); yval.push_back(k.mValue.y); zval.push_back(k.mValue.z); @@ -2515,9 +2513,10 @@ void FBXExporter::WriteModelNode( ); } if (r != zero) { + r = AI_RAD_TO_DEG(r); p.AddP70( "Lcl Rotation", "Lcl Rotation", "", "A", - double(DEG*r.x), double(DEG*r.y), double(DEG*r.z) + double(r.x), double(r.y), double(r.z) ); } if (s != one) { @@ -2601,8 +2600,7 @@ void FBXExporter::WriteModelNodes( transform_chain.emplace_back(elem->first, t); break; case 'r': // rotation - r *= float(DEG); - transform_chain.emplace_back(elem->first, r); + transform_chain.emplace_back(elem->first, AI_RAD_TO_DEG(r)); break; case 's': // scale transform_chain.emplace_back(elem->first, s); diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 56e0f38e9..afd4b11c1 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -72,30 +72,25 @@ using namespace Assimp::Formatter; using namespace Assimp::FBX; namespace { - -static const aiImporterDesc desc = { - "Autodesk FBX Importer", - "", - "", - "", - aiImporterFlags_SupportTextFlavour, - 0, - 0, - 0, - 0, - "fbx" -}; + static constexpr aiImporterDesc desc = { + "Autodesk FBX Importer", + "", + "", + "", + aiImporterFlags_SupportTextFlavour, + 0, + 0, + 0, + 0, + "fbx" + }; } -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by #Importer -FBXImporter::FBXImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool FBXImporter::CanRead(const std::string & pFile, IOSystem * pIOHandler, bool /*checkSig*/) const { // at least ASCII-FBX files usually have a 'FBX' somewhere in their head - static const char *tokens[] = { "fbx" }; + static const char *tokens[] = { " \n\r\n " }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens)); } diff --git a/code/AssetLib/FBX/FBXImporter.h b/code/AssetLib/FBX/FBXImporter.h index 9acabaddd..d12b45969 100644 --- a/code/AssetLib/FBX/FBXImporter.h +++ b/code/AssetLib/FBX/FBXImporter.h @@ -70,7 +70,7 @@ typedef class basic_formatter, std::allocator class FBXImporter : public BaseImporter, public LogFunctions { public: /// @brief The class constructor. - FBXImporter(); + FBXImporter() = default; /// @brief The class destructor, default implementation. ~FBXImporter() override = default; diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 2f575a511..bcb9bc42a 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -367,7 +367,9 @@ Video::Video(uint64_t id, const Element &element, const Document &doc, const std } Video::~Video() { - delete[] content; + if (contentLength > 0) { + delete[] content; + } } } //!FBX diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index fcbaac169..8c6499a91 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.cpp @@ -467,9 +467,9 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, std::vector uvIndices; ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName)); - if (uvIndices.size() != vertex_count) { + if (uvIndices.size() != mapping_offsets.size()) { FBXImporter::LogError("length of input data unexpected for ByVertice mapping: ", - uvIndices.size(), ", expected ", vertex_count); + uvIndices.size(), ", expected ", mapping_offsets.size()); return; } diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index 955e811cb..7baa7ed39 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -45,12 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER -//#ifdef ASSIMP_BUILD_NO_OWN_ZLIB #include "Common/Compression.h" -//# include -//#else -//# include "../contrib/zlib/zlib.h" -//#endif #include "FBXTokenizer.h" #include "FBXParser.h" diff --git a/code/AssetLib/FBX/FBXUtil.cpp b/code/AssetLib/FBX/FBXUtil.cpp index ac465d6e9..e2903c536 100644 --- a/code/AssetLib/FBX/FBXUtil.cpp +++ b/code/AssetLib/FBX/FBXUtil.cpp @@ -155,7 +155,7 @@ size_t DecodeBase64(const char* in, size_t inLength, uint8_t* out, size_t maxOut const size_t realLength = inLength - size_t(in[inLength - 1] == '=') - size_t(in[inLength - 2] == '='); size_t dst_offset = 0; int val = 0, valb = -8; - for (size_t src_offset = 0; src_offset < realLength; ++src_offset) + for (size_t src_offset = 0; src_offset < realLength && dst_offset < maxOutLength; ++src_offset) { const uint8_t table_value = Util::DecodeBase64(in[src_offset]); if (table_value == 255) diff --git a/code/AssetLib/HMP/HMPLoader.cpp b/code/AssetLib/HMP/HMPLoader.cpp index 431783a6a..5ccb2b474 100644 --- a/code/AssetLib/HMP/HMPLoader.cpp +++ b/code/AssetLib/HMP/HMPLoader.cpp @@ -57,7 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "3D GameStudio Heightmap (HMP) Importer", "", "", diff --git a/code/AssetLib/IFC/IFCLoader.cpp b/code/AssetLib/IFC/IFCLoader.cpp index 89012902c..c919d9982 100644 --- a/code/AssetLib/IFC/IFCLoader.cpp +++ b/code/AssetLib/IFC/IFCLoader.cpp @@ -103,7 +103,7 @@ void ConvertUnit(const ::Assimp::STEP::EXPRESS::DataType &dt, ConversionData &co } // namespace -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Industry Foundation Classes (IFC) Importer", "", "", @@ -185,7 +185,7 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy size_t total = 0; int read = 0; do { - int bufferSize = fileInfo.uncompressed_size < INT16_MAX ? fileInfo.uncompressed_size : INT16_MAX; + unsigned bufferSize = fileInfo.uncompressed_size < INT16_MAX ? static_cast(fileInfo.uncompressed_size) : INT16_MAX; void *buffer = malloc(bufferSize); read = unzReadCurrentFile(zip, buffer, bufferSize); if (read > 0) { diff --git a/code/AssetLib/IFC/IFCOpenings.cpp b/code/AssetLib/IFC/IFCOpenings.cpp index 48b843aa1..c47446dda 100644 --- a/code/AssetLib/IFC/IFCOpenings.cpp +++ b/code/AssetLib/IFC/IFCOpenings.cpp @@ -1372,7 +1372,7 @@ std::vector GetContourInPlane2D(const std::shared_ptr& mes const std::vector& va = mesh->mVerts; if(va.size() <= 2) { std::stringstream msg; - msg << "Skipping: Only " << va.size() << " verticies in opening mesh."; + msg << "Skipping: Only " << va.size() << " vertices in opening mesh."; IFCImporter::LogDebug(msg.str().c_str()); ok = false; return contour; 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/IQM/IQMImporter.cpp b/code/AssetLib/IQM/IQMImporter.cpp index 139b490d8..432c12113 100644 --- a/code/AssetLib/IQM/IQMImporter.cpp +++ b/code/AssetLib/IQM/IQMImporter.cpp @@ -59,7 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // http://sauerbraten.org/iqm/ // https://github.com/lsalzman/iqm - inline void swap_block( uint32_t *block, size_t size ){ (void)block; // suppress 'unreferenced formal parameter' MSVC warning size >>= 2; @@ -67,7 +66,7 @@ inline void swap_block( uint32_t *block, size_t size ){ AI_SWAP4( block[ i ] ); } -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Inter-Quake Model Importer", "", "", @@ -100,13 +99,6 @@ bool IQMImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c if (!pIOHandler) { return true; } - /* - * don't use CheckMagicToken because that checks with swapped bytes too, leading to false - * positives. This magic is not uint32_t, but char[4], so memcmp is the best way - - const char* tokens[] = {"3DMO", "3dmo"}; - return CheckMagicToken(pIOHandler,pFile,tokens,2,0,4); - */ std::unique_ptr pStream(pIOHandler->Open(pFile, "rb")); unsigned char data[15]; if (!pStream || 15 != pStream->Read(data, 1, 15)) { diff --git a/code/AssetLib/Irr/IRRLoader.cpp b/code/AssetLib/Irr/IRRLoader.cpp index ba6ebc964..2a481a6d8 100644 --- a/code/AssetLib/Irr/IRRLoader.cpp +++ b/code/AssetLib/Irr/IRRLoader.cpp @@ -66,7 +66,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Irrlicht Scene Reader", "", "", @@ -575,8 +575,8 @@ void SetupMapping(aiMaterial *mat, aiTextureMapping mode, const aiVector3D &axis m->mSemantic = prop->mSemantic; m->mType = aiPTI_Float; - m->mDataLength = 12; - m->mData = new char[12]; + m->mDataLength = sizeof(aiVector3D); + m->mData = new char[m->mDataLength]; *((aiVector3D *)m->mData) = axis; p.push_back(m); } @@ -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/IRRMeshLoader.cpp b/code/AssetLib/Irr/IRRMeshLoader.cpp index 8161a2997..b35a95c12 100644 --- a/code/AssetLib/Irr/IRRMeshLoader.cpp +++ b/code/AssetLib/Irr/IRRMeshLoader.cpp @@ -56,7 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Irrlicht Mesh Reader", "", "", diff --git a/code/AssetLib/LWO/LWOBLoader.cpp b/code/AssetLib/LWO/LWOBLoader.cpp index e49adcf98..4a9792b79 100644 --- a/code/AssetLib/LWO/LWOBLoader.cpp +++ b/code/AssetLib/LWO/LWOBLoader.cpp @@ -51,64 +51,56 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "LWOLoader.h" using namespace Assimp; - // ------------------------------------------------------------------------------------------------ -void LWOImporter::LoadLWOBFile() -{ +void LWOImporter::LoadLWOBFile() { LE_NCONST uint8_t* const end = mFileBuffer + fileSize; bool running = true; - while (running) - { - if (mFileBuffer + sizeof(IFF::ChunkHeader) > end)break; + while (running) { + if (mFileBuffer + sizeof(IFF::ChunkHeader) > end) + break; const IFF::ChunkHeader head = IFF::LoadChunk(mFileBuffer); - if (mFileBuffer + head.length > end) - { + if (mFileBuffer + head.length > end) { throw DeadlyImportError("LWOB: Invalid chunk length"); } uint8_t* const next = mFileBuffer+head.length; - switch (head.type) - { + switch (head.type) { // vertex list - case AI_LWO_PNTS: - { + case AI_LWO_PNTS: { if (!mCurLayer->mTempPoints.empty()) ASSIMP_LOG_WARN("LWO: PNTS chunk encountered twice"); - else LoadLWOPoints(head.length); - break; - } - // face list - case AI_LWO_POLS: - { + else + LoadLWOPoints(head.length); + } break; + case AI_LWO_POLS: { // face list + if (!mCurLayer->mFaces.empty()) + ASSIMP_LOG_WARN("LWO: POLS chunk encountered twice"); + else + LoadLWOBPolygons(head.length); + } break; + + case AI_LWO_SRFS: // list of tags + { + if (!mTags->empty()) + ASSIMP_LOG_WARN("LWO: SRFS chunk encountered twice"); + else + LoadLWOTags(head.length); + } break; - if (!mCurLayer->mFaces.empty()) - ASSIMP_LOG_WARN("LWO: POLS chunk encountered twice"); - else LoadLWOBPolygons(head.length); - break; - } - // list of tags - case AI_LWO_SRFS: - { - if (!mTags->empty()) - ASSIMP_LOG_WARN("LWO: SRFS chunk encountered twice"); - else LoadLWOTags(head.length); - break; - } + case AI_LWO_SURF: // surface chunk + { + LoadLWOBSurface(head.length); + } break; - // surface chunk - case AI_LWO_SURF: - { - LoadLWOBSurface(head.length); + default: break; - } } mFileBuffer = next; } } // ------------------------------------------------------------------------------------------------ -void LWOImporter::LoadLWOBPolygons(unsigned int length) -{ +void LWOImporter::LoadLWOBPolygons(unsigned int length) { // first find out how many faces and vertices we'll finally need LE_NCONST uint16_t* const end = (LE_NCONST uint16_t*)(mFileBuffer+length); LE_NCONST uint16_t* cursor = (LE_NCONST uint16_t*)mFileBuffer; @@ -123,8 +115,7 @@ void LWOImporter::LoadLWOBPolygons(unsigned int length) CountVertsAndFacesLWOB(iNumVertices,iNumFaces,cursor,end); // allocate the output array and copy face indices - if (iNumFaces) - { + if (iNumFaces) { cursor = (LE_NCONST uint16_t*)mFileBuffer; mCurLayer->mFaces.resize(iNumFaces); @@ -135,10 +126,8 @@ void LWOImporter::LoadLWOBPolygons(unsigned int length) // ------------------------------------------------------------------------------------------------ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& faces, - LE_NCONST uint16_t*& cursor, const uint16_t* const end, unsigned int max) -{ - while (cursor < end && max--) - { + LE_NCONST uint16_t*& cursor, const uint16_t* const end, unsigned int max) { + while (cursor < end && max--) { uint16_t numIndices; // must have 2 shorts left for numIndices and surface if (end - cursor < 2) { @@ -154,8 +143,7 @@ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& face cursor += numIndices; int16_t surface; ::memcpy(&surface, cursor++, 2); - if (surface < 0) - { + if (surface < 0) { // there are detail polygons ::memcpy(&numIndices, cursor++, 2); CountVertsAndFacesLWOB(verts,faces,cursor,end,numIndices); @@ -167,18 +155,14 @@ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& face void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it, LE_NCONST uint16_t*& cursor, const uint16_t* const end, - unsigned int max) -{ - while (cursor < end && max--) - { + unsigned int max) { + while (cursor < end && max--) { LWO::Face& face = *it;++it; uint16_t numIndices; ::memcpy(&numIndices, cursor++, 2); face.mNumIndices = numIndices; - if(face.mNumIndices) - { - if (cursor + face.mNumIndices >= end) - { + if(face.mNumIndices) { + if (cursor + face.mNumIndices >= end) { break; } face.mIndices = new unsigned int[face.mNumIndices]; @@ -187,8 +171,7 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it, uint16_t index; ::memcpy(&index, cursor++, 2); mi = index; - if (mi > mCurLayer->mTempPoints.size()) - { + if (mi > mCurLayer->mTempPoints.size()) { ASSIMP_LOG_WARN("LWOB: face index is out of range"); mi = (unsigned int)mCurLayer->mTempPoints.size()-1; } @@ -198,15 +181,13 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it, } int16_t surface; ::memcpy(&surface, cursor++, 2); - if (surface < 0) - { + if (surface < 0) { surface = -surface; // there are detail polygons. uint16_t numPolygons; ::memcpy(&numPolygons, cursor++, 2); - if (cursor < end) - { + if (cursor < end) { CopyFaceIndicesLWOB(it,cursor,end,numPolygons); } } @@ -215,8 +196,7 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it, } // ------------------------------------------------------------------------------------------------ -LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned int size) -{ +LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned int size) { list.emplace_back(); LWO::Texture* tex = &list.back(); @@ -224,8 +204,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i GetS0(type,size); const char* s = type.c_str(); - if(strstr(s, "Image Map")) - { + if(strstr(s, "Image Map")) { // Determine mapping type if(strstr(s, "Planar")) tex->mapMode = LWO::Texture::Planar; @@ -237,9 +216,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i tex->mapMode = LWO::Texture::Cubic; else if(strstr(s, "Front")) tex->mapMode = LWO::Texture::FrontProjection; - } - else - { + } else { // procedural or gradient, not supported ASSIMP_LOG_ERROR("LWOB: Unsupported legacy texture: ", type); } @@ -248,8 +225,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i } // ------------------------------------------------------------------------------------------------ -void LWOImporter::LoadLWOBSurface(unsigned int size) -{ +void LWOImporter::LoadLWOBSurface(unsigned int size) { LE_NCONST uint8_t* const end = mFileBuffer + size; mSurfaces->push_back( LWO::Surface () ); @@ -277,148 +253,147 @@ void LWOImporter::LoadLWOBSurface(unsigned int size) } uint8_t* const next = mFileBuffer+head.length; - switch (head.type) - { - // diffuse color - case AI_LWO_COLR: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,COLR,3); - surf.mColor.r = GetU1() / 255.0f; - surf.mColor.g = GetU1() / 255.0f; - surf.mColor.b = GetU1() / 255.0f; - break; - } - // diffuse strength ... - case AI_LWO_DIFF: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,DIFF,2); - surf.mDiffuseValue = GetU2() / 255.0f; - break; - } - // specular strength ... - case AI_LWO_SPEC: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SPEC,2); - surf.mSpecularValue = GetU2() / 255.0f; - break; - } - // luminosity ... - case AI_LWO_LUMI: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,LUMI,2); - surf.mLuminosity = GetU2() / 255.0f; - break; - } - // transparency - case AI_LWO_TRAN: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TRAN,2); - surf.mTransparency = GetU2() / 255.0f; - break; - } - // surface flags - case AI_LWO_FLAG: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,FLAG,2); - uint16_t flag = GetU2(); - if (flag & 0x4 ) surf.mMaximumSmoothAngle = 1.56207f; - if (flag & 0x8 ) surf.mColorHighlights = 1.f; - if (flag & 0x100) surf.bDoubleSided = true; - break; - } - // maximum smoothing angle - case AI_LWO_SMAN: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4); - surf.mMaximumSmoothAngle = std::fabs( GetF4() ); - break; - } - // glossiness - case AI_LWO_GLOS: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,GLOS,2); - surf.mGlossiness = (float)GetU2(); - break; - } - // color texture - case AI_LWO_CTEX: - { - pTex = SetupNewTextureLWOB(surf.mColorTextures, - head.length); - break; - } - // diffuse texture - case AI_LWO_DTEX: - { - pTex = SetupNewTextureLWOB(surf.mDiffuseTextures, - head.length); - break; - } - // specular texture - case AI_LWO_STEX: - { - pTex = SetupNewTextureLWOB(surf.mSpecularTextures, - head.length); - break; - } - // bump texture - case AI_LWO_BTEX: - { - pTex = SetupNewTextureLWOB(surf.mBumpTextures, - head.length); - break; - } - // transparency texture - case AI_LWO_TTEX: - { - pTex = SetupNewTextureLWOB(surf.mOpacityTextures, - head.length); - break; - } - // texture path - case AI_LWO_TIMG: - { - if (pTex) { - GetS0(pTex->mFileName,head.length); - } else { - ASSIMP_LOG_WARN("LWOB: Unexpected TIMG chunk"); + switch (head.type) { + // diffuse color + case AI_LWO_COLR: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,COLR,3); + surf.mColor.r = GetU1() / 255.0f; + surf.mColor.g = GetU1() / 255.0f; + surf.mColor.b = GetU1() / 255.0f; + break; } - break; - } - // texture strength - case AI_LWO_TVAL: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TVAL,1); - if (pTex) { - pTex->mStrength = (float)GetU1()/ 255.f; - } else { - ASSIMP_LOG_ERROR("LWOB: Unexpected TVAL chunk"); + // diffuse strength ... + case AI_LWO_DIFF: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,DIFF,2); + surf.mDiffuseValue = GetU2() / 255.0f; + break; } - break; - } - // texture flags - case AI_LWO_TFLG: - { - AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TFLG,2); - - if (nullptr != pTex) { - const uint16_t s = GetU2(); - if (s & 1) - pTex->majorAxis = LWO::Texture::AXIS_X; - else if (s & 2) - pTex->majorAxis = LWO::Texture::AXIS_Y; - else if (s & 4) - pTex->majorAxis = LWO::Texture::AXIS_Z; - - if (s & 16) { - ASSIMP_LOG_WARN("LWOB: Ignoring \'negate\' flag on texture"); + // specular strength ... + case AI_LWO_SPEC: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SPEC,2); + surf.mSpecularValue = GetU2() / 255.0f; + break; + } + // luminosity ... + case AI_LWO_LUMI: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,LUMI,2); + surf.mLuminosity = GetU2() / 255.0f; + break; + } + // transparency + case AI_LWO_TRAN: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TRAN,2); + surf.mTransparency = GetU2() / 255.0f; + break; + } + // surface flags + case AI_LWO_FLAG: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,FLAG,2); + uint16_t flag = GetU2(); + if (flag & 0x4 ) surf.mMaximumSmoothAngle = 1.56207f; + if (flag & 0x8 ) surf.mColorHighlights = 1.f; + if (flag & 0x100) surf.bDoubleSided = true; + break; + } + // maximum smoothing angle + case AI_LWO_SMAN: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4); + surf.mMaximumSmoothAngle = std::fabs( GetF4() ); + break; + } + // glossiness + case AI_LWO_GLOS: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,GLOS,2); + surf.mGlossiness = (float)GetU2(); + break; + } + // color texture + case AI_LWO_CTEX: + { + pTex = SetupNewTextureLWOB(surf.mColorTextures, + head.length); + break; + } + // diffuse texture + case AI_LWO_DTEX: + { + pTex = SetupNewTextureLWOB(surf.mDiffuseTextures, + head.length); + break; + } + // specular texture + case AI_LWO_STEX: + { + pTex = SetupNewTextureLWOB(surf.mSpecularTextures, + head.length); + break; + } + // bump texture + case AI_LWO_BTEX: + { + pTex = SetupNewTextureLWOB(surf.mBumpTextures, + head.length); + break; + } + // transparency texture + case AI_LWO_TTEX: + { + pTex = SetupNewTextureLWOB(surf.mOpacityTextures, + head.length); + break; + } + // texture path + case AI_LWO_TIMG: + { + if (pTex) { + GetS0(pTex->mFileName,head.length); + } else { + ASSIMP_LOG_WARN("LWOB: Unexpected TIMG chunk"); } + break; } - else { - ASSIMP_LOG_WARN("LWOB: Unexpected TFLG chunk"); + // texture strength + case AI_LWO_TVAL: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TVAL,1); + if (pTex) { + pTex->mStrength = (float)GetU1()/ 255.f; + } else { + ASSIMP_LOG_ERROR("LWOB: Unexpected TVAL chunk"); + } + break; + } + // texture flags + case AI_LWO_TFLG: + { + AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TFLG,2); + + if (nullptr != pTex) { + const uint16_t s = GetU2(); + if (s & 1) + pTex->majorAxis = LWO::Texture::AXIS_X; + else if (s & 2) + pTex->majorAxis = LWO::Texture::AXIS_Y; + else if (s & 4) + pTex->majorAxis = LWO::Texture::AXIS_Z; + + if (s & 16) { + ASSIMP_LOG_WARN("LWOB: Ignoring \'negate\' flag on texture"); + } + } + else { + ASSIMP_LOG_WARN("LWOB: Unexpected TFLG chunk"); + } + break; } - break; - } } mFileBuffer = next; } diff --git a/code/AssetLib/LWS/LWSLoader.cpp b/code/AssetLib/LWS/LWSLoader.cpp index c41ff9cac..dec834495 100644 --- a/code/AssetLib/LWS/LWSLoader.cpp +++ b/code/AssetLib/LWS/LWSLoader.cpp @@ -63,7 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "LightWave Scene Importer", "", "", @@ -139,10 +139,6 @@ LWSImporter::LWSImporter() : // nothing to do here } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -LWSImporter::~LWSImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool LWSImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/LWS/LWSLoader.h b/code/AssetLib/LWS/LWSLoader.h index 3df9fe9d9..4e92ef0d5 100644 --- a/code/AssetLib/LWS/LWSLoader.h +++ b/code/AssetLib/LWS/LWSLoader.h @@ -174,7 +174,7 @@ struct NodeDesc { class LWSImporter : public BaseImporter { public: LWSImporter(); - ~LWSImporter() override; + ~LWSImporter() override = default; // ------------------------------------------------------------------- // Check whether we can read a specific file diff --git a/code/AssetLib/M3D/M3DImporter.cpp b/code/AssetLib/M3D/M3DImporter.cpp index 895b2bf70..71f416139 100644 --- a/code/AssetLib/M3D/M3DImporter.cpp +++ b/code/AssetLib/M3D/M3DImporter.cpp @@ -85,7 +85,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. are listed in aiScene->mRootNode->children, but all without meshes */ -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Model 3D Importer", "", "", diff --git a/code/AssetLib/MD2/MD2Loader.cpp b/code/AssetLib/MD2/MD2Loader.cpp index ee7dbc6a6..596d26414 100644 --- a/code/AssetLib/MD2/MD2Loader.cpp +++ b/code/AssetLib/MD2/MD2Loader.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -41,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ - #ifndef ASSIMP_BUILD_NO_MD2_IMPORTER /** @file Implementation of the MD2 importer class */ @@ -65,7 +62,7 @@ using namespace Assimp::MD2; # define ARRAYSIZE(_array) (int(sizeof(_array) / sizeof(_array[0]))) #endif -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Quake II Mesh Importer", "", "", @@ -79,7 +76,7 @@ static const aiImporterDesc desc = { }; // ------------------------------------------------------------------------------------------------ -// Helper function to lookup a normal in Quake 2's precalculated table +// Helper function to lookup a normal in Quake 2's pre-calculated table void MD2::LookupNormalIndex(uint8_t iNormalIndex,aiVector3D& vOut) { // make sure the normal index has a valid value @@ -100,10 +97,6 @@ MD2Importer::MD2Importer() fileSize() {} -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MD2Importer::~MD2Importer() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool MD2Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const diff --git a/code/AssetLib/MD2/MD2Loader.h b/code/AssetLib/MD2/MD2Loader.h index a49ccb2fd..bab026ea0 100644 --- a/code/AssetLib/MD2/MD2Loader.h +++ b/code/AssetLib/MD2/MD2Loader.h @@ -63,7 +63,7 @@ using namespace MD2; class MD2Importer : public BaseImporter { public: MD2Importer(); - ~MD2Importer() override; + ~MD2Importer() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index fcb8d0c35..e743889e3 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -70,7 +70,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Quake III Mesh Importer", "", "", diff --git a/code/AssetLib/MD5/MD5Loader.cpp b/code/AssetLib/MD5/MD5Loader.cpp index 4236f32e9..697e758fb 100644 --- a/code/AssetLib/MD5/MD5Loader.cpp +++ b/code/AssetLib/MD5/MD5Loader.cpp @@ -64,7 +64,7 @@ using namespace Assimp; // Minimum weight value. Weights inside [-n ... n] are ignored #define AI_MD5_WEIGHT_EPSILON Math::getEpsilon() -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Doom 3 / MD5 Mesh Importer", "", "", @@ -92,10 +92,6 @@ MD5Importer::MD5Importer() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MD5Importer::~MD5Importer() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool MD5Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/MD5/MD5Loader.h b/code/AssetLib/MD5/MD5Loader.h index 63fb1c36b..c213c04e6 100644 --- a/code/AssetLib/MD5/MD5Loader.h +++ b/code/AssetLib/MD5/MD5Loader.h @@ -65,7 +65,7 @@ using namespace Assimp::MD5; class MD5Importer : public BaseImporter { public: MD5Importer(); - ~MD5Importer() override; + ~MD5Importer() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/MDC/MDCLoader.cpp b/code/AssetLib/MDC/MDCLoader.cpp index 10ea618b9..87247adec 100644 --- a/code/AssetLib/MDC/MDCLoader.cpp +++ b/code/AssetLib/MDC/MDCLoader.cpp @@ -60,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; using namespace Assimp::MDC; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Return To Castle Wolfenstein Mesh Importer", "", "", @@ -103,10 +103,6 @@ MDCImporter::MDCImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MDCImporter::~MDCImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool MDCImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/MDC/MDCLoader.h b/code/AssetLib/MDC/MDCLoader.h index 6e67cd12f..a1f8d9fc9 100644 --- a/code/AssetLib/MDC/MDCLoader.h +++ b/code/AssetLib/MDC/MDCLoader.h @@ -62,7 +62,7 @@ using namespace MDC; class MDCImporter : public BaseImporter { public: MDCImporter(); - ~MDCImporter() override; + ~MDCImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 7b2ec7115..2b14fe980 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -65,7 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Quake Mesh / 3D GameStudio Mesh Importer", "", "", @@ -96,10 +96,6 @@ MDLImporter::MDLImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MDLImporter::~MDLImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool MDLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/MDL/MDLLoader.h b/code/AssetLib/MDL/MDLLoader.h index 44ff21e3e..333f7c8b1 100644 --- a/code/AssetLib/MDL/MDLLoader.h +++ b/code/AssetLib/MDL/MDLLoader.h @@ -39,10 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ - -/** @file MDLLoader.h - * @brief Declaration of the loader for MDL files - */ +/// @file MDLLoader.h +/// @brief Declaration of the loader for MDL files #pragma once #ifndef AI_MDLLOADER_H_INCLUDED #define AI_MDLLOADER_H_INCLUDED @@ -83,11 +81,10 @@ using namespace MDL; * them all with a single 1000-line function-beast. However, it has been * split into several code paths to make the code easier to read and maintain. */ -class MDLImporter : public BaseImporter -{ +class MDLImporter : public BaseImporter { public: MDLImporter(); - ~MDLImporter() override; + ~MDLImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index 3d39fa645..f8dafdb3e 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -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/MMDImporter.cpp b/code/AssetLib/MMD/MMDImporter.cpp index 0905ce1e0..b96d45c98 100644 --- a/code/AssetLib/MMD/MMDImporter.cpp +++ b/code/AssetLib/MMD/MMDImporter.cpp @@ -57,7 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -static const aiImporterDesc desc = { "MMD Importer", +static constexpr aiImporterDesc desc = { "MMD Importer", "", "", "surfaces supported?", @@ -81,10 +81,6 @@ MMDImporter::MMDImporter() : m_strAbsPath = io.getOsSeparator(); } -// ------------------------------------------------------------------------------------------------ -// Destructor. -MMDImporter::~MMDImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns true, if file is an pmx file. bool MMDImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, diff --git a/code/AssetLib/MMD/MMDImporter.h b/code/AssetLib/MMD/MMDImporter.h index 36f384829..1f584bf12 100644 --- a/code/AssetLib/MMD/MMDImporter.h +++ b/code/AssetLib/MMD/MMDImporter.h @@ -50,46 +50,34 @@ struct aiMesh; namespace Assimp { // ------------------------------------------------------------------------------------------------ -/// \class MMDImporter -/// \brief Imports MMD a pmx/pmd/vmd file +/// @class MMDImporter +/// @brief Imports MMD a pmx/pmd/vmd file // ------------------------------------------------------------------------------------------------ class MMDImporter : public BaseImporter { public: - /// \brief Default constructor + /// @brief Default constructor MMDImporter(); - /// \brief Destructor - ~MMDImporter() override; + /// @brief Destructor + ~MMDImporter() override = default; public: - /// \brief Returns whether the class can handle the format of the given file. - /// \remark See BaseImporter::CanRead() for details. + /// @brief Returns whether the class can handle the format of the given file. + /// @remark See BaseImporter::CanRead() for details. bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const override; private: - //! \brief Appends the supported extension. const aiImporterDesc* GetInfo() const override; - - //! \brief File import implementation. void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override; - - //! \brief Create the data from imported content. void CreateDataFromImport(const pmx::PmxModel* pModel, aiScene* pScene); - - //! \brief Create the mesh aiMesh* CreateMesh(const pmx::PmxModel* pModel, const int indexStart, const int indexCount); - - //! \brief Create the material aiMaterial* CreateMaterial(const pmx::PmxMaterial* pMat, const pmx::PmxModel* pModel); private: - //! Data buffer std::vector m_Buffer; - //! Absolute pathname of model in file system std::string m_strAbsPath; }; -// ------------------------------------------------------------------------------------------------ } // Namespace Assimp diff --git a/code/AssetLib/MMD/MMDPmxParser.cpp b/code/AssetLib/MMD/MMDPmxParser.cpp index ca37ba199..6b04f02e9 100644 --- a/code/AssetLib/MMD/MMDPmxParser.cpp +++ b/code/AssetLib/MMD/MMDPmxParser.cpp @@ -42,11 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "MMDPmxParser.h" #include -#ifdef ASSIMP_USE_HUNTER -# include -#else -# include "../contrib/utf8cpp/source/utf8.h" -#endif +#include "utf8.h" #include namespace pmx @@ -93,7 +89,7 @@ namespace pmx { return std::string(); } - buffer.reserve(size); + buffer.resize(size); stream->read((char*) buffer.data(), size); if (encoding == 0) { diff --git a/code/AssetLib/MS3D/MS3DLoader.cpp b/code/AssetLib/MS3D/MS3DLoader.cpp index d4dd2be75..e0f0f8b5a 100644 --- a/code/AssetLib/MS3D/MS3DLoader.cpp +++ b/code/AssetLib/MS3D/MS3DLoader.cpp @@ -60,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Milkshape 3D Importer", "", "", @@ -84,9 +84,6 @@ MS3DImporter::MS3DImporter() : mScene() {} -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MS3DImporter::~MS3DImporter() = default; // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool MS3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const diff --git a/code/AssetLib/MS3D/MS3DLoader.h b/code/AssetLib/MS3D/MS3DLoader.h index 4bd417566..3e25f1f59 100644 --- a/code/AssetLib/MS3D/MS3DLoader.h +++ b/code/AssetLib/MS3D/MS3DLoader.h @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include + struct aiNode; namespace Assimp { @@ -58,7 +59,7 @@ namespace Assimp { class MS3DImporter : public BaseImporter { public: MS3DImporter(); - ~MS3DImporter() override; + ~MS3DImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/NDO/NDOLoader.cpp b/code/AssetLib/NDO/NDOLoader.cpp index edccc1624..405438dfc 100644 --- a/code/AssetLib/NDO/NDOLoader.cpp +++ b/code/AssetLib/NDO/NDOLoader.cpp @@ -43,8 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Implementation of the NDO importer class. */ - #ifndef ASSIMP_BUILD_NO_NDO_IMPORTER + #include "NDOLoader.h" #include #include @@ -56,7 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Nendo Mesh Importer", "", "", @@ -69,14 +69,6 @@ static const aiImporterDesc desc = { "ndo" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -NDOImporter::NDOImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -NDOImporter::~NDOImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool NDOImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const diff --git a/code/AssetLib/NDO/NDOLoader.h b/code/AssetLib/NDO/NDOLoader.h index 61dd93981..c4f127851 100644 --- a/code/AssetLib/NDO/NDOLoader.h +++ b/code/AssetLib/NDO/NDOLoader.h @@ -65,8 +65,8 @@ class Importer; */ class NDOImporter : public BaseImporter { public: - NDOImporter(); - ~NDOImporter() override; + NDOImporter() = default; + ~NDOImporter() override = default; //! Represents a single edge struct Edge { diff --git a/code/AssetLib/NFF/NFFLoader.cpp b/code/AssetLib/NFF/NFFLoader.cpp index ce7007155..78adc27bd 100644 --- a/code/AssetLib/NFF/NFFLoader.cpp +++ b/code/AssetLib/NFF/NFFLoader.cpp @@ -56,9 +56,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Neutral File Format Importer", "", "", @@ -71,14 +71,6 @@ static const aiImporterDesc desc = { "enff nff" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -NFFImporter::NFFImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -NFFImporter::~NFFImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool NFFImporter::CanRead(const std::string & pFile, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const { @@ -94,7 +86,7 @@ const aiImporterDesc *NFFImporter::GetInfo() const { // ------------------------------------------------------------------------------------------------ #define AI_NFF_PARSE_FLOAT(f) \ SkipSpaces(&sz); \ - if (!::IsLineEnd(*sz)) sz = fast_atoreal_move(sz, (ai_real &)f); + if (!IsLineEnd(*sz)) sz = fast_atoreal_move(sz, (ai_real &)f); // ------------------------------------------------------------------------------------------------ #define AI_NFF_PARSE_TRIPLE(v) \ @@ -338,8 +330,8 @@ void NFFImporter::InternReadFile(const std::string &pFile, break; } - // read the numbr of vertices - unsigned int num = ::strtoul10(sz, &sz); + // read the number of vertices + unsigned int num = strtoul10(sz, &sz); // temporary storage std::vector tempColors; @@ -365,7 +357,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // color definition if (TokenMatch(sz, "0x", 2)) { hasColor = true; - unsigned int numIdx = ::strtoul16(sz, &sz); + unsigned int numIdx = strtoul16(sz, &sz); aiColor4D clr; clr.a = 1.f; @@ -403,15 +395,16 @@ void NFFImporter::InternReadFile(const std::string &pFile, } AI_NFF2_GET_NEXT_TOKEN(); - if (!num) throw DeadlyImportError("NFF2: There are zero vertices"); - num = ::strtoul10(sz, &sz); + if (!num) + throw DeadlyImportError("NFF2: There are zero vertices"); + num = strtoul10(sz, &sz); std::vector tempIdx; tempIdx.reserve(10); for (unsigned int i = 0; i < num; ++i) { AI_NFF2_GET_NEXT_TOKEN(); SkipSpaces(line, &sz); - unsigned int numIdx = ::strtoul10(sz, &sz); + unsigned int numIdx = strtoul10(sz, &sz); // read all faces indices if (numIdx) { @@ -421,7 +414,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, for (unsigned int a = 0; a < numIdx; ++a) { SkipSpaces(sz, &sz); - unsigned int m = ::strtoul10(sz, &sz); + unsigned int m = strtoul10(sz, &sz); if (m >= (unsigned int)tempPositions.size()) { ASSIMP_LOG_ERROR("NFF2: Vertex index overflow"); m = 0; @@ -446,7 +439,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, if (TokenMatch(sz, "0x", 2)) { hasColor = true; const char *sz2 = sz; - numIdx = ::strtoul16(sz, &sz); + numIdx = strtoul16(sz, &sz); const unsigned int diff = (unsigned int)(sz - sz2); // 0xRRGGBB @@ -518,7 +511,7 @@ void NFFImporter::InternReadFile(const std::string &pFile, // Material ID? else if (!materialTable.empty() && TokenMatch(sz, "matid", 5)) { SkipSpaces(&sz); - matIdx = ::strtoul10(sz, &sz); + matIdx = strtoul10(sz, &sz); if (matIdx >= materialTable.size()) { ASSIMP_LOG_ERROR("NFF2: Material index overflow."); matIdx = 0; @@ -1165,4 +1158,6 @@ void NFFImporter::InternReadFile(const std::string &pFile, pScene->mRootNode = root; } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_NFF_IMPORTER diff --git a/code/AssetLib/NFF/NFFLoader.h b/code/AssetLib/NFF/NFFLoader.h index 7fd094306..b402aec84 100644 --- a/code/AssetLib/NFF/NFFLoader.h +++ b/code/AssetLib/NFF/NFFLoader.h @@ -63,8 +63,8 @@ namespace Assimp { */ class NFFImporter : public BaseImporter { public: - NFFImporter(); - ~NFFImporter() override; + NFFImporter() = default; + ~NFFImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/OFF/OFFLoader.cpp b/code/AssetLib/OFF/OFFLoader.cpp index f50afb57b..ce8dfc2d4 100644 --- a/code/AssetLib/OFF/OFFLoader.cpp +++ b/code/AssetLib/OFF/OFFLoader.cpp @@ -43,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the OFF importer class */ - #ifndef ASSIMP_BUILD_NO_OFF_IMPORTER // internal headers @@ -56,9 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "OFF Importer", "", "", @@ -71,99 +70,92 @@ static const aiImporterDesc desc = { "off" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -OFFImporter::OFFImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -OFFImporter::~OFFImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool OFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const -{ - static const char* tokens[] = { "off" }; - return SearchFileHeaderForToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens),3); +bool OFFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { + static const char *tokens[] = { "off" }; + return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens), 3); } // ------------------------------------------------------------------------------------------------ -const aiImporterDesc* OFFImporter::GetInfo () const -{ +const aiImporterDesc *OFFImporter::GetInfo() const { return &desc; } - // skip blank space, lines and comments -static void NextToken(const char **car, const char* end) { - SkipSpacesAndLineEnd(car); - while (*car < end && (**car == '#' || **car == '\n' || **car == '\r')) { - SkipLine(car); +static void NextToken(const char **car, const char *end) { SkipSpacesAndLineEnd(car); - } + while (*car < end && (**car == '#' || **car == '\n' || **car == '\r')) { + SkipLine(car); + SkipSpacesAndLineEnd(car); + } } // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { - std::unique_ptr file( pIOHandler->Open( pFile, "rb")); +void OFFImporter::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 == nullptr) { - throw DeadlyImportError("Failed to open OFF file ", pFile, "."); + throw DeadlyImportError("Failed to open OFF file ", pFile, "."); } // allocate storage and copy the contents of the file to a memory buffer std::vector mBuffer2; - TextFileToBuffer(file.get(),mBuffer2); - const char* buffer = &mBuffer2[0]; + TextFileToBuffer(file.get(), mBuffer2); + const char *buffer = &mBuffer2[0]; // Proper OFF header parser. We only implement normal loading for now. bool hasTexCoord = false, hasNormals = false, hasColors = false; bool hasHomogenous = false, hasDimension = false; unsigned int dimensions = 3; - const char* car = buffer; - const char* end = buffer + mBuffer2.size(); + const char *car = buffer; + const char *end = buffer + mBuffer2.size(); NextToken(&car, end); if (car < end - 2 && car[0] == 'S' && car[1] == 'T') { - hasTexCoord = true; car += 2; + hasTexCoord = true; + car += 2; } if (car < end - 1 && car[0] == 'C') { - hasColors = true; car++; + hasColors = true; + car++; } - if (car < end- 1 && car[0] == 'N') { - hasNormals = true; car++; + if (car < end - 1 && car[0] == 'N') { + hasNormals = true; + car++; } if (car < end - 1 && car[0] == '4') { - hasHomogenous = true; car++; + hasHomogenous = true; + car++; } if (car < end - 1 && car[0] == 'n') { - hasDimension = true; car++; + hasDimension = true; + car++; } if (car < end - 3 && car[0] == 'O' && car[1] == 'F' && car[2] == 'F') { car += 3; - NextToken(&car, end); + NextToken(&car, end); } else { - // in case there is no OFF header (which is allowed by the - // specification...), then we might have unintentionally read an - // additional dimension from the primitive count fields - dimensions = 3; - hasHomogenous = false; - NextToken(&car, end); + // in case there is no OFF header (which is allowed by the + // specification...), then we might have unintentionally read an + // additional dimension from the primitive count fields + dimensions = 3; + hasHomogenous = false; + NextToken(&car, end); - // at this point the next token should be an integer number - if (car >= end - 1 || *car < '0' || *car > '9') { - throw DeadlyImportError("OFF: Header is invalid"); - } + // at this point the next token should be an integer number + if (car >= end - 1 || *car < '0' || *car > '9') { + throw DeadlyImportError("OFF: Header is invalid"); + } } if (hasDimension) { dimensions = strtoul10(car, &car); - NextToken(&car, end); + NextToken(&car, end); } if (dimensions > 3) { - throw DeadlyImportError - ("OFF: Number of vertex coordinates higher than 3 unsupported"); + throw DeadlyImportError("OFF: Number of vertex coordinates higher than 3 unsupported"); } NextToken(&car, end); @@ -171,7 +163,7 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS NextToken(&car, end); const unsigned int numFaces = strtoul10(car, &car); NextToken(&car, end); - strtoul10(car, &car); // skip edge count + strtoul10(car, &car); // skip edge count NextToken(&car, end); if (!numVertices) { @@ -182,13 +174,13 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS } pScene->mNumMeshes = 1; - pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ]; + pScene->mMeshes = new aiMesh *[pScene->mNumMeshes]; - aiMesh* mesh = new aiMesh(); + aiMesh *mesh = new aiMesh(); pScene->mMeshes[0] = mesh; mesh->mNumFaces = numFaces; - aiFace* faces = new aiFace[mesh->mNumFaces]; + aiFace *faces = new aiFace[mesh->mNumFaces]; mesh->mFaces = faces; mesh->mNumVertices = numVertices; @@ -206,100 +198,101 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS // now read all vertex lines for (unsigned int i = 0; i < numVertices; ++i) { - if(!GetNextLine(buffer, line)) { + if (!GetNextLine(buffer, line)) { ASSIMP_LOG_ERROR("OFF: The number of verts in the header is incorrect"); break; } - aiVector3D& v = mesh->mVertices[i]; + aiVector3D &v = mesh->mVertices[i]; sz = line; - // helper array to write a for loop over possible dimension values - ai_real* vec[3] = {&v.x, &v.y, &v.z}; + // helper array to write a for loop over possible dimension values + ai_real *vec[3] = { &v.x, &v.y, &v.z }; - // stop at dimensions: this allows loading 1D or 2D coordinate vertices - for (unsigned int dim = 0; dim < dimensions; ++dim ) { - SkipSpaces(&sz); - sz = fast_atoreal_move(sz, *vec[dim]); - } + // stop at dimensions: this allows loading 1D or 2D coordinate vertices + for (unsigned int dim = 0; dim < dimensions; ++dim) { + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, *vec[dim]); + } - // if has homogeneous coordinate, divide others by this one - if (hasHomogenous) { - SkipSpaces(&sz); - ai_real w = 1.; - sz = fast_atoreal_move(sz, w); - for (unsigned int dim = 0; dim < dimensions; ++dim ) { - *(vec[dim]) /= w; - } - } + // if has homogeneous coordinate, divide others by this one + if (hasHomogenous) { + SkipSpaces(&sz); + ai_real w = 1.; + sz = fast_atoreal_move(sz, w); + for (unsigned int dim = 0; dim < dimensions; ++dim) { + *(vec[dim]) /= w; + } + } - // read optional normals - if (hasNormals) { - aiVector3D& n = mesh->mNormals[i]; - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)n.x); - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)n.y); - SkipSpaces(&sz); - fast_atoreal_move(sz,(ai_real&)n.z); - } + // read optional normals + if (hasNormals) { + aiVector3D &n = mesh->mNormals[i]; + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)n.x); + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)n.y); + SkipSpaces(&sz); + fast_atoreal_move(sz, (ai_real &)n.z); + } - // reading colors is a pain because the specification says it can be - // integers or floats, and any number of them between 1 and 4 included, - // until the next comment or end of line - // in theory should be testing type ! - if (hasColors) { - aiColor4D& c = mesh->mColors[0][i]; - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)c.r); + // reading colors is a pain because the specification says it can be + // integers or floats, and any number of them between 1 and 4 included, + // until the next comment or end of line + // in theory should be testing type ! + if (hasColors) { + aiColor4D &c = mesh->mColors[0][i]; + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)c.r); if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)c.g); + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)c.g); } else { - c.g = 0.; - } + c.g = 0.; + } if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)c.b); + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)c.b); } else { - c.b = 0.; - } + c.b = 0.; + } if (*sz != '#' && *sz != '\n' && *sz != '\r') { - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)c.a); + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)c.a); } else { - c.a = 1.; - } - } + c.a = 1.; + } + } if (hasTexCoord) { - aiVector3D& t = mesh->mTextureCoords[0][i]; - SkipSpaces(&sz); - sz = fast_atoreal_move(sz,(ai_real&)t.x); - SkipSpaces(&sz); - fast_atoreal_move(sz,(ai_real&)t.y); - } + aiVector3D &t = mesh->mTextureCoords[0][i]; + SkipSpaces(&sz); + sz = fast_atoreal_move(sz, (ai_real &)t.x); + SkipSpaces(&sz); + fast_atoreal_move(sz, (ai_real &)t.y); + } } // load faces with their indices faces = mesh->mFaces; - for (unsigned int i = 0; i < numFaces; ) { - if(!GetNextLine(buffer,line)) { + for (unsigned int i = 0; i < numFaces;) { + if (!GetNextLine(buffer, line)) { ASSIMP_LOG_ERROR("OFF: The number of faces in the header is incorrect"); throw DeadlyImportError("OFF: The number of faces in the header is incorrect"); } unsigned int idx; - sz = line; SkipSpaces(&sz); - idx = strtoul10(sz,&sz); - if(!idx || idx > 9) { - ASSIMP_LOG_ERROR("OFF: Faces with zero indices aren't allowed"); + sz = line; + SkipSpaces(&sz); + idx = strtoul10(sz, &sz); + if (!idx || idx > 9) { + ASSIMP_LOG_ERROR("OFF: Faces with zero indices aren't allowed"); --mesh->mNumFaces; ++i; continue; - } - faces->mNumIndices = idx; + } + faces->mNumIndices = idx; faces->mIndices = new unsigned int[faces->mNumIndices]; - for (unsigned int m = 0; m < faces->mNumIndices;++m) { + for (unsigned int m = 0; m < faces->mNumIndices; ++m) { SkipSpaces(&sz); - idx = strtoul10(sz,&sz); + idx = strtoul10(sz, &sz); if (idx >= numVertices) { ASSIMP_LOG_ERROR("OFF: Vertex index is out of range"); idx = numVertices - 1; @@ -314,20 +307,22 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS pScene->mRootNode = new aiNode(); pScene->mRootNode->mName.Set(""); pScene->mRootNode->mNumMeshes = 1; - pScene->mRootNode->mMeshes = new unsigned int [pScene->mRootNode->mNumMeshes]; + pScene->mRootNode->mMeshes = new unsigned int[pScene->mRootNode->mNumMeshes]; pScene->mRootNode->mMeshes[0] = 0; // generate a default material pScene->mNumMaterials = 1; - pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; - aiMaterial* pcMat = new aiMaterial(); + pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials]; + aiMaterial *pcMat = new aiMaterial(); - aiColor4D clr( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 1.0 ) ); - pcMat->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE); + aiColor4D clr(ai_real(0.6), ai_real(0.6), ai_real(0.6), ai_real(1.0)); + pcMat->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); pScene->mMaterials[0] = pcMat; const int twosided = 1; pcMat->AddProperty(&twosided, 1, AI_MATKEY_TWOSIDED); } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_OFF_IMPORTER diff --git a/code/AssetLib/OFF/OFFLoader.h b/code/AssetLib/OFF/OFFLoader.h index 04bb7f481..b8577e507 100644 --- a/code/AssetLib/OFF/OFFLoader.h +++ b/code/AssetLib/OFF/OFFLoader.h @@ -57,8 +57,8 @@ namespace Assimp { */ class OFFImporter : public BaseImporter { public: - OFFImporter(); - ~OFFImporter() override; + OFFImporter() = default; + ~OFFImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 173ef2074..339e90b06 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Wavefront Object Importer", "", "", @@ -78,7 +78,9 @@ using namespace std; ObjFileImporter::ObjFileImporter() : m_Buffer(), m_pRootObject(nullptr), - m_strAbsPath(std::string(1, DefaultIOSystem().getOsSeparator())) {} + m_strAbsPath(std::string(1, DefaultIOSystem().getOsSeparator())) { + // empty +} // ------------------------------------------------------------------------------------------------ // Destructor. @@ -101,8 +103,13 @@ const aiImporterDesc *ObjFileImporter::GetInfo() const { // ------------------------------------------------------------------------------------------------ // Obj-file import implementation void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { + if (m_pRootObject != nullptr) { + delete m_pRootObject; + m_pRootObject = nullptr; + } + // Read file into memory - static const std::string mode = "rb"; + static constexpr char mode[] = "rb"; auto streamCloser = [&](IOStream *pStream) { pIOHandler->Close(pStream); }; diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 09602e882..acb3f074c 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -605,7 +605,8 @@ void ObjFileParser::getMaterialDesc() { } if (needsNewMesh(strName)) { - createMesh(strName); + auto newMeshName = m_pModel->mActiveGroup.empty() ? strName : m_pModel->mActiveGroup; + createMesh(newMeshName); } m_pModel->mCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName); diff --git a/code/AssetLib/Ogre/OgreImporter.cpp b/code/AssetLib/Ogre/OgreImporter.cpp index 860aed727..5bf6901a0 100644 --- a/code/AssetLib/Ogre/OgreImporter.cpp +++ b/code/AssetLib/Ogre/OgreImporter.cpp @@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Ogre3D Mesh Importer", "", "", diff --git a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp index 16268ead5..735f56755 100644 --- a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp +++ b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp @@ -52,7 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Open Game Engine Exchange", "", "", @@ -66,42 +66,42 @@ static const aiImporterDesc desc = { }; namespace Grammar { - static const char* MetricType = "Metric"; - static const char *Metric_DistanceType = "distance"; - static const char *Metric_AngleType = "angle"; - static const char *Metric_TimeType = "time"; - static const char *Metric_UpType = "up"; - static const char *NameType = "Name"; - static const char *ObjectRefType = "ObjectRef"; - static const char *MaterialRefType = "MaterialRef"; - static const char *MetricKeyType = "key"; - static const char *GeometryNodeType = "GeometryNode"; - static const char *CameraNodeType = "CameraNode"; - static const char *LightNodeType = "LightNode"; - static const char *GeometryObjectType = "GeometryObject"; - static const char *CameraObjectType = "CameraObject"; - static const char *LightObjectType = "LightObject"; - static const char *TransformType = "Transform"; - static const char *MeshType = "Mesh"; - static const char *VertexArrayType = "VertexArray"; - static const char *IndexArrayType = "IndexArray"; - static const char *MaterialType = "Material"; - static const char *ColorType = "Color"; - static const char *ParamType = "Param"; - static const char *TextureType = "Texture"; - static const char *AttenType = "Atten"; + static constexpr char MetricType[] = "Metric"; + static constexpr char Metric_DistanceType[] = "distance"; + static constexpr char Metric_AngleType[] = "angle"; + static constexpr char Metric_TimeType[] = "time"; + static constexpr char Metric_UpType[] = "up"; + static constexpr char NameType[] = "Name"; + static constexpr char ObjectRefType[] = "ObjectRef"; + static constexpr char MaterialRefType[] = "MaterialRef"; + static constexpr char MetricKeyType[] = "key"; + static constexpr char GeometryNodeType[] = "GeometryNode"; + static constexpr char CameraNodeType[] = "CameraNode"; + static constexpr char LightNodeType[] = "LightNode"; + static constexpr char GeometryObjectType[] = "GeometryObject"; + static constexpr char CameraObjectType[] = "CameraObject"; + static constexpr char LightObjectType[] = "LightObject"; + static constexpr char TransformType[] = "Transform"; + static constexpr char MeshType[] = "Mesh"; + static constexpr char VertexArrayType[] = "VertexArray"; + static constexpr char IndexArrayType[] = "IndexArray"; + static constexpr char MaterialType[] = "Material"; + static constexpr char ColorType[] = "Color"; + static constexpr char ParamType[] = "Param"; + static constexpr char TextureType[] = "Texture"; + static constexpr char AttenType[] = "Atten"; - static const char *DiffuseColorToken = "diffuse"; - static const char *SpecularColorToken = "specular"; - static const char *EmissionColorToken = "emission"; + static constexpr char DiffuseColorToken[] = "diffuse"; + static constexpr char SpecularColorToken[] = "specular"; + static constexpr char EmissionColorToken[] = "emission"; - static const char *DiffuseTextureToken = "diffuse"; - static const char *DiffuseSpecularTextureToken = "specular"; - static const char *SpecularPowerTextureToken = "specular_power"; - static const char *EmissionTextureToken = "emission"; - static const char *OpacyTextureToken = "opacity"; - static const char *TransparencyTextureToken = "transparency"; - static const char *NormalTextureToken = "normal"; + static constexpr char DiffuseTextureToken[] = "diffuse"; + static constexpr char DiffuseSpecularTextureToken[] = "specular"; + static constexpr char SpecularPowerTextureToken[] = "specular_power"; + static constexpr char EmissionTextureToken[] = "emission"; + static constexpr char OpacyTextureToken[] = "opacity"; + static constexpr char TransparencyTextureToken[] = "transparency"; + static constexpr char NormalTextureToken[] = "normal"; enum TokenType { NoneType = -1, @@ -139,7 +139,7 @@ namespace Grammar { return false; } - int idx(-1); + int idx = -1; for (size_t i = 0; i < 4; i++) { if (ValidMetricToken[i] == token) { idx = (int)i; diff --git a/code/AssetLib/Ply/PlyLoader.cpp b/code/AssetLib/Ply/PlyLoader.cpp index 783c7f1c6..a747ba5cd 100644 --- a/code/AssetLib/Ply/PlyLoader.cpp +++ b/code/AssetLib/Ply/PlyLoader.cpp @@ -53,9 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace ::Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Stanford Polygon Library (PLY) Importer", "", "", @@ -71,16 +71,16 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Internal stuff namespace { -// ------------------------------------------------------------------------------------------------ -// Checks that property index is within range -template -inline const T &GetProperty(const std::vector &props, int idx) { - if (static_cast(idx) >= props.size()) { - throw DeadlyImportError("Invalid .ply file: Property index is out of range."); - } + // ------------------------------------------------------------------------------------------------ + // Checks that property index is within range + template + inline const T &GetProperty(const std::vector &props, int idx) { + if (static_cast(idx) >= props.size()) { + throw DeadlyImportError("Invalid .ply file: Property index is out of range."); + } - return props[idx]; -} + return props[idx]; + } } // namespace // ------------------------------------------------------------------------------------------------ @@ -92,10 +92,6 @@ PLYImporter::PLYImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -PLYImporter::~PLYImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool PLYImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -215,7 +211,7 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy throw DeadlyImportError("Invalid .ply file: Missing format specification"); } - //free the file buffer + // free the file buffer streamedBuffer.close(); if (mGeneratedMesh == nullptr) { @@ -376,7 +372,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn haveNormal = true; } - //Colors + // Colors aiColor4D cOut; bool haveColor = false; if (0xFFFFFFFF != aiColors[0]) { @@ -415,7 +411,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn haveColor = true; } - //Texture coordinates + // Texture coordinates aiVector3D tOut; tOut.z = 0; bool haveTextureCoords = false; @@ -431,7 +427,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn haveTextureCoords = true; } - //create aiMesh if needed + // create aiMesh if needed if (nullptr == mGeneratedMesh) { mGeneratedMesh = new aiMesh(); mGeneratedMesh->mMaterialIndex = 0; @@ -512,8 +508,8 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst bool bIsTriStrip = false; // index of the material index property - //unsigned int iMaterialIndex = 0xFFFFFFFF; - //PLY::EDataType eType2 = EDT_Char; + // unsigned int iMaterialIndex = 0xFFFFFFFF; + // PLY::EDataType eType2 = EDT_Char; // texture coordinates unsigned int iTextureCoord = 0xFFFFFFFF; @@ -595,7 +591,7 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst if (0xFFFFFFFF != iTextureCoord) { const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iTextureCoord).avList.size(); - //should be 6 coords + // should be 6 coords std::vector::const_iterator p = GetProperty(instElement->alProperties, iTextureCoord).avList.begin(); @@ -625,7 +621,7 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst // a value of -1 indicates a restart of the strip bool flip = false; const std::vector &quak = GetProperty(instElement->alProperties, iProperty).avList; - //pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u)); //Limits memory consumption + // pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u)); //Limits memory consumption int aiTable[2] = { -1, -1 }; for (std::vector::const_iterator a = quak.begin(); a != quak.end(); ++a) { @@ -863,7 +859,7 @@ void PLYImporter::LoadMaterial(std::vector *pvOut, std::string &de const int two_sided = 1; pcHelper->AddProperty(&two_sided, 1, AI_MATKEY_TWOSIDED); - //default texture + // default texture if (!defaultTexture.empty()) { const aiString name(defaultTexture.c_str()); pcHelper->AddProperty(&name, _AI_MATKEY_TEXTURE_BASE, aiTextureType_DIFFUSE, 0); @@ -873,7 +869,7 @@ void PLYImporter::LoadMaterial(std::vector *pvOut, std::string &de pcHelper->AddProperty(&two_sided, 1, AI_MATKEY_TWOSIDED); } - //set to wireframe, so when using this material info we can switch to points rendering + // set to wireframe, so when using this material info we can switch to points rendering if (pointsOnly) { const int wireframe = 1; pcHelper->AddProperty(&wireframe, 1, AI_MATKEY_ENABLE_WIREFRAME); @@ -890,7 +886,7 @@ void PLYImporter::LoadMaterial(std::vector *pvOut, std::string &de int iMode = (int)aiShadingMode_Gouraud; pcHelper->AddProperty(&iMode, 1, AI_MATKEY_SHADING_MODEL); - //generate white material most 3D engine just multiply ambient / diffuse color with actual ambient / light color + // generate white material most 3D engine just multiply ambient / diffuse color with actual ambient / light color aiColor3D clr; clr.b = clr.g = clr.r = 1.0f; pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); @@ -906,13 +902,13 @@ void PLYImporter::LoadMaterial(std::vector *pvOut, std::string &de pcHelper->AddProperty(&two_sided, 1, AI_MATKEY_TWOSIDED); } - //default texture + // default texture if (!defaultTexture.empty()) { const aiString name(defaultTexture.c_str()); pcHelper->AddProperty(&name, _AI_MATKEY_TEXTURE_BASE, aiTextureType_DIFFUSE, 0); } - //set to wireframe, so when using this material info we can switch to points rendering + // set to wireframe, so when using this material info we can switch to points rendering if (pointsOnly) { const int wireframe = 1; pcHelper->AddProperty(&wireframe, 1, AI_MATKEY_ENABLE_WIREFRAME); @@ -922,4 +918,6 @@ void PLYImporter::LoadMaterial(std::vector *pvOut, std::string &de } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER diff --git a/code/AssetLib/Ply/PlyLoader.h b/code/AssetLib/Ply/PlyLoader.h index e29da1db6..f85445f91 100644 --- a/code/AssetLib/Ply/PlyLoader.h +++ b/code/AssetLib/Ply/PlyLoader.h @@ -65,7 +65,7 @@ using namespace PLY; class PLYImporter : public BaseImporter { public: PLYImporter(); - ~PLYImporter() override; + ~PLYImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/Ply/PlyParser.cpp b/code/AssetLib/Ply/PlyParser.cpp index 6edba71fc..662da805e 100644 --- a/code/AssetLib/Ply/PlyParser.cpp +++ b/code/AssetLib/Ply/PlyParser.cpp @@ -425,7 +425,8 @@ bool PLY::DOM::ParseHeader(IOStreamBuffer &streamBuffer, std::vector break; } else { // ignore unknown header elements - streamBuffer.getNextLine(buffer); + if (!streamBuffer.getNextLine(buffer)) + return false; } } diff --git a/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp b/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp index 924949eeb..a82f29cf1 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp +++ b/code/AssetLib/Q3BSP/Q3BSPFileImporter.cpp @@ -48,11 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#ifdef ASSIMP_BUILD_NO_OWN_ZLIB -#include -#else -#include "../contrib/zlib/zlib.h" -#endif +#include "zlib.h" #include #include @@ -65,7 +61,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Quake III BSP Importer", "", "", @@ -146,7 +142,11 @@ Q3BSPFileImporter::Q3BSPFileImporter() : // ------------------------------------------------------------------------------------------------ // Destructor. Q3BSPFileImporter::~Q3BSPFileImporter() { - // Clear face-to-material map + clear(); +} + +// ------------------------------------------------------------------------------------------------ +void Q3BSPFileImporter::clear() { for (FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it) { const std::string &matName = it->first; if (!matName.empty()) { @@ -173,6 +173,7 @@ const aiImporterDesc *Q3BSPFileImporter::GetInfo() const { // ------------------------------------------------------------------------------------------------ // Import method. void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene *scene, IOSystem *ioHandler) { + clear(); ZipArchiveIOSystem Archive(ioHandler, rFile); if (!Archive.isOpen()) { throw DeadlyImportError("Failed to open file ", rFile, "."); @@ -394,7 +395,10 @@ void Q3BSPFileImporter::createTriangleTopology(const Q3BSP::Q3BSPModel *pModel, m_pCurrentFace->mIndices = new unsigned int[3]; m_pCurrentFace->mIndices[idx] = vertIdx; } - } + } else { + m_pCurrentFace->mIndices[idx] = vertIdx; + } + pMesh->mVertices[vertIdx].Set(pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z); pMesh->mNormals[vertIdx].Set(pVertex->vNormal.x, pVertex->vNormal.y, pVertex->vNormal.z); diff --git a/code/AssetLib/Q3BSP/Q3BSPFileImporter.h b/code/AssetLib/Q3BSP/Q3BSPFileImporter.h index fdcfff876..63d6edb21 100644 --- a/code/AssetLib/Q3BSP/Q3BSPFileImporter.h +++ b/code/AssetLib/Q3BSP/Q3BSPFileImporter.h @@ -81,6 +81,7 @@ protected: using FaceMapIt = std::map* >::iterator; using FaceMapConstIt = std::map*>::const_iterator; + void clear(); const aiImporterDesc* GetInfo () const override; void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override; void separateMapName( const std::string &rImportName, std::string &rArchiveName, std::string &rMapName ); diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index 22d1065de..b599ad8f2 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -55,9 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Quick3D Importer", "", "", @@ -127,7 +127,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile, std::vector materials; try { materials.reserve(numMats); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc &) { ASSIMP_LOG_ERROR("Invalid alloc for materials."); throw DeadlyImportError("Invalid Quick3D-file, material allocation failed."); } @@ -135,7 +135,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile, std::vector meshes; try { meshes.reserve(numMeshes); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc &) { ASSIMP_LOG_ERROR("Invalid alloc for meshes."); throw DeadlyImportError("Invalid Quick3D-file, mesh allocation failed."); } @@ -237,7 +237,6 @@ void Q3DImporter::InternReadFile(const std::string &pFile, if (minor > '0' && major == '3') stream.IncPtr(mesh.faces.size()); } - // stream.IncPtr(4); // unknown value here } break; // materials chunk @@ -275,8 +274,6 @@ void Q3DImporter::InternReadFile(const std::string &pFile, // read the transparency mat.transparency = stream.GetF4(); - // unknown value here - // stream.IncPtr(4); // FIX: it could be the texture index ... mat.texIdx = (unsigned int)stream.GetI4(); } @@ -425,7 +422,8 @@ outer: pScene->mMeshes = new aiMesh *[pScene->mNumMaterials]; for (unsigned int i = 0, real = 0; i < (unsigned int)materials.size(); ++i) { - if (fidx[i].empty()) continue; + if (fidx[i].empty()) + continue; // Allocate a mesh and a material aiMesh *mesh = pScene->mMeshes[real] = new aiMesh(); @@ -548,14 +546,9 @@ outer: // Now we need to attach the meshes to the root node of the scene pScene->mRootNode->mNumMeshes = pScene->mNumMeshes; pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes]; - for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) + for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { pScene->mRootNode->mMeshes[i] = i; - - /*pScene->mRootNode->mTransformation *= aiMatrix4x4( - 1.f, 0.f, 0.f, 0.f, - 0.f, -1.f,0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f);*/ + } // Add cameras and light sources to the scene root node pScene->mRootNode->mNumChildren = pScene->mNumLights + pScene->mNumCameras; @@ -577,4 +570,6 @@ outer: } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_Q3D_IMPORTER diff --git a/code/AssetLib/Raw/RawLoader.cpp b/code/AssetLib/Raw/RawLoader.cpp index 1791a5c52..4c5f852b0 100644 --- a/code/AssetLib/Raw/RawLoader.cpp +++ b/code/AssetLib/Raw/RawLoader.cpp @@ -55,9 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Raw Importer", "", "", @@ -70,14 +70,6 @@ static const aiImporterDesc desc = { "raw" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -RAWImporter::RAWImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -RAWImporter::~RAWImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool RAWImporter::CanRead(const std::string &filename, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const { @@ -295,4 +287,6 @@ void RAWImporter::InternReadFile(const std::string &pFile, } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_RAW_IMPORTER diff --git a/code/AssetLib/Raw/RawLoader.h b/code/AssetLib/Raw/RawLoader.h index 54314f728..83e4a9f1f 100644 --- a/code/AssetLib/Raw/RawLoader.h +++ b/code/AssetLib/Raw/RawLoader.h @@ -57,8 +57,8 @@ namespace Assimp { */ class RAWImporter : public BaseImporter { public: - RAWImporter(); - ~RAWImporter() override; + RAWImporter() = default; + ~RAWImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/SIB/SIBImporter.cpp b/code/AssetLib/SIB/SIBImporter.cpp index 9f299180b..840f74b7d 100644 --- a/code/AssetLib/SIB/SIBImporter.cpp +++ b/code/AssetLib/SIB/SIBImporter.cpp @@ -56,11 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#ifdef ASSIMP_USE_HUNTER -#include -#else -#include "../contrib/utf8cpp/source/utf8.h" -#endif +#include "utf8.h" #include #include #include @@ -69,9 +65,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Silo SIB Importer", "Richard Mitton (http://www.codersnotes.com/about)", "", @@ -94,7 +90,7 @@ enum { N }; -typedef std::pair SIBPair; +using SIBPair = std::pair; struct SIBEdge { uint32_t faceA, faceB; @@ -199,15 +195,6 @@ static aiString ReadString(StreamReaderLE *stream, uint32_t numWChars) { return result; } - -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -SIBImporter::SIBImporter() = default; - -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -SIBImporter::~SIBImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool SIBImporter::CanRead(const std::string &filename, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const { @@ -882,4 +869,6 @@ void SIBImporter::InternReadFile(const std::string &pFile, } } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_SIB_IMPORTER diff --git a/code/AssetLib/SIB/SIBImporter.h b/code/AssetLib/SIB/SIBImporter.h index 2b197ddca..903c36561 100644 --- a/code/AssetLib/SIB/SIBImporter.h +++ b/code/AssetLib/SIB/SIBImporter.h @@ -57,8 +57,8 @@ namespace Assimp { */ class ASSIMP_API SIBImporter : public BaseImporter { public: - SIBImporter(); - ~SIBImporter() override; + SIBImporter() = default; + ~SIBImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/SMD/SMDLoader.cpp b/code/AssetLib/SMD/SMDLoader.cpp index 9af871cee..4b63dd9d0 100644 --- a/code/AssetLib/SMD/SMDLoader.cpp +++ b/code/AssetLib/SMD/SMDLoader.cpp @@ -64,9 +64,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define strtok_s strtok_r #endif -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Valve SMD Importer", "", "", @@ -1077,4 +1077,6 @@ void SMDImporter::ParseVertex(const char* szCurrent, SMDI_PARSE_RETURN; } +} + #endif // !! ASSIMP_BUILD_NO_SMD_IMPORTER diff --git a/code/AssetLib/STEPParser/STEPFileEncoding.cpp b/code/AssetLib/STEPParser/STEPFileEncoding.cpp index d4456e674..92eb4f284 100644 --- a/code/AssetLib/STEPParser/STEPFileEncoding.cpp +++ b/code/AssetLib/STEPParser/STEPFileEncoding.cpp @@ -45,11 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "STEPFileEncoding.h" #include -#ifdef ASSIMP_USE_HUNTER -# include -#else -# include -#endif +#include "utf8.h" #include diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 9c0fb4f59..269ee1467 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -52,11 +52,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { namespace { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Stereolithography (STL) Importer", "", "", @@ -129,7 +129,7 @@ STLImporter::STLImporter() : mBuffer(), mFileSize(0), mScene() { - // empty + // empty } // ------------------------------------------------------------------------------------------------ @@ -250,13 +250,13 @@ void STLImporter::LoadASCIIFile(aiNode *root) { sz += 5; // skip the "solid" SkipSpaces(&sz); const char *szMe = sz; - while (!::IsSpaceOrNewLine(*sz)) { + while (!IsSpaceOrNewLine(*sz)) { sz++; } size_t temp = (size_t)(sz - szMe); // setup the name of the node - if ( temp ) { + if (temp) { if (temp >= MAXLEN) { throw DeadlyImportError("STL: Node name too long"); } @@ -303,7 +303,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) { normalBuffer.emplace_back(vn); normalBuffer.emplace_back(vn); } - } else if (!strncmp(sz, "vertex", 6) && ::IsSpaceOrNewLine(*(sz + 6))) { // vertex 1.50000 1.50000 0.00000 + } else if (!strncmp(sz, "vertex", 6) && IsSpaceOrNewLine(*(sz + 6))) { // vertex 1.50000 1.50000 0.00000 if (faceVertexCounter >= 3) { ASSIMP_LOG_ERROR("STL: a facet with more than 3 vertices has been found"); ++sz; @@ -325,14 +325,14 @@ void STLImporter::LoadASCIIFile(aiNode *root) { } else if (!::strncmp(sz, "endsolid", 8)) { do { ++sz; - } while (!::IsLineEnd(*sz)); + } while (!IsLineEnd(*sz)); SkipSpacesAndLineEnd(&sz); // finished! break; } else { // else skip the whole identifier do { ++sz; - } while (!::IsSpaceOrNewLine(*sz)); + } while (!IsSpaceOrNewLine(*sz)); } } @@ -349,14 +349,14 @@ void STLImporter::LoadASCIIFile(aiNode *root) { throw DeadlyImportError("Normal buffer size does not match position buffer size"); } - // only process positionbuffer when filled, else exception when accessing with index operator + // only process position buffer when filled, else exception when accessing with index operator // see line 353: only warning is triggered - // see line 373(now): access to empty positionbuffer with index operator forced exception + // see line 373(now): access to empty position buffer with index operator forced exception if (!positionBuffer.empty()) { pMesh->mNumFaces = static_cast(positionBuffer.size() / 3); pMesh->mNumVertices = static_cast(positionBuffer.size()); pMesh->mVertices = new aiVector3D[pMesh->mNumVertices]; - for (size_t i=0; imNumVertices; ++i ) { + for (size_t i = 0; i < pMesh->mNumVertices; ++i) { pMesh->mVertices[i].x = positionBuffer[i].x; pMesh->mVertices[i].y = positionBuffer[i].y; pMesh->mVertices[i].z = positionBuffer[i].z; @@ -366,7 +366,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) { // also only process normalBuffer when filled, else exception when accessing with index operator if (!normalBuffer.empty()) { pMesh->mNormals = new aiVector3D[pMesh->mNumVertices]; - for (size_t i=0; imNumVertices; ++i ) { + for (size_t i = 0; i < pMesh->mNumVertices; ++i) { pMesh->mNormals[i].x = normalBuffer[i].x; pMesh->mNormals[i].y = normalBuffer[i].y; pMesh->mNormals[i].z = normalBuffer[i].z; @@ -450,9 +450,8 @@ bool STLImporter::LoadBinaryFile() { aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices]; aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices]; - typedef aiVector3t aiVector3F; - aiVector3F *theVec; - aiVector3F theVec3F; + aiVector3f *theVec; + aiVector3f theVec3F; for (unsigned int i = 0; i < pMesh->mNumFaces; ++i) { // NOTE: Blender sometimes writes empty normals ... this is not @@ -460,8 +459,8 @@ bool STLImporter::LoadBinaryFile() { // There's one normal for the face in the STL; use it three times // for vertex normals - theVec = (aiVector3F *)sz; - ::memcpy(&theVec3F, theVec, sizeof(aiVector3F)); + theVec = (aiVector3f *)sz; + ::memcpy(&theVec3F, theVec, sizeof(aiVector3f)); vn->x = theVec3F.x; vn->y = theVec3F.y; vn->z = theVec3F.z; @@ -471,7 +470,7 @@ bool STLImporter::LoadBinaryFile() { vn += 3; // vertex 1 - ::memcpy(&theVec3F, theVec, sizeof(aiVector3F)); + ::memcpy(&theVec3F, theVec, sizeof(aiVector3f)); vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; @@ -479,7 +478,7 @@ bool STLImporter::LoadBinaryFile() { ++vp; // vertex 2 - ::memcpy(&theVec3F, theVec, sizeof(aiVector3F)); + ::memcpy(&theVec3F, theVec, sizeof(aiVector3f)); vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; @@ -487,7 +486,7 @@ bool STLImporter::LoadBinaryFile() { ++vp; // vertex 3 - ::memcpy(&theVec3F, theVec, sizeof(aiVector3F)); + ::memcpy(&theVec3F, theVec, sizeof(aiVector3f)); vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; @@ -570,4 +569,6 @@ void STLImporter::pushMeshesToNode(std::vector &meshIndices, aiNod meshIndices.clear(); } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_STL_IMPORTER diff --git a/code/AssetLib/Terragen/TerragenLoader.cpp b/code/AssetLib/Terragen/TerragenLoader.cpp index 738ad8e27..b1870414c 100644 --- a/code/AssetLib/Terragen/TerragenLoader.cpp +++ b/code/AssetLib/Terragen/TerragenLoader.cpp @@ -51,9 +51,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Terragen Heightmap Importer", "", "", @@ -73,10 +73,6 @@ TerragenImporter::TerragenImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -TerragenImporter::~TerragenImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool TerragenImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -244,4 +240,6 @@ void TerragenImporter::InternReadFile(const std::string &pFile, pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN; } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_TERRAGEN_IMPORTER diff --git a/code/AssetLib/Terragen/TerragenLoader.h b/code/AssetLib/Terragen/TerragenLoader.h index cb9ff9166..0c7b686e9 100644 --- a/code/AssetLib/Terragen/TerragenLoader.h +++ b/code/AssetLib/Terragen/TerragenLoader.h @@ -73,7 +73,7 @@ namespace Assimp { class TerragenImporter : public BaseImporter { public: TerragenImporter(); - ~TerragenImporter() override; + ~TerragenImporter() override = default; // ------------------------------------------------------------------- bool CanRead(const std::string &pFile, IOSystem *pIOHandler, diff --git a/code/AssetLib/Unreal/UnrealLoader.cpp b/code/AssetLib/Unreal/UnrealLoader.cpp index f2b0ab118..5f622da42 100644 --- a/code/AssetLib/Unreal/UnrealLoader.cpp +++ b/code/AssetLib/Unreal/UnrealLoader.cpp @@ -63,7 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { namespace Unreal { @@ -152,7 +152,7 @@ inline void DecompressVertex(aiVector3D &v, int32_t in) { } // end namespace Unreal -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Unreal Mesh Importer", "", "", @@ -178,7 +178,7 @@ UnrealImporter::~UnrealImporter() = default; // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool UnrealImporter::CanRead(const std::string & filename, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const { +bool UnrealImporter::CanRead(const std::string &filename, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const { return SimpleExtensionCheck(filename, "3d", "uc"); } @@ -336,12 +336,12 @@ void UnrealImporter::InternReadFile(const std::string &pFile, tempTextures.emplace_back(); std::pair &me = tempTextures.back(); for (; !IsLineEnd(*data); ++data) { - if (!::ASSIMP_strincmp(data, "NAME=", 5)) { + if (!ASSIMP_strincmp(data, "NAME=", 5)) { const char *d = data += 5; for (; !IsSpaceOrNewLine(*data); ++data) ; me.first = std::string(d, (size_t)(data - d)); - } else if (!::ASSIMP_strincmp(data, "FILE=", 5)) { + } else if (!ASSIMP_strincmp(data, "FILE=", 5)) { const char *d = data += 5; for (; !IsSpaceOrNewLine(*data); ++data) ; @@ -363,10 +363,10 @@ void UnrealImporter::InternReadFile(const std::string &pFile, std::pair &me = textures.back(); for (; !IsLineEnd(*data); ++data) { - if (!::ASSIMP_strincmp(data, "NUM=", 4)) { + if (!ASSIMP_strincmp(data, "NUM=", 4)) { data += 4; me.first = strtoul10(data, &data); - } else if (!::ASSIMP_strincmp(data, "TEXTURE=", 8)) { + } else if (!ASSIMP_strincmp(data, "TEXTURE=", 8)) { data += 8; const char *d = data; for (; !IsSpaceOrNewLine(*data); ++data) @@ -516,4 +516,6 @@ void UnrealImporter::InternReadFile(const std::string &pFile, flipper.Execute(pScene); } +} // namespace Assimp + #endif // !! ASSIMP_BUILD_NO_3D_IMPORTER diff --git a/code/AssetLib/X/XFileImporter.cpp b/code/AssetLib/X/XFileImporter.cpp index 1474ad808..00f44b34b 100644 --- a/code/AssetLib/X/XFileImporter.cpp +++ b/code/AssetLib/X/XFileImporter.cpp @@ -57,10 +57,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { + using namespace Assimp::Formatter; -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "Direct3D XFile Importer", "", "", @@ -73,142 +74,137 @@ static const aiImporterDesc desc = { "x" }; -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -XFileImporter::XFileImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool XFileImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const { +bool XFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { static const uint32_t token[] = { AI_MAKE_MAGIC("xof ") }; - return CheckMagicToken(pIOHandler,pFile,token,AI_COUNT_OF(token)); + return CheckMagicToken(pIOHandler, pFile, token, AI_COUNT_OF(token)); } // ------------------------------------------------------------------------------------------------ // Get file extension list -const aiImporterDesc* XFileImporter::GetInfo () const { +const aiImporterDesc *XFileImporter::GetInfo() const { return &desc; } // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void XFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { +void XFileImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { // read file into memory - std::unique_ptr file( pIOHandler->Open( pFile)); + std::unique_ptr file(pIOHandler->Open(pFile)); if (file == nullptr) { - throw DeadlyImportError( "Failed to open file ", pFile, "." ); + throw DeadlyImportError("Failed to open file ", pFile, "."); } static const size_t MinSize = 16; size_t fileSize = file->FileSize(); - if ( fileSize < MinSize ) { - throw DeadlyImportError( "XFile is too small." ); + if (fileSize < MinSize) { + throw DeadlyImportError("XFile is too small."); } // in the hope that binary files will never start with a BOM ... - mBuffer.resize( fileSize + 1); - file->Read( &mBuffer.front(), 1, fileSize); + mBuffer.resize(fileSize + 1); + file->Read(&mBuffer.front(), 1, fileSize); ConvertToUTF8(mBuffer); // parse the file into a temporary representation - XFileParser parser( mBuffer); + XFileParser parser(mBuffer); // and create the proper return structures out of it - CreateDataRepresentationFromImport( pScene, parser.GetImportedData()); + CreateDataRepresentationFromImport(pScene, parser.GetImportedData()); // if nothing came from it, report it as error - if ( !pScene->mRootNode ) { - throw DeadlyImportError( "XFile is ill-formatted - no content imported." ); + if (!pScene->mRootNode) { + throw DeadlyImportError("XFile is ill-formatted - no content imported."); } } // ------------------------------------------------------------------------------------------------ // Constructs the return data structure out of the imported data. -void XFileImporter::CreateDataRepresentationFromImport( aiScene* pScene, XFile::Scene* pData) -{ +void XFileImporter::CreateDataRepresentationFromImport(aiScene *pScene, XFile::Scene *pData) { // Read the global materials first so that meshes referring to them can find them later - ConvertMaterials( pScene, pData->mGlobalMaterials); + ConvertMaterials(pScene, pData->mGlobalMaterials); // copy nodes, extracting meshes and materials on the way - pScene->mRootNode = CreateNodes( pScene, nullptr, pData->mRootNode); + pScene->mRootNode = CreateNodes(pScene, nullptr, pData->mRootNode); // extract animations - CreateAnimations( pScene, pData); + CreateAnimations(pScene, pData); // read the global meshes that were stored outside of any node - if( !pData->mGlobalMeshes.empty() ) { + if (!pData->mGlobalMeshes.empty()) { // create a root node to hold them if there isn't any, yet - if( pScene->mRootNode == nullptr ) { + if (pScene->mRootNode == nullptr) { pScene->mRootNode = new aiNode; - pScene->mRootNode->mName.Set( "$dummy_node"); + pScene->mRootNode->mName.Set("$dummy_node"); } // convert all global meshes and store them in the root node. // If there was one before, the global meshes now suddenly have its transformation matrix... // Don't know what to do there, I don't want to insert another node under the present root node // just to avoid this. - CreateMeshes( pScene, pScene->mRootNode, pData->mGlobalMeshes); + CreateMeshes(pScene, pScene->mRootNode, pData->mGlobalMeshes); } if (!pScene->mRootNode) { - throw DeadlyImportError( "No root node" ); + throw DeadlyImportError("No root node"); } // Convert everything to OpenGL space... it's the same operation as the conversion back, so we can reuse the step directly MakeLeftHandedProcess convertProcess; - convertProcess.Execute( pScene); + convertProcess.Execute(pScene); FlipWindingOrderProcess flipper; flipper.Execute(pScene); // finally: create a dummy material if not material was imported - if( pScene->mNumMaterials == 0) { + if (pScene->mNumMaterials == 0) { pScene->mNumMaterials = 1; // create the Material - aiMaterial* mat = new aiMaterial; - int shadeMode = (int) aiShadingMode_Gouraud; - mat->AddProperty( &shadeMode, 1, AI_MATKEY_SHADING_MODEL); + aiMaterial *mat = new aiMaterial; + int shadeMode = (int)aiShadingMode_Gouraud; + mat->AddProperty(&shadeMode, 1, AI_MATKEY_SHADING_MODEL); // material colours int specExp = 1; - aiColor3D clr = aiColor3D( 0, 0, 0); - mat->AddProperty( &clr, 1, AI_MATKEY_COLOR_EMISSIVE); - mat->AddProperty( &clr, 1, AI_MATKEY_COLOR_SPECULAR); + aiColor3D clr = aiColor3D(0, 0, 0); + mat->AddProperty(&clr, 1, AI_MATKEY_COLOR_EMISSIVE); + mat->AddProperty(&clr, 1, AI_MATKEY_COLOR_SPECULAR); - clr = aiColor3D( 0.5f, 0.5f, 0.5f); - mat->AddProperty( &clr, 1, AI_MATKEY_COLOR_DIFFUSE); - mat->AddProperty( &specExp, 1, AI_MATKEY_SHININESS); + clr = aiColor3D(0.5f, 0.5f, 0.5f); + mat->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); + mat->AddProperty(&specExp, 1, AI_MATKEY_SHININESS); - pScene->mMaterials = new aiMaterial*[1]; + pScene->mMaterials = new aiMaterial *[1]; pScene->mMaterials[0] = mat; } } // ------------------------------------------------------------------------------------------------ // Recursively creates scene nodes from the imported hierarchy. -aiNode* XFileImporter::CreateNodes( aiScene* pScene, aiNode* pParent, const XFile::Node* pNode) { - if ( !pNode ) { +aiNode *XFileImporter::CreateNodes(aiScene *pScene, aiNode *pParent, const XFile::Node *pNode) { + if (!pNode) { return nullptr; } // create node - aiNode* node = new aiNode; + aiNode *node = new aiNode; node->mName.length = (ai_uint32)pNode->mName.length(); node->mParent = pParent; - memcpy( node->mName.data, pNode->mName.c_str(), pNode->mName.length()); + memcpy(node->mName.data, pNode->mName.c_str(), pNode->mName.length()); node->mName.data[node->mName.length] = 0; node->mTransformation = pNode->mTrafoMatrix; // convert meshes from the source node - CreateMeshes( pScene, node, pNode->mMeshes); + CreateMeshes(pScene, node, pNode->mMeshes); // handle children - if( !pNode->mChildren.empty() ) { + if (!pNode->mChildren.empty()) { node->mNumChildren = (unsigned int)pNode->mChildren.size(); - node->mChildren = new aiNode* [node->mNumChildren]; + node->mChildren = new aiNode *[node->mNumChildren]; - for ( unsigned int a = 0; a < pNode->mChildren.size(); ++a ) { - node->mChildren[ a ] = CreateNodes( pScene, node, pNode->mChildren[ a ] ); + for (unsigned int a = 0; a < pNode->mChildren.size(); ++a) { + node->mChildren[a] = CreateNodes(pScene, node, pNode->mChildren[a]); } } @@ -217,55 +213,55 @@ aiNode* XFileImporter::CreateNodes( aiScene* pScene, aiNode* pParent, const XFil // ------------------------------------------------------------------------------------------------ // Creates the meshes for the given node. -void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vector& pMeshes) { +void XFileImporter::CreateMeshes(aiScene *pScene, aiNode *pNode, const std::vector &pMeshes) { if (pMeshes.empty()) { return; } // create a mesh for each mesh-material combination in the source node - std::vector meshes; - for( unsigned int a = 0; a < pMeshes.size(); ++a ) { - XFile::Mesh* sourceMesh = pMeshes[a]; - if ( nullptr == sourceMesh ) { + std::vector meshes; + for (unsigned int a = 0; a < pMeshes.size(); ++a) { + XFile::Mesh *sourceMesh = pMeshes[a]; + if (nullptr == sourceMesh) { continue; } // first convert its materials so that we can find them with their index afterwards - ConvertMaterials( pScene, sourceMesh->mMaterials); + ConvertMaterials(pScene, sourceMesh->mMaterials); - unsigned int numMaterials = std::max( (unsigned int)sourceMesh->mMaterials.size(), 1u); - for( unsigned int b = 0; b < numMaterials; ++b ) { + unsigned int numMaterials = std::max((unsigned int)sourceMesh->mMaterials.size(), 1u); + for (unsigned int b = 0; b < numMaterials; ++b) { // collect the faces belonging to this material std::vector faces; unsigned int numVertices = 0; - if( !sourceMesh->mFaceMaterials.empty() ) { + if (!sourceMesh->mFaceMaterials.empty()) { // if there is a per-face material defined, select the faces with the corresponding material - for( unsigned int c = 0; c < sourceMesh->mFaceMaterials.size(); ++c ) { - if( sourceMesh->mFaceMaterials[c] == b) { - faces.push_back( c); + for (unsigned int c = 0; c < sourceMesh->mFaceMaterials.size(); ++c) { + if (sourceMesh->mFaceMaterials[c] == b) { + faces.push_back(c); numVertices += (unsigned int)sourceMesh->mPosFaces[c].mIndices.size(); } } } else { // if there is no per-face material, place everything into one mesh - for( unsigned int c = 0; c < sourceMesh->mPosFaces.size(); ++c ) { - faces.push_back( c); + for (unsigned int c = 0; c < sourceMesh->mPosFaces.size(); ++c) { + faces.push_back(c); numVertices += (unsigned int)sourceMesh->mPosFaces[c].mIndices.size(); } } // no faces/vertices using this material? strange... - if ( numVertices == 0 ) { + if (numVertices == 0) { continue; } // create a submesh using this material - aiMesh* mesh = new aiMesh; - meshes.push_back( mesh); + aiMesh *mesh = new aiMesh; + meshes.push_back(mesh); // find the material in the scene's material list. Either own material // or referenced material, it should already have a valid index - if( !sourceMesh->mFaceMaterials.empty() ) { + if (!sourceMesh->mFaceMaterials.empty()) { mesh->mMaterialIndex = static_cast(sourceMesh->mMaterials[b].sceneIndex); } else { mesh->mMaterialIndex = 0; @@ -282,41 +278,41 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec mesh->mName.Set(sourceMesh->mName); // normals? - if ( sourceMesh->mNormals.size() > 0 ) { - mesh->mNormals = new aiVector3D[ numVertices ]; + if (sourceMesh->mNormals.size() > 0) { + mesh->mNormals = new aiVector3D[numVertices]; } // texture coords - for( unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++c ) { - if ( !sourceMesh->mTexCoords[ c ].empty() ) { - mesh->mTextureCoords[ c ] = new aiVector3D[ numVertices ]; + for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++c) { + if (!sourceMesh->mTexCoords[c].empty()) { + mesh->mTextureCoords[c] = new aiVector3D[numVertices]; } } // vertex colors - for( unsigned int c = 0; c < AI_MAX_NUMBER_OF_COLOR_SETS; ++c ) { - if ( !sourceMesh->mColors[ c ].empty() ) { - mesh->mColors[ c ] = new aiColor4D[ numVertices ]; + for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_COLOR_SETS; ++c) { + if (!sourceMesh->mColors[c].empty()) { + mesh->mColors[c] = new aiColor4D[numVertices]; } } // now collect the vertex data of all data streams present in the imported mesh - unsigned int newIndex( 0 ); + unsigned int newIndex(0); std::vector orgPoints; // from which original point each new vertex stems - orgPoints.resize( numVertices, 0); + orgPoints.resize(numVertices, 0); - for( unsigned int c = 0; c < faces.size(); ++c ) { + for (unsigned int c = 0; c < faces.size(); ++c) { unsigned int f = faces[c]; // index of the source face - const XFile::Face& pf = sourceMesh->mPosFaces[f]; // position source face + const XFile::Face &pf = sourceMesh->mPosFaces[f]; // position source face // create face. either triangle or triangle fan depending on the index count - aiFace& df = mesh->mFaces[c]; // destination face + aiFace &df = mesh->mFaces[c]; // destination face df.mNumIndices = (unsigned int)pf.mIndices.size(); - df.mIndices = new unsigned int[ df.mNumIndices]; + df.mIndices = new unsigned int[df.mNumIndices]; // collect vertex data for indices of this face - for( unsigned int d = 0; d < df.mNumIndices; ++d ) { - df.mIndices[ d ] = newIndex; - const unsigned int newIdx( pf.mIndices[ d ] ); - if ( newIdx > sourceMesh->mPositions.size() ) { + for (unsigned int d = 0; d < df.mNumIndices; ++d) { + df.mIndices[d] = newIndex; + const unsigned int newIdx = pf.mIndices[d]; + if (newIdx >= sourceMesh->mPositions.size()) { continue; } @@ -325,24 +321,26 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec // Position mesh->mVertices[newIndex] = sourceMesh->mPositions[pf.mIndices[d]]; // Normal, if present - if ( mesh->HasNormals() ) { - if ( sourceMesh->mNormFaces[ f ].mIndices.size() > d ) { - const size_t idx( sourceMesh->mNormFaces[ f ].mIndices[ d ] ); - mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ idx ]; + if (mesh->HasNormals()) { + if (sourceMesh->mNormFaces[f].mIndices.size() > d) { + const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]); + if (idx < sourceMesh->mNormals.size()) { + mesh->mNormals[newIndex] = sourceMesh->mNormals[idx]; + } } } // texture coord sets - for( unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e ) { - if( mesh->HasTextureCoords( e)) { + for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e) { + if (mesh->HasTextureCoords(e)) { aiVector2D tex = sourceMesh->mTexCoords[e][pf.mIndices[d]]; - mesh->mTextureCoords[e][newIndex] = aiVector3D( tex.x, 1.0f - tex.y, 0.0f); + mesh->mTextureCoords[e][newIndex] = aiVector3D(tex.x, 1.0f - tex.y, 0.0f); } } // vertex color sets - for ( unsigned int e = 0; e < AI_MAX_NUMBER_OF_COLOR_SETS; ++e ) { - if ( mesh->HasVertexColors( e ) ) { - mesh->mColors[ e ][ newIndex ] = sourceMesh->mColors[ e ][ pf.mIndices[ d ] ]; + for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_COLOR_SETS; ++e) { + if (mesh->HasVertexColors(e)) { + mesh->mColors[e][newIndex] = sourceMesh->mColors[e][pf.mIndices[d]]; } } @@ -351,63 +349,66 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec } // there should be as much new vertices as we calculated before - ai_assert( newIndex == numVertices); + ai_assert(newIndex == numVertices); // convert all bones of the source mesh which influence vertices in this newly created mesh - const std::vector& bones = sourceMesh->mBones; - std::vector newBones; - for( unsigned int c = 0; c < bones.size(); ++c ) { - const XFile::Bone& obone = bones[c]; + const std::vector &bones = sourceMesh->mBones; + std::vector newBones; + for (unsigned int c = 0; c < bones.size(); ++c) { + const XFile::Bone &obone = bones[c]; // 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 ) { - oldWeights[ obone.mWeights[ d ].mVertex ] = obone.mWeights[ d ].mWeight; + 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()) { + oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight; + } } // collect all vertex weights that influence a vertex in the new mesh std::vector newWeights; - newWeights.reserve( numVertices); - for( unsigned int d = 0; d < orgPoints.size(); ++d ) { + newWeights.reserve(numVertices); + for (unsigned int d = 0; d < orgPoints.size(); ++d) { // does the new vertex stem from an old vertex which was influenced by this bone? ai_real w = oldWeights[orgPoints[d]]; - if ( w > 0.0 ) { - newWeights.emplace_back( d, w ); + if (w > 0.0) { + newWeights.emplace_back(d, w); } } // if the bone has no weights in the newly created mesh, ignore it - if ( newWeights.empty() ) { + if (newWeights.empty()) { continue; } // create - aiBone* nbone = new aiBone; - newBones.push_back( nbone); + aiBone *nbone = new aiBone; + newBones.push_back(nbone); // copy name and matrix - nbone->mName.Set( obone.mName); + nbone->mName.Set(obone.mName); nbone->mOffsetMatrix = obone.mOffsetMatrix; nbone->mNumWeights = (unsigned int)newWeights.size(); nbone->mWeights = new aiVertexWeight[nbone->mNumWeights]; - for ( unsigned int d = 0; d < newWeights.size(); ++d ) { - nbone->mWeights[ d ] = newWeights[ d ]; + for (unsigned int d = 0; d < newWeights.size(); ++d) { + nbone->mWeights[d] = newWeights[d]; } } // store the bones in the mesh mesh->mNumBones = (unsigned int)newBones.size(); - if( !newBones.empty()) { - mesh->mBones = new aiBone*[mesh->mNumBones]; - std::copy( newBones.begin(), newBones.end(), mesh->mBones); + if (!newBones.empty()) { + mesh->mBones = new aiBone *[mesh->mNumBones]; + std::copy(newBones.begin(), newBones.end(), mesh->mBones); } } } // reallocate scene mesh array to be large enough - aiMesh** prevArray = pScene->mMeshes; - pScene->mMeshes = new aiMesh*[pScene->mNumMeshes + meshes.size()]; - if( prevArray) { - memcpy( pScene->mMeshes, prevArray, pScene->mNumMeshes * sizeof( aiMesh*)); - delete [] prevArray; + aiMesh **prevArray = pScene->mMeshes; + pScene->mMeshes = new aiMesh *[pScene->mNumMeshes + meshes.size()]; + if (prevArray) { + memcpy(pScene->mMeshes, prevArray, pScene->mNumMeshes * sizeof(aiMesh *)); + delete[] prevArray; } // allocate mesh index array in the node @@ -415,7 +416,7 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec pNode->mMeshes = new unsigned int[pNode->mNumMeshes]; // store all meshes in the mesh library of the scene and store their indices in the node - for( unsigned int a = 0; a < meshes.size(); a++) { + for (unsigned int a = 0; a < meshes.size(); a++) { pScene->mMeshes[pScene->mNumMeshes] = meshes[a]; pNode->mMeshes[a] = pScene->mNumMeshes; pScene->mNumMeshes++; @@ -424,35 +425,34 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec // ------------------------------------------------------------------------------------------------ // Converts the animations from the given imported data and creates them in the scene. -void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData) { - std::vector newAnims; +void XFileImporter::CreateAnimations(aiScene *pScene, const XFile::Scene *pData) { + std::vector newAnims; - for( unsigned int a = 0; a < pData->mAnims.size(); ++a ) { - const XFile::Animation* anim = pData->mAnims[a]; + for (unsigned int a = 0; a < pData->mAnims.size(); ++a) { + const XFile::Animation *anim = pData->mAnims[a]; // some exporters mock me with empty animation tags. - if ( anim->mAnims.empty() ) { + if (anim->mAnims.empty()) { continue; } // create a new animation to hold the data - aiAnimation* nanim = new aiAnimation; - newAnims.push_back( nanim); - nanim->mName.Set( anim->mName); + aiAnimation *nanim = new aiAnimation; + newAnims.push_back(nanim); + nanim->mName.Set(anim->mName); // duration will be determined by the maximum length nanim->mDuration = 0; nanim->mTicksPerSecond = pData->mAnimTicksPerSecond; nanim->mNumChannels = (unsigned int)anim->mAnims.size(); - nanim->mChannels = new aiNodeAnim*[nanim->mNumChannels]; + nanim->mChannels = new aiNodeAnim *[nanim->mNumChannels]; - for( unsigned int b = 0; b < anim->mAnims.size(); ++b ) { - const XFile::AnimBone* bone = anim->mAnims[b]; - aiNodeAnim* nbone = new aiNodeAnim; - nbone->mNodeName.Set( bone->mBoneName); + for (unsigned int b = 0; b < anim->mAnims.size(); ++b) { + const XFile::AnimBone *bone = anim->mAnims[b]; + aiNodeAnim *nbone = new aiNodeAnim; + nbone->mNodeName.Set(bone->mBoneName); nanim->mChannels[b] = nbone; // key-frames are given as combined transformation matrix keys - if( !bone->mTrafoKeys.empty() ) - { + if (!bone->mTrafoKeys.empty()) { nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size(); nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; nbone->mNumRotationKeys = (unsigned int)bone->mTrafoKeys.size(); @@ -460,44 +460,44 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mNumScalingKeys = (unsigned int)bone->mTrafoKeys.size(); nbone->mScalingKeys = new aiVectorKey[nbone->mNumScalingKeys]; - for( unsigned int c = 0; c < bone->mTrafoKeys.size(); ++c) { + for (unsigned int c = 0; c < bone->mTrafoKeys.size(); ++c) { // deconstruct each matrix into separate position, rotation and scaling double time = bone->mTrafoKeys[c].mTime; aiMatrix4x4 trafo = bone->mTrafoKeys[c].mMatrix; // extract position - aiVector3D pos( trafo.a4, trafo.b4, trafo.c4); + aiVector3D pos(trafo.a4, trafo.b4, trafo.c4); nbone->mPositionKeys[c].mTime = time; nbone->mPositionKeys[c].mValue = pos; // extract scaling aiVector3D scale; - scale.x = aiVector3D( trafo.a1, trafo.b1, trafo.c1).Length(); - scale.y = aiVector3D( trafo.a2, trafo.b2, trafo.c2).Length(); - scale.z = aiVector3D( trafo.a3, trafo.b3, trafo.c3).Length(); + scale.x = aiVector3D(trafo.a1, trafo.b1, trafo.c1).Length(); + scale.y = aiVector3D(trafo.a2, trafo.b2, trafo.c2).Length(); + scale.z = aiVector3D(trafo.a3, trafo.b3, trafo.c3).Length(); nbone->mScalingKeys[c].mTime = time; nbone->mScalingKeys[c].mValue = scale; // reconstruct rotation matrix without scaling aiMatrix3x3 rotmat( - trafo.a1 / scale.x, trafo.a2 / scale.y, trafo.a3 / scale.z, - trafo.b1 / scale.x, trafo.b2 / scale.y, trafo.b3 / scale.z, - trafo.c1 / scale.x, trafo.c2 / scale.y, trafo.c3 / scale.z); + trafo.a1 / scale.x, trafo.a2 / scale.y, trafo.a3 / scale.z, + trafo.b1 / scale.x, trafo.b2 / scale.y, trafo.b3 / scale.z, + trafo.c1 / scale.x, trafo.c2 / scale.y, trafo.c3 / scale.z); // and convert it into a quaternion nbone->mRotationKeys[c].mTime = time; - nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); + nbone->mRotationKeys[c].mValue = aiQuaternion(rotmat); } // longest lasting key sequence determines duration - nanim->mDuration = std::max( nanim->mDuration, bone->mTrafoKeys.back().mTime); + nanim->mDuration = std::max(nanim->mDuration, bone->mTrafoKeys.back().mTime); } else { // separate key sequences for position, rotation, scaling nbone->mNumPositionKeys = (unsigned int)bone->mPosKeys.size(); if (nbone->mNumPositionKeys != 0) { nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; - for( unsigned int c = 0; c < nbone->mNumPositionKeys; ++c ) { + for (unsigned int c = 0; c < nbone->mNumPositionKeys; ++c) { aiVector3D pos = bone->mPosKeys[c].mValue; nbone->mPositionKeys[c].mTime = bone->mPosKeys[c].mTime; @@ -509,11 +509,11 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mNumRotationKeys = (unsigned int)bone->mRotKeys.size(); if (nbone->mNumRotationKeys != 0) { nbone->mRotationKeys = new aiQuatKey[nbone->mNumRotationKeys]; - for( unsigned int c = 0; c < nbone->mNumRotationKeys; ++c ) { + for (unsigned int c = 0; c < nbone->mNumRotationKeys; ++c) { aiMatrix3x3 rotmat = bone->mRotKeys[c].mValue.GetMatrix(); nbone->mRotationKeys[c].mTime = bone->mRotKeys[c].mTime; - nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); + nbone->mRotationKeys[c].mValue = aiQuaternion(rotmat); nbone->mRotationKeys[c].mValue.w *= -1.0f; // needs quat inversion } } @@ -522,153 +522,149 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mNumScalingKeys = (unsigned int)bone->mScaleKeys.size(); if (nbone->mNumScalingKeys != 0) { nbone->mScalingKeys = new aiVectorKey[nbone->mNumScalingKeys]; - for( unsigned int c = 0; c < nbone->mNumScalingKeys; c++) + for (unsigned int c = 0; c < nbone->mNumScalingKeys; c++) nbone->mScalingKeys[c] = bone->mScaleKeys[c]; } // longest lasting key sequence determines duration - if( bone->mPosKeys.size() > 0) - nanim->mDuration = std::max( nanim->mDuration, bone->mPosKeys.back().mTime); - if( bone->mRotKeys.size() > 0) - nanim->mDuration = std::max( nanim->mDuration, bone->mRotKeys.back().mTime); - if( bone->mScaleKeys.size() > 0) - nanim->mDuration = std::max( nanim->mDuration, bone->mScaleKeys.back().mTime); + if (bone->mPosKeys.size() > 0) + nanim->mDuration = std::max(nanim->mDuration, bone->mPosKeys.back().mTime); + if (bone->mRotKeys.size() > 0) + nanim->mDuration = std::max(nanim->mDuration, bone->mRotKeys.back().mTime); + if (bone->mScaleKeys.size() > 0) + nanim->mDuration = std::max(nanim->mDuration, bone->mScaleKeys.back().mTime); } } } // store all converted animations in the scene - if( newAnims.size() > 0) - { + if (newAnims.size() > 0) { pScene->mNumAnimations = (unsigned int)newAnims.size(); - pScene->mAnimations = new aiAnimation* [pScene->mNumAnimations]; - for( unsigned int a = 0; a < newAnims.size(); a++) + pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations]; + for (unsigned int a = 0; a < newAnims.size(); a++) pScene->mAnimations[a] = newAnims[a]; } } // ------------------------------------------------------------------------------------------------ // Converts all materials in the given array and stores them in the scene's material list. -void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector& pMaterials) -{ +void XFileImporter::ConvertMaterials(aiScene *pScene, std::vector &pMaterials) { // count the non-referrer materials in the array - unsigned int numNewMaterials( 0 ); - for ( unsigned int a = 0; a < pMaterials.size(); ++a ) { - if ( !pMaterials[ a ].mIsReference ) { + unsigned int numNewMaterials(0); + for (unsigned int a = 0; a < pMaterials.size(); ++a) { + if (!pMaterials[a].mIsReference) { ++numNewMaterials; } } // resize the scene's material list to offer enough space for the new materials - if( numNewMaterials > 0 ) { - aiMaterial** prevMats = pScene->mMaterials; - pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials + numNewMaterials]; - if( nullptr != prevMats) { - ::memcpy( pScene->mMaterials, prevMats, pScene->mNumMaterials * sizeof( aiMaterial*)); - delete [] prevMats; + if (numNewMaterials > 0) { + aiMaterial **prevMats = pScene->mMaterials; + pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials + numNewMaterials]; + if (nullptr != prevMats) { + ::memcpy(pScene->mMaterials, prevMats, pScene->mNumMaterials * sizeof(aiMaterial *)); + delete[] prevMats; } } // convert all the materials given in the array - for( unsigned int a = 0; a < pMaterials.size(); ++a ) { - XFile::Material& oldMat = pMaterials[a]; - if( oldMat.mIsReference) { + for (unsigned int a = 0; a < pMaterials.size(); ++a) { + XFile::Material &oldMat = pMaterials[a]; + if (oldMat.mIsReference) { // find the material it refers to by name, and store its index - for( size_t b = 0; b < pScene->mNumMaterials; ++b ) { + for (size_t b = 0; b < pScene->mNumMaterials; ++b) { aiString name; - pScene->mMaterials[b]->Get( AI_MATKEY_NAME, name); - if( strcmp( name.C_Str(), oldMat.mName.data()) == 0 ) { + pScene->mMaterials[b]->Get(AI_MATKEY_NAME, name); + if (strcmp(name.C_Str(), oldMat.mName.data()) == 0) { oldMat.sceneIndex = b; break; } } - if( oldMat.sceneIndex == SIZE_MAX ) { - ASSIMP_LOG_WARN( "Could not resolve global material reference \"", oldMat.mName, "\"" ); + if (oldMat.sceneIndex == SIZE_MAX) { + ASSIMP_LOG_WARN("Could not resolve global material reference \"", oldMat.mName, "\""); oldMat.sceneIndex = 0; } continue; } - aiMaterial* mat = new aiMaterial; + aiMaterial *mat = new aiMaterial; aiString name; - name.Set( oldMat.mName); - mat->AddProperty( &name, AI_MATKEY_NAME); + name.Set(oldMat.mName); + mat->AddProperty(&name, AI_MATKEY_NAME); // Shading model: hard-coded to PHONG, there is no such information in an XFile // FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix // for some models in the SDK (e.g. good old tiny.x) - int shadeMode = (int)oldMat.mSpecularExponent == 0.0f - ? aiShadingMode_Gouraud : aiShadingMode_Phong; + int shadeMode = (int)oldMat.mSpecularExponent == 0.0f ? aiShadingMode_Gouraud : aiShadingMode_Phong; - mat->AddProperty( &shadeMode, 1, AI_MATKEY_SHADING_MODEL); + mat->AddProperty(&shadeMode, 1, AI_MATKEY_SHADING_MODEL); // material colours // Unclear: there's no ambient colour, but emissive. What to put for ambient? // Probably nothing at all, let the user select a suitable default. - mat->AddProperty( &oldMat.mEmissive, 1, AI_MATKEY_COLOR_EMISSIVE); - mat->AddProperty( &oldMat.mDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE); - mat->AddProperty( &oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR); - mat->AddProperty( &oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS); - + mat->AddProperty(&oldMat.mEmissive, 1, AI_MATKEY_COLOR_EMISSIVE); + mat->AddProperty(&oldMat.mDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE); + mat->AddProperty(&oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR); + mat->AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS); // texture, if there is one - if (1 == oldMat.mTextures.size() ) { - const XFile::TexEntry& otex = oldMat.mTextures.back(); + if (1 == oldMat.mTextures.size()) { + const XFile::TexEntry &otex = oldMat.mTextures.back(); if (otex.mName.length()) { // if there is only one texture assume it contains the diffuse color - aiString tex( otex.mName); - if ( otex.mIsNormalMap ) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_NORMALS( 0 ) ); + aiString tex(otex.mName); + if (otex.mIsNormalMap) { + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_NORMALS(0)); } else { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_DIFFUSE(0)); } } } else { // Otherwise ... try to search for typical strings in the // texture's file name like 'bump' or 'diffuse' - unsigned int iHM = 0,iNM = 0,iDM = 0,iSM = 0,iAM = 0,iEM = 0; - for( unsigned int b = 0; b < oldMat.mTextures.size(); ++b ) { - const XFile::TexEntry& otex = oldMat.mTextures[b]; + unsigned int iHM = 0, iNM = 0, iDM = 0, iSM = 0, iAM = 0, iEM = 0; + for (unsigned int b = 0; b < oldMat.mTextures.size(); ++b) { + const XFile::TexEntry &otex = oldMat.mTextures[b]; std::string sz = otex.mName; - if ( !sz.length() ) { + if (!sz.length()) { continue; } // find the file name std::string::size_type s = sz.find_last_of("\\/"); - if ( std::string::npos == s ) { + if (std::string::npos == s) { s = 0; } // cut off the file extension std::string::size_type sExt = sz.find_last_of('.'); - if (std::string::npos != sExt){ + if (std::string::npos != sExt) { sz[sExt] = '\0'; } // convert to lower case for easier comparison - for ( unsigned int c = 0; c < sz.length(); ++c ) { - sz[ c ] = (char) tolower( (unsigned char) sz[ c ] ); + for (unsigned int c = 0; c < sz.length(); ++c) { + sz[c] = (char)tolower((unsigned char)sz[c]); } // Place texture filename property under the corresponding name - aiString tex( oldMat.mTextures[b].mName); + aiString tex(oldMat.mTextures[b].mName); // bump map if (std::string::npos != sz.find("bump", s) || std::string::npos != sz.find("height", s)) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_HEIGHT(iHM++)); - } else if (otex.mIsNormalMap || std::string::npos != sz.find( "normal", s) || std::string::npos != sz.find("nm", s)) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_NORMALS(iNM++)); - } else if (std::string::npos != sz.find( "spec", s) || std::string::npos != sz.find( "glanz", s)) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_SPECULAR(iSM++)); - } else if (std::string::npos != sz.find( "ambi", s) || std::string::npos != sz.find( "env", s)) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_AMBIENT(iAM++)); - } else if (std::string::npos != sz.find( "emissive", s) || std::string::npos != sz.find( "self", s)) { - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_EMISSIVE(iEM++)); + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_HEIGHT(iHM++)); + } else if (otex.mIsNormalMap || std::string::npos != sz.find("normal", s) || std::string::npos != sz.find("nm", s)) { + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_NORMALS(iNM++)); + } else if (std::string::npos != sz.find("spec", s) || std::string::npos != sz.find("glanz", s)) { + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_SPECULAR(iSM++)); + } else if (std::string::npos != sz.find("ambi", s) || std::string::npos != sz.find("env", s)) { + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_AMBIENT(iAM++)); + } else if (std::string::npos != sz.find("emissive", s) || std::string::npos != sz.find("self", s)) { + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_EMISSIVE(iEM++)); } else { // Assume it is a diffuse texture - mat->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE(iDM++)); + mat->AddProperty(&tex, AI_MATKEY_TEXTURE_DIFFUSE(iDM++)); } } } @@ -679,4 +675,6 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, 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_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 04e303370..9efd5d628 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-2022, assimp team +Copyright (c) 2006-2023, assimp team All rights reserved. @@ -56,64 +56,46 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -//#include -//#include -using namespace Assimp; +namespace Assimp { -namespace Assimp { // this has to be in here because LogFunctions is in ::Assimp +static constexpr uint32_t ErrorId = ~0u; template <> const char *LogFunctions::Prefix() { return "XGL: "; } -} // namespace Assimp - -static const aiImporterDesc desc = { - "XGL Importer", - "", - "", - "", - aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportCompressedFlavour, - 0, - 0, - 0, - 0, - "xgl zgl" -}; +static constexpr aiImporterDesc desc = { + "XGL Importer", "", "", "", + aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportCompressedFlavour, + 0, 0, 0, 0, "xgl zgl"}; // ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -XGLImporter::XGLImporter() : - mXmlParser(nullptr), - m_scene(nullptr) { +XGLImporter::XGLImporter() : mXmlParser(nullptr), m_scene(nullptr) { // empty } // ------------------------------------------------------------------------------------------------ -// Destructor, private as well XGLImporter::~XGLImporter() { - delete mXmlParser; + clear(); } // ------------------------------------------------------------------------------------------------ -// Returns whether the class can handle the format of the given file. bool XGLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { static const char *tokens[] = { "", "", "" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens)); } // ------------------------------------------------------------------------------------------------ -// Get a list of all file extensions which are handled by this class const aiImporterDesc *XGLImporter::GetInfo() const { return &desc; } // ------------------------------------------------------------------------------------------------ -// Imports the given file into the given scene structure. void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - #ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL + clear(); +#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL std::vector uncompressed; #endif @@ -159,7 +141,7 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy std::vector &meshes = scope.meshes_linear; std::vector &materials = scope.materials_linear; - if (!meshes.size() || !materials.size()) { + if (meshes.empty() || materials.empty()) { ThrowException("failed to extract data from XGL file, no meshes loaded"); } @@ -184,6 +166,13 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy scope.dismiss(); } +// ------------------------------------------------------------------------------------------------ +void XGLImporter::clear() { + delete mXmlParser; + mXmlParser = nullptr; +} + + // ------------------------------------------------------------------------------------------------ void XGLImporter::ReadWorld(XmlNode &node, TempScope &scope) { for (XmlNode ¤tNode : node.children()) { @@ -199,9 +188,10 @@ void XGLImporter::ReadWorld(XmlNode &node, TempScope &scope) { } aiNode *const nd = ReadObject(node, scope); - if (!nd) { + if (nd == nullptr) { ThrowException("failure reading "); } + if (nd->mName.length == 0) { nd->mName.Set("WORLD"); } @@ -254,15 +244,17 @@ aiNode *XGLImporter::ReadObject(XmlNode &node, TempScope &scope) { const std::string &s = ai_stdStrToLower(child.name()); if (s == "mesh") { const size_t prev = scope.meshes_linear.size(); - bool empty; - if (ReadMesh(child, scope, empty)) { + if (ReadMesh(child, scope)) { const size_t newc = scope.meshes_linear.size(); for (size_t i = 0; i < newc - prev; ++i) { meshes.push_back(static_cast(i + prev)); } - } + } } else if (s == "mat") { - ReadMaterial(child, scope); + const uint32_t matId = ReadMaterial(child, scope); + if (matId == ErrorId) { + ThrowException("Invalid material id detected."); + } } else if (s == "object") { children.push_back(ReadObject(child, scope)); } else if (s == "objectref") { @@ -438,18 +430,25 @@ aiMesh *XGLImporter::ToOutputMesh(const TempMaterialMesh &m) { return mesh.release(); } -// ------------------------------------------------------------------------------------------------ -bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope, bool &empty) { - TempMesh t; +// ------------------------------------------------------------------------------------------------ +inline static unsigned int generateMeshId(unsigned int meshId, bool nor, bool uv) { + unsigned int currentMeshId = meshId | ((nor ? 1 : 0) << 31) | ((uv ? 1 : 0) << 30); + return currentMeshId; +} + +// ------------------------------------------------------------------------------------------------ +bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) { + TempMesh t; + uint32_t matId = 99999; + bool mesh_created = false; std::map bymat; const unsigned int mesh_id = ReadIDAttr(node); - bool empty_mesh = true; for (XmlNode &child : node.children()) { const std::string &s = ai_stdStrToLower(child.name()); if (s == "mat") { - ReadMaterial(child, scope); + matId = ReadMaterial(child, scope); } else if (s == "p") { pugi::xml_attribute attr = child.attribute("ID"); if (attr.empty()) { @@ -477,66 +476,41 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope, bool &empty) { } else if (s == "f" || s == "l" || s == "p") { const unsigned int vcount = s == "f" ? 3 : (s == "l" ? 2 : 1); - unsigned int mid = ~0u; - TempFace tf[3]; + unsigned int meshId = ErrorId; + TempFace tempFace[3] = {}; bool has[3] = { false }; - for (XmlNode &sub_child : child.children()) { - const std::string &scn = ai_stdStrToLower(sub_child.name()); - if (scn == "fv1" || scn == "lv1" || scn == "pv1") { - ReadFaceVertex(sub_child, t, tf[0]); - has[0] = true; - } else if (scn == "fv2" || scn == "lv2") { - ReadFaceVertex(sub_child, t, tf[1]); - has[1] = true; - } else if (scn == "fv3") { - ReadFaceVertex(sub_child, t, tf[2]); - has[2] = true; - } else if (scn == "mat") { - if (mid != ~0u) { - LogWarn("only one material tag allowed per "); - } - mid = ResolveMaterialRef(sub_child, scope); - } else if (scn == "matref") { - if (mid != ~0u) { - LogWarn("only one material tag allowed per "); - } - mid = ResolveMaterialRef(sub_child, scope); - } - } - if (has[0] || has[1] || has[2]) { - empty_mesh = false; - } - - if (mid == ~0u) { + meshId = ReadVertices(child, t, tempFace, has, meshId, scope); + if (meshId == ErrorId) { ThrowException("missing material index"); } - bool nor = false; - bool uv = false; + bool nor = false, uv = false; for (unsigned int i = 0; i < vcount; ++i) { if (!has[i]) { ThrowException("missing face vertex data"); } - nor = nor || tf[i].has_normal; - uv = uv || tf[i].has_uv; + nor = nor || tempFace[i].has_normal; + uv = uv || tempFace[i].has_uv; } - if (mid >= (1 << 30)) { + if (meshId >= (1 << 30)) { LogWarn("material indices exhausted, this may cause errors in the output"); } - unsigned int meshId = mid | ((nor ? 1 : 0) << 31) | ((uv ? 1 : 0) << 30); + const unsigned int currentMeshId = generateMeshId(meshId, nor, uv); - TempMaterialMesh &mesh = bymat[meshId]; - mesh.matid = mid; + // Generate the temp mesh + TempMaterialMesh &mesh = bymat[currentMeshId]; + mesh.matid = meshId; + mesh_created = true; for (unsigned int i = 0; i < vcount; ++i) { - mesh.positions.push_back(tf[i].pos); + mesh.positions.push_back(tempFace[i].pos); if (nor) { - mesh.normals.push_back(tf[i].normal); + mesh.normals.push_back(tempFace[i].normal); } if (uv) { - mesh.uvs.push_back(tf[i].uv); + mesh.uvs.push_back(tempFace[i].uv); } mesh.pflags |= 1 << (vcount - 1); @@ -546,25 +520,59 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope, bool &empty) { } } - // finally extract output meshes and add them to the scope - using pairt = std::pair; - for (const pairt &p : bymat) { - aiMesh *const m = ToOutputMesh(p.second); - scope.meshes_linear.push_back(m); - - // if this is a definition, keep it on the stack - if (mesh_id != ~0u) { - scope.meshes.insert(std::pair(mesh_id, m)); - } - } - if (empty_mesh) { - LogWarn("Mesh is empty, skipping."); - empty = empty_mesh; - return false; + if (!mesh_created) { + TempMaterialMesh &mesh = bymat[mesh_id]; + mesh.matid = matId; } + // finally extract output meshes and add them to the scope + AppendOutputMeshes(bymat, scope, mesh_id); + // no id == not a reference, insert this mesh right *here* - return mesh_id == ~0u; + return mesh_id == ErrorId; +} + +// ---------------------------------------------------------------------------------------------- +void XGLImporter::AppendOutputMeshes(std::map bymat, TempScope &scope, + const unsigned int mesh_id) { + using pairt = std::pair; + for (const pairt &p : bymat) { + aiMesh *const m = ToOutputMesh(p.second); + scope.meshes_linear.push_back(m); + + // if this is a definition, keep it on the stack + if (mesh_id != ErrorId) { + scope.meshes.insert(std::pair(mesh_id, m)); + } + } +} + +// ---------------------------------------------------------------------------------------------- +unsigned int XGLImporter::ReadVertices(XmlNode &child, TempMesh t, TempFace *tf, bool *has, unsigned int mid, TempScope &scope) { + for (XmlNode &sub_child : child.children()) { + const std::string &scn = ai_stdStrToLower(sub_child.name()); + if (scn == "fv1" || scn == "lv1" || scn == "pv1") { + ReadFaceVertex(sub_child, t, tf[0]); + has[0] = true; + } else if (scn == "fv2" || scn == "lv2") { + ReadFaceVertex(sub_child, t, tf[1]); + has[1] = true; + } else if (scn == "fv3") { + ReadFaceVertex(sub_child, t, tf[2]); + has[2] = true; + } else if (scn == "mat") { + if (mid != ErrorId) { + LogWarn("only one material tag allowed per "); + } + mid = ResolveMaterialRef(sub_child, scope); + } else if (scn == "matref") { + if (mid != ErrorId) { + LogWarn("only one material tag allowed per "); + } + mid = ResolveMaterialRef(sub_child, scope); + } + } + return mid; } // ---------------------------------------------------------------------------------------------- @@ -598,10 +606,10 @@ unsigned int XGLImporter::ResolveMaterialRef(XmlNode &node, TempScope &scope) { } // ------------------------------------------------------------------------------------------------ -void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) { +unsigned int XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) { const unsigned int mat_id = ReadIDAttr(node); - auto *mat(new aiMaterial); + auto *mat = new aiMaterial; for (XmlNode &child : node.children()) { const std::string &s = ai_stdStrToLower(child.name()); if (s == "amb") { @@ -627,6 +635,8 @@ void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) { scope.materials[mat_id] = mat; scope.materials_linear.push_back(mat); + + return mat_id; } // ---------------------------------------------------------------------------------------------- @@ -683,7 +693,7 @@ unsigned int XGLImporter::ReadIDAttr(XmlNode &node) { } } - return ~0u; + return ErrorId; } // ------------------------------------------------------------------------------------------------ @@ -712,14 +722,14 @@ unsigned int XGLImporter::ReadIndexFromText(XmlNode &node) { const char *s = v.c_str(); if (!SkipSpaces(&s)) { LogError("unexpected EOL, failed to parse index element"); - return ~0u; + return ErrorId; } - const char *se; + const char *se = nullptr; const unsigned int t = strtoul10(s, &se); if (se == s) { LogError("failed to read index"); - return ~0u; + return ErrorId; } return t; @@ -786,4 +796,6 @@ aiColor3D XGLImporter::ReadCol3(XmlNode &node) { return aiColor3D(v.x, v.y, v.z); } +} // namespace Assimp + #endif // ASSIMP_BUILD_NO_XGL_IMPORTER diff --git a/code/AssetLib/XGL/XGLLoader.h b/code/AssetLib/XGL/XGLLoader.h index ae7ccddc2..f620561d1 100644 --- a/code/AssetLib/XGL/XGLLoader.h +++ b/code/AssetLib/XGL/XGLLoader.h @@ -69,16 +69,20 @@ namespace Assimp { */ class XGLImporter : public BaseImporter, public LogFunctions { public: + /// @brief The class constructor. XGLImporter(); + + /// @brief The class destructor. ~XGLImporter() override; - // ------------------------------------------------------------------- - /** Returns whether the class can handle the format of the given file. - * See BaseImporter::CanRead() for details. */ + /// @brief Returns whether the class can handle the format of the given file. + /// @see BaseImporter::CanRead() for details. */ bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override; protected: + void clear(); + // ------------------------------------------------------------------- /** Return importer meta information. * See #BaseImporter::GetInfo for the details */ @@ -92,10 +96,7 @@ protected: private: struct TempScope { - TempScope() : - light() { - // empty - } + TempScope() : light() {} ~TempScope() { for (aiMesh *m : meshes_linear) { @@ -145,9 +146,7 @@ private: }; struct TempMaterialMesh { - TempMaterialMesh() : - pflags(), - matid() { + TempMaterialMesh() : pflags(), matid() { // empty } @@ -160,9 +159,7 @@ private: }; struct TempFace { - TempFace() : - has_uv(), - has_normal() { + TempFace() : has_uv(), has_normal() { // empty } @@ -175,26 +172,25 @@ private: private: void Cleanup(); - std::string GetElementName(); bool ReadElement(); bool ReadElementUpToClosing(const char *closetag); bool SkipToText(); unsigned int ReadIDAttr(XmlNode &node); - void ReadWorld(XmlNode &node, TempScope &scope); void ReadLighting(XmlNode &node, TempScope &scope); aiLight *ReadDirectionalLight(XmlNode &node); aiNode *ReadObject(XmlNode &node, TempScope &scope); - bool ReadMesh(XmlNode &node, TempScope &scope, bool &empty); - void ReadMaterial(XmlNode &node, TempScope &scope); + bool ReadMesh(XmlNode &node, TempScope &scope); + void AppendOutputMeshes(std::map bymat, TempScope &scope, const unsigned int mesh_id); + unsigned int ReadVertices(XmlNode &child, TempMesh t, TempFace *tf, bool *has, unsigned int mid, TempScope &scope); + unsigned int ReadMaterial(XmlNode &node, TempScope &scope); aiVector2D ReadVec2(XmlNode &node); aiVector3D ReadVec3(XmlNode &node); aiColor3D ReadCol3(XmlNode &node); aiMatrix4x4 ReadTrafo(XmlNode &node); unsigned int ReadIndexFromText(XmlNode &node); float ReadFloat(XmlNode &node); - aiMesh *ToOutputMesh(const TempMaterialMesh &m); void ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out); unsigned int ResolveMaterialRef(XmlNode &node, TempScope &scope); diff --git a/code/AssetLib/glTF/glTFImporter.cpp b/code/AssetLib/glTF/glTFImporter.cpp index 110a2a52f..cd8b7762d 100644 --- a/code/AssetLib/glTF/glTFImporter.cpp +++ b/code/AssetLib/glTF/glTFImporter.cpp @@ -62,11 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; using namespace glTF; -// -// glTFImporter -// - -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "glTF Importer", "", "", diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 3ae40f07e..8d500b156 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -720,7 +720,7 @@ const vec4 defaultBaseColor = { 1, 1, 1, 1 }; const vec3 defaultEmissiveFactor = { 0, 0, 0 }; const vec4 defaultDiffuseFactor = { 1, 1, 1, 1 }; const vec3 defaultSpecularFactor = { 1, 1, 1 }; -const vec3 defaultSpecularColorFactor = { 0, 0, 0 }; +const vec3 defaultSpecularColorFactor = { 1, 1, 1 }; const vec3 defaultSheenFactor = { 0, 0, 0 }; const vec3 defaultAttenuationColor = { 1, 1, 1 }; diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 53ffdaf31..61964d1b4 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -1392,7 +1392,7 @@ inline void PbrSpecularGlossiness::SetDefaults() { inline void MaterialSpecular::SetDefaults() { //KHR_materials_specular properties SetVector(specularColorFactor, defaultSpecularColorFactor); - specularFactor = 0.f; + specularFactor = 1.f; } inline void MaterialSheen::SetDefaults() { @@ -1552,6 +1552,22 @@ inline void Mesh::Read(Value &pJSON_Object, Asset &pAsset_Root) { } } } + + if(this->targetNames.empty()) + { + Value *curExtras = FindObject(primitive, "extras"); + if (nullptr != curExtras) { + if (Value *curTargetNames = FindArray(*curExtras, "targetNames")) { + this->targetNames.resize(curTargetNames->Size()); + for (unsigned int j = 0; j < curTargetNames->Size(); ++j) { + Value &targetNameValue = (*curTargetNames)[j]; + if (targetNameValue.IsString()) { + this->targetNames[j] = targetNameValue.GetString(); + } + } + } + } + } } } diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 30f2580a2..bfd9135d3 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -426,13 +426,14 @@ namespace glTF2 { if (specular.specularFactor != 0.0f) { WriteFloat(materialSpecular, specular.specularFactor, "specularFactor", w.mAl); - WriteTex(materialSpecular, specular.specularTexture, "specularTexture", w.mAl); } if (specular.specularColorFactor[0] != defaultSpecularColorFactor[0] && specular.specularColorFactor[1] != defaultSpecularColorFactor[1] && specular.specularColorFactor[2] != defaultSpecularColorFactor[2]) { WriteVec(materialSpecular, specular.specularColorFactor, "specularColorFactor", w.mAl); - WriteTex(materialSpecular, specular.specularColorTexture, "specularColorTexture", w.mAl); } + WriteTex(materialSpecular, specular.specularTexture, "specularTexture", w.mAl); + WriteTex(materialSpecular, specular.specularColorTexture, "specularColorTexture", w.mAl); + if (!materialSpecular.ObjectEmpty()) { exts.AddMember("KHR_materials_specular", materialSpecular, w.mAl); } diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 614ce763c..17d162466 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -559,7 +559,11 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, Ref &texture, unsi aiString tex; // Read texcoord (UV map index) - mat.Get(AI_MATKEY_UVWSRC(tt, slot), texCoord); + // Note: must be an int to be successful. + int tmp = 0; + const auto ok = mat.Get(AI_MATKEY_UVWSRC(tt, slot), tmp); + if (ok == aiReturn_SUCCESS) texCoord = tmp; + if (mat.Get(AI_MATKEY_TEXTURE(tt, slot), tex) == AI_SUCCESS) { std::string path = tex.C_Str(); @@ -726,8 +730,8 @@ bool glTF2Exporter::GetMatSpecular(const aiMaterial &mat, glTF2::MaterialSpecula } else if (colorFactorIsZero) { specular.specularColorFactor[0] = specular.specularColorFactor[1] = specular.specularColorFactor[2] = 1.0f; } - GetMatTex(mat, specular.specularColorTexture, aiTextureType_SPECULAR); - GetMatTex(mat, specular.specularTexture, aiTextureType_SPECULAR); + GetMatTex(mat, specular.specularTexture, aiTextureType_SPECULAR, 0); + GetMatTex(mat, specular.specularColorTexture, aiTextureType_SPECULAR, 1); return true; } @@ -908,6 +912,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; diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 0fed11cef..e89baaf0d 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -82,7 +82,7 @@ struct Tangent { // glTF2Importer // -static const aiImporterDesc desc = { +static constexpr aiImporterDesc desc = { "glTF2 Importer", "", "", @@ -288,8 +288,8 @@ static aiMaterial *ImportMaterial(std::vector &embeddedTexIdxs, Asset &r, M if (std::memcmp(specular.specularColorFactor, defaultSpecularColorFactor, sizeof(glTFCommon::vec3)) != 0 || specular.specularFactor != 0.0f) { SetMaterialColorProperty(r, specular.specularColorFactor, aimat, AI_MATKEY_COLOR_SPECULAR); aimat->AddProperty(&specular.specularFactor, 1, AI_MATKEY_SPECULAR_FACTOR); - SetMaterialTextureProperty(embeddedTexIdxs, r, specular.specularTexture, aimat, aiTextureType_SPECULAR); - SetMaterialTextureProperty(embeddedTexIdxs, r, specular.specularColorTexture, aimat, aiTextureType_SPECULAR); + SetMaterialTextureProperty(embeddedTexIdxs, r, specular.specularTexture, aimat, aiTextureType_SPECULAR, 0); + SetMaterialTextureProperty(embeddedTexIdxs, r, specular.specularColorTexture, aimat, aiTextureType_SPECULAR, 1); } } // pbrSpecularGlossiness diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 0fe2291f8..9b0b964c0 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -923,7 +923,7 @@ IF(ASSIMP_HUNTER_ENABLED) hunter_add_package(utf8) find_package(utf8cpp CONFIG REQUIRED) ELSE() - # utf8 is header-only, so Assimp doesn't need to do anything. + INCLUDE_DIRECTORIES("../contrib/utf8cpp/source") ENDIF() # polyclipping @@ -1380,7 +1380,12 @@ ENDIF() IF(NOT ASSIMP_HUNTER_ENABLED) if (UNZIP_FOUND) INCLUDE_DIRECTORIES(${UNZIP_INCLUDE_DIRS}) - TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES}) + # TODO if cmake required version has been updated to >3.12.0, collapse this to the second case only + if(${CMAKE_VERSION} VERSION_LESS "3.12.0") + TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES}) + else() + TARGET_LINK_LIBRARIES(assimp ${UNZIP_LINK_LIBRARIES}) + endif() else () INCLUDE_DIRECTORIES("../") endif () diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index a169c8a10..9ef69a8e6 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -357,11 +357,7 @@ std::string BaseImporter::GetExtension(const std::string &pFile) { return false; } -#ifdef ASSIMP_USE_HUNTER -#include -#else -#include "../contrib/utf8cpp/source/utf8.h" -#endif +#include "utf8.h" // ------------------------------------------------------------------------------------------------ // Convert to UTF8 data diff --git a/code/Common/Compression.cpp b/code/Common/Compression.cpp index 3bf306dee..a6a7be7e4 100644 --- a/code/Common/Compression.cpp +++ b/code/Common/Compression.cpp @@ -66,6 +66,10 @@ Compression::Compression() : Compression::~Compression() { ai_assert(mImpl != nullptr); + if (mImpl->mOpen) { + close(); + } + delete mImpl; } @@ -124,7 +128,7 @@ static int getFlushMode(Compression::FlushMode flush) { return z_flush; } -constexpr size_t MYBLOCK = 32786; +static constexpr size_t MYBLOCK = 32786; size_t Compression::decompress(const void *data, size_t in, std::vector &uncompressed) { ai_assert(mImpl != nullptr); diff --git a/code/Common/Compression.h b/code/Common/Compression.h index 13a79af3f..cfedc7409 100644 --- a/code/Common/Compression.h +++ b/code/Common/Compression.h @@ -41,11 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once -#ifdef ASSIMP_BUILD_NO_OWN_ZLIB -# include -#else -# include "../contrib/zlib/zlib.h" -#endif +#include "zlib.h" #include #include // size_t diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index b28910c70..a72627154 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -99,12 +99,12 @@ bool DefaultIOSystem::Exists(const char *pFile) const { return false; } #else - FILE *file = ::fopen(pFile, "rb"); - if (!file) { + struct stat statbuf; + stat(pFile, &statbuf); + // test for a regular file + if (!S_ISREG(statbuf.st_mode)) { return false; } - - ::fclose(file); #endif return true; @@ -116,6 +116,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) { ai_assert(strFile != nullptr); ai_assert(strMode != nullptr); FILE *file; + #ifdef _WIN32 std::wstring name = Utf8ToWide(strFile); if (name.empty()) { @@ -126,6 +127,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) { #else file = ::fopen(strFile, strMode); #endif + if (!file) { return nullptr; } diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 67937019f..9e4ca293d 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -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..a4b1a608a 100644 --- a/code/Pbrt/PbrtExporter.h +++ b/code/Pbrt/PbrtExporter.h @@ -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/PretransformVertices.cpp b/code/PostProcessing/PretransformVertices.cpp index 87af2297d..aff6e535a 100644 --- a/code/PostProcessing/PretransformVertices.cpp +++ b/code/PostProcessing/PretransformVertices.cpp @@ -290,12 +290,6 @@ void PretransformVertices::ComputeAbsoluteTransform(aiNode *pcNode) { } } -static void normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, size_t numVectors) { - for (size_t i=0; iHasNormals()) { - normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices); + for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { + mesh->mNormals[i] = (m * mesh->mNormals[i]).Normalize(); + } } + if (mesh->HasTangentsAndBitangents()) { for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { mesh->mTangents[i] = (m * mesh->mTangents[i]).Normalize(); 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/zlib/zconf.h.included b/contrib/zlib/zconf.h.included index 352f552b8..2271dc5f5 100644 --- a/contrib/zlib/zconf.h.included +++ b/contrib/zlib/zconf.h.included @@ -40,6 +40,9 @@ # define crc32 z_crc32 # define crc32_combine z_crc32_combine # define crc32_combine64 z_crc32_combine64 +# define crc32_combine_gen z_crc32_combine_gen +# define crc32_combine_gen64 z_crc32_combine_gen64 +# define crc32_combine_op z_crc32_combine_op # define crc32_z z_crc32_z # define deflate z_deflate # define deflateBound z_deflateBound @@ -351,6 +354,9 @@ # ifdef FAR # undef FAR # endif +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include /* No need for _export, use ZLIB.DEF instead. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */ @@ -469,11 +475,18 @@ typedef uLong FAR uLongf; # undef _LARGEFILE64_SOURCE #endif -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H +#ifndef Z_HAVE_UNISTD_H +# ifdef __WATCOMC__ +# define Z_HAVE_UNISTD_H +# endif +#endif +#ifndef Z_HAVE_UNISTD_H +# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32) +# define Z_HAVE_UNISTD_H +# endif #endif #ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# if defined(Z_HAVE_UNISTD_H) # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # ifdef VMS # include /* for off_t */ diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index d0b173171..f9df32b32 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -63,6 +63,7 @@ struct aiImporterDesc; namespace Assimp { +// Forward declarations class Importer; class IOSystem; class BaseProcess; @@ -73,6 +74,9 @@ class IOStream; #define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \ (string[1] << 16) + (string[2] << 8) + string[3])) +using UByteBuffer = std::vector; +using ByteBuffer = std::vector; + // --------------------------------------------------------------------------- /** FOR IMPORTER PLUGINS ONLY: The BaseImporter defines a common interface * for all importer worker classes. diff --git a/include/assimp/IOStreamBuffer.h b/include/assimp/IOStreamBuffer.h index fae480e71..47db35a95 100644 --- a/include/assimp/IOStreamBuffer.h +++ b/include/assimp/IOStreamBuffer.h @@ -287,7 +287,7 @@ static AI_FORCE_INLINE bool isEndOfCache(size_t pos, size_t cacheSize) { template AI_FORCE_INLINE bool IOStreamBuffer::getNextLine(std::vector &buffer) { buffer.resize(m_cacheSize); - if (isEndOfCache(m_cachePos, m_cacheSize) || 0 == m_filePos) { + if (m_cachePos >= m_cacheSize || 0 == m_filePos) { if (!readNextBlock()) { return false; } diff --git a/include/assimp/IOSystem.hpp b/include/assimp/IOSystem.hpp index 30f48b81c..acb1f8eae 100644 --- a/include/assimp/IOSystem.hpp +++ b/include/assimp/IOSystem.hpp @@ -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/ParsingUtils.h b/include/assimp/ParsingUtils.h index b08f23227..7e7fb161c 100644 --- a/include/assimp/ParsingUtils.h +++ b/include/assimp/ParsingUtils.h @@ -70,7 +70,6 @@ namespace Assimp { static const unsigned int BufferSize = 4096; - // --------------------------------------------------------------------------------- template AI_FORCE_INLINE bool IsUpper(char_t in) { diff --git a/include/assimp/mesh.h b/include/assimp/mesh.h index 3ef94e606..45f50d5a5 100644 --- a/include/assimp/mesh.h +++ b/include/assimp/mesh.h @@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #ifdef __cplusplus +#include + extern "C" { #endif @@ -872,11 +874,15 @@ struct aiMesh { // DO NOT REMOVE THIS ADDITIONAL CHECK if (mNumBones && mBones) { + std::unordered_set bones; for (unsigned int a = 0; a < mNumBones; a++) { if (mBones[a]) { - delete mBones[a]; + bones.insert(mBones[a]); } } + for (const aiBone *bone: bones) { + delete bone; + } delete[] mBones; } diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index 5d0962b6a..eb940e7f9 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -151,6 +151,8 @@ public: typedef aiVector3t aiVector3D; +typedef aiVector3t aiVector3f; +typedef aiVector3t aiVector3d; #else diff --git a/samples/SimpleTexturedDirectx11/CMakeLists.txt b/samples/SimpleTexturedDirectx11/CMakeLists.txt index de83734ba..f64923179 100644 --- a/samples/SimpleTexturedDirectx11/CMakeLists.txt +++ b/samples/SimpleTexturedDirectx11/CMakeLists.txt @@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include ${Assimp_SOURCE_DIR}/code ${SAMPLES_SHARED_CODE_DIR} + ${Assimp_SOURCE_DIR}/contrib/utf8cpp/source ) LINK_DIRECTORIES( diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp index 4da5820a1..ec031a594 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "ModelLoader.h" #include "SafeRelease.hpp" diff --git a/samples/SimpleTexturedOpenGL/CMakeLists.txt b/samples/SimpleTexturedOpenGL/CMakeLists.txt index 70837e87c..a10a15101 100644 --- a/samples/SimpleTexturedOpenGL/CMakeLists.txt +++ b/samples/SimpleTexturedOpenGL/CMakeLists.txt @@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES( ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} ${SAMPLES_SHARED_CODE_DIR} + ${Assimp_SOURCE_DIR}/contrib/utf8cpp/source ) LINK_DIRECTORIES( diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index 7d730a630..f6d3097fe 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef _MSC_VER #pragma warning(disable: 4100) // Disable warning 'unreferenced formal parameter' diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afe487411..da6a5b00b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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/crash-30d6d0f7c529b3b66b4131700b7a4580cd7082df.ply b/test/models/invalid/crash-30d6d0f7c529b3b66b4131700b7a4580cd7082df.ply new file mode 100644 index 000000000..948f5bcf9 Binary files /dev/null and b/test/models/invalid/crash-30d6d0f7c529b3b66b4131700b7a4580cd7082df.ply differ 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/utACImportExport.cpp b/test/unit/utACImportExport.cpp index c844603cf..ee22f44f8 100644 --- a/test/unit/utACImportExport.cpp +++ b/test/unit/utACImportExport.cpp @@ -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/utBlendImportAreaLight.cpp b/test/unit/utBlendImportAreaLight.cpp index 4a16e662c..470d80737 100644 --- a/test/unit/utBlendImportAreaLight.cpp +++ b/test/unit/utBlendImportAreaLight.cpp @@ -48,6 +48,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class BlendImportAreaLight : public ::testing::Test { public: + BlendImportAreaLight() : + im(nullptr) {} + ~BlendImportAreaLight() override = default; void SetUp() override { im = new Assimp::Importer(); } diff --git a/test/unit/utBlenderWork.cpp b/test/unit/utBlenderWork.cpp index b20720521..977877250 100644 --- a/test/unit/utBlenderWork.cpp +++ b/test/unit/utBlenderWork.cpp @@ -48,11 +48,14 @@ using namespace ::Assimp; class BlenderWorkTest : public ::testing::Test { public: - virtual void SetUp() { + BlenderWorkTest() : im(nullptr) {} + ~BlenderWorkTest() override = default; + + void SetUp() override { im = new Assimp::Importer(); } - virtual void TearDown() { + void TearDown() override { delete im; } diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 1f733c0e7..13c90fc47 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -196,3 +196,10 @@ TEST_F(utPLYImportExport, parseErrorTest) { const aiScene *scene = importer.ReadFileFromMemory(test_file, strlen(test_file), 0); EXPECT_NE(nullptr, scene); } + +// This file is invalid, we just want to ensure that the importer is not crashing +TEST_F(utPLYImportExport, parseInvalid) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/invalid/crash-30d6d0f7c529b3b66b4131700b7a4580cd7082df.ply", 0); + EXPECT_EQ(nullptr, scene); +} diff --git a/test/unit/utX3DImportExport.cpp b/test/unit/utX3DImportExport.cpp index f2df81ac2..a654765de 100644 --- a/test/unit/utX3DImportExport.cpp +++ b/test/unit/utX3DImportExport.cpp @@ -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/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index e00c6e39d..8f2d131d2 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -291,7 +291,7 @@ int LoadAsset() { //------------------------------------------------------------------------------- // Delete the loaded asset -// The function does nothing is no asset is loaded +// The function does nothing if no asset is loaded //------------------------------------------------------------------------------- int DeleteAsset(void) { if (!g_pcAsset) {