Merge branch 'master' into fix-mingw-priumax

pull/3328/head
Kim Kulling 2020-07-24 11:14:15 +02:00 committed by GitHub
commit c7a9ef30cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 1212 additions and 784 deletions

View File

@ -35,6 +35,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW) SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW)
CMAKE_MINIMUM_REQUIRED( VERSION 3.0 ) CMAKE_MINIMUM_REQUIRED( VERSION 3.0 )
@ -257,7 +258,11 @@ IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT CMAKE_COMPILER_IS_MINGW)
SET(LIBSTDC++_LIBRARIES -lstdc++) SET(LIBSTDC++_LIBRARIES -lstdc++)
ELSEIF(MSVC) ELSEIF(MSVC)
# enable multi-core compilation with MSVC # enable multi-core compilation with MSVC
IF( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) # clang-cl
ADD_COMPILE_OPTIONS(/bigobj /W4 /WX )
ELSE() # msvc
ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX) ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX)
ENDIF()
# disable "elements of array '' will be default initialized" warning on MSVC2013 # disable "elements of array '' will be default initialized" warning on MSVC2013
IF(MSVC12) IF(MSVC12)
ADD_COMPILE_OPTIONS(/wd4351) ADD_COMPILE_OPTIONS(/wd4351)

View File

@ -4,8 +4,6 @@ A library to import and export various 3d-model-formats including scene-post-pro
### Current project status ### ### Current project status ###
[![Financial Contributors on Open Collective](https://opencollective.com/assimp/all/badge.svg?label=financial+contributors)](https://opencollective.com/assimp) [![Financial Contributors on Open Collective](https://opencollective.com/assimp/all/badge.svg?label=financial+contributors)](https://opencollective.com/assimp)
![C/C++ CI](https://github.com/assimp/assimp/workflows/C/C++%20CI/badge.svg) ![C/C++ CI](https://github.com/assimp/assimp/workflows/C/C++%20CI/badge.svg)
[![Linux Build Status](https://travis-ci.org/assimp/assimp.svg)](https://travis-ci.org/assimp/assimp)
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/tmo433wax6u6cjp4?svg=true)](https://ci.appveyor.com/project/kimkulling/assimp)
<a href="https://scan.coverity.com/projects/5607"> <a href="https://scan.coverity.com/projects/5607">
<img alt="Coverity Scan Build Status" <img alt="Coverity Scan Build Status"
src="https://scan.coverity.com/projects/5607/badge.svg"/> src="https://scan.coverity.com/projects/5607/badge.svg"/>

View File

@ -321,9 +321,10 @@ public:
struct Face : public FaceWithSmoothingGroup { struct Face : public FaceWithSmoothingGroup {
}; };
#if _MSC_VER > 1920 #ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4315) #pragma warning(disable : 4315)
#endif #endif // _MSC_VER
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Helper structure representing a texture */ /** Helper structure representing a texture */
@ -412,6 +413,10 @@ struct Texture {
#include <assimp/Compiler/poppack1.h> #include <assimp/Compiler/poppack1.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Helper structure representing a 3ds material */ /** Helper structure representing a 3ds material */
struct Material { struct Material {

View File

@ -471,32 +471,33 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
++node->mNumMeshes; ++node->mNumMeshes;
} }
switch ((*it).flags & 0xf) { switch ((*it).GetType()) {
// closed line // closed line
case 0x1: case Surface::ClosedLine:
needMat[idx].first += (unsigned int)(*it).entries.size(); needMat[idx].first += (unsigned int)(*it).entries.size();
needMat[idx].second += (unsigned int)(*it).entries.size() << 1u; needMat[idx].second += (unsigned int)(*it).entries.size() << 1u;
break; break;
// unclosed line // unclosed line
case 0x2: case Surface::OpenLine:
needMat[idx].first += (unsigned int)(*it).entries.size() - 1; needMat[idx].first += (unsigned int)(*it).entries.size() - 1;
needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u;
break; break;
// triangle strip // triangle strip
case 0x4: case Surface::TriangleStrip:
needMat[idx].first += (unsigned int)(*it).entries.size() - 2; needMat[idx].first += (unsigned int)(*it).entries.size() - 2;
needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3; needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3;
break; break;
// 0 == polygon, else unknown
default: default:
if ((*it).flags & 0xf) { // Coerce unknowns to a polygon and warn
ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown"); ASSIMP_LOG_WARN_F("AC3D: The type flag of a surface is unknown: ", (*it).flags);
(*it).flags &= ~(0xf); (*it).flags &= ~(Surface::Mask);
} // fallthrough
// polygon
case Surface::Polygon:
// the number of faces increments by one, the number // the number of faces increments by one, the number
// of vertices by surface.numref. // of vertices by surface.numref.
needMat[idx].first++; needMat[idx].first++;
@ -552,8 +553,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
const Surface &src = *it; const Surface &src = *it;
// closed polygon // closed polygon
unsigned int type = (*it).flags & 0xf; uint8_t type = (*it).GetType();
if (!type) { if (type == Surface::Polygon) {
aiFace &face = *faces++; aiFace &face = *faces++;
face.mNumIndices = (unsigned int)src.entries.size(); face.mNumIndices = (unsigned int)src.entries.size();
if (0 != face.mNumIndices) { 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) { for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) {
const Surface::SurfaceEntry &entry1 = src.entries[i]; const Surface::SurfaceEntry &entry1 = src.entries[i];
const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; const Surface::SurfaceEntry &entry2 = src.entries[i + 1];
@ -640,7 +641,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
// either a closed or an unclosed line // either a closed or an unclosed line
unsigned int tmp = (unsigned int)(*it).entries.size(); 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) { for (unsigned int m = 0; m < tmp; ++m) {
aiFace &face = *faces++; aiFace &face = *faces++;
@ -663,7 +664,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
++uv; ++uv;
} }
if (0x1 == type && tmp - 1 == m) { if (Surface::ClosedLine == type && tmp - 1 == m) {
// if this is a closed line repeat its beginning now // if this is a closed line repeat its beginning now
it2 = (*it).entries.begin(); it2 = (*it).entries.begin();
} else } else

View File

@ -69,7 +69,10 @@ public:
// Represents an AC3D material // Represents an AC3D material
struct Material { struct Material {
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 // base color of the material
aiColor3D rgb; aiColor3D rgb;
@ -96,18 +99,43 @@ public:
// Represents an AC3D surface // Represents an AC3D surface
struct Surface { struct Surface {
Surface() : Surface() :
mat(0), flags(0) {} mat(0),
flags(0) {}
unsigned int mat, flags; unsigned int mat, flags;
typedef std::pair<unsigned int, aiVector2D> SurfaceEntry; typedef std::pair<unsigned int, aiVector2D> SurfaceEntry;
std::vector<SurfaceEntry> entries; std::vector<SurfaceEntry> 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 // Represents an AC3D object
struct Object { struct Object {
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 // Type description
enum Type { enum Type {

View File

@ -386,7 +386,14 @@ void BlenderTessellatorP2T::ReferencePoints( std::vector< Blender::PointP2T >& p
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& point ) const 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 ); unsigned int pointOffset = offsetof( PointP2T, point2D );
#if defined __clang__
# pragma clang diagnostic pop
#endif
PointP2T& pointStruct = *reinterpret_cast< PointP2T* >( reinterpret_cast< char* >( &point ) - pointOffset ); PointP2T& pointStruct = *reinterpret_cast< PointP2T* >( reinterpret_cast< char* >( &point ) - pointOffset );
if ( pointStruct.magic != static_cast<int>( BLEND_TESS_MAGIC ) ) if ( pointStruct.magic != static_cast<int>( BLEND_TESS_MAGIC ) )
{ {
@ -394,7 +401,6 @@ inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& poi
} }
return pointStruct; return pointStruct;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void BlenderTessellatorP2T::MakeFacesFromTriangles( std::vector< p2t::Triangle* >& triangles ) const void BlenderTessellatorP2T::MakeFacesFromTriangles( std::vector< p2t::Triangle* >& triangles ) const
{ {

View File

@ -45,9 +45,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AssetLib/Step/STEPFile.h" #include "AssetLib/Step/STEPFile.h"
#if _MSC_VER > 1920 #ifdef _MSC_VER
# pragma warning(push)
# pragma warning( disable : 4512 ) # pragma warning( disable : 4512 )
#endif // _WIN32 #endif // _MSC_VER
namespace Assimp { namespace Assimp {
namespace IFC { namespace IFC {
@ -4372,4 +4373,8 @@ namespace STEP {
} //! STEP } //! STEP
} //! Assimp } //! Assimp
#ifdef _MSC_VER
# pragma warning(pop)
#endif // _MSC_VER
#endif // INCLUDED_IFC_READER_GEN_H #endif // INCLUDED_IFC_READER_GEN_H

View File

@ -84,7 +84,7 @@ typedef uint16_t M3D_INDEX;
#ifndef M3D_BONEMAXLEVEL #ifndef M3D_BONEMAXLEVEL
#define M3D_BONEMAXLEVEL 8 #define M3D_BONEMAXLEVEL 8
#endif #endif
#ifndef _MSC_VER #if !defined(_MSC_VER) || defined(__clang__)
#ifndef _inline #ifndef _inline
#define _inline __inline__ #define _inline __inline__
#endif #endif
@ -101,13 +101,13 @@ typedef uint16_t M3D_INDEX;
#define _register #define _register
#endif #endif
#if _MSC_VER > 1920 #if _MSC_VER > 1920 && !defined(__clang__)
# pragma warning(push) # pragma warning(push)
# pragma warning(disable : 4100 4127 4189 4505 4244 4403 4701 4703) # pragma warning(disable : 4100 4127 4189 4505 4244 4403 4701 4703)
# if (_MSC_VER > 1800 ) # if (_MSC_VER > 1800 )
# pragma warning(disable : 5573 5744) # pragma warning(disable : 5573 5744)
# endif # endif
#endif // _WIN32 #endif // _MSC_VER
/*** File format structures ***/ /*** File format structures ***/
@ -5889,7 +5889,7 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
} }
#endif #endif
#endif #endif /* M3D_IMPLEMENTATION */
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -6147,11 +6147,11 @@ public:
#endif /* impl */ #endif /* impl */
} // namespace M3D } // namespace M3D
#ifdef _WIN32 #endif /* M3D_CPPWRAPPER */
# pragma warning(pop)
#endif // _WIN32
#endif #ifdef _MSC_VER
# pragma warning(pop)
#endif /* _MSC_VER */
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -68,9 +68,9 @@ namespace Assimp {
namespace MDL { namespace MDL {
namespace HalfLife { namespace HalfLife {
#if _MSC_VER > 1920 #ifdef _MSC_VER
# pragma warning(disable : 4706) # pragma warning(disable : 4706)
#endif // _WIN32 #endif // _MSC_VER
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
HL1MDLLoader::HL1MDLLoader( HL1MDLLoader::HL1MDLLoader(

View File

@ -54,10 +54,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
#if _MSC_VER > 1920 #ifdef _MSC_VER
# pragma warning(push) # pragma warning(push)
# pragma warning(disable : 4127 4456 4245 4512 ) # pragma warning(disable : 4127 4456 4245 4512 )
#endif // _WIN32 #endif // _MSC_VER
// //
#if _MSC_VER > 1500 || (defined __GNUC___) #if _MSC_VER > 1500 || (defined __GNUC___)
@ -130,8 +130,8 @@ namespace STEP {
* coupled with a line number. */ * coupled with a line number. */
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
struct SyntaxError : DeadlyImportError { struct SyntaxError : DeadlyImportError {
enum { enum : uint64_t {
LINE_NOT_SPECIFIED = 0xffffffffffffffffLL LINE_NOT_SPECIFIED = 0xfffffffffffffffLL
}; };
SyntaxError(const std::string &s, uint64_t line = LINE_NOT_SPECIFIED); 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.*/ * It is typically coupled with both an entity id and a line number.*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
struct TypeError : DeadlyImportError { struct TypeError : DeadlyImportError {
enum { enum : uint64_t {
ENTITY_NOT_SPECIFIED = 0xffffffffffffffffLL, ENTITY_NOT_SPECIFIED = 0xffffffffffffffffUL,
ENTITY_NOT_SPECIFIED_32 = 0x00000000ffffffff ENTITY_NOT_SPECIFIED_32 = 0x00000000ffffffff
}; };
@ -960,9 +960,9 @@ private:
const EXPRESS::ConversionSchema *schema; const EXPRESS::ConversionSchema *schema;
}; };
#if _MSC_VER > 1920 #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif // _WIN32 #endif // _MSC_VER
} // namespace STEP } // namespace STEP

View File

@ -298,25 +298,37 @@ void glTF2Importer::ImportMaterials(glTF2::Asset &r) {
} }
} }
static inline void SetFace(aiFace &face, int a) { static inline void SetFaceAndAdvance1(aiFace*& face, unsigned int numVertices, unsigned int a) {
face.mNumIndices = 1; if (a >= numVertices) {
face.mIndices = new unsigned int[1]; return;
face.mIndices[0] = a; }
face->mNumIndices = 1;
face->mIndices = new unsigned int[1];
face->mIndices[0] = a;
++face;
} }
static inline void SetFace(aiFace &face, int a, int b) { static inline void SetFaceAndAdvance2(aiFace*& face, unsigned int numVertices, unsigned int a, unsigned int b) {
face.mNumIndices = 2; if ((a >= numVertices) || (b >= numVertices)) {
face.mIndices = new unsigned int[2]; return;
face.mIndices[0] = a; }
face.mIndices[1] = b; face->mNumIndices = 2;
face->mIndices = new unsigned int[2];
face->mIndices[0] = a;
face->mIndices[1] = b;
++face;
} }
static inline void SetFace(aiFace &face, int a, int b, int c) { static inline void SetFaceAndAdvance3(aiFace*& face, unsigned int numVertices, unsigned int a, unsigned int b, unsigned int c) {
face.mNumIndices = 3; if ((a >= numVertices) || (b >= numVertices) || (c >= numVertices)) {
face.mIndices = new unsigned int[3]; return;
face.mIndices[0] = a; }
face.mIndices[1] = b; face->mNumIndices = 3;
face.mIndices[2] = c; face->mIndices = new unsigned int[3];
face->mIndices[0] = a;
face->mIndices[1] = b;
face->mIndices[2] = c;
++face;
} }
#ifdef ASSIMP_BUILD_DEBUG #ifdef ASSIMP_BUILD_DEBUG
@ -335,7 +347,7 @@ static inline bool CheckValidFacesIndices(aiFace *faces, unsigned nFaces, unsign
void glTF2Importer::ImportMeshes(glTF2::Asset &r) { void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes"); ASSIMP_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes");
std::vector<aiMesh *> meshes; std::vector<std::unique_ptr<aiMesh>> meshes;
unsigned int k = 0; unsigned int k = 0;
meshOffsets.clear(); meshOffsets.clear();
@ -350,7 +362,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
Mesh::Primitive &prim = mesh.primitives[p]; Mesh::Primitive &prim = mesh.primitives[p];
aiMesh *aim = new aiMesh(); aiMesh *aim = new aiMesh();
meshes.push_back(aim); meshes.push_back(std::unique_ptr<aiMesh>(aim));
aim->mName = mesh.name.empty() ? mesh.id : mesh.name; aim->mName = mesh.name.empty() ? mesh.id : mesh.name;
@ -486,6 +498,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
} }
aiFace *faces = nullptr; aiFace *faces = nullptr;
aiFace *facePtr = nullptr;
size_t nFaces = 0; size_t nFaces = 0;
if (prim.indices) { if (prim.indices) {
@ -497,9 +510,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
switch (prim.mode) { switch (prim.mode) {
case PrimitiveMode_POINTS: { case PrimitiveMode_POINTS: {
nFaces = count; nFaces = count;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; ++i) { for (unsigned int i = 0; i < count; ++i) {
SetFace(faces[i], data.GetUInt(i)); SetFaceAndAdvance1(facePtr, aim->mNumVertices, data.GetUInt(i));
} }
break; break;
} }
@ -510,9 +523,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped."); ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped.");
count = nFaces * 2; count = nFaces * 2;
} }
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; i += 2) { for (unsigned int i = 0; i < count; i += 2) {
SetFace(faces[i / 2], data.GetUInt(i), data.GetUInt(i + 1)); SetFaceAndAdvance2(facePtr, aim->mNumVertices, data.GetUInt(i), data.GetUInt(i + 1));
} }
break; break;
} }
@ -520,13 +533,13 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
case PrimitiveMode_LINE_LOOP: case PrimitiveMode_LINE_LOOP:
case PrimitiveMode_LINE_STRIP: { case PrimitiveMode_LINE_STRIP: {
nFaces = count - ((prim.mode == PrimitiveMode_LINE_STRIP) ? 1 : 0); nFaces = count - ((prim.mode == PrimitiveMode_LINE_STRIP) ? 1 : 0);
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
SetFace(faces[0], data.GetUInt(0), data.GetUInt(1)); SetFaceAndAdvance2(facePtr, aim->mNumVertices, data.GetUInt(0), data.GetUInt(1));
for (unsigned int i = 2; i < count; ++i) { for (unsigned int i = 2; i < count; ++i) {
SetFace(faces[i - 1], faces[i - 2].mIndices[1], data.GetUInt(i)); SetFaceAndAdvance2(facePtr, aim->mNumVertices, data.GetUInt(i - 1), data.GetUInt(i));
} }
if (prim.mode == PrimitiveMode_LINE_LOOP) { // close the loop if (prim.mode == PrimitiveMode_LINE_LOOP) { // close the loop
SetFace(faces[count - 1], faces[count - 2].mIndices[1], faces[0].mIndices[0]); SetFaceAndAdvance2(facePtr, aim->mNumVertices, data.GetUInt(static_cast<int>(count) - 1), faces[0].mIndices[0]);
} }
break; break;
} }
@ -537,33 +550,33 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped."); ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped.");
count = nFaces * 3; count = nFaces * 3;
} }
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; i += 3) { for (unsigned int i = 0; i < count; i += 3) {
SetFace(faces[i / 3], data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2)); SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2));
} }
break; break;
} }
case PrimitiveMode_TRIANGLE_STRIP: { case PrimitiveMode_TRIANGLE_STRIP: {
nFaces = count - 2; nFaces = count - 2;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < nFaces; ++i) { for (unsigned int i = 0; i < nFaces; ++i) {
//The ordering is to ensure that the triangles are all drawn with the same orientation //The ordering is to ensure that the triangles are all drawn with the same orientation
if ((i + 1) % 2 == 0) { if ((i + 1) % 2 == 0) {
//For even n, vertices n + 1, n, and n + 2 define triangle n //For even n, vertices n + 1, n, and n + 2 define triangle n
SetFace(faces[i], data.GetUInt(i + 1), data.GetUInt(i), data.GetUInt(i + 2)); SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(i + 1), data.GetUInt(i), data.GetUInt(i + 2));
} else { } else {
//For odd n, vertices n, n+1, and n+2 define triangle n //For odd n, vertices n, n+1, and n+2 define triangle n
SetFace(faces[i], data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2)); SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2));
} }
} }
break; break;
} }
case PrimitiveMode_TRIANGLE_FAN: case PrimitiveMode_TRIANGLE_FAN:
nFaces = count - 2; nFaces = count - 2;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2)); SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
for (unsigned int i = 1; i < nFaces; ++i) { for (unsigned int i = 1; i < nFaces; ++i) {
SetFace(faces[i], faces[0].mIndices[0], faces[i - 1].mIndices[2], data.GetUInt(i + 2)); SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(0), data.GetUInt(i + 1), data.GetUInt(i + 2));
} }
break; break;
} }
@ -575,9 +588,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
switch (prim.mode) { switch (prim.mode) {
case PrimitiveMode_POINTS: { case PrimitiveMode_POINTS: {
nFaces = count; nFaces = count;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; ++i) { for (unsigned int i = 0; i < count; ++i) {
SetFace(faces[i], i); SetFaceAndAdvance1(facePtr, aim->mNumVertices, i);
} }
break; break;
} }
@ -588,9 +601,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped."); ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped.");
count = (unsigned int)nFaces * 2; count = (unsigned int)nFaces * 2;
} }
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; i += 2) { for (unsigned int i = 0; i < count; i += 2) {
SetFace(faces[i / 2], i, i + 1); SetFaceAndAdvance2(facePtr, aim->mNumVertices, i, i + 1);
} }
break; break;
} }
@ -598,13 +611,13 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
case PrimitiveMode_LINE_LOOP: case PrimitiveMode_LINE_LOOP:
case PrimitiveMode_LINE_STRIP: { case PrimitiveMode_LINE_STRIP: {
nFaces = count - ((prim.mode == PrimitiveMode_LINE_STRIP) ? 1 : 0); nFaces = count - ((prim.mode == PrimitiveMode_LINE_STRIP) ? 1 : 0);
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
SetFace(faces[0], 0, 1); SetFaceAndAdvance2(facePtr, aim->mNumVertices, 0, 1);
for (unsigned int i = 2; i < count; ++i) { for (unsigned int i = 2; i < count; ++i) {
SetFace(faces[i - 1], faces[i - 2].mIndices[1], i); SetFaceAndAdvance2(facePtr, aim->mNumVertices, i - 1, i);
} }
if (prim.mode == PrimitiveMode_LINE_LOOP) { // close the loop if (prim.mode == PrimitiveMode_LINE_LOOP) { // close the loop
SetFace(faces[count - 1], faces[count - 2].mIndices[1], faces[0].mIndices[0]); SetFaceAndAdvance2(facePtr, aim->mNumVertices, count - 1, 0);
} }
break; break;
} }
@ -615,42 +628,50 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped."); ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped.");
count = (unsigned int)nFaces * 3; count = (unsigned int)nFaces * 3;
} }
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < count; i += 3) { for (unsigned int i = 0; i < count; i += 3) {
SetFace(faces[i / 3], i, i + 1, i + 2); SetFaceAndAdvance3(facePtr, aim->mNumVertices, i, i + 1, i + 2);
} }
break; break;
} }
case PrimitiveMode_TRIANGLE_STRIP: { case PrimitiveMode_TRIANGLE_STRIP: {
nFaces = count - 2; nFaces = count - 2;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
for (unsigned int i = 0; i < nFaces; ++i) { for (unsigned int i = 0; i < nFaces; ++i) {
//The ordering is to ensure that the triangles are all drawn with the same orientation //The ordering is to ensure that the triangles are all drawn with the same orientation
if ((i + 1) % 2 == 0) { if ((i + 1) % 2 == 0) {
//For even n, vertices n + 1, n, and n + 2 define triangle n //For even n, vertices n + 1, n, and n + 2 define triangle n
SetFace(faces[i], i + 1, i, i + 2); SetFaceAndAdvance3(facePtr, aim->mNumVertices, i + 1, i, i + 2);
} else { } else {
//For odd n, vertices n, n+1, and n+2 define triangle n //For odd n, vertices n, n+1, and n+2 define triangle n
SetFace(faces[i], i, i + 1, i + 2); SetFaceAndAdvance3(facePtr, aim->mNumVertices, i, i + 1, i + 2);
} }
} }
break; break;
} }
case PrimitiveMode_TRIANGLE_FAN: case PrimitiveMode_TRIANGLE_FAN:
nFaces = count - 2; nFaces = count - 2;
faces = new aiFace[nFaces]; facePtr = faces = new aiFace[nFaces];
SetFace(faces[0], 0, 1, 2); SetFaceAndAdvance3(facePtr, aim->mNumVertices, 0, 1, 2);
for (unsigned int i = 1; i < nFaces; ++i) { for (unsigned int i = 1; i < nFaces; ++i) {
SetFace(faces[i], faces[0].mIndices[0], faces[i - 1].mIndices[2], i + 2); SetFaceAndAdvance3(facePtr, aim->mNumVertices, 0, i + 1, i + 2);
} }
break; break;
} }
} }
if (nullptr != faces) { if (faces) {
aim->mFaces = faces; aim->mFaces = faces;
aim->mNumFaces = static_cast<unsigned int>(nFaces); const unsigned int actualNumFaces = static_cast<unsigned int>(facePtr - faces);
ai_assert(CheckValidFacesIndices(faces, static_cast<unsigned>(nFaces), aim->mNumVertices)); if (actualNumFaces < nFaces) {
ASSIMP_LOG_WARN("Some faces had out-of-range indices. Those faces were dropped.");
}
if (actualNumFaces == 0)
{
throw DeadlyImportError(std::string("Mesh \"") + aim->mName.C_Str() + "\" has no faces");
}
aim->mNumFaces = actualNumFaces;
ai_assert(CheckValidFacesIndices(faces, actualNumFaces, aim->mNumVertices));
} }
if (prim.material) { if (prim.material) {

View File

@ -1066,7 +1066,7 @@ endif()
ADD_DEFINITIONS( -DASSIMP_BUILD_DLL_EXPORT ) 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_SCL_SECURE_NO_WARNINGS )
ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
endif () endif ()

View File

@ -74,9 +74,9 @@ Here we implement only the C++ interface (Assimp::Exporter).
namespace Assimp { namespace Assimp {
#if _MSC_VER > 1920 #ifdef _MSC_VER
# pragma warning( disable : 4800 ) # pragma warning( disable : 4800 )
#endif // _WIN32 #endif // _MSC_VER
// PostStepRegistry.cpp // PostStepRegistry.cpp

View File

@ -53,9 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp; using namespace Assimp;
void mydummy() {} void mydummy() {}
#if _MSC_VER > 1920 #ifdef _MSC_VER
#pragma warning(disable : 4709) #pragma warning(disable : 4709)
#endif // _WIN32 #endif // _MSC_VER
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
/** Subdivider stub class to implement the Catmull-Clarke subdivision algorithm. The /** Subdivider stub class to implement the Catmull-Clarke subdivision algorithm. The
* implementation is basing on recursive refinement. Directly evaluating the result is also * implementation is basing on recursive refinement. Directly evaluating the result is also

View File

@ -312,10 +312,22 @@
__pragma(warning(disable: warnings)) __pragma(warning(disable: warnings))
# define GTEST_DISABLE_MSC_WARNINGS_POP_() \ # define GTEST_DISABLE_MSC_WARNINGS_POP_() \
__pragma(warning(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 #else
// Older versions of MSVC don't have __pragma. // Older versions of MSVC don't have __pragma.
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
# define GTEST_DISABLE_MSC_WARNINGS_POP_() # define GTEST_DISABLE_MSC_WARNINGS_POP_()
# define GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_()
# define GTEST_DISABLE_CLANG_WARNINGS_POP_()
#endif #endif
#ifndef GTEST_LANG_CXX11 #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. // Functions deprecated by MSVC 8.0.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */) 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) { inline const char* StrNCpy(char* dest, const char* src, size_t n) {
return strncpy(dest, src, n); return strncpy(dest, src, n);
@ -2399,6 +2412,7 @@ inline const char* GetEnv(const char* name) {
#endif #endif
} }
GTEST_DISABLE_CLANG_WARNINGS_POP_()
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE

View File

@ -926,7 +926,7 @@ GTestLog::~GTestLog() {
// Disable Microsoft deprecation warnings for POSIX functions called from // Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close) // this class (creat, dup, dup2, and close)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
GTEST_DISABLE_CLANG_DEPRECATED_WARNINGS_PUSH_()
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Object that captures an output stream (stdout/stderr). // Object that captures an output stream (stdout/stderr).
@ -1010,6 +1010,7 @@ class CapturedStream {
}; };
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
GTEST_DISABLE_CLANG_WARNINGS_POP_()
static CapturedStream* g_captured_stderr = NULL; static CapturedStream* g_captured_stderr = NULL;
static CapturedStream* g_captured_stdout = NULL; static CapturedStream* g_captured_stdout = NULL;

View File

@ -31,7 +31,7 @@
#include <limits> #include <limits>
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
#ifdef _MSC_VER #if defined(_MSC_VER) && !(__clang__)
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
#endif #endif

View File

@ -17,7 +17,7 @@
#include "rapidjson.h" #include "rapidjson.h"
#ifdef _MSC_VER #if defined(_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data
RAPIDJSON_DIAG_OFF(4702) // unreachable code RAPIDJSON_DIAG_OFF(4702) // unreachable code
@ -709,7 +709,7 @@ struct Transcoder<Encoding, Encoding> {
RAPIDJSON_NAMESPACE_END RAPIDJSON_NAMESPACE_END
#if defined(__GNUC__) || defined(_MSC_VER) #if defined(__GNUC__) || (defined(_MSC_VER) && !defined(__clang__))
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif

View File

@ -21,7 +21,7 @@
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++) RAPIDJSON_DIAG_OFF(effc++)
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(6334) RAPIDJSON_DIAG_OFF(6334)
#endif #endif
@ -174,7 +174,7 @@ template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type;
RAPIDJSON_NAMESPACE_END RAPIDJSON_NAMESPACE_END
//@endcond //@endcond
#if defined(__GNUC__) || defined(_MSC_VER) #if defined(__GNUC__) || (defined(_MSC_VER) && !defined(__clang__))
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif

View File

@ -37,7 +37,7 @@
#include <arm_neon.h> #include <arm_neon.h>
#endif #endif
#ifdef _MSC_VER #if defined(_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
RAPIDJSON_DIAG_OFF(4702) // unreachable code RAPIDJSON_DIAG_OFF(4702) // unreachable code
@ -2214,7 +2214,7 @@ RAPIDJSON_DIAG_POP
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif
#ifdef _MSC_VER #if defined(_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif

View File

@ -36,7 +36,7 @@
#include <arm_neon.h> #include <arm_neon.h>
#endif #endif
#ifdef _MSC_VER #if defined (_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
#endif #endif
@ -700,11 +700,11 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
RAPIDJSON_NAMESPACE_END RAPIDJSON_NAMESPACE_END
#ifdef _MSC_VER #if defined(_MSC_VER) && !defined(__clang__)
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif
#ifdef __clang__ #if defined(__clang__)
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif

View File

@ -16,6 +16,10 @@
#ifdef _WIN32 #ifdef _WIN32
# pragma warning(push) # pragma warning(push)
# pragma warning(disable : 4131 4100) # pragma warning(disable : 4131 4100)
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-parameter"
# endif
#endif // _WIN32 #endif // _WIN32
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ /* 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 #ifdef _WIN32
# pragma warning(pop) # pragma warning(pop)
# ifdef __clang__
# pragma clang diagnostic pop
# endif
#endif // _WIN32 #endif // _WIN32

View File

@ -24,7 +24,7 @@
#ifndef ZCALLBACK #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 #define ZCALLBACK CALLBACK
#else #else
#define ZCALLBACK #define ZCALLBACK

View File

@ -1554,7 +1554,6 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
char *szComment; char *szComment;
uLong uSizeBuf; uLong uSizeBuf;
{ {
int err=UNZ_OK;
unz_s* s; unz_s* s;
uLong uReadThis ; uLong uReadThis ;
if (file==NULL) if (file==NULL)

View File

@ -5361,7 +5361,7 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip,
} else { } else {
// Temporarily allocate a read buffer. // Temporarily allocate a read buffer.
read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); 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))) && if (((0, sizeof(size_t) == sizeof(mz_uint32))) &&
(read_buf_size > 0x7FFFFFFF)) (read_buf_size > 0x7FFFFFFF))
#else #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); uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; 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)) if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
#else #else
if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) 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)) { if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) {
// The file is stored or the caller has requested the compressed data. // The file is stored or the caller has requested the compressed data.
if (pZip->m_pState->m_pMem) { if (pZip->m_pState->m_pMem) {
#ifdef _MSC_VER #if defined (_MSC_VER) && !defined(__clang__)
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && if (((0, sizeof(size_t) == sizeof(mz_uint32))) &&
(file_stat.m_comp_size > 0xFFFFFFFF)) (file_stat.m_comp_size > 0xFFFFFFFF))
#else #else

View File

@ -39,9 +39,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
*/ */
#include <assimp/cimport.h> #include <assimp/cimport.h>
#include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
using namespace Assimp;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) {
aiLogStream stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); aiLogStream stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
aiAttachLogStream(&stream); aiAttachLogStream(&stream);

View File

@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
#include <memory>
struct aiScene; struct aiScene;
struct aiImporterDesc; struct aiImporterDesc;
@ -391,6 +392,24 @@ public: // static utilities
} }
} }
// -------------------------------------------------------------------
/** Utility function to move a std::vector of unique_ptrs into a aiScene array
* @param vec The vector of unique_ptrs to be moved
* @param out The output pointer to the allocated array.
* @param numOut The output count of elements copied. */
template <typename T>
AI_FORCE_INLINE static void CopyVector(
std::vector<std::unique_ptr<T>> &vec,
T **&out,
unsigned int &outLength) {
outLength = unsigned(vec.size());
if (outLength) {
out = new T*[outLength];
T** outPtr = out;
std::for_each(vec.begin(), vec.end(), [&outPtr](std::unique_ptr<T>& uPtr){*outPtr = uPtr.release(); ++outPtr; });
}
}
protected: protected:
/// Error description in case there was one. /// Error description in case there was one.
std::string m_ErrorText; std::string m_ErrorText;

