diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index db152b813..b6cfae367 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -7,10 +7,10 @@ on: branches: [ master ] permissions: - contents: read # to fetch code (actions/checkout) + contents: write # to fetch code (actions/checkout),and release jobs: - job: + build: name: ${{ matrix.name }}-build-and-test runs-on: ${{ matrix.os }} strategy: @@ -70,12 +70,12 @@ jobs: - name: Set Windows specific CMake arguments if: contains(matrix.name, 'windows') id: windows_extra_cmake_args - run: echo "::set-output name=args::-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1 -DASSIMP_BUILD_ZLIB=1" + run: echo ":set-output name=args::=-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1" >> $GITHUB_OUTPUT - name: Set Hunter specific CMake arguments if: contains(matrix.name, 'hunter') id: hunter_extra_cmake_args - run: echo "::set-output name=args::-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" + run: echo "args=-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" >> $GITHUB_OUTPUT - name: configure and build uses: lukka/run-cmake@v3 @@ -92,7 +92,7 @@ jobs: - name: Exclude certain tests in Hunter specific builds if: contains(matrix.name, 'hunter') id: hunter_extra_test_args - run: echo "::set-output name=args::--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" + run: echo "args=--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" >> $GITHUB_OUTPUT - name: test run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }} @@ -101,5 +101,89 @@ jobs: - uses: actions/upload-artifact@v4 if: matrix.name == 'windows-msvc' with: - name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' - path: build/bin + name: 'assimp-bins-${{ matrix.name }}' + path: build/bin/assimp*.exe + + - uses: marvinpinto/action-automatic-releases@latest + if: contains(matrix.name, 'windows-msvc-hunter') + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "master" + prerelease: true + title: "AutoRelease" + files: | + build/bin/assimp*.exe + + create-release: + needs: [build] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}' + with: + tag_name: '${{github.ref}}' + release_name: 'Release ${{github.ref}}' + draft: false + prerelease: true + - run: | + echo '${{steps.create-release.outputs.upload_url}}' > release_upload_url.txt + - uses: actions/upload-artifact@v4 + with: + name: create-release + path: release_upload_url.txt + + upload-release: + strategy: + matrix: + name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter, windows-msvc-hunter] + # For Windows msvc, for Linux and macOS let's use the clang compiler, use gcc for Linux. + include: + - name: windows-latest-cl.exe + os: windows-latest + cxx: cl.exe + cc: cl.exe + - name: ubuntu-latest-clang++ + os: ubuntu-latest + cxx: clang++ + cc: clang + - name: macos-latest-clang++ + os: macos-latest + cxx: clang++ + cc: clang + - name: ubuntu-latest-g++ + 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 + + needs: [create-release] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: softprops/action-gh-release@v2 + with: + name: create-release + - id: upload-url + run: | + echo "url=$(cat create-release/release_upload_url.txt)" >> $GITHUB_OUTPUT + - uses: actions/download-artifact@v4 + with: + name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' + - uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}' + with: + files: | + *.zip + diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fc0ef819..074d64839 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,7 @@ IF (WIN32) IF(MSVC) OPTION( ASSIMP_INSTALL_PDB - "Install MSVC debug files." + "Create MSVC debug symbol files and add to Install target." ON ) IF(NOT (MSVC_VERSION LESS 1900)) # Multibyte character set has been deprecated since at least MSVC2015 (possibly earlier) @@ -308,8 +308,15 @@ ELSEIF(MSVC) # supress warning for double to float conversion if Double precision is activated ADD_COMPILE_OPTIONS(/wd4244) SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /Zi /Od") - SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /PDBALTPATH:%_PDB% /OPT:REF /OPT:ICF") + # Allow user to disable PDBs + if(ASSIMP_INSTALL_PDB) + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") + SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /PDBALTPATH:%_PDB% /OPT:REF /OPT:ICF") + elseif((GENERATOR_IS_MULTI_CONFIG) OR (CMAKE_BUILD_TYPE MATCHES Release)) + message("-- MSVC PDB generation disabled. Release binary will not be debuggable.") + endif() + # Source code is encoded in UTF-8 + ADD_COMPILE_OPTIONS(/source-charset:utf-8) ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) IF(NOT ASSIMP_HUNTER_ENABLED) SET(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -652,7 +659,7 @@ ELSE() IF ( ASSIMP_BUILD_DRACO ) # Primarily for glTF v2 # Enable Draco glTF feature set - set(DRACO_GLTF ON CACHE BOOL "" FORCE) + set(DRACO_GLTF_BITSTREAM ON CACHE BOOL "" FORCE) # Disable unnecessary or omitted components set(DRACO_JS_GLUE OFF CACHE BOOL "" FORCE) set(DRACO_WASM OFF CACHE BOOL "" FORCE) diff --git a/code/AssetLib/3DS/3DSExporter.cpp b/code/AssetLib/3DS/3DSExporter.cpp index 8477ed09f..5341a69f1 100644 --- a/code/AssetLib/3DS/3DSExporter.cpp +++ b/code/AssetLib/3DS/3DSExporter.cpp @@ -52,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include diff --git a/code/AssetLib/3MF/D3MFExporter.cpp b/code/AssetLib/3MF/D3MFExporter.cpp index 6caa4c84e..6c09f097d 100644 --- a/code/AssetLib/3MF/D3MFExporter.cpp +++ b/code/AssetLib/3MF/D3MFExporter.cpp @@ -249,10 +249,10 @@ void D3MFExporter::writeBaseMaterials() { if (color.r <= 1 && color.g <= 1 && color.b <= 1 && color.a <= 1) { hexDiffuseColor = ai_rgba2hex( - (int)((ai_real)color.r) * 255, - (int)((ai_real)color.g) * 255, - (int)((ai_real)color.b) * 255, - (int)((ai_real)color.a) * 255, + (int)(((ai_real)color.r) * 255), + (int)(((ai_real)color.g) * 255), + (int)(((ai_real)color.b) * 255), + (int)(((ai_real)color.a) * 255), true); } else { diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 234931cbe..fd54c63f4 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -2128,6 +2128,10 @@ void FBXConverter::SetTextureProperties(aiMaterial *out_mat, const TextureMap &_ TrySetTextureProperties(out_mat, _textures, "Maya|emissionColor", aiTextureType_EMISSION_COLOR, mesh); TrySetTextureProperties(out_mat, _textures, "Maya|metalness", aiTextureType_METALNESS, mesh); TrySetTextureProperties(out_mat, _textures, "Maya|diffuseRoughness", aiTextureType_DIFFUSE_ROUGHNESS, mesh); + TrySetTextureProperties(out_mat, _textures, "Maya|base", aiTextureType_MAYA_BASE, mesh); + TrySetTextureProperties(out_mat, _textures, "Maya|specular", aiTextureType_MAYA_SPECULAR, mesh); + TrySetTextureProperties(out_mat, _textures, "Maya|specularColor", aiTextureType_MAYA_SPECULAR_COLOR, mesh); + TrySetTextureProperties(out_mat, _textures, "Maya|specularRoughness", aiTextureType_MAYA_SPECULAR_ROUGHNESS, mesh); // Maya stingray TrySetTextureProperties(out_mat, _textures, "Maya|TEX_color_map", aiTextureType_BASE_COLOR, mesh); diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index 3b1dd335e..bfefc92c9 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -1217,10 +1217,8 @@ void FBXExporter::WriteObjects () } // colors, if any - // TODO only one color channel currently - const int32_t colorChannelIndex = 0; - if (m->HasVertexColors(colorChannelIndex)) { - FBX::Node vertexcolors("LayerElementColor", int32_t(colorChannelIndex)); + for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) { + FBX::Node vertexcolors("LayerElementColor", int32_t(ci)); vertexcolors.Begin(outstream, binary, indent); vertexcolors.DumpProperties(outstream, binary, indent); vertexcolors.EndProperties(outstream, binary, indent); @@ -1230,7 +1228,7 @@ void FBXExporter::WriteObjects () "Version", int32_t(101), outstream, binary, indent ); char layerName[8]; - snprintf(layerName, sizeof(layerName), "COLOR_%d", colorChannelIndex); + snprintf(layerName, sizeof(layerName), "COLOR_%d", int32_t(ci)); FBX::Node::WritePropertyNode( "Name", (const char*)layerName, outstream, binary, indent ); @@ -1247,7 +1245,7 @@ void FBXExporter::WriteObjects () for (size_t fi = 0; fi < m->mNumFaces; ++fi) { const aiFace &f = m->mFaces[fi]; for (size_t pvi = 0; pvi < f.mNumIndices; ++pvi) { - const aiColor4D &c = m->mColors[colorChannelIndex][f.mIndices[pvi]]; + const aiColor4D &c = m->mColors[ci][f.mIndices[pvi]]; color_data.push_back(c.r); color_data.push_back(c.g); color_data.push_back(c.b); @@ -1354,11 +1352,14 @@ void FBXExporter::WriteObjects () le.AddChild("Type", "LayerElementNormal"); le.AddChild("TypedIndex", int32_t(0)); layer.AddChild(le); - // TODO only 1 color channel currently - le = FBX::Node("LayerElement"); - le.AddChild("Type", "LayerElementColor"); - le.AddChild("TypedIndex", int32_t(0)); - layer.AddChild(le); + + for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) { + le = FBX::Node("LayerElement"); + le.AddChild("Type", "LayerElementColor"); + le.AddChild("TypedIndex", int32_t(ci)); + layer.AddChild(le); + } + le = FBX::Node("LayerElement"); le.AddChild("Type", "LayerElementMaterial"); le.AddChild("TypedIndex", int32_t(0)); diff --git a/code/AssetLib/Ply/PlyLoader.cpp b/code/AssetLib/Ply/PlyLoader.cpp index 0c2463f24..b211818df 100644 --- a/code/AssetLib/Ply/PlyLoader.cpp +++ b/code/AssetLib/Ply/PlyLoader.cpp @@ -81,6 +81,27 @@ namespace { return props[idx]; } + + // ------------------------------------------------------------------------------------------------ + static bool isBigEndian(const char *szMe) { + ai_assert(nullptr != szMe); + + // binary_little_endian + // binary_big_endian + bool isBigEndian{ false }; +#if (defined AI_BUILD_BIG_ENDIAN) + if ('l' == *szMe || 'L' == *szMe) { + isBigEndian = true; + } +#else + if ('b' == *szMe || 'B' == *szMe) { + isBigEndian = true; + } +#endif // ! AI_BUILD_BIG_ENDIAN + + return isBigEndian; + } + } // namespace // ------------------------------------------------------------------------------------------------ @@ -92,6 +113,11 @@ PLYImporter::PLYImporter() : // empty } +// ------------------------------------------------------------------------------------------------ +PLYImporter::~PLYImporter() { + delete mGeneratedMesh; +} + // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool PLYImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { @@ -104,26 +130,6 @@ const aiImporterDesc *PLYImporter::GetInfo() const { return &desc; } -// ------------------------------------------------------------------------------------------------ -static bool isBigEndian(const char *szMe) { - ai_assert(nullptr != szMe); - - // binary_little_endian - // binary_big_endian - bool isBigEndian(false); -#if (defined AI_BUILD_BIG_ENDIAN) - if ('l' == *szMe || 'L' == *szMe) { - isBigEndian = true; - } -#else - if ('b' == *szMe || 'B' == *szMe) { - isBigEndian = true; - } -#endif // ! AI_BUILD_BIG_ENDIAN - - return isBigEndian; -} - // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { @@ -134,7 +140,7 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } // Get the file-size - const size_t fileSize(fileStream->FileSize()); + const size_t fileSize = fileStream->FileSize(); if (0 == fileSize) { throw DeadlyImportError("File ", pFile, " is empty."); } @@ -180,7 +186,7 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } } else if (!::strncmp(szMe, "binary_", 7)) { szMe += 7; - const bool bIsBE(isBigEndian(szMe)); + const bool bIsBE = isBigEndian(szMe); // skip the line, parse the rest of the header and build the DOM if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE)) { @@ -241,7 +247,9 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // fill the mesh list pScene->mNumMeshes = 1; pScene->mMeshes = new aiMesh *[pScene->mNumMeshes]; - pScene->mMeshes[0] = mGeneratedMesh; + pScene->mMeshes[0] = mGeneratedMesh; + + // Move the mesh ownership into the scene instance mGeneratedMesh = nullptr; // generate a simple node structure @@ -254,20 +262,22 @@ void PLYImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy } } +static constexpr ai_uint NotSet = 0xFFFFFFFF; + void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementInstance *instElement, unsigned int pos) { ai_assert(nullptr != pcElement); ai_assert(nullptr != instElement); - ai_uint aiPositions[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; + ai_uint aiPositions[3] = { NotSet, NotSet, NotSet }; PLY::EDataType aiTypes[3] = { EDT_Char, EDT_Char, EDT_Char }; - ai_uint aiNormal[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; + ai_uint aiNormal[3] = { NotSet, NotSet, NotSet }; PLY::EDataType aiNormalTypes[3] = { EDT_Char, EDT_Char, EDT_Char }; - unsigned int aiColors[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; + unsigned int aiColors[4] = { NotSet, NotSet, NotSet, NotSet }; PLY::EDataType aiColorsTypes[4] = { EDT_Char, EDT_Char, EDT_Char, EDT_Char }; - unsigned int aiTexcoord[2] = { 0xFFFFFFFF, 0xFFFFFFFF }; + unsigned int aiTexcoord[2] = { NotSet, NotSet }; PLY::EDataType aiTexcoordTypes[2] = { EDT_Char, EDT_Char }; // now check whether which normal components are available @@ -337,17 +347,17 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn if (0 != cnt) { // Position aiVector3D vOut; - if (0xFFFFFFFF != aiPositions[0]) { + if (NotSet != aiPositions[0]) { vOut.x = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiPositions[0]).avList.front(), aiTypes[0]); } - if (0xFFFFFFFF != aiPositions[1]) { + if (NotSet != aiPositions[1]) { vOut.y = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiPositions[1]).avList.front(), aiTypes[1]); } - if (0xFFFFFFFF != aiPositions[2]) { + if (NotSet != aiPositions[2]) { vOut.z = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiPositions[2]).avList.front(), aiTypes[2]); } @@ -355,19 +365,19 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn // Normals aiVector3D nOut; bool haveNormal = false; - if (0xFFFFFFFF != aiNormal[0]) { + if (NotSet != aiNormal[0]) { nOut.x = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiNormal[0]).avList.front(), aiNormalTypes[0]); haveNormal = true; } - if (0xFFFFFFFF != aiNormal[1]) { + if (NotSet != aiNormal[1]) { nOut.y = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiNormal[1]).avList.front(), aiNormalTypes[1]); haveNormal = true; } - if (0xFFFFFFFF != aiNormal[2]) { + if (NotSet != aiNormal[2]) { nOut.z = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiNormal[2]).avList.front(), aiNormalTypes[2]); haveNormal = true; @@ -376,7 +386,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn // Colors aiColor4D cOut; bool haveColor = false; - if (0xFFFFFFFF != aiColors[0]) { + if (NotSet != aiColors[0]) { cOut.r = NormalizeColorValue(GetProperty(instElement->alProperties, aiColors[0]) .avList.front(), @@ -384,7 +394,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn haveColor = true; } - if (0xFFFFFFFF != aiColors[1]) { + if (NotSet != aiColors[1]) { cOut.g = NormalizeColorValue(GetProperty(instElement->alProperties, aiColors[1]) .avList.front(), @@ -392,7 +402,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn haveColor = true; } - if (0xFFFFFFFF != aiColors[2]) { + if (NotSet != aiColors[2]) { cOut.b = NormalizeColorValue(GetProperty(instElement->alProperties, aiColors[2]) .avList.front(), @@ -401,7 +411,7 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn } // assume 1.0 for the alpha channel if it is not set - if (0xFFFFFFFF == aiColors[3]) { + if (NotSet == aiColors[3]) { cOut.a = 1.0; } else { cOut.a = NormalizeColorValue(GetProperty(instElement->alProperties, @@ -416,13 +426,13 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn aiVector3D tOut; tOut.z = 0; bool haveTextureCoords = false; - if (0xFFFFFFFF != aiTexcoord[0]) { + if (NotSet != aiTexcoord[0]) { tOut.x = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiTexcoord[0]).avList.front(), aiTexcoordTypes[0]); haveTextureCoords = true; } - if (0xFFFFFFFF != aiTexcoord[1]) { + if (NotSet != aiTexcoord[1]) { tOut.y = PLY::PropertyInstance::ConvertTo( GetProperty(instElement->alProperties, aiTexcoord[1]).avList.front(), aiTexcoordTypes[1]); haveTextureCoords = true; @@ -504,16 +514,12 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst bool bOne = false; // index of the vertex index list - unsigned int iProperty = 0xFFFFFFFF; + unsigned int iProperty = NotSet; PLY::EDataType eType = EDT_Char; bool bIsTriStrip = false; - // index of the material index property - // unsigned int iMaterialIndex = 0xFFFFFFFF; - // PLY::EDataType eType2 = EDT_Char; - // texture coordinates - unsigned int iTextureCoord = 0xFFFFFFFF; + unsigned int iTextureCoord = NotSet; PLY::EDataType eType3 = EDT_Char; // face = unique number of vertex indices @@ -572,7 +578,7 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst if (!bIsTriStrip) { // parse the list of vertex indices - if (0xFFFFFFFF != iProperty) { + if (NotSet != iProperty) { const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iProperty).avList.size(); mGeneratedMesh->mFaces[pos].mNumIndices = iNum; mGeneratedMesh->mFaces[pos].mIndices = new unsigned int[iNum]; @@ -585,15 +591,7 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst } } - // parse the material index - // cannot be handled without processing the whole file first - /*if (0xFFFFFFFF != iMaterialIndex) - { - mGeneratedMesh->mFaces[pos]. = PLY::PropertyInstance::ConvertTo( - GetProperty(instElement->alProperties, iMaterialIndex).avList.front(), eType2); - }*/ - - if (0xFFFFFFFF != iTextureCoord) { + if (NotSet != iTextureCoord) { const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iTextureCoord).avList.size(); // should be 6 coords @@ -679,41 +677,29 @@ void PLYImporter::GetMaterialColor(const std::vector &avL aiColor4D *clrOut) { ai_assert(nullptr != clrOut); - if (0xFFFFFFFF == aiPositions[0]) + if (NotSet == aiPositions[0]) { clrOut->r = 0.0f; - else { - clrOut->r = NormalizeColorValue(GetProperty(avList, - aiPositions[0]) - .avList.front(), - aiTypes[0]); + } else { + clrOut->r = NormalizeColorValue(GetProperty(avList, aiPositions[0]).avList.front(), aiTypes[0]); } - if (0xFFFFFFFF == aiPositions[1]) + if (NotSet == aiPositions[1]) { clrOut->g = 0.0f; - else { - clrOut->g = NormalizeColorValue(GetProperty(avList, - aiPositions[1]) - .avList.front(), - aiTypes[1]); + } else { + clrOut->g = NormalizeColorValue(GetProperty(avList, aiPositions[1]).avList.front(), aiTypes[1]); } - if (0xFFFFFFFF == aiPositions[2]) + if (NotSet == aiPositions[2]) clrOut->b = 0.0f; else { - clrOut->b = NormalizeColorValue(GetProperty(avList, - aiPositions[2]) - .avList.front(), - aiTypes[2]); + clrOut->b = NormalizeColorValue(GetProperty(avList, aiPositions[2]).avList.front(), aiTypes[2]); } // assume 1.0 for the alpha channel ifit is not set - if (0xFFFFFFFF == aiPositions[3]) + if (NotSet == aiPositions[3]) clrOut->a = 1.0f; else { - clrOut->a = NormalizeColorValue(GetProperty(avList, - aiPositions[3]) - .avList.front(), - aiTypes[3]); + clrOut->a = NormalizeColorValue(GetProperty(avList, aiPositions[3]).avList.front(), aiTypes[3]); } } diff --git a/code/AssetLib/Ply/PlyLoader.h b/code/AssetLib/Ply/PlyLoader.h index 048f40e3f..bc9f276af 100644 --- a/code/AssetLib/Ply/PlyLoader.h +++ b/code/AssetLib/Ply/PlyLoader.h @@ -62,10 +62,10 @@ using namespace PLY; // --------------------------------------------------------------------------- /** Importer class to load the stanford PLY file format */ -class PLYImporter : public BaseImporter { +class PLYImporter final : public BaseImporter { public: PLYImporter(); - ~PLYImporter() override = default; + ~PLYImporter() override; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. @@ -120,13 +120,9 @@ protected: PLY::PropertyInstance::ValueUnion val, PLY::EDataType eType); - /** Buffer to hold the loaded file */ +private: unsigned char *mBuffer; - - /** Document object model representation extracted from the file */ PLY::DOM *pcDOM; - - /** Mesh generated by loader */ aiMesh *mGeneratedMesh; }; diff --git a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp index dbe9b6240..3e32917f9 100644 --- a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp +++ b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp @@ -72,7 +72,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../../contrib/tinyusdz/assimp_tinyusdz_logging.inc" namespace { - static constexpr char Tag[] = "tinyusdz loader"; + static constexpr char TAG[] = "tinyusdz loader"; } namespace Assimp { diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index e4e67e682..9b2708623 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1334,7 +1334,7 @@ ADD_LIBRARY(assimp::assimp ALIAS assimp) IF (BUILD_SHARED_LIBS) TARGET_COMPILE_DEFINITIONS(assimp PRIVATE ASSIMP_BUILD_DLL_EXPORT) ELSE () - TARGET_COMPILE_DEFINITIONS(assimp PRIVATE OPENDDL_STATIC_LIBARY) + TARGET_COMPILE_DEFINITIONS(assimp PRIVATE OPENDDL_STATIC_LIBARY P2T_STATIC_EXPORTS) ENDIF () TARGET_USE_COMMON_OUTPUT_DIRECTORY(assimp) @@ -1575,7 +1575,7 @@ if(MSVC AND ASSIMP_INSTALL_PDB) COMPILE_PDB_NAME_DEBUG assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX} ) - IF(GENERATOR_IS_MULTI_CONFIG) + IF(is_multi_config) install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb DESTINATION ${ASSIMP_LIB_INSTALL_DIR} CONFIGURATIONS Debug diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 9abac7ee2..ef3ee7b5d 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -512,6 +512,11 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene *pIn, ASSIMP_END_EXCEPTION_REGION(void); } +// ------------------------------------------------------------------------------------------------ +ASSIMP_API const C_STRUCT aiTexture *aiGetEmbeddedTexture(const C_STRUCT aiScene *pIn, const char *filename) { + return pIn->GetEmbeddedTexture(filename); +} + // ------------------------------------------------------------------------------------------------ ASSIMP_API aiPropertyStore *aiCreatePropertyStore(void) { return reinterpret_cast(new PropertyMap()); @@ -1268,7 +1273,6 @@ ASSIMP_API void aiQuaternionInterpolate( aiQuaternion::Interpolate(*dst, *start, *end, factor); } - // stb_image is a lightweight image loader. It is shared by: // - M3D import // - PBRT export @@ -1279,21 +1283,21 @@ ASSIMP_API void aiQuaternionInterpolate( #define ASSIMP_HAS_M3D ((!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_M3D_EXPORTER) || !ASSIMP_BUILD_NO_M3D_IMPORTER) #ifndef STB_USE_HUNTER -# if ASSIMP_HAS_PBRT_EXPORT -# define ASSIMP_NEEDS_STB_IMAGE 1 -# elif ASSIMP_HAS_M3D -# define ASSIMP_NEEDS_STB_IMAGE 1 -# define STBI_ONLY_PNG -# endif +#if ASSIMP_HAS_PBRT_EXPORT +#define ASSIMP_NEEDS_STB_IMAGE 1 +#elif ASSIMP_HAS_M3D +#define ASSIMP_NEEDS_STB_IMAGE 1 +#define STBI_ONLY_PNG +#endif #endif // Ensure all symbols are linked correctly #if ASSIMP_NEEDS_STB_IMAGE - // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. -# define STBI_ONLY_PNG -# ifdef ASSIMP_USE_STB_IMAGE_STATIC -# define STB_IMAGE_STATIC -# endif -# define STB_IMAGE_IMPLEMENTATION -# include "Common/StbCommon.h" +// Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. +#define STBI_ONLY_PNG +#ifdef ASSIMP_USE_STB_IMAGE_STATIC +#define STB_IMAGE_STATIC +#endif +#define STB_IMAGE_IMPLEMENTATION +#include "Common/StbCommon.h" #endif diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index e74add55f..ddb5b3b60 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -93,6 +93,10 @@ static std::string WideToUtf8(const wchar_t *in) { // ------------------------------------------------------------------------------------------------ // Tests for the existence of a file at the given path. bool DefaultIOSystem::Exists(const char *pFile) const { + if (pFile == nullptr) { + return false; + } + #ifdef _WIN32 struct __stat64 filestat; if (_wstat64(Utf8ToWide(pFile).c_str(), &filestat) != 0) { diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 7954d4d01..88fa49793 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace Assimp { @@ -252,6 +253,14 @@ void SceneCombiner::AttachToGraph(aiScene *master, std::vector &srcList, unsigned int flags) { if (nullptr == _dest) { + std::unordered_set uniqueScenes; + uniqueScenes.insert(master); + for (const auto &item : srcList) { + uniqueScenes.insert(item.scene); + } + for (const auto &item : uniqueScenes) { + delete item; + } return; } @@ -259,6 +268,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vectormFlags = src->mFlags; // source private data might be nullptr if the scene is user-allocated (i.e. for use with the export API) - if (dest->mPrivate != nullptr) { + if (src->mPrivate != nullptr) { ScenePriv(dest)->mPPStepsApplied = ScenePriv(src) ? ScenePriv(src)->mPPStepsApplied : 0; } } diff --git a/code/PostProcessing/FindDegenerates.cpp b/code/PostProcessing/FindDegenerates.cpp index c506b08b5..7401ea0e7 100644 --- a/code/PostProcessing/FindDegenerates.cpp +++ b/code/PostProcessing/FindDegenerates.cpp @@ -143,9 +143,13 @@ bool FindDegeneratesProcess::ExecuteOnMesh(aiMesh *mesh) { for (unsigned int a = 0; a < mesh->mNumFaces; ++a) { aiFace &face = mesh->mFaces[a]; bool first = true; + auto vertex_in_range = [numVertices = mesh->mNumVertices](unsigned int vertex_idx) { return vertex_idx < numVertices; }; // check whether the face contains degenerated entries for (unsigned int i = 0; i < face.mNumIndices; ++i) { + if (!std::all_of(face.mIndices, face.mIndices + face.mNumIndices, vertex_in_range)) + continue; + // Polygons with more than 4 points are allowed to have double points, that is // simulating polygons with holes just with concave polygons. However, // double points may not come directly after another. diff --git a/code/PostProcessing/ImproveCacheLocality.cpp b/code/PostProcessing/ImproveCacheLocality.cpp index c165b0114..e108354b1 100644 --- a/code/PostProcessing/ImproveCacheLocality.cpp +++ b/code/PostProcessing/ImproveCacheLocality.cpp @@ -380,3 +380,4 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes } } // namespace Assimp + diff --git a/contrib/poly2tri/poly2tri/common/dll_symbol.h b/contrib/poly2tri/poly2tri/common/dll_symbol.h index 72ed5a75f..c18c2baec 100644 --- a/contrib/poly2tri/poly2tri/common/dll_symbol.h +++ b/contrib/poly2tri/poly2tri/common/dll_symbol.h @@ -53,7 +53,9 @@ # define P2T_DLL_SYMBOL # elif defined(P2T_SHARED_EXPORTS) # define P2T_DLL_SYMBOL P2T_COMPILER_DLLEXPORT -# else +# elif defined(BUILD_SHARED_LIBS) # define P2T_DLL_SYMBOL P2T_COMPILER_DLLIMPORT +# else +# define P2T_DLL_SYMBOL # endif #endif diff --git a/include/assimp/StringComparison.h b/include/assimp/StringComparison.h index 283d8ba6b..c4174c520 100644 --- a/include/assimp/StringComparison.h +++ b/include/assimp/StringComparison.h @@ -57,7 +57,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma GCC system_header #endif -#include #include #include diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index 80edfe221..b793eca44 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -58,6 +58,7 @@ extern "C" { #endif struct aiScene; +struct aiTexture; struct aiFileIO; typedef void (*aiLogStreamCallback)(const char * /* message */, char * /* user */); @@ -373,6 +374,13 @@ ASSIMP_API void aiGetMemoryRequirements( const C_STRUCT aiScene *pIn, C_STRUCT aiMemoryInfo *in); +// -------------------------------------------------------------------------------- +/** Returns an embedded texture, or nullptr. + * @param pIn Input asset. + * @param filename Texture path extracted from aiGetMaterialString. + */ +ASSIMP_API const C_STRUCT aiTexture *aiGetEmbeddedTexture(const C_STRUCT aiScene *pIn, const char *filename); + // -------------------------------------------------------------------------------- /** Create an empty property store. Property stores are used to collect import * settings. diff --git a/include/assimp/material.h b/include/assimp/material.h index a8c6282c4..244c6607e 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -292,6 +292,14 @@ enum aiTextureType { aiTextureType_DIFFUSE_ROUGHNESS = 16, aiTextureType_AMBIENT_OCCLUSION = 17, + /** Unknown texture + * + * A texture reference that does not match any of the definitions + * above is considered to be 'unknown'. It is still imported, + * but is excluded from any further post-processing. + */ + aiTextureType_UNKNOWN = 18, + /** PBR Material Modifiers * Some modern renderers have further PBR modifiers that may be overlaid * on top of the 'base' PBR materials for additional realism. @@ -318,20 +326,20 @@ enum aiTextureType { */ aiTextureType_TRANSMISSION = 21, - /** Unknown texture - * - * A texture reference that does not match any of the definitions - * above is considered to be 'unknown'. It is still imported, - * but is excluded from any further post-processing. - */ - aiTextureType_UNKNOWN = 18, + /** + * Maya material declarations + */ + aiTextureType_MAYA_BASE = 22, + aiTextureType_MAYA_SPECULAR = 23, + aiTextureType_MAYA_SPECULAR_COLOR = 24, + aiTextureType_MAYA_SPECULAR_ROUGHNESS = 25, #ifndef SWIG _aiTextureType_Force32Bit = INT_MAX #endif }; -#define AI_TEXTURE_TYPE_MAX aiTextureType_TRANSMISSION +#define AI_TEXTURE_TYPE_MAX aiTextureType_MAYA_SPECULAR_ROUGHNESS // ------------------------------------------------------------------------------- /** diff --git a/include/assimp/scene.h b/include/assimp/scene.h index 9137a856c..f3701d600 100644 --- a/include/assimp/scene.h +++ b/include/assimp/scene.h @@ -401,8 +401,9 @@ struct ASSIMP_API aiScene { //! Returns a short filename from a full path static const char* GetShortFilename(const char* filename) { const char* lastSlash = strrchr(filename, '/'); - if (lastSlash == nullptr) { - lastSlash = strrchr(filename, '\\'); + const char* lastBackSlash = strrchr(filename, '\\'); + if (lastSlash < lastBackSlash) { + lastSlash = lastBackSlash; } const char* shortFilename = lastSlash != nullptr ? lastSlash + 1 : filename; return shortFilename; diff --git a/test/unit/utFindDegenerates.cpp b/test/unit/utFindDegenerates.cpp index 04f554716..405c35230 100644 --- a/test/unit/utFindDegenerates.cpp +++ b/test/unit/utFindDegenerates.cpp @@ -206,3 +206,38 @@ TEST_F(FindDegeneratesProcessTest, meshRemoval) { EXPECT_EQ(scene->mRootNode->mNumMeshes, 1u); EXPECT_EQ(scene->mRootNode->mMeshes[0], 0u); } + +TEST_F(FindDegeneratesProcessTest, invalidVertexIndex) { + mProcess->EnableAreaCheck(true); + mProcess->EnableInstantRemoval(true); + mProcess->ExecuteOnMesh(mMesh); + + std::unique_ptr scene(new aiScene); + scene->mNumMeshes = 1; + scene->mMeshes = new aiMesh *[1]; + + std::unique_ptr mesh(new aiMesh); + mesh->mNumVertices = 1; + mesh->mVertices = new aiVector3D[1]; + mesh->mVertices[0] = aiVector3D{ 0.0f, 0.0f, 0.0f }; + mesh->mNumFaces = 1; + mesh->mFaces = new aiFace[1]; + mesh->mFaces[0].mNumIndices = 3; + mesh->mFaces[0].mIndices = new unsigned int[3]; + mesh->mFaces[0].mIndices[0] = 0; + mesh->mFaces[0].mIndices[1] = 1; + mesh->mFaces[0].mIndices[2] = 99999; + + scene->mMeshes[0] = mesh.release(); + + scene->mRootNode = new aiNode; + scene->mRootNode->mNumMeshes = 1; + scene->mRootNode->mMeshes = new unsigned int[1]; + scene->mRootNode->mMeshes[0] = 0; + + mProcess->Execute(scene.get()); + + EXPECT_EQ(scene->mNumMeshes, 1u); + EXPECT_EQ(scene->mRootNode->mNumMeshes, 1u); + EXPECT_EQ(scene->mRootNode->mMeshes[0], 0u); +} diff --git a/test/unit/utMaterialSystem.cpp b/test/unit/utMaterialSystem.cpp index 8b1691b3f..4d335a979 100644 --- a/test/unit/utMaterialSystem.cpp +++ b/test/unit/utMaterialSystem.cpp @@ -260,6 +260,10 @@ TEST_F(MaterialSystemTest, testMaterialTextureTypeEnum) { case aiTextureType_METALNESS: case aiTextureType_DIFFUSE_ROUGHNESS: case aiTextureType_AMBIENT_OCCLUSION: + case aiTextureType_MAYA_BASE: + case aiTextureType_MAYA_SPECULAR: + case aiTextureType_MAYA_SPECULAR_COLOR: + case aiTextureType_MAYA_SPECULAR_ROUGHNESS: case aiTextureType_SHEEN: case aiTextureType_CLEARCOAT: case aiTextureType_TRANSMISSION: