diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 08292d55f..e542821e8 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -44,16 +44,46 @@ jobs: with: CXX: ${{ matrix.cxx }} CC: ${{ matrix.cc }} + + - name: Cache DX SDK + id: dxcache + if: matrix.name == 'windows-msvc' + uses: actions/cache@v2 + with: + path: '${{ github.workspace }}/DX_SDK' + key: ${{ runner.os }}-DX_SDK + restore-keys: | + ${{ runner.os }}-DX_SDK + + - name: Download DXSetup + if: matrix.name == 'windows-msvc' && steps.dxcache.outputs.cache-hit != 'true' + run: | + curl -s -o DXSDK_Jun10.exe --location https://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe + cmd.exe /c start /wait .\DXSDK_Jun10.exe /U /O /F /S /P "${{ github.workspace }}\DX_SDK" + + - name: Set Windows specific CMake arguments + if: matrix.name == 'windows-msvc' + id: windows_extra_cmake_args + run: echo "::set-output name=args::'-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1'" - name: configure and build uses: lukka/run-cmake@v2 + env: + DXSDK_DIR: '${{ github.workspace }}/DX_SDK' + with: cmakeListsOrSettingsJson: CMakeListsTxtAdvanced cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' - cmakeAppendedArgs: '-GNinja -DCMAKE_BUILD_TYPE=Release' + cmakeAppendedArgs: '-GNinja -DCMAKE_BUILD_TYPE=Release ${{ steps.windows_extra_cmake_args.outputs.args }}' buildWithCMakeArgs: '-- -v' buildDirectory: '${{ github.workspace }}/build/' - name: test run: cd build/bin && ./unit shell: bash + + - uses: actions/upload-artifact@v2 + if: matrix.name == 'windows-msvc' + with: + name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' + path: build/bin diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b350f6e3..5bf20dee5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #---------------------------------------------------------------------- SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW) +SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW) CMAKE_MINIMUM_REQUIRED( VERSION 3.0 ) @@ -44,8 +45,8 @@ option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF) IF(ASSIMP_HUNTER_ENABLED) include("cmake/HunterGate.cmake") HunterGate( - URL "https://github.com/ruslo/hunter/archive/v0.23.176.tar.gz" - SHA1 "2e9ae973d028660b735ac4c6142725ca36a0048a" + URL "https://github.com/cpp-pm/hunter/archive/v0.23.261.tar.gz" + SHA1 "1540dad7b97c849784a09e8c452ba811c9f71ba2" ) add_definitions(-DASSIMP_USE_HUNTER) @@ -257,7 +258,11 @@ IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT CMAKE_COMPILER_IS_MINGW) SET(LIBSTDC++_LIBRARIES -lstdc++) ELSEIF(MSVC) # enable multi-core compilation with MSVC - ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX ) + IF( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) # clang-cl + ADD_COMPILE_OPTIONS(/bigobj /W4 /WX ) + ELSE() # msvc + ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX) + ENDIF() # disable "elements of array '' will be default initialized" warning on MSVC2013 IF(MSVC12) ADD_COMPILE_OPTIONS(/wd4351) @@ -357,6 +362,34 @@ IF (NOT TARGET uninstall) ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") ENDIF() +# cmake configuration files +if(${BUILD_SHARED_LIBS}) + set(BUILD_LIB_TYPE SHARED) +else() + set(BUILD_LIB_TYPE STATIC) +endif() + +IF( UNIX ) + # Use GNUInstallDirs for Unix predefined directories + INCLUDE(GNUInstallDirs) + + SET( ASSIMP_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) + SET( ASSIMP_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + SET( ASSIMP_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) +ELSE() + # Cache these to allow the user to override them on non-Unix platforms + SET( ASSIMP_LIB_INSTALL_DIR "lib" CACHE STRING + "Path the built library files are installed to." ) + SET( ASSIMP_INCLUDE_INSTALL_DIR "include" CACHE STRING + "Path the header files are installed to." ) + SET( ASSIMP_BIN_INSTALL_DIR "bin" CACHE STRING + "Path the tool executables are installed to." ) + + SET(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_INCLUDE_INSTALL_DIR}) + SET(CMAKE_INSTALL_FULL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_LIB_INSTALL_DIR}) + SET(CMAKE_INSTALL_FULL_BINDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_BIN_INSTALL_DIR}) +ENDIF() + IF(ASSIMP_HUNTER_ENABLED) set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}") set(INCLUDE_INSTALL_DIR "include") @@ -395,34 +428,6 @@ IF(ASSIMP_HUNTER_ENABLED) DESTINATION "${CONFIG_INSTALL_DIR}" ) ELSE() - # cmake configuration files - if(${BUILD_SHARED_LIBS}) - set(BUILD_LIB_TYPE SHARED) - else() - set(BUILD_LIB_TYPE STATIC) - endif() - - IF( UNIX ) - # Use GNUInstallDirs for Unix predefined directories - INCLUDE(GNUInstallDirs) - - SET( ASSIMP_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) - SET( ASSIMP_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) - SET( ASSIMP_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) - ELSE() - # Cache these to allow the user to override them on non-Unix platforms - SET( ASSIMP_LIB_INSTALL_DIR "lib" CACHE STRING - "Path the built library files are installed to." ) - SET( ASSIMP_INCLUDE_INSTALL_DIR "include" CACHE STRING - "Path the header files are installed to." ) - SET( ASSIMP_BIN_INSTALL_DIR "bin" CACHE STRING - "Path the tool executables are installed to." ) - - SET(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_INCLUDE_INSTALL_DIR}) - SET(CMAKE_INSTALL_FULL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_LIB_INSTALL_DIR}) - SET(CMAKE_INSTALL_FULL_BINDIR ${CMAKE_INSTALL_PREFIX}/${ASSIMP_BIN_INSTALL_DIR}) - ENDIF() - CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/assimp-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/assimp-config.cmake" @ONLY IMMEDIATE) CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/assimpTargets.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/assimpTargets.cmake" @ONLY IMMEDIATE) IF (is_multi_config) diff --git a/cmake/assimp-hunter-config.cmake.in b/cmake/assimp-hunter-config.cmake.in index 34762ac54..8707602e5 100644 --- a/cmake/assimp-hunter-config.cmake.in +++ b/cmake/assimp-hunter-config.cmake.in @@ -2,7 +2,7 @@ find_package(RapidJSON CONFIG REQUIRED) find_package(ZLIB CONFIG REQUIRED) -find_package(utf8 CONFIG REQUIRED) +find_package(utf8cpp CONFIG REQUIRED) find_package(irrXML CONFIG REQUIRED) find_package(minizip CONFIG REQUIRED) find_package(openddlparser CONFIG REQUIRED) diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 3ccb1fd07..a2be07874 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -321,9 +321,10 @@ public: struct Face : public FaceWithSmoothingGroup { }; -#if _MSC_VER > 1920 +#ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4315) -#endif +#endif // _MSC_VER // --------------------------------------------------------------------------- /** Helper structure representing a texture */ @@ -412,6 +413,10 @@ struct Texture { #include +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + // --------------------------------------------------------------------------- /** Helper structure representing a 3ds material */ struct Material { diff --git a/code/AssetLib/AC/ACLoader.cpp b/code/AssetLib/AC/ACLoader.cpp index 5b63d315e..4291ce8d1 100644 --- a/code/AssetLib/AC/ACLoader.cpp +++ b/code/AssetLib/AC/ACLoader.cpp @@ -471,32 +471,33 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, ++node->mNumMeshes; } - switch ((*it).flags & 0xf) { + switch ((*it).GetType()) { // closed line - case 0x1: + case Surface::ClosedLine: needMat[idx].first += (unsigned int)(*it).entries.size(); needMat[idx].second += (unsigned int)(*it).entries.size() << 1u; break; // unclosed line - case 0x2: + case Surface::OpenLine: needMat[idx].first += (unsigned int)(*it).entries.size() - 1; needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; break; // triangle strip - case 0x4: + case Surface::TriangleStrip: needMat[idx].first += (unsigned int)(*it).entries.size() - 2; needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3; break; - // 0 == polygon, else unknown default: - if ((*it).flags & 0xf) { - ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown"); - (*it).flags &= ~(0xf); - } + // Coerce unknowns to a polygon and warn + ASSIMP_LOG_WARN_F("AC3D: The type flag of a surface is unknown: ", (*it).flags); + (*it).flags &= ~(Surface::Mask); + // fallthrough + // polygon + case Surface::Polygon: // the number of faces increments by one, the number // of vertices by surface.numref. needMat[idx].first++; @@ -552,8 +553,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, const Surface &src = *it; // closed polygon - unsigned int type = (*it).flags & 0xf; - if (!type) { + uint8_t type = (*it).GetType(); + if (type == Surface::Polygon) { aiFace &face = *faces++; face.mNumIndices = (unsigned int)src.entries.size(); if (0 != face.mNumIndices) { @@ -576,7 +577,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, } } } - } else if (type == 0x4) { + } else if (type == Surface::TriangleStrip) { for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) { const Surface::SurfaceEntry &entry1 = src.entries[i]; const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; @@ -584,8 +585,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, // 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]) { + object.vertices[entry1.first] == object.vertices[entry3.first] || + object.vertices[entry2.first] == object.vertices[entry3.first]) { mesh->mNumFaces--; mesh->mNumVertices -= 3; continue; @@ -640,7 +641,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, // either a closed or an unclosed line unsigned int tmp = (unsigned int)(*it).entries.size(); - if (0x2 == type) --tmp; + if (Surface::OpenLine == type) --tmp; for (unsigned int m = 0; m < tmp; ++m) { aiFace &face = *faces++; @@ -663,7 +664,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, ++uv; } - if (0x1 == type && tmp - 1 == m) { + if (Surface::ClosedLine == type && tmp - 1 == m) { // if this is a closed line repeat its beginning now it2 = (*it).entries.begin(); } else diff --git a/code/AssetLib/AC/ACLoader.h b/code/AssetLib/AC/ACLoader.h index e330ddf1b..92a5114f1 100644 --- a/code/AssetLib/AC/ACLoader.h +++ b/code/AssetLib/AC/ACLoader.h @@ -69,7 +69,10 @@ public: // Represents an AC3D material struct Material { Material() : - rgb(0.6f, 0.6f, 0.6f), spec(1.f, 1.f, 1.f), shin(0.f), trans(0.f) {} + rgb(0.6f, 0.6f, 0.6f), + spec(1.f, 1.f, 1.f), + shin(0.f), + trans(0.f) {} // base color of the material aiColor3D rgb; @@ -96,18 +99,43 @@ public: // Represents an AC3D surface struct Surface { Surface() : - mat(0), flags(0) {} + mat(0), + flags(0) {} unsigned int mat, flags; typedef std::pair SurfaceEntry; std::vector entries; + + // Type is low nibble of flags + enum Type : uint8_t { + Polygon = 0x0, + ClosedLine = 0x1, + OpenLine = 0x2, + TriangleStrip = 0x4, // ACC extension (TORCS and Speed Dreams) + + Mask = 0xf, + }; + + inline constexpr uint8_t GetType() const { return (flags & Mask); } }; // Represents an AC3D object struct Object { Object() : - type(World), name(""), children(), texture(""), texRepeat(1.f, 1.f), texOffset(0.0f, 0.0f), rotation(), translation(), vertices(), surfaces(), numRefs(0), subDiv(0), crease() {} + type(World), + name(""), + children(), + texture(""), + texRepeat(1.f, 1.f), + texOffset(0.0f, 0.0f), + rotation(), + translation(), + vertices(), + surfaces(), + numRefs(0), + subDiv(0), + crease() {} // Type description enum Type { diff --git a/code/AssetLib/Blender/BlenderTessellator.cpp b/code/AssetLib/Blender/BlenderTessellator.cpp index 3c1cd6ea8..3366d56c5 100644 --- a/code/AssetLib/Blender/BlenderTessellator.cpp +++ b/code/AssetLib/Blender/BlenderTessellator.cpp @@ -386,7 +386,14 @@ void BlenderTessellatorP2T::ReferencePoints( std::vector< Blender::PointP2T >& p // ------------------------------------------------------------------------------------------------ inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& point ) const { +#if defined __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Winvalid-offsetof" +#endif // __clang__ unsigned int pointOffset = offsetof( PointP2T, point2D ); +#if defined __clang__ +# pragma clang diagnostic pop +#endif PointP2T& pointStruct = *reinterpret_cast< PointP2T* >( reinterpret_cast< char* >( &point ) - pointOffset ); if ( pointStruct.magic != static_cast( BLEND_TESS_MAGIC ) ) { @@ -394,7 +401,6 @@ inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& poi } return pointStruct; } - // ------------------------------------------------------------------------------------------------ void BlenderTessellatorP2T::MakeFacesFromTriangles( std::vector< p2t::Triangle* >& triangles ) const { diff --git a/code/AssetLib/IFC/IFCReaderGen_2x3.h b/code/AssetLib/IFC/IFCReaderGen_2x3.h index b3f71a7f1..f87f121b9 100644 --- a/code/AssetLib/IFC/IFCReaderGen_2x3.h +++ b/code/AssetLib/IFC/IFCReaderGen_2x3.h @@ -45,9 +45,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssetLib/Step/STEPFile.h" -#if _MSC_VER > 1920 +#ifdef _MSC_VER +# pragma warning(push) # pragma warning( disable : 4512 ) -#endif // _WIN32 +#endif // _MSC_VER namespace Assimp { namespace IFC { @@ -4372,4 +4373,8 @@ namespace STEP { } //! STEP } //! Assimp +#ifdef _MSC_VER +# pragma warning(pop) +#endif // _MSC_VER + #endif // INCLUDED_IFC_READER_GEN_H diff --git a/code/AssetLib/M3D/m3d.h b/code/AssetLib/M3D/m3d.h index 5ab3d16de..fb980b9c4 100644 --- a/code/AssetLib/M3D/m3d.h +++ b/code/AssetLib/M3D/m3d.h @@ -84,7 +84,7 @@ typedef uint16_t M3D_INDEX; #ifndef M3D_BONEMAXLEVEL #define M3D_BONEMAXLEVEL 8 #endif -#ifndef _MSC_VER +#if !defined(_MSC_VER) || defined(__clang__) #ifndef _inline #define _inline __inline__ #endif @@ -101,13 +101,13 @@ typedef uint16_t M3D_INDEX; #define _register #endif -#if _MSC_VER > 1920 +#if _MSC_VER > 1920 && !defined(__clang__) # pragma warning(push) # pragma warning(disable : 4100 4127 4189 4505 4244 4403 4701 4703) # if (_MSC_VER > 1800 ) # pragma warning(disable : 5573 5744) # endif -#endif // _WIN32 +#endif // _MSC_VER /*** File format structures ***/ @@ -821,7 +821,7 @@ static unsigned char *_m3dstbi__convert_format(unsigned char *data, int img_n, i break; STBI__CASE(4, 3) { dest[0] = src[0], dest[1] = src[1], dest[2] = src[2]; } break; - default: STBI_ASSERT(0); + default: STBI_ASSERT(0); } #undef STBI__CASE } @@ -881,7 +881,7 @@ static _m3dstbi__uint16 *_m3dstbi__convert_format16(_m3dstbi__uint16 *data, int break; STBI__CASE(4, 3) { dest[0] = src[0], dest[1] = src[1], dest[2] = src[2]; } break; - default: STBI_ASSERT(0); + default: STBI_ASSERT(0); } #undef STBI__CASE } @@ -1358,13 +1358,13 @@ static int _m3dstbi__create_png_image_raw(_m3dstbi__png *a, unsigned char *raw, for (k = 0; k < filter_bytes; ++k) { switch (filter) { - case STBI__F_none: cur[k] = raw[k]; break; - case STBI__F_sub: cur[k] = raw[k]; break; - case STBI__F_up: cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; - case STBI__F_avg: cur[k] = STBI__BYTECAST(raw[k] + (prior[k] >> 1)); break; - case STBI__F_paeth: cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(0, prior[k], 0)); break; - case STBI__F_avg_first: cur[k] = raw[k]; break; - case STBI__F_paeth_first: cur[k] = raw[k]; break; + case STBI__F_none: cur[k] = raw[k]; break; + case STBI__F_sub: cur[k] = raw[k]; break; + case STBI__F_up: cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; + case STBI__F_avg: cur[k] = STBI__BYTECAST(raw[k] + (prior[k] >> 1)); break; + case STBI__F_paeth: cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(0, prior[k], 0)); break; + case STBI__F_avg_first: cur[k] = raw[k]; break; + case STBI__F_paeth_first: cur[k] = raw[k]; break; } } @@ -1394,21 +1394,21 @@ static int _m3dstbi__create_png_image_raw(_m3dstbi__png *a, unsigned char *raw, case f: \ for (k = 0; k < nk; ++k) switch (filter) { - case STBI__F_none: - memcpy(cur, raw, nk); - break; - STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k - filter_bytes]); } - break; - STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } - break; - STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k - filter_bytes]) >> 1)); } - break; - STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k - filter_bytes], prior[k], prior[k - filter_bytes])); } - break; - STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k - filter_bytes] >> 1)); } - break; - STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k - filter_bytes], 0, 0)); } - break; + case STBI__F_none: + memcpy(cur, raw, nk); + break; + STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k - filter_bytes]); } + break; + STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } + break; + STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k - filter_bytes]) >> 1)); } + break; + STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k - filter_bytes], prior[k], prior[k - filter_bytes])); } + break; + STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k - filter_bytes] >> 1)); } + break; + STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k - filter_bytes], 0, 0)); } + break; } #undef STBI__CASE raw += nk; @@ -1658,155 +1658,155 @@ static int _m3dstbi__parse_png_file(_m3dstbi__png *z, int scan, int req_comp) { for (;;) { _m3dstbi__pngchunk c = _m3dstbi__get_chunk_header(s); switch (c.type) { - case STBI__PNG_TYPE('C', 'g', 'B', 'I'): - _m3dstbi__skip(s, c.length); - break; - case STBI__PNG_TYPE('I', 'H', 'D', 'R'): { - int comp, filter; - if (!first) return _m3dstbi__err("multiple IHDR", "Corrupt PNG"); - first = 0; - if (c.length != 13) return _m3dstbi__err("bad IHDR len", "Corrupt PNG"); - s->img_x = _m3dstbi__get32be(s); - if (s->img_x > (1 << 24)) return _m3dstbi__err("too large", "Very large image (corrupt?)"); - s->img_y = _m3dstbi__get32be(s); - if (s->img_y > (1 << 24)) return _m3dstbi__err("too large", "Very large image (corrupt?)"); - z->depth = _m3dstbi__get8(s); - if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return _m3dstbi__err("1/2/4/8/16-bit only", "PNG not supported: 1/2/4/8/16-bit only"); - color = _m3dstbi__get8(s); - if (color > 6) return _m3dstbi__err("bad ctype", "Corrupt PNG"); - if (color == 3 && z->depth == 16) return _m3dstbi__err("bad ctype", "Corrupt PNG"); - if (color == 3) - pal_img_n = 3; - else if (color & 1) - return _m3dstbi__err("bad ctype", "Corrupt PNG"); - comp = _m3dstbi__get8(s); - if (comp) return _m3dstbi__err("bad comp method", "Corrupt PNG"); - filter = _m3dstbi__get8(s); - if (filter) return _m3dstbi__err("bad filter method", "Corrupt PNG"); - interlace = _m3dstbi__get8(s); - if (interlace > 1) return _m3dstbi__err("bad interlace method", "Corrupt PNG"); - if (!s->img_x || !s->img_y) return _m3dstbi__err("0-pixel image", "Corrupt PNG"); - if (!pal_img_n) { - s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); - if ((1 << 30) / s->img_x / s->img_n < s->img_y) return _m3dstbi__err("too large", "Image too large to decode"); - if (scan == STBI__SCAN_header) return 1; - } else { - s->img_n = 1; - if ((1 << 30) / s->img_x / 4 < s->img_y) return _m3dstbi__err("too large", "Corrupt PNG"); - } - break; + case STBI__PNG_TYPE('C', 'g', 'B', 'I'): + _m3dstbi__skip(s, c.length); + break; + case STBI__PNG_TYPE('I', 'H', 'D', 'R'): { + int comp, filter; + if (!first) return _m3dstbi__err("multiple IHDR", "Corrupt PNG"); + first = 0; + if (c.length != 13) return _m3dstbi__err("bad IHDR len", "Corrupt PNG"); + s->img_x = _m3dstbi__get32be(s); + if (s->img_x > (1 << 24)) return _m3dstbi__err("too large", "Very large image (corrupt?)"); + s->img_y = _m3dstbi__get32be(s); + if (s->img_y > (1 << 24)) return _m3dstbi__err("too large", "Very large image (corrupt?)"); + z->depth = _m3dstbi__get8(s); + if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return _m3dstbi__err("1/2/4/8/16-bit only", "PNG not supported: 1/2/4/8/16-bit only"); + color = _m3dstbi__get8(s); + if (color > 6) return _m3dstbi__err("bad ctype", "Corrupt PNG"); + if (color == 3 && z->depth == 16) return _m3dstbi__err("bad ctype", "Corrupt PNG"); + if (color == 3) + pal_img_n = 3; + else if (color & 1) + return _m3dstbi__err("bad ctype", "Corrupt PNG"); + comp = _m3dstbi__get8(s); + if (comp) return _m3dstbi__err("bad comp method", "Corrupt PNG"); + filter = _m3dstbi__get8(s); + if (filter) return _m3dstbi__err("bad filter method", "Corrupt PNG"); + interlace = _m3dstbi__get8(s); + if (interlace > 1) return _m3dstbi__err("bad interlace method", "Corrupt PNG"); + if (!s->img_x || !s->img_y) return _m3dstbi__err("0-pixel image", "Corrupt PNG"); + if (!pal_img_n) { + s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); + if ((1 << 30) / s->img_x / s->img_n < s->img_y) return _m3dstbi__err("too large", "Image too large to decode"); + if (scan == STBI__SCAN_header) return 1; + } else { + s->img_n = 1; + if ((1 << 30) / s->img_x / 4 < s->img_y) return _m3dstbi__err("too large", "Corrupt PNG"); } + break; + } - case STBI__PNG_TYPE('P', 'L', 'T', 'E'): { - if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); - if (c.length > 256 * 3) return _m3dstbi__err("invalid PLTE", "Corrupt PNG"); - pal_len = c.length / 3; - if (pal_len * 3 != c.length) return _m3dstbi__err("invalid PLTE", "Corrupt PNG"); - for (i = 0; i < pal_len; ++i) { - palette[i * 4 + 0] = _m3dstbi__get8(s); - palette[i * 4 + 1] = _m3dstbi__get8(s); - palette[i * 4 + 2] = _m3dstbi__get8(s); - palette[i * 4 + 3] = 255; - } - break; + case STBI__PNG_TYPE('P', 'L', 'T', 'E'): { + if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); + if (c.length > 256 * 3) return _m3dstbi__err("invalid PLTE", "Corrupt PNG"); + pal_len = c.length / 3; + if (pal_len * 3 != c.length) return _m3dstbi__err("invalid PLTE", "Corrupt PNG"); + for (i = 0; i < pal_len; ++i) { + palette[i * 4 + 0] = _m3dstbi__get8(s); + palette[i * 4 + 1] = _m3dstbi__get8(s); + palette[i * 4 + 2] = _m3dstbi__get8(s); + palette[i * 4 + 3] = 255; } + break; + } - case STBI__PNG_TYPE('t', 'R', 'N', 'S'): { - if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); - if (z->idata) return _m3dstbi__err("tRNS after IDAT", "Corrupt PNG"); - if (pal_img_n) { - if (scan == STBI__SCAN_header) { - s->img_n = 4; - return 1; - } - if (pal_len == 0) return _m3dstbi__err("tRNS before PLTE", "Corrupt PNG"); - if (c.length > pal_len) return _m3dstbi__err("bad tRNS len", "Corrupt PNG"); - pal_img_n = 4; - for (i = 0; i < c.length; ++i) - palette[i * 4 + 3] = _m3dstbi__get8(s); - } else { - if (!(s->img_n & 1)) return _m3dstbi__err("tRNS with alpha", "Corrupt PNG"); - if (c.length != (_m3dstbi__uint32)s->img_n * 2) return _m3dstbi__err("bad tRNS len", "Corrupt PNG"); - has_trans = 1; - if (z->depth == 16) { - for (k = 0; k < s->img_n; ++k) - tc16[k] = (_m3dstbi__uint16)_m3dstbi__get16be(s); - } else { - for (k = 0; k < s->img_n; ++k) - tc[k] = (unsigned char)(_m3dstbi__get16be(s) & 255) * _m3dstbi__depth_scale_table[z->depth]; - } - } - break; - } - - case STBI__PNG_TYPE('I', 'D', 'A', 'T'): { - if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); - if (pal_img_n && !pal_len) return _m3dstbi__err("no PLTE", "Corrupt PNG"); + case STBI__PNG_TYPE('t', 'R', 'N', 'S'): { + if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); + if (z->idata) return _m3dstbi__err("tRNS after IDAT", "Corrupt PNG"); + if (pal_img_n) { if (scan == STBI__SCAN_header) { - s->img_n = pal_img_n; + s->img_n = 4; return 1; } - if ((int)(ioff + c.length) < (int)ioff) return 0; - if (ioff + c.length > idata_limit) { - _m3dstbi__uint32 idata_limit_old = idata_limit; - unsigned char *p; - if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; - while (ioff + c.length > idata_limit) - idata_limit *= 2; - STBI_NOTUSED(idata_limit_old); - p = (unsigned char *)STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); - if (p == NULL) return _m3dstbi__err("outofmem", "Out of memory"); - z->idata = p; + if (pal_len == 0) return _m3dstbi__err("tRNS before PLTE", "Corrupt PNG"); + if (c.length > pal_len) return _m3dstbi__err("bad tRNS len", "Corrupt PNG"); + pal_img_n = 4; + for (i = 0; i < c.length; ++i) + palette[i * 4 + 3] = _m3dstbi__get8(s); + } else { + if (!(s->img_n & 1)) return _m3dstbi__err("tRNS with alpha", "Corrupt PNG"); + if (c.length != (_m3dstbi__uint32)s->img_n * 2) return _m3dstbi__err("bad tRNS len", "Corrupt PNG"); + has_trans = 1; + if (z->depth == 16) { + for (k = 0; k < s->img_n; ++k) + tc16[k] = (_m3dstbi__uint16)_m3dstbi__get16be(s); + } else { + for (k = 0; k < s->img_n; ++k) + tc[k] = (unsigned char)(_m3dstbi__get16be(s) & 255) * _m3dstbi__depth_scale_table[z->depth]; } - if (!_m3dstbi__getn(s, z->idata + ioff, c.length)) return _m3dstbi__err("outofdata", "Corrupt PNG"); - ioff += c.length; - break; } + break; + } - case STBI__PNG_TYPE('I', 'E', 'N', 'D'): { - _m3dstbi__uint32 raw_len, bpl; - if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); - if (scan != STBI__SCAN_load) return 1; - if (z->idata == NULL) return _m3dstbi__err("no IDAT", "Corrupt PNG"); - bpl = (s->img_x * z->depth + 7) / 8; - raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; - z->expanded = (unsigned char *)_m3dstbi_zlib_decode_malloc_guesssize_headerflag((char *)z->idata, ioff, raw_len, (int *)&raw_len, 1); - if (z->expanded == NULL) return 0; - STBI_FREE(z->idata); - z->idata = NULL; - if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans) - s->img_out_n = s->img_n + 1; - else - s->img_out_n = s->img_n; - if (!_m3dstbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; - if (has_trans) { - if (z->depth == 16) { - if (!_m3dstbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; - } else { - if (!_m3dstbi__compute_transparency(z, tc, s->img_out_n)) return 0; - } - } - if (pal_img_n) { - s->img_n = pal_img_n; - s->img_out_n = pal_img_n; - if (req_comp >= 3) s->img_out_n = req_comp; - if (!_m3dstbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) - return 0; - } else if (has_trans) { - ++s->img_n; - } - STBI_FREE(z->expanded); - z->expanded = NULL; + case STBI__PNG_TYPE('I', 'D', 'A', 'T'): { + if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); + if (pal_img_n && !pal_len) return _m3dstbi__err("no PLTE", "Corrupt PNG"); + if (scan == STBI__SCAN_header) { + s->img_n = pal_img_n; return 1; } + if ((int)(ioff + c.length) < (int)ioff) return 0; + if (ioff + c.length > idata_limit) { + _m3dstbi__uint32 idata_limit_old = idata_limit; + unsigned char *p; + if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; + while (ioff + c.length > idata_limit) + idata_limit *= 2; + STBI_NOTUSED(idata_limit_old); + p = (unsigned char *)STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); + if (p == NULL) return _m3dstbi__err("outofmem", "Out of memory"); + z->idata = p; + } + if (!_m3dstbi__getn(s, z->idata + ioff, c.length)) return _m3dstbi__err("outofdata", "Corrupt PNG"); + ioff += c.length; + break; + } - default: - if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); - if ((c.type & (1 << 29)) == 0) { - return _m3dstbi__err("invalid_chunk", "PNG not supported: unknown PNG chunk type"); + case STBI__PNG_TYPE('I', 'E', 'N', 'D'): { + _m3dstbi__uint32 raw_len, bpl; + if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); + if (scan != STBI__SCAN_load) return 1; + if (z->idata == NULL) return _m3dstbi__err("no IDAT", "Corrupt PNG"); + bpl = (s->img_x * z->depth + 7) / 8; + raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; + z->expanded = (unsigned char *)_m3dstbi_zlib_decode_malloc_guesssize_headerflag((char *)z->idata, ioff, raw_len, (int *)&raw_len, 1); + if (z->expanded == NULL) return 0; + STBI_FREE(z->idata); + z->idata = NULL; + if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans) + s->img_out_n = s->img_n + 1; + else + s->img_out_n = s->img_n; + if (!_m3dstbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; + if (has_trans) { + if (z->depth == 16) { + if (!_m3dstbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; + } else { + if (!_m3dstbi__compute_transparency(z, tc, s->img_out_n)) return 0; } - _m3dstbi__skip(s, c.length); - break; + } + if (pal_img_n) { + s->img_n = pal_img_n; + s->img_out_n = pal_img_n; + if (req_comp >= 3) s->img_out_n = req_comp; + if (!_m3dstbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) + return 0; + } else if (has_trans) { + ++s->img_n; + } + STBI_FREE(z->expanded); + z->expanded = NULL; + return 1; + } + + default: + if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); + if ((c.type & (1 << 29)) == 0) { + return _m3dstbi__err("invalid_chunk", "PNG not supported: unknown PNG chunk type"); + } + _m3dstbi__skip(s, c.length); + break; } _m3dstbi__get32be(s); } @@ -2283,18 +2283,18 @@ void _m3d_getpr(m3d_t *model, _unused m3dread_t readfilecb, _unused m3dfree_t fr } while (0) _inline static unsigned char *_m3d_getidx(unsigned char *data, char type, M3D_INDEX *idx) { switch (type) { - case 1: - *idx = data[0] > 253 ? (int8_t)data[0] : data[0]; - data++; - break; - case 2: - *idx = *((uint16_t *)data) > 65533 ? *((int16_t *)data) : *((uint16_t *)data); - data += 2; - break; - case 4: - *idx = *((int32_t *)data); - data += 4; - break; + case 1: + *idx = data[0] > 253 ? (int8_t)data[0] : data[0]; + data++; + break; + case 2: + *idx = *((uint16_t *)data) > 65533 ? *((int16_t *)data) : *((uint16_t *)data); + data += 2; + break; + case 4: + *idx = *((int32_t *)data); + data += 4; + break; } return data; } @@ -2682,27 +2682,27 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d if (!m->prop) goto memerr; m->prop[j].type = n + (k == m3dpf_map && n < 128 ? 128 : 0); switch (k) { - case m3dpf_color: ptr = _m3d_gethex(ptr, &m->prop[j].value.color); break; - case m3dpf_uint8: - case m3dpf_uint16: - case m3dpf_uint32: ptr = _m3d_getint(ptr, &m->prop[j].value.num); break; - case m3dpf_float: ptr = _m3d_getfloat(ptr, &m->prop[j].value.fnum); break; - case m3dpf_map: - pe = _m3d_safestr(ptr, 0); - if (!pe || !*pe) goto asciiend; - m->prop[j].value.textureid = _m3d_gettx(model, readfilecb, freecb, pe); - if (model->errcode == M3D_ERR_ALLOC) { - M3D_FREE(pe); - goto memerr; - } - /* this error code only returned if readfilecb was specified */ - if (m->prop[j].value.textureid == M3D_UNDEF) { - M3D_LOG("Texture not found"); - M3D_LOG(pe); - m->numprop--; - } + case m3dpf_color: ptr = _m3d_gethex(ptr, &m->prop[j].value.color); break; + case m3dpf_uint8: + case m3dpf_uint16: + case m3dpf_uint32: ptr = _m3d_getint(ptr, &m->prop[j].value.num); break; + case m3dpf_float: ptr = _m3d_getfloat(ptr, &m->prop[j].value.fnum); break; + case m3dpf_map: + pe = _m3d_safestr(ptr, 0); + if (!pe || !*pe) goto asciiend; + m->prop[j].value.textureid = _m3d_gettx(model, readfilecb, freecb, pe); + if (model->errcode == M3D_ERR_ALLOC) { M3D_FREE(pe); - break; + goto memerr; + } + /* this error code only returned if readfilecb was specified */ + if (m->prop[j].value.textureid == M3D_UNDEF) { + M3D_LOG("Texture not found"); + M3D_LOG(pe); + m->numprop--; + } + M3D_FREE(pe); + break; } } else { M3D_LOG("Unknown material property in"); @@ -2835,48 +2835,48 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d } if (*ptr == ']' || *ptr == '\r' || *ptr == '\n') break; switch (cd->a[((k - n) % (cd->p - n)) + n]) { - case m3dcp_mi_t: - mi = M3D_UNDEF; - if (*ptr != '\r' && *ptr != '\n') { - pe = _m3d_safestr(ptr, 0); - if (!pe || !*pe) goto asciiend; - for (n = 0; n < model->nummaterial; n++) - if (!strcmp(pe, model->material[n].name)) { - mi = (M3D_INDEX)n; - break; - } - if (mi == M3D_UNDEF && !(model->flags & M3D_FLG_MTLLIB)) { - mi = model->nummaterial++; - model->material = (m3dm_t *)M3D_REALLOC(model->material, - model->nummaterial * sizeof(m3dm_t)); - if (!model->material) goto memerr; - model->material[mi].name = pe; - model->material[mi].numprop = 1; - model->material[mi].prop = NULL; - } else - M3D_FREE(pe); - } - h->cmd[j].arg[k] = mi; - break; - case m3dcp_vc_t: - _m3d_getfloat(ptr, &w); - h->cmd[j].arg[k] = *((uint32_t *)&w); - break; - case m3dcp_va_t: - ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); - n = k + 1; - l += (h->cmd[j].arg[k] - 1) * (cd->p - k - 1); - h->cmd[j].arg = (uint32_t *)M3D_REALLOC(h->cmd[j].arg, l * sizeof(uint32_t)); - if (!h->cmd[j].arg) goto memerr; - memset(&h->cmd[j].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); - break; - case m3dcp_qi_t: - ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); - model->vertex[h->cmd[i].arg[k]].skinid = M3D_INDEXMAX; - break; - default: - ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); - break; + case m3dcp_mi_t: + mi = M3D_UNDEF; + if (*ptr != '\r' && *ptr != '\n') { + pe = _m3d_safestr(ptr, 0); + if (!pe || !*pe) goto asciiend; + for (n = 0; n < model->nummaterial; n++) + if (!strcmp(pe, model->material[n].name)) { + mi = (M3D_INDEX)n; + break; + } + if (mi == M3D_UNDEF && !(model->flags & M3D_FLG_MTLLIB)) { + mi = model->nummaterial++; + model->material = (m3dm_t *)M3D_REALLOC(model->material, + model->nummaterial * sizeof(m3dm_t)); + if (!model->material) goto memerr; + model->material[mi].name = pe; + model->material[mi].numprop = 1; + model->material[mi].prop = NULL; + } else + M3D_FREE(pe); + } + h->cmd[j].arg[k] = mi; + break; + case m3dcp_vc_t: + _m3d_getfloat(ptr, &w); + h->cmd[j].arg[k] = *((uint32_t *)&w); + break; + case m3dcp_va_t: + ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); + n = k + 1; + l += (h->cmd[j].arg[k] - 1) * (cd->p - k - 1); + h->cmd[j].arg = (uint32_t *)M3D_REALLOC(h->cmd[j].arg, l * sizeof(uint32_t)); + if (!h->cmd[j].arg) goto memerr; + memset(&h->cmd[j].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); + break; + case m3dcp_qi_t: + ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); + model->vertex[h->cmd[i].arg[k]].skinid = M3D_INDEXMAX; + break; + default: + ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); + break; } } } else { @@ -3207,22 +3207,22 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d if (!model->tmap) goto memerr; for (i = 0, data += sizeof(m3dchunk_t); data < chunk; i++) { switch (model->vc_s) { - case 1: - model->tmap[i].u = (M3D_FLOAT)(data[0]) / (M3D_FLOAT)255.0; - model->tmap[i].v = (M3D_FLOAT)(data[1]) / (M3D_FLOAT)255.0; - break; - case 2: - model->tmap[i].u = (M3D_FLOAT)(*((int16_t *)(data + 0))) / (M3D_FLOAT)65535.0; - model->tmap[i].v = (M3D_FLOAT)(*((int16_t *)(data + 2))) / (M3D_FLOAT)65535.0; - break; - case 4: - model->tmap[i].u = (M3D_FLOAT)(*((float *)(data + 0))); - model->tmap[i].v = (M3D_FLOAT)(*((float *)(data + 4))); - break; - case 8: - model->tmap[i].u = (M3D_FLOAT)(*((double *)(data + 0))); - model->tmap[i].v = (M3D_FLOAT)(*((double *)(data + 8))); - break; + case 1: + model->tmap[i].u = (M3D_FLOAT)(data[0]) / (M3D_FLOAT)255.0; + model->tmap[i].v = (M3D_FLOAT)(data[1]) / (M3D_FLOAT)255.0; + break; + case 2: + model->tmap[i].u = (M3D_FLOAT)(*((int16_t *)(data + 0))) / (M3D_FLOAT)65535.0; + model->tmap[i].v = (M3D_FLOAT)(*((int16_t *)(data + 2))) / (M3D_FLOAT)65535.0; + break; + case 4: + model->tmap[i].u = (M3D_FLOAT)(*((float *)(data + 0))); + model->tmap[i].v = (M3D_FLOAT)(*((float *)(data + 4))); + break; + case 8: + model->tmap[i].u = (M3D_FLOAT)(*((double *)(data + 0))); + model->tmap[i].v = (M3D_FLOAT)(*((double *)(data + 8))); + break; } data += reclen; } @@ -3243,49 +3243,49 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d memset(model->vertex, 0, model->numvertex * sizeof(m3dv_t)); for (i = 0, data += sizeof(m3dchunk_t); data < chunk && i < model->numvertex; i++) { switch (model->vc_s) { - case 1: - model->vertex[i].x = (M3D_FLOAT)((int8_t)data[0]) / (M3D_FLOAT)127.0; - model->vertex[i].y = (M3D_FLOAT)((int8_t)data[1]) / (M3D_FLOAT)127.0; - model->vertex[i].z = (M3D_FLOAT)((int8_t)data[2]) / (M3D_FLOAT)127.0; - model->vertex[i].w = (M3D_FLOAT)((int8_t)data[3]) / (M3D_FLOAT)127.0; - data += 4; - break; - case 2: - model->vertex[i].x = (M3D_FLOAT)(*((int16_t *)(data + 0))) / (M3D_FLOAT)32767.0; - model->vertex[i].y = (M3D_FLOAT)(*((int16_t *)(data + 2))) / (M3D_FLOAT)32767.0; - model->vertex[i].z = (M3D_FLOAT)(*((int16_t *)(data + 4))) / (M3D_FLOAT)32767.0; - model->vertex[i].w = (M3D_FLOAT)(*((int16_t *)(data + 6))) / (M3D_FLOAT)32767.0; - data += 8; - break; - case 4: - model->vertex[i].x = (M3D_FLOAT)(*((float *)(data + 0))); - model->vertex[i].y = (M3D_FLOAT)(*((float *)(data + 4))); - model->vertex[i].z = (M3D_FLOAT)(*((float *)(data + 8))); - model->vertex[i].w = (M3D_FLOAT)(*((float *)(data + 12))); - data += 16; - break; - case 8: - model->vertex[i].x = (M3D_FLOAT)(*((double *)(data + 0))); - model->vertex[i].y = (M3D_FLOAT)(*((double *)(data + 8))); - model->vertex[i].z = (M3D_FLOAT)(*((double *)(data + 16))); - model->vertex[i].w = (M3D_FLOAT)(*((double *)(data + 24))); - data += 32; - break; + case 1: + model->vertex[i].x = (M3D_FLOAT)((int8_t)data[0]) / (M3D_FLOAT)127.0; + model->vertex[i].y = (M3D_FLOAT)((int8_t)data[1]) / (M3D_FLOAT)127.0; + model->vertex[i].z = (M3D_FLOAT)((int8_t)data[2]) / (M3D_FLOAT)127.0; + model->vertex[i].w = (M3D_FLOAT)((int8_t)data[3]) / (M3D_FLOAT)127.0; + data += 4; + break; + case 2: + model->vertex[i].x = (M3D_FLOAT)(*((int16_t *)(data + 0))) / (M3D_FLOAT)32767.0; + model->vertex[i].y = (M3D_FLOAT)(*((int16_t *)(data + 2))) / (M3D_FLOAT)32767.0; + model->vertex[i].z = (M3D_FLOAT)(*((int16_t *)(data + 4))) / (M3D_FLOAT)32767.0; + model->vertex[i].w = (M3D_FLOAT)(*((int16_t *)(data + 6))) / (M3D_FLOAT)32767.0; + data += 8; + break; + case 4: + model->vertex[i].x = (M3D_FLOAT)(*((float *)(data + 0))); + model->vertex[i].y = (M3D_FLOAT)(*((float *)(data + 4))); + model->vertex[i].z = (M3D_FLOAT)(*((float *)(data + 8))); + model->vertex[i].w = (M3D_FLOAT)(*((float *)(data + 12))); + data += 16; + break; + case 8: + model->vertex[i].x = (M3D_FLOAT)(*((double *)(data + 0))); + model->vertex[i].y = (M3D_FLOAT)(*((double *)(data + 8))); + model->vertex[i].z = (M3D_FLOAT)(*((double *)(data + 16))); + model->vertex[i].w = (M3D_FLOAT)(*((double *)(data + 24))); + data += 32; + break; } switch (model->ci_s) { - case 1: - model->vertex[i].color = model->cmap ? model->cmap[data[0]] : 0; - data++; - break; - case 2: - model->vertex[i].color = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; - data += 2; - break; - case 4: - model->vertex[i].color = *((uint32_t *)data); - data += 4; - break; - /* case 8: break; */ + case 1: + model->vertex[i].color = model->cmap ? model->cmap[data[0]] : 0; + data++; + break; + case 2: + model->vertex[i].color = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; + data += 2; + break; + case 4: + model->vertex[i].color = *((uint32_t *)data); + data += 4; + break; + /* case 8: break; */ } model->vertex[i].skinid = M3D_UNDEF; data = _m3d_getidx(data, model->sk_s, &model->vertex[i].skinid); @@ -3414,55 +3414,55 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d } } switch (k) { - case m3dpf_color: - switch (model->ci_s) { - case 1: - m->prop[i].value.color = model->cmap ? model->cmap[data[0]] : 0; - data++; - break; - case 2: - m->prop[i].value.color = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; - data += 2; - break; - case 4: - m->prop[i].value.color = *((uint32_t *)data); - data += 4; - break; - } + case m3dpf_color: + switch (model->ci_s) { + case 1: + m->prop[i].value.color = model->cmap ? model->cmap[data[0]] : 0; + data++; break; - - case m3dpf_uint8: m->prop[i].value.num = *data++; break; - case m3dpf_uint16: - m->prop[i].value.num = *((uint16_t *)data); + case 2: + m->prop[i].value.color = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; data += 2; break; - case m3dpf_uint32: - m->prop[i].value.num = *((uint32_t *)data); - data += 4; - break; - case m3dpf_float: - m->prop[i].value.fnum = *((float *)data); + case 4: + m->prop[i].value.color = *((uint32_t *)data); data += 4; break; + } + break; - case m3dpf_map: - M3D_GETSTR(name); - m->prop[i].value.textureid = _m3d_gettx(model, readfilecb, freecb, name); - if (model->errcode == M3D_ERR_ALLOC) goto memerr; - /* this error code only returned if readfilecb was specified */ - if (m->prop[i].value.textureid == M3D_UNDEF) { - M3D_LOG("Texture not found"); - M3D_LOG(m->name); - m->numprop--; - } - break; + case m3dpf_uint8: m->prop[i].value.num = *data++; break; + case m3dpf_uint16: + m->prop[i].value.num = *((uint16_t *)data); + data += 2; + break; + case m3dpf_uint32: + m->prop[i].value.num = *((uint32_t *)data); + data += 4; + break; + case m3dpf_float: + m->prop[i].value.fnum = *((float *)data); + data += 4; + break; - default: - M3D_LOG("Unknown material property in"); + case m3dpf_map: + M3D_GETSTR(name); + m->prop[i].value.textureid = _m3d_gettx(model, readfilecb, freecb, name); + if (model->errcode == M3D_ERR_ALLOC) goto memerr; + /* this error code only returned if readfilecb was specified */ + if (m->prop[i].value.textureid == M3D_UNDEF) { + M3D_LOG("Texture not found"); M3D_LOG(m->name); - model->errcode = M3D_ERR_UNKPROP; - data = chunk; - break; + m->numprop--; + } + break; + + default: + M3D_LOG("Unknown material property in"); + M3D_LOG(m->name); + model->errcode = M3D_ERR_UNKPROP; + data = chunk; + break; } } m->prop = (m3dp_t *)M3D_REALLOC(m->prop, m->numprop * sizeof(m3dp_t)); @@ -3570,45 +3570,45 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d memset(h->cmd[i].arg, 0, cd->p * sizeof(uint32_t)); for (k = n = 0, l = cd->p; k < l; k++) switch (cd->a[((k - n) % (cd->p - n)) + n]) { - case m3dcp_mi_t: - h->cmd[i].arg[k] = M3D_NOTDEFINED; - M3D_GETSTR(name); - if (name) { - for (n = 0; n < model->nummaterial; n++) - if (!strcmp(name, model->material[n].name)) { - h->cmd[i].arg[k] = n; - break; - } - if (h->cmd[i].arg[k] == M3D_NOTDEFINED) model->errcode = M3D_ERR_MTRL; - } - break; - case m3dcp_vc_t: - f = 0.0f; - switch (model->vc_s) { - case 1: f = (float)((int8_t)data[0]) / 127; break; - case 2: f = (float)(*((int16_t *)(data + 0))) / 32767; break; - case 4: f = (float)(*((float *)(data + 0))); break; - case 8: f = (float)(*((double *)(data + 0))); break; - } - h->cmd[i].arg[k] = *((uint32_t *)&f); - data += model->vc_s; - break; - case m3dcp_hi_t: data = _m3d_getidx(data, model->hi_s, &h->cmd[i].arg[k]); break; - case m3dcp_fi_t: data = _m3d_getidx(data, model->fi_s, &h->cmd[i].arg[k]); break; - case m3dcp_ti_t: data = _m3d_getidx(data, model->ti_s, &h->cmd[i].arg[k]); break; - case m3dcp_qi_t: - case m3dcp_vi_t: data = _m3d_getidx(data, model->vi_s, &h->cmd[i].arg[k]); break; - case m3dcp_i1_t: data = _m3d_getidx(data, 1, &h->cmd[i].arg[k]); break; - case m3dcp_i2_t: data = _m3d_getidx(data, 2, &h->cmd[i].arg[k]); break; - case m3dcp_i4_t: data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); break; - case m3dcp_va_t: - data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); - n = k + 1; - l += (h->cmd[i].arg[k] - 1) * (cd->p - k - 1); - h->cmd[i].arg = (uint32_t *)M3D_REALLOC(h->cmd[i].arg, l * sizeof(uint32_t)); - if (!h->cmd[i].arg) goto memerr; - memset(&h->cmd[i].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); - break; + case m3dcp_mi_t: + h->cmd[i].arg[k] = M3D_NOTDEFINED; + M3D_GETSTR(name); + if (name) { + for (n = 0; n < model->nummaterial; n++) + if (!strcmp(name, model->material[n].name)) { + h->cmd[i].arg[k] = n; + break; + } + if (h->cmd[i].arg[k] == M3D_NOTDEFINED) model->errcode = M3D_ERR_MTRL; + } + break; + case m3dcp_vc_t: + f = 0.0f; + switch (model->vc_s) { + case 1: f = (float)((int8_t)data[0]) / 127; break; + case 2: f = (float)(*((int16_t *)(data + 0))) / 32767; break; + case 4: f = (float)(*((float *)(data + 0))); break; + case 8: f = (float)(*((double *)(data + 0))); break; + } + h->cmd[i].arg[k] = *((uint32_t *)&f); + data += model->vc_s; + break; + case m3dcp_hi_t: data = _m3d_getidx(data, model->hi_s, &h->cmd[i].arg[k]); break; + case m3dcp_fi_t: data = _m3d_getidx(data, model->fi_s, &h->cmd[i].arg[k]); break; + case m3dcp_ti_t: data = _m3d_getidx(data, model->ti_s, &h->cmd[i].arg[k]); break; + case m3dcp_qi_t: + case m3dcp_vi_t: data = _m3d_getidx(data, model->vi_s, &h->cmd[i].arg[k]); break; + case m3dcp_i1_t: data = _m3d_getidx(data, 1, &h->cmd[i].arg[k]); break; + case m3dcp_i2_t: data = _m3d_getidx(data, 2, &h->cmd[i].arg[k]); break; + case m3dcp_i4_t: data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); break; + case m3dcp_va_t: + data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); + n = k + 1; + l += (h->cmd[i].arg[k] - 1) * (cd->p - k - 1); + h->cmd[i].arg = (uint32_t *)M3D_REALLOC(h->cmd[i].arg, l * sizeof(uint32_t)); + if (!h->cmd[i].arg) goto memerr; + memset(&h->cmd[i].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); + break; } } } else @@ -3627,19 +3627,19 @@ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d if (model->ci_s && model->ci_s < 4 && !model->cmap) model->errcode = M3D_ERR_CMAP; k = 0; switch (model->ci_s) { - case 1: - k = model->cmap ? model->cmap[data[0]] : 0; - data++; - break; - case 2: - k = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; - data += 2; - break; - case 4: - k = *((uint32_t *)data); - data += 4; - break; - /* case 8: break; */ + case 1: + k = model->cmap ? model->cmap[data[0]] : 0; + data++; + break; + case 2: + k = model->cmap ? model->cmap[*((uint16_t *)data)] : 0; + data += 2; + break; + case 4: + k = *((uint32_t *)data); + data += 4; + break; + /* case 8: break; */ } reclen = model->vi_s + model->si_s; i = model->numlabel; @@ -4267,16 +4267,16 @@ static uint32_t _m3d_cmapidx(uint32_t *cmap, uint32_t numcmap, uint32_t color) { /* add index to output */ static unsigned char *_m3d_addidx(unsigned char *out, char type, uint32_t idx) { switch (type) { - case 1: *out++ = (uint8_t)(idx); break; - case 2: - *((uint16_t *)out) = (uint16_t)(idx); - out += 2; - break; - case 4: - *((uint32_t *)out) = (uint32_t)(idx); - out += 4; - break; - /* case 0: case 8: break; */ + case 1: *out++ = (uint8_t)(idx); break; + case 2: + *((uint16_t *)out) = (uint16_t)(idx); + out += 2; + break; + case 4: + *((uint32_t *)out) = (uint32_t)(idx); + out += 4; + break; + /* case 0: case 8: break; */ } return out; } @@ -4288,26 +4288,26 @@ static void _m3d_round(int quality, m3dv_t *src, m3dv_t *dst) { if (src != dst) memcpy(dst, src, sizeof(m3dv_t)); /* round according to quality */ switch (quality) { - case M3D_EXP_INT8: - t = (int)(src->x * 127 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->x = (M3D_FLOAT)t / (M3D_FLOAT)127.0; - t = (int)(src->y * 127 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->y = (M3D_FLOAT)t / (M3D_FLOAT)127.0; - t = (int)(src->z * 127 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->z = (M3D_FLOAT)t / (M3D_FLOAT)127.0; - t = (int)(src->w * 127 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->w = (M3D_FLOAT)t / (M3D_FLOAT)127.0; - break; - case M3D_EXP_INT16: - t = (int)(src->x * 32767 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->x = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; - t = (int)(src->y * 32767 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->y = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; - t = (int)(src->z * 32767 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->z = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; - t = (int)(src->w * 32767 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); - dst->w = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; - break; + case M3D_EXP_INT8: + t = (int)(src->x * 127 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->x = (M3D_FLOAT)t / (M3D_FLOAT)127.0; + t = (int)(src->y * 127 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->y = (M3D_FLOAT)t / (M3D_FLOAT)127.0; + t = (int)(src->z * 127 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->z = (M3D_FLOAT)t / (M3D_FLOAT)127.0; + t = (int)(src->w * 127 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->w = (M3D_FLOAT)t / (M3D_FLOAT)127.0; + break; + case M3D_EXP_INT16: + t = (int)(src->x * 32767 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->x = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; + t = (int)(src->y * 32767 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->y = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; + t = (int)(src->z * 32767 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->z = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; + t = (int)(src->w * 32767 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); + dst->w = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; + break; } if (dst->x == (M3D_FLOAT)-0.0) dst->x = (M3D_FLOAT)0.0; if (dst->y == (M3D_FLOAT)-0.0) dst->y = (M3D_FLOAT)0.0; @@ -4484,23 +4484,23 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size cd = &m3d_commandtypes[cmd->type]; for (k = n = 0, l = cd->p; k < l; k++) switch (cd->a[((k - n) % (cd->p - n)) + n]) { - case m3dcp_mi_t: - if (!(flags & M3D_EXP_NOMATERIAL) && cmd->arg[k] < model->nummaterial) - mtrlidx[cmd->arg[k]] = 0; - break; - case m3dcp_ti_t: - if (!(flags & M3D_EXP_NOTXTCRD) && cmd->arg[k] < model->numtmap) - tmapidx[cmd->arg[k]] = 0; - break; - case m3dcp_qi_t: - case m3dcp_vi_t: - if (cmd->arg[k] < model->numvertex) - vrtxidx[cmd->arg[k]] = 0; - break; - case m3dcp_va_t: - n = k + 1; - l += (cmd->arg[k] - 1) * (cd->p - k - 1); - break; + case m3dcp_mi_t: + if (!(flags & M3D_EXP_NOMATERIAL) && cmd->arg[k] < model->nummaterial) + mtrlidx[cmd->arg[k]] = 0; + break; + case m3dcp_ti_t: + if (!(flags & M3D_EXP_NOTXTCRD) && cmd->arg[k] < model->numtmap) + tmapidx[cmd->arg[k]] = 0; + break; + case m3dcp_qi_t: + case m3dcp_vi_t: + if (cmd->arg[k] < model->numvertex) + vrtxidx[cmd->arg[k]] = 0; + break; + case m3dcp_va_t: + n = k + 1; + l += (cmd->arg[k] - 1) * (cd->p - k - 1); + break; } } } @@ -4615,22 +4615,22 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size for (i = 0; i < model->numtmap; i++) { if (tmapidx[i] == M3D_UNDEF) continue; switch (quality) { - case M3D_EXP_INT8: - l = (unsigned int)(model->tmap[i].u * 255); - tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)255.0; - l = (unsigned int)(model->tmap[i].v * 255); - tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)255.0; - break; - case M3D_EXP_INT16: - l = (unsigned int)(model->tmap[i].u * 65535); - tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; - l = (unsigned int)(model->tmap[i].v * 65535); - tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; - break; - default: - tcoord.data.u = model->tmap[i].u; - tcoord.data.v = model->tmap[i].v; - break; + case M3D_EXP_INT8: + l = (unsigned int)(model->tmap[i].u * 255); + tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)255.0; + l = (unsigned int)(model->tmap[i].v * 255); + tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)255.0; + break; + case M3D_EXP_INT16: + l = (unsigned int)(model->tmap[i].u * 65535); + tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; + l = (unsigned int)(model->tmap[i].v * 65535); + tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; + break; + default: + tcoord.data.u = model->tmap[i].u; + tcoord.data.v = model->tmap[i].v; + break; } if (flags & M3D_EXP_FLIPTXTCRD) tcoord.data.v = (M3D_FLOAT)1.0 - tcoord.data.v; @@ -4959,26 +4959,26 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size } } switch (k) { - case m3dpf_color: ptr += sprintf(ptr, "%s #%08x\r\n", sn, m->prop[i].value.color); break; - case m3dpf_uint8: - case m3dpf_uint16: - case m3dpf_uint32: ptr += sprintf(ptr, "%s %d\r\n", sn, m->prop[i].value.num); break; - case m3dpf_float: ptr += sprintf(ptr, "%s %g\r\n", sn, m->prop[i].value.fnum); break; - case m3dpf_map: - if (m->prop[i].value.textureid < model->numtexture && - model->texture[m->prop[i].value.textureid].name) { - sl = _m3d_safestr(model->texture[m->prop[i].value.textureid].name, 0); - if (!sl) { - setlocale(LC_NUMERIC, ol); - goto memerr; - } - if (*sl) - ptr += sprintf(ptr, "map_%s %s\r\n", sn, sl); - M3D_FREE(sn); - M3D_FREE(sl); - sl = NULL; + case m3dpf_color: ptr += sprintf(ptr, "%s #%08x\r\n", sn, m->prop[i].value.color); break; + case m3dpf_uint8: + case m3dpf_uint16: + case m3dpf_uint32: ptr += sprintf(ptr, "%s %d\r\n", sn, m->prop[i].value.num); break; + case m3dpf_float: ptr += sprintf(ptr, "%s %g\r\n", sn, m->prop[i].value.fnum); break; + case m3dpf_map: + if (m->prop[i].value.textureid < model->numtexture && + model->texture[m->prop[i].value.textureid].name) { + sl = _m3d_safestr(model->texture[m->prop[i].value.textureid].name, 0); + if (!sl) { + setlocale(LC_NUMERIC, ol); + goto memerr; } - break; + if (*sl) + ptr += sprintf(ptr, "map_%s %s\r\n", sn, sl); + M3D_FREE(sn); + M3D_FREE(sl); + sl = NULL; + } + break; } sn = NULL; } @@ -5102,16 +5102,16 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(cd->key) + (uintptr_t)3); for (k = 0; k < cd->p; k++) switch (cd->a[k]) { - case m3dcp_mi_t: - if (cmd->arg[k] != M3D_NOTDEFINED) { - len += (unsigned int)strlen(model->material[cmd->arg[k]].name) + 1; - } - break; - case m3dcp_va_t: - len += cmd->arg[k] * (cd->p - k - 1) * 16; - k = cd->p; - break; - default: len += 16; break; + case m3dcp_mi_t: + if (cmd->arg[k] != M3D_NOTDEFINED) { + len += (unsigned int)strlen(model->material[cmd->arg[k]].name) + 1; + } + break; + case m3dcp_va_t: + len += cmd->arg[k] * (cd->p - k - 1) * 16; + k = cd->p; + break; + default: len += 16; break; } out = (unsigned char *)M3D_REALLOC(out, len); ptr += (uintptr_t)out; @@ -5122,25 +5122,25 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size ptr += sprintf(ptr, "%s", cd->key); for (k = n = 0, l = cd->p; k < l; k++) { switch (cd->a[((k - n) % (cd->p - n)) + n]) { - case m3dcp_mi_t: - if (cmd->arg[k] != M3D_NOTDEFINED) { - sn = _m3d_safestr(model->material[cmd->arg[k]].name, 0); - if (!sn) { - setlocale(LC_NUMERIC, ol); - goto memerr; - } - ptr += sprintf(ptr, " %s", sn); - M3D_FREE(sn); - sn = NULL; + case m3dcp_mi_t: + if (cmd->arg[k] != M3D_NOTDEFINED) { + sn = _m3d_safestr(model->material[cmd->arg[k]].name, 0); + if (!sn) { + setlocale(LC_NUMERIC, ol); + goto memerr; } - break; - case m3dcp_vc_t: ptr += sprintf(ptr, " %g", *((float *)&cmd->arg[k])); break; - case m3dcp_va_t: - ptr += sprintf(ptr, " %d[", cmd->arg[k]); - n = k + 1; - l += (cmd->arg[k] - 1) * (cd->p - k - 1); - break; - default: ptr += sprintf(ptr, " %d", cmd->arg[k]); break; + ptr += sprintf(ptr, " %s", sn); + M3D_FREE(sn); + sn = NULL; + } + break; + case m3dcp_vc_t: ptr += sprintf(ptr, " %g", *((float *)&cmd->arg[k])); break; + case m3dcp_va_t: + ptr += sprintf(ptr, " %d[", cmd->arg[k]); + n = k + 1; + l += (cmd->arg[k] - 1) * (cd->p - k - 1); + break; + default: ptr += sprintf(ptr, " %d", cmd->arg[k]); break; } } ptr += sprintf(ptr, "%s\r\n", l > cd->p ? " ]" : ""); @@ -5384,28 +5384,28 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size if (tmap[i].newidx == last) continue; last = tmap[i].newidx; switch (vc_s) { - case 1: - *out++ = (uint8_t)(tmap[i].data.u * 255); - *out++ = (uint8_t)(tmap[i].data.v * 255); - break; - case 2: - *((uint16_t *)out) = (uint16_t)(tmap[i].data.u * 65535); - out += 2; - *((uint16_t *)out) = (uint16_t)(tmap[i].data.v * 65535); - out += 2; - break; - case 4: - *((float *)out) = tmap[i].data.u; - out += 4; - *((float *)out) = tmap[i].data.v; - out += 4; - break; - case 8: - *((double *)out) = tmap[i].data.u; - out += 8; - *((double *)out) = tmap[i].data.v; - out += 8; - break; + case 1: + *out++ = (uint8_t)(tmap[i].data.u * 255); + *out++ = (uint8_t)(tmap[i].data.v * 255); + break; + case 2: + *((uint16_t *)out) = (uint16_t)(tmap[i].data.u * 65535); + out += 2; + *((uint16_t *)out) = (uint16_t)(tmap[i].data.v * 65535); + out += 2; + break; + case 4: + *((float *)out) = tmap[i].data.u; + out += 4; + *((float *)out) = tmap[i].data.v; + out += 4; + break; + case 8: + *((double *)out) = tmap[i].data.u; + out += 8; + *((double *)out) = tmap[i].data.v; + out += 8; + break; } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len)); @@ -5425,54 +5425,54 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size if (vrtx[i].newidx == last) continue; last = vrtx[i].newidx; switch (vc_s) { - case 1: - *out++ = (int8_t)(vrtx[i].data.x * 127); - *out++ = (int8_t)(vrtx[i].data.y * 127); - *out++ = (int8_t)(vrtx[i].data.z * 127); - *out++ = (int8_t)(vrtx[i].data.w * 127); - break; - case 2: - *((int16_t *)out) = (int16_t)(vrtx[i].data.x * 32767); - out += 2; - *((int16_t *)out) = (int16_t)(vrtx[i].data.y * 32767); - out += 2; - *((int16_t *)out) = (int16_t)(vrtx[i].data.z * 32767); - out += 2; - *((int16_t *)out) = (int16_t)(vrtx[i].data.w * 32767); - out += 2; - break; - case 4: - memcpy(out, &vrtx[i].data.x, sizeof(float)); - out += 4; - memcpy(out, &vrtx[i].data.y, sizeof(float)); - out += 4; - memcpy(out, &vrtx[i].data.z, sizeof(float)); - out += 4; - memcpy(out, &vrtx[i].data.w, sizeof(float)); - out += 4; - break; - case 8: - *((double *)out) = vrtx[i].data.x; - out += 8; - *((double *)out) = vrtx[i].data.y; - out += 8; - *((double *)out) = vrtx[i].data.z; - out += 8; - *((double *)out) = vrtx[i].data.w; - out += 8; - break; + case 1: + *out++ = (int8_t)(vrtx[i].data.x * 127); + *out++ = (int8_t)(vrtx[i].data.y * 127); + *out++ = (int8_t)(vrtx[i].data.z * 127); + *out++ = (int8_t)(vrtx[i].data.w * 127); + break; + case 2: + *((int16_t *)out) = (int16_t)(vrtx[i].data.x * 32767); + out += 2; + *((int16_t *)out) = (int16_t)(vrtx[i].data.y * 32767); + out += 2; + *((int16_t *)out) = (int16_t)(vrtx[i].data.z * 32767); + out += 2; + *((int16_t *)out) = (int16_t)(vrtx[i].data.w * 32767); + out += 2; + break; + case 4: + memcpy(out, &vrtx[i].data.x, sizeof(float)); + out += 4; + memcpy(out, &vrtx[i].data.y, sizeof(float)); + out += 4; + memcpy(out, &vrtx[i].data.z, sizeof(float)); + out += 4; + memcpy(out, &vrtx[i].data.w, sizeof(float)); + out += 4; + break; + case 8: + *((double *)out) = vrtx[i].data.x; + out += 8; + *((double *)out) = vrtx[i].data.y; + out += 8; + *((double *)out) = vrtx[i].data.z; + out += 8; + *((double *)out) = vrtx[i].data.w; + out += 8; + break; } idx = _m3d_cmapidx(cmap, numcmap, vrtx[i].data.color); switch (ci_s) { - case 1: *out++ = (uint8_t)(idx); break; - case 2: - *((uint16_t *)out) = (uint16_t)(idx); - out += 2; - break; - case 4: - *((uint32_t *)out) = vrtx[i].data.color; - out += 4; - break; + case 1: *out++ = (uint8_t)(idx); break; + case 2: + *((uint16_t *)out) = (uint16_t)(idx); + out += 2; + break; + case 4: + *((uint32_t *)out) = vrtx[i].data.color; + out += 4; + break; } out = _m3d_addidx(out, sk_s, vrtx[i].data.skinid); } @@ -5510,19 +5510,19 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size j++) weights[j] = (uint8_t)(skin[i].data.weight[j] * 255); switch (nb_s) { - case 1: weights[0] = 255; break; - case 2: - *((uint16_t *)out) = *((uint16_t *)&weights[0]); - out += 2; - break; - case 4: - *((uint32_t *)out) = *((uint32_t *)&weights[0]); - out += 4; - break; - case 8: - *((uint64_t *)out) = *((uint64_t *)&weights[0]); - out += 8; - break; + case 1: weights[0] = 255; break; + case 2: + *((uint16_t *)out) = *((uint16_t *)&weights[0]); + out += 2; + break; + case 4: + *((uint32_t *)out) = *((uint32_t *)&weights[0]); + out += 4; + break; + case 8: + *((uint64_t *)out) = *((uint64_t *)&weights[0]); + out += 8; + break; } for (j = 0; j < (uint32_t)nb_s && skin[i].data.boneid[j] != M3D_UNDEF && weights[j]; j++) { out = _m3d_addidx(out, bi_s, skin[i].data.boneid[j]); @@ -5561,41 +5561,41 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size if (k == 256) continue; *out++ = m->prop[i].type; switch (k) { - case m3dpf_color: - if (!(flags & M3D_EXP_NOCMAP)) { - idx = _m3d_cmapidx(cmap, numcmap, m->prop[i].value.color); - switch (ci_s) { - case 1: *out++ = (uint8_t)(idx); break; - case 2: - *((uint16_t *)out) = (uint16_t)(idx); - out += 2; - break; - case 4: - *((uint32_t *)out) = (uint32_t)(m->prop[i].value.color); - out += 4; - break; - } - } else - out--; - break; - case m3dpf_uint8: *out++ = m->prop[i].value.num; break; - case m3dpf_uint16: - *((uint16_t *)out) = m->prop[i].value.num; - out += 2; - break; - case m3dpf_uint32: - *((uint32_t *)out) = m->prop[i].value.num; - out += 4; - break; - case m3dpf_float: - *((float *)out) = m->prop[i].value.fnum; - out += 4; - break; + case m3dpf_color: + if (!(flags & M3D_EXP_NOCMAP)) { + idx = _m3d_cmapidx(cmap, numcmap, m->prop[i].value.color); + switch (ci_s) { + case 1: *out++ = (uint8_t)(idx); break; + case 2: + *((uint16_t *)out) = (uint16_t)(idx); + out += 2; + break; + case 4: + *((uint32_t *)out) = (uint32_t)(m->prop[i].value.color); + out += 4; + break; + } + } else + out--; + break; + case m3dpf_uint8: *out++ = m->prop[i].value.num; break; + case m3dpf_uint16: + *((uint16_t *)out) = m->prop[i].value.num; + out += 2; + break; + case m3dpf_uint32: + *((uint32_t *)out) = m->prop[i].value.num; + out += 4; + break; + case m3dpf_float: + *((float *)out) = m->prop[i].value.fnum; + out += 4; + break; - case m3dpf_map: - idx = _m3d_stridx(str, numstr, model->texture[m->prop[i].value.textureid].name); - out = _m3d_addidx(out, si_s, idx); - break; + case m3dpf_map: + idx = _m3d_stridx(str, numstr, model->texture[m->prop[i].value.textureid].name); + out = _m3d_addidx(out, si_s, idx); + break; } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len)); @@ -5689,40 +5689,40 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size if (cmd->type > 127) *out++ = (cmd->type >> 7) & 0xff; for (k = n = 0, l = cd->p; k < l; k++) { switch (cd->a[((k - n) % (cd->p - n)) + n]) { - case m3dcp_mi_t: - out = _m3d_addidx(out, si_s, cmd->arg[k] < model->nummaterial ? _m3d_stridx(str, numstr, model->material[cmd->arg[k]].name) : 0); + case m3dcp_mi_t: + out = _m3d_addidx(out, si_s, cmd->arg[k] < model->nummaterial ? _m3d_stridx(str, numstr, model->material[cmd->arg[k]].name) : 0); + break; + case m3dcp_vc_t: + min_x = *((float *)&cmd->arg[k]); + switch (vc_s) { + case 1: *out++ = (int8_t)(min_x * 127); break; + case 2: + *((int16_t *)out) = (int16_t)(min_x * 32767); + out += 2; break; - case m3dcp_vc_t: - min_x = *((float *)&cmd->arg[k]); - switch (vc_s) { - case 1: *out++ = (int8_t)(min_x * 127); break; - case 2: - *((int16_t *)out) = (int16_t)(min_x * 32767); - out += 2; - break; - case 4: - *((float *)out) = min_x; - out += 4; - break; - case 8: - *((double *)out) = min_x; - out += 8; - break; - } + case 4: + *((float *)out) = min_x; + out += 4; break; - case m3dcp_hi_t: out = _m3d_addidx(out, hi_s, cmd->arg[k]); break; - case m3dcp_fi_t: out = _m3d_addidx(out, fi_s, cmd->arg[k]); break; - case m3dcp_ti_t: out = _m3d_addidx(out, ti_s, cmd->arg[k]); break; - case m3dcp_qi_t: - case m3dcp_vi_t: out = _m3d_addidx(out, vi_s, cmd->arg[k]); break; - case m3dcp_i1_t: out = _m3d_addidx(out, 1, cmd->arg[k]); break; - case m3dcp_i2_t: out = _m3d_addidx(out, 2, cmd->arg[k]); break; - case m3dcp_i4_t: out = _m3d_addidx(out, 4, cmd->arg[k]); break; - case m3dcp_va_t: - out = _m3d_addidx(out, 4, cmd->arg[k]); - n = k + 1; - l += (cmd->arg[k] - 1) * (cd->p - k - 1); + case 8: + *((double *)out) = min_x; + out += 8; break; + } + break; + case m3dcp_hi_t: out = _m3d_addidx(out, hi_s, cmd->arg[k]); break; + case m3dcp_fi_t: out = _m3d_addidx(out, fi_s, cmd->arg[k]); break; + case m3dcp_ti_t: out = _m3d_addidx(out, ti_s, cmd->arg[k]); break; + case m3dcp_qi_t: + case m3dcp_vi_t: out = _m3d_addidx(out, vi_s, cmd->arg[k]); break; + case m3dcp_i1_t: out = _m3d_addidx(out, 1, cmd->arg[k]); break; + case m3dcp_i2_t: out = _m3d_addidx(out, 2, cmd->arg[k]); break; + case m3dcp_i4_t: out = _m3d_addidx(out, 4, cmd->arg[k]); break; + case m3dcp_va_t: + out = _m3d_addidx(out, 4, cmd->arg[k]); + n = k + 1; + l += (cmd->arg[k] - 1) * (cd->p - k - 1); + break; } } } @@ -5756,15 +5756,15 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->label[l].lang)); idx = _m3d_cmapidx(cmap, numcmap, model->label[i].color); switch (ci_s) { - case 1: *out++ = (uint8_t)(idx); break; - case 2: - *((uint16_t *)out) = (uint16_t)(idx); - out += 2; - break; - case 4: - *((uint32_t *)out) = model->label[i].color; - out += 4; - break; + case 1: *out++ = (uint8_t)(idx); break; + case 2: + *((uint16_t *)out) = (uint16_t)(idx); + out += 2; + break; + case 4: + *((uint32_t *)out) = model->label[i].color; + out += 4; + break; } } out = _m3d_addidx(out, vi_s, vrtxidx[model->label[i].vertexid]); @@ -5889,7 +5889,7 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size } #endif -#endif +#endif /* M3D_IMPLEMENTATION */ #ifdef __cplusplus } @@ -6147,11 +6147,11 @@ public: #endif /* impl */ } // namespace M3D -#ifdef _WIN32 -# pragma warning(pop) -#endif // _WIN32 +#endif /* M3D_CPPWRAPPER */ -#endif +#ifdef _MSC_VER +# pragma warning(pop) +#endif /* _MSC_VER */ #endif /* __cplusplus */ diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index e9930dfed..c57b43c11 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -68,9 +68,9 @@ namespace Assimp { namespace MDL { namespace HalfLife { -#if _MSC_VER > 1920 +#ifdef _MSC_VER # pragma warning(disable : 4706) -#endif // _WIN32 +#endif // _MSC_VER // ------------------------------------------------------------------------------------------------ HL1MDLLoader::HL1MDLLoader( diff --git a/code/AssetLib/MMD/MMDPmxParser.cpp b/code/AssetLib/MMD/MMDPmxParser.cpp index 6421f38cb..7ac5ac399 100644 --- a/code/AssetLib/MMD/MMDPmxParser.cpp +++ b/code/AssetLib/MMD/MMDPmxParser.cpp @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "MMDPmxParser.h" #include #ifdef ASSIMP_USE_HUNTER -# include +# include #else # include "../contrib/utf8cpp/source/utf8.h" #endif diff --git a/code/AssetLib/SIB/SIBImporter.cpp b/code/AssetLib/SIB/SIBImporter.cpp index b36c6d9b1..33beb0087 100644 --- a/code/AssetLib/SIB/SIBImporter.cpp +++ b/code/AssetLib/SIB/SIBImporter.cpp @@ -59,7 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #ifdef ASSIMP_USE_HUNTER -#include +#include #else //# include "../contrib/ConvertUTF/ConvertUTF.h" #include "../contrib/utf8cpp/source/utf8.h" diff --git a/code/AssetLib/STEPParser/STEPFileEncoding.cpp b/code/AssetLib/STEPParser/STEPFileEncoding.cpp index d917c28f3..1d1150c08 100644 --- a/code/AssetLib/STEPParser/STEPFileEncoding.cpp +++ b/code/AssetLib/STEPParser/STEPFileEncoding.cpp @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "STEPFileEncoding.h" #include #ifdef ASSIMP_USE_HUNTER -# include +# include #else # include #endif diff --git a/code/AssetLib/Step/STEPFile.h b/code/AssetLib/Step/STEPFile.h index 72648e462..3f4fe942b 100644 --- a/code/AssetLib/Step/STEPFile.h +++ b/code/AssetLib/Step/STEPFile.h @@ -54,10 +54,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#if _MSC_VER > 1920 +#ifdef _MSC_VER # pragma warning(push) # pragma warning(disable : 4127 4456 4245 4512 ) -#endif // _WIN32 +#endif // _MSC_VER // #if _MSC_VER > 1500 || (defined __GNUC___) @@ -130,8 +130,8 @@ namespace STEP { * coupled with a line number. */ // ------------------------------------------------------------------------------- struct SyntaxError : DeadlyImportError { - enum { - LINE_NOT_SPECIFIED = 0xffffffffffffffffLL + enum : uint64_t { + LINE_NOT_SPECIFIED = 0xfffffffffffffffLL }; SyntaxError(const std::string &s, uint64_t line = LINE_NOT_SPECIFIED); @@ -143,8 +143,8 @@ struct SyntaxError : DeadlyImportError { * It is typically coupled with both an entity id and a line number.*/ // ------------------------------------------------------------------------------- struct TypeError : DeadlyImportError { - enum { - ENTITY_NOT_SPECIFIED = 0xffffffffffffffffLL, + enum : uint64_t { + ENTITY_NOT_SPECIFIED = 0xffffffffffffffffUL, ENTITY_NOT_SPECIFIED_32 = 0x00000000ffffffff }; @@ -960,9 +960,9 @@ private: const EXPRESS::ConversionSchema *schema; }; -#if _MSC_VER > 1920 +#ifdef _MSC_VER #pragma warning(pop) -#endif // _WIN32 +#endif // _MSC_VER } // namespace STEP diff --git a/code/AssetLib/X3D/FIReader.cpp b/code/AssetLib/X3D/FIReader.cpp index de9f035f2..c1b439bda 100644 --- a/code/AssetLib/X3D/FIReader.cpp +++ b/code/AssetLib/X3D/FIReader.cpp @@ -61,7 +61,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #ifdef ASSIMP_USE_HUNTER -# include +# include #else # include "../contrib/utf8cpp/source/utf8.h" #endif diff --git a/code/AssetLib/glTF/glTFAsset.h b/code/AssetLib/glTF/glTFAsset.h index d6d1dd372..15947c8c6 100644 --- a/code/AssetLib/glTF/glTFAsset.h +++ b/code/AssetLib/glTF/glTFAsset.h @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GLTFASSET_H_INC #define GLTFASSET_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_IMPORTER) #include diff --git a/code/AssetLib/glTF/glTFAsset.inl b/code/AssetLib/glTF/glTFAsset.inl index 116f76535..c72b9698d 100644 --- a/code/AssetLib/glTF/glTFAsset.inl +++ b/code/AssetLib/glTF/glTFAsset.inl @@ -836,8 +836,8 @@ inline void Mesh::Read(Value &pJSON_Object, Asset &pAsset_Root) { if (json_extensions == nullptr) goto mr_skip_extensions; - for (Value::MemberIterator it_memb = json_extensions->MemberBegin(); it_memb != json_extensions->MemberEnd(); it_memb++) { #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC + for (Value::MemberIterator it_memb = json_extensions->MemberBegin(); it_memb != json_extensions->MemberEnd(); it_memb++) { if (it_memb->name.GetString() == std::string("Open3DGC-compression")) { // Search for compressed data. // Compressed data contain description of part of "buffer" which is encoded. This part must be decoded and @@ -887,11 +887,11 @@ inline void Mesh::Read(Value &pJSON_Object, Asset &pAsset_Root) { Extension.push_back(ext_o3dgc); // store info in mesh extensions list. } // if(it_memb->name.GetString() == "Open3DGC-compression") else -#endif { throw DeadlyImportError(std::string("GLTF: Unknown mesh extension: \"") + it_memb->name.GetString() + "\"."); } } // for(Value::MemberIterator it_memb = json_extensions->MemberBegin(); it_memb != json_extensions->MemberEnd(); json_extensions++) +#endif mr_skip_extensions: diff --git a/code/AssetLib/glTF/glTFAssetWriter.h b/code/AssetLib/glTF/glTFAssetWriter.h index f166ee532..ed81d12cd 100644 --- a/code/AssetLib/glTF/glTFAssetWriter.h +++ b/code/AssetLib/glTF/glTFAssetWriter.h @@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GLTFASSETWRITER_H_INC #define GLTFASSETWRITER_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_IMPORTER) #include "glTFAsset.h" diff --git a/code/AssetLib/glTF/glTFAssetWriter.inl b/code/AssetLib/glTF/glTFAssetWriter.inl index d8d2556fa..5b07eb2e9 100644 --- a/code/AssetLib/glTF/glTFAssetWriter.inl +++ b/code/AssetLib/glTF/glTFAssetWriter.inl @@ -305,11 +305,11 @@ namespace glTF { Value json_extensions; json_extensions.SetObject(); +#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC for(Mesh::SExtension* ptr_ext : m.Extension) { switch(ptr_ext->Type) { -#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC case Mesh::SExtension::EType::Compression_Open3DGC: { Value json_comp_data; @@ -339,11 +339,11 @@ namespace glTF { } break; -#endif default: throw DeadlyImportError("GLTF: Can not write mesh: unknown mesh extension, only Open3DGC is supported."); }// switch(ptr_ext->Type) }// for(Mesh::SExtension* ptr_ext : m.Extension) +#endif // Add extensions to mesh obj.AddMember("extensions", json_extensions, w.mAl); diff --git a/code/AssetLib/glTF/glTFExporter.h b/code/AssetLib/glTF/glTFExporter.h index 415992314..fe7592566 100644 --- a/code/AssetLib/glTF/glTFExporter.h +++ b/code/AssetLib/glTF/glTFExporter.h @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_GLTFEXPORTER_H_INC #define AI_GLTFEXPORTER_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_EXPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_EXPORTER) #include #include diff --git a/code/AssetLib/glTF/glTFImporter.cpp b/code/AssetLib/glTF/glTFImporter.cpp index b4ef9b06f..c106acf21 100644 --- a/code/AssetLib/glTF/glTFImporter.cpp +++ b/code/AssetLib/glTF/glTFImporter.cpp @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_IMPORTER) #include "AssetLib/glTF/glTFImporter.h" #include "AssetLib/glTF/glTFAsset.h" @@ -215,8 +215,8 @@ void glTFImporter::ImportMeshes(glTF::Asset &r) { // Check if mesh extensions is used if (mesh.Extension.size() > 0) { - for (Mesh::SExtension *cur_ext : mesh.Extension) { #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC + for (Mesh::SExtension *cur_ext : mesh.Extension) { if (cur_ext->Type == Mesh::SExtension::EType::Compression_Open3DGC) { // Limitations for meshes when using Open3DGC-compression. // It's a current limitation of sp... Specification have not this part still - about mesh compression. Why only one primitive? @@ -233,12 +233,12 @@ void glTFImporter::ImportMeshes(glTF::Asset &r) { buf->EncodedRegion_SetCurrent(mesh.id); } else -#endif { throw DeadlyImportError("GLTF: Can not import mesh: unknown mesh extension (code: \"" + to_string(cur_ext->Type) + "\"), only Open3DGC is supported."); } } +#endif } // if(mesh.Extension.size() > 0) meshOffsets.push_back(k); diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 7a167eaed..e45b53006 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GLTF2ASSET_H_INC #define GLTF2ASSET_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER) #include diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.h b/code/AssetLib/glTF2/glTF2AssetWriter.h index 784ab2ea5..ce58717f3 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.h +++ b/code/AssetLib/glTF2/glTF2AssetWriter.h @@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GLTF2ASSETWRITER_H_INC #define GLTF2ASSETWRITER_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER) #include "glTF2Asset.h" diff --git a/code/AssetLib/glTF2/glTF2Exporter.h b/code/AssetLib/glTF2/glTF2Exporter.h index 421a4806e..1d28ed459 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.h +++ b/code/AssetLib/glTF2/glTF2Exporter.h @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_GLTF2EXPORTER_H_INC #define AI_GLTF2EXPORTER_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER) #include #include diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 23d42ba97..00c647ed2 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER) #include "AssetLib/glTF2/glTF2Importer.h" #include "PostProcessing/MakeVerboseFormat.h" diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 9f8f519d9..7ccc6439f 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -899,7 +899,7 @@ ENDIF() # utf8 IF(ASSIMP_HUNTER_ENABLED) hunter_add_package(utf8) - find_package(utf8 CONFIG REQUIRED) + find_package(utf8cpp CONFIG REQUIRED) ELSE() # utf8 is header-only, so Assimp doesn't need to do anything. ENDIF() @@ -1066,7 +1066,7 @@ endif() ADD_DEFINITIONS( -DASSIMP_BUILD_DLL_EXPORT ) -if ( MSVC ) +IF( MSVC OR "${CMAKE_CXX_SIMULATE_ID}" MATCHES "MSVC") # clang with MSVC ABI ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) endif () @@ -1159,7 +1159,7 @@ IF(ASSIMP_HUNTER_ENABLED) minizip::minizip ZLIB::zlib RapidJSON::rapidjson - utf8::utf8 + utf8cpp zip::zip ) ELSE() diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 47ff05f2f..bcea076be 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -343,7 +343,7 @@ std::string BaseImporter::GetExtension(const std::string &file) { } #ifdef ASSIMP_USE_HUNTER -#include +#include #else #include "../contrib/utf8cpp/source/utf8.h" #endif diff --git a/code/Common/DefaultIOStream.cpp b/code/Common/DefaultIOStream.cpp index 65edd1bdd..32f47ab07 100644 --- a/code/Common/DefaultIOStream.cpp +++ b/code/Common/DefaultIOStream.cpp @@ -100,7 +100,6 @@ size_t DefaultIOStream::Write(const void *pvBuffer, size_t pCount) { ai_assert(nullptr != pvBuffer); ai_assert(0 != pSize); - ai_assert(0 != pCount); return (mFile ? ::fwrite(pvBuffer, pSize, pCount, mFile) : 0); } diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 77ac4b7a6..6b3a50346 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -74,9 +74,9 @@ Here we implement only the C++ interface (Assimp::Exporter). namespace Assimp { -#if _MSC_VER > 1920 +#ifdef _MSC_VER # pragma warning( disable : 4800 ) -#endif // _WIN32 +#endif // _MSC_VER // PostStepRegistry.cpp @@ -179,11 +179,14 @@ static void setupExporterArray(std::vector &exporte aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices)); #endif -#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_EXPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_EXPORTER) exporters.push_back(Exporter::ExportFormatEntry("gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType)); exporters.push_back(Exporter::ExportFormatEntry("glb2", "GL Transmission Format v. 2 (binary)", "glb", &ExportSceneGLB2, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType)); +#endif + +#if !defined(ASSIMP_BUILD_NO_GLTF_EXPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_EXPORTER) exporters.push_back(Exporter::ExportFormatEntry("gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType)); exporters.push_back(Exporter::ExportFormatEntry("glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB, diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index a46d39b48..77eb8ef8c 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -1174,7 +1174,7 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const { // add all bone anims for (unsigned int a = 0; a < pc->mNumChannels; ++a) { - const aiNodeAnim* pc2 = pc->mChannels[i]; + const aiNodeAnim* pc2 = pc->mChannels[a]; in.animations += sizeof(aiNodeAnim); in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey); in.animations += pc2->mNumScalingKeys * sizeof(aiVectorKey); diff --git a/code/Common/ImporterRegistry.cpp b/code/Common/ImporterRegistry.cpp index da51696bc..c24f39a31 100644 --- a/code/Common/ImporterRegistry.cpp +++ b/code/Common/ImporterRegistry.cpp @@ -1,4 +1,4 @@ -/* +/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- @@ -179,8 +179,10 @@ corresponding preprocessor flag to selectively disable formats. #ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER #include "AssetLib/Assbin/AssbinLoader.h" #endif -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_IMPORTER) #include "AssetLib/glTF/glTFImporter.h" +#endif +#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER) #include "AssetLib/glTF2/glTF2Importer.h" #endif #ifndef ASSIMP_BUILD_NO_C4D_IMPORTER @@ -339,8 +341,10 @@ void GetImporterInstanceList(std::vector &out) { #if (!defined ASSIMP_BUILD_NO_ASSBIN_IMPORTER) out.push_back(new AssbinImporter()); #endif -#if (!defined ASSIMP_BUILD_NO_GLTF_IMPORTER) +#if (!defined ASSIMP_BUILD_NO_GLTF_IMPORTER && !defined ASSIMP_BUILD_NO_GLTF1_IMPORTER) out.push_back(new glTFImporter()); +#endif +#if (!defined ASSIMP_BUILD_NO_GLTF_IMPORTER && !defined ASSIMP_BUILD_NO_GLTF2_IMPORTER) out.push_back(new glTF2Importer()); #endif #if (!defined ASSIMP_BUILD_NO_C4D_IMPORTER) diff --git a/code/Common/Subdivision.cpp b/code/Common/Subdivision.cpp index 4f64a00c4..c60d2f0d3 100644 --- a/code/Common/Subdivision.cpp +++ b/code/Common/Subdivision.cpp @@ -53,9 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; void mydummy() {} -#if _MSC_VER > 1920 +#ifdef _MSC_VER #pragma warning(disable : 4709) -#endif // _WIN32 +#endif // _MSC_VER // ------------------------------------------------------------------------------------------------ /** Subdivider stub class to implement the Catmull-Clarke subdivision algorithm. The * implementation is basing on recursive refinement. Directly evaluating the result is also diff --git a/contrib/gtest/include/gtest/internal/gtest-port.h b/contrib/gtest/include/gtest/internal/gtest-port.h index 0094ed507..f66d9cd32 100644 --- a/contrib/gtest/include/gtest/internal/gtest-port.h +++ b/contrib/gtest/include/gtest/internal/gtest-port.h @@ -312,10 +312,22 @@ __pragma(warning(disable: warnings)) # define GTEST_DISABLE_MSC_WARNINGS_POP_() \ __pragma(warning(pop)) +# if defined(__clang__) +# define GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_() \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +# define GTEST_DISABLE_CLANG_WARNINGS_POP_() \ + _Pragma("clang diagnostic pop") +# else +# define GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_() +# define GTEST_DISABLE_CLANG_WARNINGS_POP_() +# endif #else // Older versions of MSVC don't have __pragma. # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) # define GTEST_DISABLE_MSC_WARNINGS_POP_() +# define GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_() +# define GTEST_DISABLE_CLANG_WARNINGS_POP_() #endif #ifndef GTEST_LANG_CXX11 @@ -2352,6 +2364,7 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } // Functions deprecated by MSVC 8.0. GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */) +GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_() inline const char* StrNCpy(char* dest, const char* src, size_t n) { return strncpy(dest, src, n); @@ -2399,6 +2412,7 @@ inline const char* GetEnv(const char* name) { #endif } +GTEST_DISABLE_CLANG_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() #if GTEST_OS_WINDOWS_MOBILE diff --git a/contrib/gtest/src/gtest-port.cc b/contrib/gtest/src/gtest-port.cc index e5bf3dd2b..e04aa9a57 100644 --- a/contrib/gtest/src/gtest-port.cc +++ b/contrib/gtest/src/gtest-port.cc @@ -926,7 +926,7 @@ GTestLog::~GTestLog() { // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) - +GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_() #if GTEST_HAS_STREAM_REDIRECTION // Object that captures an output stream (stdout/stderr). @@ -1010,6 +1010,7 @@ class CapturedStream { }; GTEST_DISABLE_MSC_WARNINGS_POP_() +GTEST_DISABLE_CLANG_WARNINGS_POP_() static CapturedStream* g_captured_stderr = NULL; static CapturedStream* g_captured_stdout = NULL; diff --git a/contrib/rapidjson/include/rapidjson/document.h b/contrib/rapidjson/include/rapidjson/document.h index 473d846e3..17df30725 100644 --- a/contrib/rapidjson/include/rapidjson/document.h +++ b/contrib/rapidjson/include/rapidjson/document.h @@ -31,7 +31,7 @@ #include RAPIDJSON_DIAG_PUSH -#ifdef _MSC_VER +#if defined(_MSC_VER) && !(__clang__) RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data #endif diff --git a/contrib/rapidjson/include/rapidjson/encodings.h b/contrib/rapidjson/include/rapidjson/encodings.h index 0df1c3435..de4d9d216 100644 --- a/contrib/rapidjson/include/rapidjson/encodings.h +++ b/contrib/rapidjson/include/rapidjson/encodings.h @@ -17,7 +17,7 @@ #include "rapidjson.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data RAPIDJSON_DIAG_OFF(4702) // unreachable code @@ -709,7 +709,7 @@ struct Transcoder { RAPIDJSON_NAMESPACE_END -#if defined(__GNUC__) || defined(_MSC_VER) +#if defined(__GNUC__) || (defined(_MSC_VER) && !defined(__clang__)) RAPIDJSON_DIAG_POP #endif diff --git a/contrib/rapidjson/include/rapidjson/internal/meta.h b/contrib/rapidjson/include/rapidjson/internal/meta.h index 5a9aaa428..bcbfc7709 100644 --- a/contrib/rapidjson/include/rapidjson/internal/meta.h +++ b/contrib/rapidjson/include/rapidjson/internal/meta.h @@ -21,7 +21,7 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(6334) #endif @@ -174,7 +174,7 @@ template struct RemoveSfinaeTag { typedef T Type; RAPIDJSON_NAMESPACE_END //@endcond -#if defined(__GNUC__) || defined(_MSC_VER) +#if defined(__GNUC__) || (defined(_MSC_VER) && !defined(__clang__)) RAPIDJSON_DIAG_POP #endif diff --git a/contrib/rapidjson/include/rapidjson/reader.h b/contrib/rapidjson/include/rapidjson/reader.h index 120c31115..4b172e953 100644 --- a/contrib/rapidjson/include/rapidjson/reader.h +++ b/contrib/rapidjson/include/rapidjson/reader.h @@ -37,7 +37,7 @@ #include #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4702) // unreachable code @@ -2214,7 +2214,7 @@ RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_POP #endif diff --git a/contrib/rapidjson/include/rapidjson/writer.h b/contrib/rapidjson/include/rapidjson/writer.h index e610ebb60..53d1a5d7f 100644 --- a/contrib/rapidjson/include/rapidjson/writer.h +++ b/contrib/rapidjson/include/rapidjson/writer.h @@ -36,7 +36,7 @@ #include #endif -#ifdef _MSC_VER +#if defined (_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant #endif @@ -700,11 +700,11 @@ inline bool Writer::ScanWriteUnescapedString(StringStream& is, siz RAPIDJSON_NAMESPACE_END -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) RAPIDJSON_DIAG_POP #endif -#ifdef __clang__ +#if defined(__clang__) RAPIDJSON_DIAG_POP #endif diff --git a/contrib/unzip/ioapi.c b/contrib/unzip/ioapi.c index e1ef46088..5e0497f9e 100644 --- a/contrib/unzip/ioapi.c +++ b/contrib/unzip/ioapi.c @@ -16,6 +16,10 @@ #ifdef _WIN32 # pragma warning(push) # pragma warning(disable : 4131 4100) +# ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-parameter" +# endif #endif // _WIN32 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ @@ -181,4 +185,7 @@ void fill_fopen_filefunc (pzlib_filefunc_def) #ifdef _WIN32 # pragma warning(pop) +# ifdef __clang__ +# pragma clang diagnostic pop +# endif #endif // _WIN32 diff --git a/contrib/unzip/ioapi.h b/contrib/unzip/ioapi.h index 7d457baab..63ec641bf 100644 --- a/contrib/unzip/ioapi.h +++ b/contrib/unzip/ioapi.h @@ -24,7 +24,7 @@ #ifndef ZCALLBACK -#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) +#if (defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) #define ZCALLBACK CALLBACK #else #define ZCALLBACK diff --git a/contrib/unzip/unzip.c b/contrib/unzip/unzip.c index 3937f821e..7bac01df0 100644 --- a/contrib/unzip/unzip.c +++ b/contrib/unzip/unzip.c @@ -1554,7 +1554,6 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) char *szComment; uLong uSizeBuf; { - int err=UNZ_OK; unz_s* s; uLong uReadThis ; if (file==NULL) diff --git a/contrib/zip/src/miniz.h b/contrib/zip/src/miniz.h index 07f7b2de2..7570ae929 100644 --- a/contrib/zip/src/miniz.h +++ b/contrib/zip/src/miniz.h @@ -5361,7 +5361,7 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, } else { // Temporarily allocate a read buffer. read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) #else @@ -5454,7 +5454,7 @@ void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) #else if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) @@ -5560,7 +5560,7 @@ mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) { // The file is stored or the caller has requested the compressed data. if (pZip->m_pState->m_pMem) { -#ifdef _MSC_VER +#if defined (_MSC_VER) && !defined(__clang__) if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF)) #else diff --git a/include/assimp/Compiler/poppack1.h b/include/assimp/Compiler/poppack1.h index e033bc147..a8e9a3c7e 100644 --- a/include/assimp/Compiler/poppack1.h +++ b/include/assimp/Compiler/poppack1.h @@ -14,7 +14,7 @@ #endif // reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) +#if (defined(_MSC_VER) && !defined(__clang__)) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) # pragma pack( pop ) #endif #undef PACK_STRUCT diff --git a/include/assimp/Compiler/pushpack1.h b/include/assimp/Compiler/pushpack1.h index 4c9fbb857..2a5e2dfe6 100644 --- a/include/assimp/Compiler/pushpack1.h +++ b/include/assimp/Compiler/pushpack1.h @@ -22,7 +22,7 @@ # error poppack1.h must be included after pushpack1.h #endif -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) +#if (defined(_MSC_VER) && !defined(__clang__)) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) # pragma pack(push,1) # define PACK_STRUCT #elif defined( __GNUC__ ) || defined(__clang__) diff --git a/test/unit/UnitTestFileGenerator.h b/test/unit/UnitTestFileGenerator.h index 91d69357f..2166c6939 100644 --- a/test/unit/UnitTestFileGenerator.h +++ b/test/unit/UnitTestFileGenerator.h @@ -44,21 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined(__GNUC__) || defined(__clang__) -#define TMP_PATH "/tmp/" -inline FILE* MakeTmpFile(char* tmplate) -{ - auto fd = mkstemp(tmplate); - EXPECT_NE(-1, fd); - if(fd == -1) - { - return nullptr; - } - auto fs = fdopen(fd, "w+"); - EXPECT_NE(nullptr, fs); - return fs; -} -#elif defined(_MSC_VER) +#if defined(_MSC_VER) #include #define TMP_PATH "./" inline FILE* MakeTmpFile(char* tmplate) @@ -73,4 +59,18 @@ inline FILE* MakeTmpFile(char* tmplate) EXPECT_NE(fs, nullptr); return fs; } +#elif defined(__GNUC__) || defined(__clang__) +#define TMP_PATH "/tmp/" +inline FILE* MakeTmpFile(char* tmplate) +{ + auto fd = mkstemp(tmplate); + EXPECT_NE(-1, fd); + if(fd == -1) + { + return nullptr; + } + auto fs = fdopen(fd, "w+"); + EXPECT_NE(nullptr, fs); + return fs; +} #endif diff --git a/test/unit/utColladaImportExport.cpp b/test/unit/utColladaImportExport.cpp index 451c8e235..100ca548a 100644 --- a/test/unit/utColladaImportExport.cpp +++ b/test/unit/utColladaImportExport.cpp @@ -157,7 +157,6 @@ public: static inline void CheckNodeIdNames(IdNameMap &nodeIdMap, IdNameMap &nodeNameMap, const aiNode *parent, size_t index) { IdNameString namePair = GetItemIdName(parent, index); - const auto result = nodeNameMap.insert(namePair); IdNameString idPair = GetColladaIdName(parent, index); ReportDuplicate(nodeIdMap, idPair, typeid(aiNode).name());