View File

@ -14,7 +14,7 @@
#endif #endif
// reset packing to the original value // 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 ) # pragma pack( pop )
#endif #endif
#undef PACK_STRUCT #undef PACK_STRUCT

View File

@ -22,7 +22,7 @@
# error poppack1.h must be included after pushpack1.h # error poppack1.h must be included after pushpack1.h
#endif #endif
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #if (defined(_MSC_VER) && !defined(__clang__)) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack(push,1) # pragma pack(push,1)
# define PACK_STRUCT # define PACK_STRUCT
#elif defined( __GNUC__ ) || defined(__clang__) #elif defined( __GNUC__ ) || defined(__clang__)

View File

@ -0,0 +1,142 @@
{
"asset": {
"generator": "COLLADA2GLTF",
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"mesh": 0
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "Mesh"
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"count": 36,
"max": [
255
],
"min": [
0
],
"type": "SCALAR"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"count": 24,
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 288,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
0.800000011920929,
0.0,
0.0,
1.0
],
"metallicFactor": 0.0
},
"name": "Red"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 576,
"byteLength": 72,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 576,
"byteStride": 12,
"target": 34962
}
],
"buffers": [
{
"byteLength": 648,
"uri": "AllIndicesOutOfRange.bin"
}
]
}

View File

@ -0,0 +1,142 @@
{
"asset": {
"generator": "COLLADA2GLTF",
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"mesh": 0
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "Mesh"
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"count": 36,
"max": [
255
],
"min": [
0
],
"type": "SCALAR"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"count": 24,
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 288,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
0.800000011920929,
0.0,
0.0,
1.0
],
"metallicFactor": 0.0
},
"name": "Red"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 576,
"byteLength": 72,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 576,
"byteStride": 12,
"target": 34962
}
],
"buffers": [
{
"byteLength": 648,
"uri": "IndexOutOfRange.bin"
}
]
}

View File

@ -44,21 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstdlib> #include <cstdlib>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#if defined(__GNUC__) || defined(__clang__) #if defined(_MSC_VER)
#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)
#include <io.h> #include <io.h>
#define TMP_PATH "./" #define TMP_PATH "./"
inline FILE* MakeTmpFile(char* tmplate) inline FILE* MakeTmpFile(char* tmplate)
@ -73,4 +59,18 @@ inline FILE* MakeTmpFile(char* tmplate)
EXPECT_NE(fs, nullptr); EXPECT_NE(fs, nullptr);
return fs; 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 #endif

View File

@ -157,7 +157,6 @@ public:
static inline void CheckNodeIdNames(IdNameMap &nodeIdMap, IdNameMap &nodeNameMap, const aiNode *parent, size_t index) { static inline void CheckNodeIdNames(IdNameMap &nodeIdMap, IdNameMap &nodeNameMap, const aiNode *parent, size_t index) {
IdNameString namePair = GetItemIdName(parent, index); IdNameString namePair = GetItemIdName(parent, index);
const auto result = nodeNameMap.insert(namePair);
IdNameString idPair = GetColladaIdName(parent, index); IdNameString idPair = GetColladaIdName(parent, index);
ReportDuplicate(nodeIdMap, idPair, typeid(aiNode).name()); ReportDuplicate(nodeIdMap, idPair, typeid(aiNode).name());

View File

@ -46,11 +46,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/Exporter.hpp> #include <assimp/Exporter.hpp>
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/LogStream.hpp>
#include <assimp/DefaultLogger.hpp>
#include <array> #include <array>
#include <assimp/pbrmaterial.h> #include <assimp/pbrmaterial.h>
using namespace Assimp; using namespace Assimp;
class utglTF2ImportExport : public AbstractImportExportBase { class utglTF2ImportExport : public AbstractImportExportBase {
@ -541,3 +543,34 @@ TEST_F(utglTF2ImportExport, norootnode_issue_3269) {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/issue_3269/texcoord_crash.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/issue_3269/texcoord_crash.gltf", aiProcess_ValidateDataStructure);
ASSERT_EQ(scene, nullptr); ASSERT_EQ(scene, nullptr);
} }
TEST_F(utglTF2ImportExport, indexOutOfRange) {
// The contents of an asset should not lead to an assert.
Assimp::Importer importer;
struct LogObserver : Assimp::LogStream {
bool m_observedWarning = false;
void write(const char *message) override {
m_observedWarning = m_observedWarning || std::strstr(message, "faces were dropped");
}
};
LogObserver logObserver;
DefaultLogger::get()->attachStream(&logObserver);
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/IndexOutOfRange/IndexOutOfRange.gltf", aiProcess_ValidateDataStructure);
ASSERT_NE(scene, nullptr);
ASSERT_NE(scene->mRootNode, nullptr);
ASSERT_EQ(scene->mNumMeshes, 1u);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 11u);
DefaultLogger::get()->detachStream(&logObserver);
EXPECT_TRUE(logObserver.m_observedWarning);
}
TEST_F(utglTF2ImportExport, allIndicesOutOfRange) {
// The contents of an asset should not lead to an assert.
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/IndexOutOfRange/AllIndicesOutOfRange.gltf", aiProcess_ValidateDataStructure);
ASSERT_EQ(scene, nullptr);
std::string error = importer.GetErrorString();
ASSERT_NE(error.find("Mesh \"Mesh\" has no faces"), std::string::npos);
}