From 87ac6fbfd94199c049037a5d76ab117944c26b3c Mon Sep 17 00:00:00 2001 From: "Andrea Baldacci, Ph.D" Date: Tue, 31 Oct 2017 02:05:01 +0100 Subject: [PATCH 01/25] Update CMakeLists.txt --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c30278b7f..270aad38a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,11 @@ ELSEIF( CMAKE_COMPILER_IS_MINGW ) ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() +if(IOS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") +endif(IOS) + if (ASSIMP_COVERALLS) MESSAGE(STATUS "Coveralls enabled") INCLUDE(Coveralls) From 978c156c2ad84d3b8afcabbc55ff966aafe3ecec Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Wed, 10 Jan 2018 20:02:41 +0100 Subject: [PATCH 02/25] added import of material properties (double sided and transparency) in glTF 1.0 importer. --- code/glTFImporter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index 381e459fd..9e341c632 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -193,9 +193,16 @@ void glTFImporter::ImportMaterials(glTF::Asset& r) aimat->AddProperty(&str, AI_MATKEY_NAME); } - SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE); + SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT ); + SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE ); SetMaterialColorProperty(embeddedTexIdxs, r, mat.specular, aimat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR); - SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT); + SetMaterialColorProperty(embeddedTexIdxs, r, mat.emission, aimat, aiTextureType_EMISSIVE, AI_MATKEY_COLOR_EMISSIVE); + + aimat->AddProperty(&mat.doubleSided, 1, AI_MATKEY_TWOSIDED); + + if (mat.transparent && (mat.transparency != 1.0f)) { + aimat->AddProperty(&mat.transparency, 1, AI_MATKEY_OPACITY); + } if (mat.shininess > 0.f) { aimat->AddProperty(&mat.shininess, 1, AI_MATKEY_SHININESS); From c749594e9de7b98ae63000aef19013dcc020d441 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Thu, 18 Jan 2018 19:12:51 +0100 Subject: [PATCH 03/25] gltf instant ok on valid extension. --- code/glTF2Importer.cpp | 4 ++-- code/glTFImporter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 92328ec2d..8136af2dc 100644 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -103,8 +103,8 @@ bool glTF2Importer::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension != "gltf" && extension != "glb") - return false; + if (extension == "gltf" || extension == "glb") + return true; if (pIOHandler) { glTF2::Asset asset(pIOHandler); diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index b4d69e32f..4df9e1763 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -102,8 +102,8 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension != "gltf" && extension != "glb") - return false; + if (extension == "gltf" || extension == "glb") + return true; if (pIOHandler) { glTF::Asset asset(pIOHandler); From 5f38bd01ece06876250fd3bab4f72456170cf3e4 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Thu, 18 Jan 2018 22:28:44 +0100 Subject: [PATCH 04/25] restored gltf checks. --- code/glTF2Importer.cpp | 4 ++-- code/glTFImporter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 8136af2dc..92328ec2d 100644 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -103,8 +103,8 @@ bool glTF2Importer::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension == "gltf" || extension == "glb") - return true; + if (extension != "gltf" && extension != "glb") + return false; if (pIOHandler) { glTF2::Asset asset(pIOHandler); diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index 4df9e1763..b4d69e32f 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -102,8 +102,8 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension == "gltf" || extension == "glb") - return true; + if (extension != "gltf" && extension != "glb") + return false; if (pIOHandler) { glTF::Asset asset(pIOHandler); From 59ea3b6c8577c4e46e8ca0ca68afcf9efa92cf0a Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Fri, 9 Feb 2018 16:02:27 +0100 Subject: [PATCH 05/25] fixed android zlib compile error. --- CMakeLists.txt | 8 ++++---- contrib/zlib/zlib.h | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d3616ab7..15374a3fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,10 +230,10 @@ ELSEIF( CMAKE_COMPILER_IS_MINGW ) ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() -if(IOS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") -endif(IOS) +if (IOS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") +endif() if (ASSIMP_COVERALLS) MESSAGE(STATUS "Coveralls enabled") diff --git a/contrib/zlib/zlib.h b/contrib/zlib/zlib.h index 2d6bb2976..dcb7b5063 100644 --- a/contrib/zlib/zlib.h +++ b/contrib/zlib/zlib.h @@ -77,8 +77,9 @@ extern "C" { the consistency of the compressed data, so the library should never crash even in the case of corrupted input. */ -#ifdef __ANDROID__ -using zcrc_t = unsigned_long; + +#ifdef __ANDROID__ +typedef unsigned long zcrc_t; #endif typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); From c874fd8ae2626334f7920715d4e6977529297dff Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Fri, 9 Feb 2018 16:18:49 +0100 Subject: [PATCH 06/25] changed std::to_string to to_string. --- code/3DSLoader.cpp | 2 +- code/glTFAsset.inl | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index 9d61e125c..92a64e3d8 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -349,7 +349,7 @@ void Discreet3DSImporter::ParseObjectChunk() case Discreet3DS::CHUNK_MAT_MATERIAL: // Add a new material to the list - mScene->mMaterials.push_back(D3DS::Material(std::string("UNNAMED_" + std::to_string(mScene->mMaterials.size())))); + mScene->mMaterials.push_back(D3DS::Material(std::string("UNNAMED_" + to_string(mScene->mMaterials.size())))); ParseMaterialChunk(); break; diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index b31846abd..bd43b19f2 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -948,24 +948,24 @@ Ref buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer); size_t size_coordindex = ifs.GetNCoordIndex() * 3;// See float attributes note. if(primitives[0].indices->count != size_coordindex) - throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + std::to_string(size_coordindex) + - ") not equal to uncompressed (" + std::to_string(primitives[0].indices->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + to_string(size_coordindex) + + ") not equal to uncompressed (" + to_string(primitives[0].indices->count) + ")."); size_coordindex *= sizeof(IndicesType); // Coordinates size_t size_coord = ifs.GetNCoord();// See float attributes note. if(primitives[0].attributes.position[0]->count != size_coord) - throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + std::to_string(size_coord) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.position[0]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + to_string(size_coord) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.position[0]->count) + ")."); size_coord *= 3 * sizeof(float); // Normals size_t size_normal = ifs.GetNNormal();// See float attributes note. if(primitives[0].attributes.normal[0]->count != size_normal) - throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + std::to_string(size_normal) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.normal[0]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + to_string(size_normal) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.normal[0]->count) + ")."); size_normal *= 3 * sizeof(float); // Additional attributes. @@ -989,8 +989,8 @@ Ref buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer); if(idx_texcoord < primitives[0].attributes.texcoord.size()) { if(primitives[0].attributes.texcoord[idx]->count != tval) - throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + std::to_string(tval) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.texcoord[idx]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + to_string(tval) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.texcoord[idx]->count) + ")."); idx_texcoord++; } From 4b7cd97fea9dc37f4b741840090c42c6a6a027ae Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 17:44:40 +0100 Subject: [PATCH 07/25] added support for embedded textures defined with buffer views. --- code/glTF2Asset.inl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 520785081..cf43d67f1 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -669,7 +669,7 @@ inline Image::Image() } -inline void Image::Read(Value& obj, Asset& /*r*/) +inline void Image::Read(Value& obj, Asset& r) { if (!mDataLength) { if (Value* uri = FindString(obj, "uri")) { @@ -686,6 +686,18 @@ inline void Image::Read(Value& obj, Asset& /*r*/) this->uri = uristr; } } + else if (Value* bufferViewVal = FindUInt(obj, "bufferView")) { + this->bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint()); + Ref buffer = this->bufferView->buffer; + + this->mDataLength = this->bufferView->byteLength; + this->mData = new uint8_t [this->mDataLength]; + memcpy(this->mData, buffer->GetPointer(), this->mDataLength); + + if (Value* mtype = FindString(obj, "mimeType")) { + this->mimeType = mtype->GetString(); + } + } } } From 138b990d0a9e7833bec242517f448df8ee69e861 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 17:57:42 +0100 Subject: [PATCH 08/25] added missing install of pbrmaterial.h --- code/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 6430187b0..6e2db91db 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -72,6 +72,7 @@ SET( PUBLIC_HEADERS ${HEADER_PATH}/matrix4x4.h ${HEADER_PATH}/matrix4x4.inl ${HEADER_PATH}/mesh.h + ${HEADER_PATH}/pbrmaterial.h ${HEADER_PATH}/postprocess.h ${HEADER_PATH}/quaternion.h ${HEADER_PATH}/quaternion.inl From 72e9f3ecb9bd12056d6992d87d3511546486df72 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 18:47:43 +0100 Subject: [PATCH 09/25] fixed embedded texture reading. --- code/glTF2Asset.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index cf43d67f1..8f2b14e1a 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -691,8 +691,9 @@ inline void Image::Read(Value& obj, Asset& r) Ref buffer = this->bufferView->buffer; this->mDataLength = this->bufferView->byteLength; + // maybe this memcpy could be avoided if aiTexture does not delete[] pcData at destruction. this->mData = new uint8_t [this->mDataLength]; - memcpy(this->mData, buffer->GetPointer(), this->mDataLength); + memcpy(this->mData, buffer->GetPointer() + this->bufferView->byteOffset, this->mDataLength); if (Value* mtype = FindString(obj, "mimeType")) { this->mimeType = mtype->GetString(); From e7736022c8aae264011b7d097ae8338e29cebe47 Mon Sep 17 00:00:00 2001 From: Tommy Date: Sun, 25 Feb 2018 09:34:14 +0100 Subject: [PATCH 10/25] assimp_cmd info: list meshes and print basic mesh stats. --- tools/assimp_cmd/Info.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/assimp_cmd/Info.cpp b/tools/assimp_cmd/Info.cpp index a9f66eb1f..c4d5fe189 100644 --- a/tools/assimp_cmd/Info.cpp +++ b/tools/assimp_cmd/Info.cpp @@ -329,6 +329,29 @@ int Assimp_Info (const char* const* params, unsigned int num) special_points[2][0],special_points[2][1],special_points[2][2] ) ; + + // meshes + if (scene->mNumMeshes) { + printf("\nMeshes: (name) [vertices / bones / faces | primitive_types]\n"); + } + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) { + const aiMesh* mesh = scene->mMeshes[i]; + printf(" %d (%s)", i, mesh->mName.C_Str()); + printf( + ": [%d / %d / %d |", + mesh->mNumVertices, + mesh->mNumBones, + mesh->mNumFaces + ); + const unsigned int ptypes = mesh->mPrimitiveTypes; + if (ptypes & aiPrimitiveType_POINT) { printf(" point"); } + if (ptypes & aiPrimitiveType_LINE) { printf(" line"); } + if (ptypes & aiPrimitiveType_TRIANGLE) { printf(" triangle"); } + if (ptypes & aiPrimitiveType_POLYGON) { printf(" polygon"); } + printf("]\n"); + } + + // materials unsigned int total=0; for(unsigned int i = 0;i < scene->mNumMaterials; ++i) { aiString name; @@ -340,6 +363,7 @@ int Assimp_Info (const char* const* params, unsigned int num) printf("\n"); } + // textures total=0; for(unsigned int i = 0;i < scene->mNumMaterials; ++i) { aiString name; @@ -369,6 +393,7 @@ int Assimp_Info (const char* const* params, unsigned int num) printf("\n"); } + // animations total=0; for(unsigned int i = 0;i < scene->mNumAnimations; ++i) { if (scene->mAnimations[i]->mName.length) { @@ -379,6 +404,7 @@ int Assimp_Info (const char* const* params, unsigned int num) printf("\n"); } + // node hierarchy printf("\nNode hierarchy:\n"); unsigned int cline=0; PrintHierarchy(scene->mRootNode,20,1000,cline,verbose); From 190190c1d75c32e0f2a758c9bbe37bd085a0d59e Mon Sep 17 00:00:00 2001 From: Josh Faust Date: Tue, 27 Feb 2018 14:58:04 -0800 Subject: [PATCH 11/25] Fix material index off-by-one error in some OBJ files (seen in a C4D export) --- code/ObjFileMtlImporter.cpp | 5 ++-- test/models/OBJ/cube_mtllib_after_g.mtl | 5 ++++ test/models/OBJ/cube_mtllib_after_g.obj | 32 +++++++++++++++++++++++++ test/unit/utObjImportExport.cpp | 13 ++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/models/OBJ/cube_mtllib_after_g.mtl create mode 100644 test/models/OBJ/cube_mtllib_after_g.obj diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index 835f529cc..584b3115c 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -303,11 +303,12 @@ void ObjFileMtlImporter::createMaterial() // New Material created m_pModel->m_pCurrentMaterial = new ObjFile::Material(); m_pModel->m_pCurrentMaterial->MaterialName.Set( name ); + m_pModel->m_MaterialLib.push_back( name ); + m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial; + if (m_pModel->m_pCurrentMesh) { m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast(m_pModel->m_MaterialLib.size() - 1); } - m_pModel->m_MaterialLib.push_back( name ); - m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial; } else { // Use older material m_pModel->m_pCurrentMaterial = (*it).second; diff --git a/test/models/OBJ/cube_mtllib_after_g.mtl b/test/models/OBJ/cube_mtllib_after_g.mtl new file mode 100644 index 000000000..63dde71af --- /dev/null +++ b/test/models/OBJ/cube_mtllib_after_g.mtl @@ -0,0 +1,5 @@ +newmtl MyMaterial +Ka 1.000 1.000 1.000 +Kd 1.000 1.000 1.000 +Ns 200.000 +Ks 0.050 0.050 0.050 diff --git a/test/models/OBJ/cube_mtllib_after_g.obj b/test/models/OBJ/cube_mtllib_after_g.obj new file mode 100644 index 000000000..dfd5997e8 --- /dev/null +++ b/test/models/OBJ/cube_mtllib_after_g.obj @@ -0,0 +1,32 @@ +g Object +mtllib cube_mtllib_after_g.mat +usemtl MyMaterial + +v 0.0 0.0 0.0 +v 0.0 0.0 1.0 +v 0.0 1.0 0.0 +v 0.0 1.0 1.0 +v 1.0 0.0 0.0 +v 1.0 0.0 1.0 +v 1.0 1.0 0.0 +v 1.0 1.0 1.0 + +vn 0.0 0.0 1.0 +vn 0.0 0.0 -1.0 +vn 0.0 1.0 0.0 +vn 0.0 -1.0 0.0 +vn 1.0 0.0 0.0 +vn -1.0 0.0 0.0 + +f 1//2 7//2 5//2 +f 1//2 3//2 7//2 +f 1//6 4//6 3//6 +f 1//6 2//6 4//6 +f 3//3 8//3 7//3 +f 3//3 4//3 8//3 +f 5//5 7//5 8//5 +f 5//5 8//5 6//5 +f 1//4 5//4 6//4 +f 1//4 6//4 2//4 +f 2//1 6//1 8//1 +f 2//1 8//1 4//1 diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 5a2e42350..10207a5bf 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -354,3 +354,16 @@ TEST_F(utObjImportExport, 0based_array_Test) { const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), 0); EXPECT_EQ(nullptr, scene); } + +TEST_F( utObjImportExport, mtllib_after_g ) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OBJ/cube_mtllib_after_g.obj", aiProcess_ValidateDataStructure ); + ASSERT_NE( nullptr, scene ); + + EXPECT_EQ(scene->mNumMeshes, 1U); + const aiMesh *mesh = scene->mMeshes[0]; + const aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex]; + aiString name; + ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name)); + EXPECT_STREQ("MyMaterial", name.C_Str()); +} \ No newline at end of file From a58f8e1c1a4127df2051ad955f87e4bab64909bd Mon Sep 17 00:00:00 2001 From: Tommy Date: Wed, 28 Feb 2018 23:38:49 +0100 Subject: [PATCH 12/25] FBX Export: add missing 0 value to file footer. --- code/FBXExporter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index f1c6290e2..8e32ed46c 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -247,6 +247,11 @@ void FBXExporter::WriteBinaryFooter() outfile->Write("\x00", 1, 1); } + // not sure what this is, but it seems to always be 0 in modern files + for (size_t i = 0; i < 4; ++i) { + outfile->Write("\x00", 1, 1); + } + // now the file version again { StreamWriterLE outstream(outfile); From 701f9ccfe9c6fce31a6b7d798b9fc75afcbd0f38 Mon Sep 17 00:00:00 2001 From: Tommy Date: Sat, 3 Mar 2018 19:53:49 +0100 Subject: [PATCH 13/25] FBX Export: minor tweak to footer. Should now be identical to those output by the FBX SDK. --- code/FBXExporter.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index 8e32ed46c..a2e6024ed 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -235,9 +235,6 @@ void FBXExporter::WriteBinaryFooter() outfile->Write(NULL_RECORD.c_str(), NULL_RECORD.size(), 1); outfile->Write(GENERIC_FOOTID.c_str(), GENERIC_FOOTID.size(), 1); - for (size_t i = 0; i < 4; ++i) { - outfile->Write("\x00", 1, 1); - } // here some padding is added for alignment to 16 bytes. // if already aligned, the full 16 bytes is added. From 065c264b34fc3151acfe215af5fece11d5010c67 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 12:52:38 +0100 Subject: [PATCH 14/25] Fix #1415 : float-color.ply is broken float-color.ply was broken because it doesn't have a newline at the end. I'm not sure if a file without newline should be considered valid ? Added more checks to float-color unit-test in order to fail as excepted. Fixed the shipped unit test. Add postprocess validation to PLY unit tests --- test/models/PLY/float-color.ply | 2 +- test/unit/utPLYImportExport.cpp | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/test/models/PLY/float-color.ply b/test/models/PLY/float-color.ply index 34353ad53..f419be34e 100644 --- a/test/models/PLY/float-color.ply +++ b/test/models/PLY/float-color.ply @@ -15,4 +15,4 @@ end_header 0.0 0.0 0.0 0 0 1 1 100.0 0.0 0.0 0 0 1 1 200.0 200.0 0.0 0 0 1 1 -3 0 1 2 \ No newline at end of file +3 0 1 2 diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 633beda5f..900f494f8 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include "AbstractImportExportBase.h" +#include using namespace ::Assimp; @@ -52,7 +53,7 @@ class utPLYImportExport : public AbstractImportExportBase { public: virtual bool importerTest() { Assimp::Importer importer; - const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0 ); + const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_EQ( 1u, scene->mNumMeshes ); EXPECT_NE( nullptr, scene->mMeshes[0] ); EXPECT_EQ( 8u, scene->mMeshes[0]->mNumVertices ); @@ -65,7 +66,7 @@ public: virtual bool exporterTest() { Importer importer; Exporter exporter; - const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "ply", ASSIMP_TEST_MODELS_DIR "/PLY/cube_test.ply")); @@ -89,19 +90,28 @@ TEST_F(utPLYImportExport, exportTest_Success ) { //Test issue 1623, crash when loading two PLY files in a row TEST_F(utPLYImportExport, importerMultipleTest) { Assimp::Importer importer; - const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); + scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); } TEST_F( utPLYImportExport, vertexColorTest ) { Assimp::Importer importer; - const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", 0 ); + const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", aiProcess_ValidateDataStructure); EXPECT_NE( nullptr, scene ); + EXPECT_EQ(1u, scene->mMeshes[0]->mNumFaces); + EXPECT_EQ(aiPrimitiveType_TRIANGLE, scene->mMeshes[0]->mPrimitiveTypes); + EXPECT_EQ(true, scene->mMeshes[0]->HasVertexColors(0)); + + auto first_face = scene->mMeshes[0]->mFaces[0]; + EXPECT_EQ(3, first_face.mNumIndices); + EXPECT_EQ(0, first_face.mIndices[0]); + EXPECT_EQ(1, first_face.mIndices[1]); + EXPECT_EQ(2, first_face.mIndices[2]); } static const char *test_file = @@ -125,6 +135,6 @@ static const char *test_file = TEST_F( utPLYImportExport, parseErrorTest ) { Assimp::Importer importer; - const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), 0 ); + const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), aiProcess_ValidateDataStructure); EXPECT_NE( nullptr, scene ); } From cd5881c9c05941f915c551416c2ef4673fb34e49 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 13:07:40 +0100 Subject: [PATCH 15/25] Add unit-test for PLY with UV coordinates --- test/models/PLY/cube_uv.ply | 45 +++++++++++++++++++++++++++++++++ test/unit/utPLYImportExport.cpp | 12 +++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/models/PLY/cube_uv.ply diff --git a/test/models/PLY/cube_uv.ply b/test/models/PLY/cube_uv.ply new file mode 100644 index 000000000..45ab0607a --- /dev/null +++ b/test/models/PLY/cube_uv.ply @@ -0,0 +1,45 @@ +ply +format ascii 1.0 +comment Created by Blender 2.77 (sub 0) - www.blender.org, source file: '' +element vertex 24 +property float x +property float y +property float z +property float nx +property float ny +property float nz +property float s +property float t +element face 6 +property list uchar uint vertex_indices +end_header +1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.000000 0.000000 +1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 1.000000 0.000000 +-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 1.000000 1.000000 +-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.000000 1.000000 +1.000000 0.999999 1.000000 0.000000 -0.000000 1.000000 0.000000 0.000000 +-1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000 1.000000 0.000000 +-1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 1.000000 1.000000 +0.999999 -1.000001 1.000000 0.000000 -0.000000 1.000000 0.000000 1.000000 +1.000000 1.000000 -1.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 +1.000000 0.999999 1.000000 1.000000 -0.000000 0.000000 1.000000 0.000000 +0.999999 -1.000001 1.000000 1.000000 -0.000000 0.000000 1.000000 1.000000 +1.000000 -1.000000 -1.000000 1.000000 -0.000000 0.000000 0.000000 1.000000 +1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 0.000000 0.000000 +0.999999 -1.000001 1.000000 -0.000000 -1.000000 -0.000000 1.000000 0.000000 +-1.000000 -1.000000 1.000000 -0.000000 -1.000000 -0.000000 1.000000 1.000000 +-1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 0.000000 1.000000 +-1.000000 -1.000000 -1.000000 -1.000000 0.000000 -0.000000 0.000000 0.000000 +-1.000000 -1.000000 1.000000 -1.000000 0.000000 -0.000000 1.000000 0.000000 +-1.000000 1.000000 1.000000 -1.000000 0.000000 -0.000000 1.000000 1.000000 +-1.000000 1.000000 -1.000000 -1.000000 0.000000 -0.000000 0.000000 1.000000 +1.000000 0.999999 1.000000 0.000000 1.000000 0.000000 0.000000 0.000000 +1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 +-1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 1.000000 +-1.000000 1.000000 1.000000 0.000000 1.000000 0.000000 0.000000 1.000000 +4 0 1 2 3 +4 4 5 6 7 +4 8 9 10 11 +4 12 13 14 15 +4 16 17 18 19 +4 20 21 22 23 diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 900f494f8..0bef096e7 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -99,6 +99,18 @@ TEST_F(utPLYImportExport, importerMultipleTest) { EXPECT_NE(nullptr, scene); } +TEST_F(utPLYImportExport, importPLYwithUV) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_uv.ply", aiProcess_ValidateDataStructure); + + EXPECT_NE(nullptr, scene); + EXPECT_NE(nullptr, scene->mMeshes[0]); + //This test model is using n-gons, so 6 faces instead of 12 tris + EXPECT_EQ(6u, scene->mMeshes[0]->mNumFaces); + EXPECT_EQ(aiPrimitiveType_POLYGON, scene->mMeshes[0]->mPrimitiveTypes); + EXPECT_EQ(true, scene->mMeshes[0]->HasTextureCoords(0)); +} + TEST_F( utPLYImportExport, vertexColorTest ) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", aiProcess_ValidateDataStructure); From bd80e92f788215708b5a0b7f3600c6d69df5c1ce Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 12:42:21 +0100 Subject: [PATCH 16/25] Add PLY loader unit test for binary files --- test/models/PLY/cube_binary.ply | Bin 0 -> 447 bytes test/unit/utPLYImportExport.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+) create mode 100644 test/models/PLY/cube_binary.ply diff --git a/test/models/PLY/cube_binary.ply b/test/models/PLY/cube_binary.ply new file mode 100644 index 0000000000000000000000000000000000000000..14d29ebd86d5be53fedd1933abe9b1bf95671c59 GIT binary patch literal 447 zcmZvW!EVAZ5JUrMLGoAZ7gSA8+>qdakb34C8D|5Q949iSBAobic8tmMeshes[0]->HasTextureCoords(0)); } +TEST_F(utPLYImportExport, importBinaryPLY) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_binary.ply", 0); + + EXPECT_NE(nullptr, scene); + EXPECT_NE(nullptr, scene->mMeshes[0]); + //This test model is double sided, so 12 faces instead of 6 + EXPECT_EQ(12u, scene->mMeshes[0]->mNumFaces); +} + TEST_F( utPLYImportExport, vertexColorTest ) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", aiProcess_ValidateDataStructure); From d2547e84f530fa5a243f95068a17f50178f3ad47 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 21:41:19 +0100 Subject: [PATCH 17/25] Fix for undefined behavior when loading binary PLY This commit fix undefined behavior reported by UBSAN when loading a binary PLY file. --- code/PlyParser.cpp | 68 ++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/code/PlyParser.cpp b/code/PlyParser.cpp index 85c0f823e..672ac9bde 100644 --- a/code/PlyParser.cpp +++ b/code/PlyParser.cpp @@ -1043,71 +1043,91 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer &streamBuffer, switch (eType) { case EDT_UInt: - out->iUInt = (uint32_t)*((uint32_t*)pCur); - pCur += 4; + { + uint32_t t; + memcpy(&t, pCur, sizeof(uint32_t)); + pCur += sizeof(uint32_t); // Swap endianness - if (p_bBE)ByteSwap::Swap((int32_t*)&out->iUInt); + if (p_bBE)ByteSwap::Swap(&t); + out->iUInt = t; break; + } case EDT_UShort: { - uint16_t i = *((uint16_t*)pCur); + uint16_t t; + memcpy(&t, pCur, sizeof(uint16_t)); + pCur += sizeof(uint16_t); // Swap endianness - if (p_bBE)ByteSwap::Swap(&i); - out->iUInt = (uint32_t)i; - pCur += 2; + if (p_bBE)ByteSwap::Swap(&t); + out->iUInt = t; break; } case EDT_UChar: { - out->iUInt = (uint32_t)(*((uint8_t*)pCur)); - pCur++; + uint8_t t; + memcpy(&t, pCur, sizeof(uint8_t)); + pCur += sizeof(uint8_t); + out->iUInt = t; break; } case EDT_Int: - out->iInt = *((int32_t*)pCur); - pCur += 4; + { + int32_t t; + memcpy(&t, pCur, sizeof(int32_t)); + pCur += sizeof(int32_t); // Swap endianness - if (p_bBE)ByteSwap::Swap(&out->iInt); + if (p_bBE)ByteSwap::Swap(&t); + out->iInt = t; break; + } case EDT_Short: { - int16_t i = *((int16_t*)pCur); + int16_t t; + memcpy(&t, pCur, sizeof(int16_t)); + pCur += sizeof(int16_t); // Swap endianness - if (p_bBE)ByteSwap::Swap(&i); - out->iInt = (int32_t)i; - pCur += 2; + if (p_bBE)ByteSwap::Swap(&t); + out->iInt = t; break; } case EDT_Char: - out->iInt = (int32_t)*((int8_t*)pCur); - pCur++; + { + int8_t t; + memcpy(&t, pCur, sizeof(int8_t)); + pCur += sizeof(int8_t); + out->iInt = t; break; + } case EDT_Float: { - out->fFloat = *((float*)pCur); + float t; + memcpy(&t, pCur, sizeof(float)); + pCur += sizeof(float); // Swap endianness - if (p_bBE)ByteSwap::Swap((int32_t*)&out->fFloat); - pCur += 4; + if (p_bBE)ByteSwap::Swap(&t); + out->fFloat = t; break; } case EDT_Double: { - out->fDouble = *((double*)pCur); + double t; + memcpy(&t, pCur, sizeof(double)); + pCur += sizeof(double); // Swap endianness - if (p_bBE)ByteSwap::Swap((int64_t*)&out->fDouble); - pCur += 8; + if (p_bBE)ByteSwap::Swap(&t); + out->fDouble = t; break; } default: From ecb64c5949b534a416726ed5f8e2fbfdc8962ebd Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 3 Mar 2018 16:44:15 +0100 Subject: [PATCH 18/25] Add unit test for issue 623 --- test/models/PLY/issue623.ply | 36 +++++++++++++++++++++++++++++++++ test/unit/utPLYImportExport.cpp | 12 +++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/models/PLY/issue623.ply diff --git a/test/models/PLY/issue623.ply b/test/models/PLY/issue623.ply new file mode 100644 index 000000000..af8811752 --- /dev/null +++ b/test/models/PLY/issue623.ply @@ -0,0 +1,36 @@ +ply +format ascii 1.0 +comment Created by Blender 2.77 (sub 0) - www.blender.org, source file: '' +element vertex 24 +property float x +property float y +property float z +property float nx +property float ny +property float nz +property list uchar uint vertex_indices +end_header +7.941797 1.432409 -0.927566 0.000000 0.000000 -1.000000 +7.941797 -2.321273 -0.927566 0.000000 0.000000 -1.000000 +4.188114 -2.321273 -0.927566 0.000000 0.000000 -1.000000 +4.188115 1.432410 -0.927566 0.000000 0.000000 -1.000000 +7.941798 1.432408 2.826117 0.000000 -0.000000 1.000000 +4.188114 1.432409 2.826117 0.000000 -0.000000 1.000000 +4.188113 -2.321273 2.826117 0.000000 -0.000000 1.000000 +7.941795 -2.321275 2.826117 0.000000 -0.000000 1.000000 +7.941797 1.432409 -0.927566 1.000000 -0.000000 0.000000 +7.941798 1.432408 2.826117 1.000000 -0.000000 0.000000 +7.941795 -2.321275 2.826117 1.000000 -0.000000 0.000000 +7.941797 -2.321273 -0.927566 1.000000 -0.000000 0.000000 +7.941797 -2.321273 -0.927566 -0.000000 -1.000000 -0.000000 +7.941795 -2.321275 2.826117 -0.000000 -1.000000 -0.000000 +4.188113 -2.321273 2.826117 -0.000000 -1.000000 -0.000000 +4.188114 -2.321273 -0.927566 -0.000000 -1.000000 -0.000000 +4.188114 -2.321273 -0.927566 -1.000000 0.000000 -0.000000 +4.188113 -2.321273 2.826117 -1.000000 0.000000 -0.000000 +4.188114 1.432409 2.826117 -1.000000 0.000000 -0.000000 +4.188115 1.432410 -0.927566 -1.000000 0.000000 -0.000000 +7.941798 1.432408 2.826117 0.000000 1.000000 0.000000 +7.941797 1.432409 -0.927566 0.000000 1.000000 0.000000 +4.188115 1.432410 -0.927566 0.000000 1.000000 0.000000 +4.188114 1.432409 2.826117 0.000000 1.000000 0.000000 diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index e5268a400..4e4b4dce9 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -136,6 +136,18 @@ TEST_F( utPLYImportExport, vertexColorTest ) { EXPECT_EQ(2, first_face.mIndices[2]); } +//Test issue #623, PLY importer should not automatically create faces +TEST_F(utPLYImportExport, pointcloudTest) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/issue623.ply", 0); + EXPECT_NE(nullptr, scene); + + EXPECT_EQ(1u, scene->mNumMeshes); + EXPECT_NE(nullptr, scene->mMeshes[0]); + EXPECT_EQ(24u, scene->mMeshes[0]->mNumVertices); + EXPECT_EQ(0u, scene->mMeshes[0]->mNumFaces); +} + static const char *test_file = "ply\n" "format ascii 1.0\n" From f053695176517da997fdb549f65bcc741112d786 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 3 Mar 2018 16:56:48 +0100 Subject: [PATCH 19/25] Fix issue #623 PLY importer should not create faces When the PLY file contains no faces, we should not create them. --- code/PlyLoader.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/code/PlyLoader.cpp b/code/PlyLoader.cpp index 5f4e556c1..88be670cc 100644 --- a/code/PlyLoader.cpp +++ b/code/PlyLoader.cpp @@ -244,30 +244,6 @@ void PLYImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSy // if no face list is existing we assume that the vertex // list is containing a list of points bool pointsOnly = mGeneratedMesh->mFaces == NULL ? true : false; - if (pointsOnly) { - if (mGeneratedMesh->mNumVertices < 3) { - if (mGeneratedMesh != NULL) { - delete(mGeneratedMesh); - mGeneratedMesh = nullptr; - } - - streamedBuffer.close(); - throw DeadlyImportError("Invalid .ply file: Not enough " - "vertices to build a proper face list. "); - } - - const unsigned int iNum = (unsigned int)mGeneratedMesh->mNumVertices / 3; - mGeneratedMesh->mNumFaces = iNum; - mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces]; - - for (unsigned int i = 0; i < iNum; ++i) { - mGeneratedMesh->mFaces[i].mNumIndices = 3; - mGeneratedMesh->mFaces[i].mIndices = new unsigned int[3]; - mGeneratedMesh->mFaces[i].mIndices[0] = (i * 3); - mGeneratedMesh->mFaces[i].mIndices[1] = (i * 3) + 1; - mGeneratedMesh->mFaces[i].mIndices[2] = (i * 3) + 2; - } - } // now load a list of all materials std::vector avMaterials; From 15fa86f100e1d4e4b71593198c408132fc827a97 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 00:12:53 +0100 Subject: [PATCH 20/25] Set primitive_type to point when PLY is a point cloud --- code/PlyLoader.cpp | 3 +++ test/unit/utPLYImportExport.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/code/PlyLoader.cpp b/code/PlyLoader.cpp index 88be670cc..1bdd6e694 100644 --- a/code/PlyLoader.cpp +++ b/code/PlyLoader.cpp @@ -244,6 +244,9 @@ void PLYImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSy // if no face list is existing we assume that the vertex // list is containing a list of points bool pointsOnly = mGeneratedMesh->mFaces == NULL ? true : false; + if (pointsOnly) { + mGeneratedMesh->mPrimitiveTypes = aiPrimitiveType::aiPrimitiveType_POINT; + } // now load a list of all materials std::vector avMaterials; diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 4e4b4dce9..c19571199 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -97,6 +97,8 @@ TEST_F(utPLYImportExport, importerMultipleTest) { scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); + EXPECT_NE(nullptr, scene->mMeshes[0]); + EXPECT_EQ(6u, scene->mMeshes[0]->mNumFaces); } TEST_F(utPLYImportExport, importPLYwithUV) { @@ -145,6 +147,7 @@ TEST_F(utPLYImportExport, pointcloudTest) { EXPECT_EQ(1u, scene->mNumMeshes); EXPECT_NE(nullptr, scene->mMeshes[0]); EXPECT_EQ(24u, scene->mMeshes[0]->mNumVertices); + EXPECT_EQ(aiPrimitiveType::aiPrimitiveType_POINT, scene->mMeshes[0]->mPrimitiveTypes); EXPECT_EQ(0u, scene->mMeshes[0]->mNumFaces); } From e7869c7db3392217e0e2cf9056798bc8f4f00e47 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 4 Mar 2018 23:10:30 +0100 Subject: [PATCH 21/25] PLY unit test : Fix aiPostProcess validation errors --- test/unit/utPLYImportExport.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index c19571199..e0f96195b 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -115,7 +115,7 @@ TEST_F(utPLYImportExport, importPLYwithUV) { TEST_F(utPLYImportExport, importBinaryPLY) { Assimp::Importer importer; - const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_binary.ply", 0); + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_binary.ply", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene->mMeshes[0]); @@ -141,6 +141,7 @@ TEST_F( utPLYImportExport, vertexColorTest ) { //Test issue #623, PLY importer should not automatically create faces TEST_F(utPLYImportExport, pointcloudTest) { Assimp::Importer importer; + //Could not use aiProcess_ValidateDataStructure since it's missing faces. const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/issue623.ply", 0); EXPECT_NE(nullptr, scene); @@ -172,6 +173,7 @@ static const char *test_file = TEST_F( utPLYImportExport, parseErrorTest ) { Assimp::Importer importer; - const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), aiProcess_ValidateDataStructure); + //Could not use aiProcess_ValidateDataStructure since it's missing faces. + const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), 0); EXPECT_NE( nullptr, scene ); } From d82fff757bcb003cb10af9d11f862b8451bebbde Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 5 Mar 2018 15:01:37 +0100 Subject: [PATCH 22/25] Update utObjImportExport.cpp Add missing end of line. --- test/unit/utObjImportExport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 10207a5bf..8aec9c443 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -366,4 +366,4 @@ TEST_F( utObjImportExport, mtllib_after_g ) { aiString name; ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name)); EXPECT_STREQ("MyMaterial", name.C_Str()); -} \ No newline at end of file +} From f4c37fa2455f9928348165213fe2a00892fef753 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Sat, 3 Mar 2018 17:03:30 +0100 Subject: [PATCH 23/25] Collada: add importer property that forces the use of collada names. Closes #1375. --- code/ColladaLoader.cpp | 6 ++++++ code/ColladaLoader.h | 1 + include/assimp/config.h.in | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index a3516f9c4..959a905ae 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -131,6 +131,7 @@ void ColladaLoader::SetupProperties(const Importer* pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0; + useColladaName = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES,0) != 0; } // ------------------------------------------------------------------------------------------------ @@ -1913,6 +1914,11 @@ const Collada::Node* ColladaLoader::FindNodeBySID( const Collada::Node* pNode, c // The name must be unique for proper node-bone association. std::string ColladaLoader::FindNameForNode( const Collada::Node* pNode) { + // If explicitly requested, just use the collada name. + if (useColladaName) { + return pNode->mName; + } + // Now setup the name of the assimp node. The collada name might not be // unique, so we use the collada ID. if (!pNode->mID.empty()) diff --git a/code/ColladaLoader.h b/code/ColladaLoader.h index c63bf2945..d61845b24 100644 --- a/code/ColladaLoader.h +++ b/code/ColladaLoader.h @@ -248,6 +248,7 @@ protected: bool noSkeletonMesh; bool ignoreUpDirection; + bool useColladaName; /** Used by FindNameForNode() to generate unique node names */ unsigned int mNodeNameCounter; diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index 071d58cd2..c9555fb38 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -934,6 +934,16 @@ enum aiComponent */ #define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION" +// --------------------------------------------------------------------------- +/** @brief Specifies whether the Collada loader should use Collada names as node names. + * + * If this property is set to true, the Collada names will be used as the + * node name. The default is to use the id tag (resp. sid tag, if no id tag is present) + * instead. + * Property type: Bool. Default value: false. + */ +#define AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES "IMPORT_COLLADA_USE_COLLADA_NAMES" + // ---------- All the Export defines ------------ /** @brief Specifies the xfile use double for real values of float From 0dab5c508e15d72ac9502a7e9f155ab880fa58e2 Mon Sep 17 00:00:00 2001 From: JeffH-BMG <37119778+JeffH-BMG@users.noreply.github.com> Date: Tue, 6 Mar 2018 13:55:32 -0500 Subject: [PATCH 24/25] STL binary Export should write 4-byte floats for vertex and normal coordinates The STL binary format uses 4-byte floats. When using double-precision builds of Asset Importer, the STL exporter was writing out 8-byte double values instead.. --- code/STLExporter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/STLExporter.cpp b/code/STLExporter.cpp index 4c7a8a639..3d681f8c7 100644 --- a/code/STLExporter.cpp +++ b/code/STLExporter.cpp @@ -172,12 +172,16 @@ void STLExporter :: WriteMeshBinary(const aiMesh* m) } nor.Normalize(); } - ai_real nx = nor.x, ny = nor.y, nz = nor.z; + // STL binary files use 4-byte floats. This may possibly cause loss of precision + // for clients using 8-byte doubles + float nx = (float) nor.x; + float ny = (float) nor.y; + float nz = (float) nor.z; AI_SWAP4(nx); AI_SWAP4(ny); AI_SWAP4(nz); mOutput.write((char *)&nx, 4); mOutput.write((char *)&ny, 4); mOutput.write((char *)&nz, 4); for(unsigned int a = 0; a < f.mNumIndices; ++a) { const aiVector3D& v = m->mVertices[f.mIndices[a]]; - ai_real vx = v.x, vy = v.y, vz = v.z; + float vx = (float) v.x, vy = (float) v.y, vz = (float) v.z; AI_SWAP4(vx); AI_SWAP4(vy); AI_SWAP4(vz); mOutput.write((char *)&vx, 4); mOutput.write((char *)&vy, 4); mOutput.write((char *)&vz, 4); } From 9f02c8a97c530e4d5d3ccf70688fd0f84e9c1923 Mon Sep 17 00:00:00 2001 From: Tommy Date: Thu, 1 Mar 2018 18:03:04 +0100 Subject: [PATCH 25/25] Fix default opacity of materials exported to FBX by Blender. --- code/FBXMaterial.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/code/FBXMaterial.cpp b/code/FBXMaterial.cpp index 10f3bbe6c..8bb3920de 100644 --- a/code/FBXMaterial.cpp +++ b/code/FBXMaterial.cpp @@ -54,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXProperties.h" #include +#include // std::transform + namespace Assimp { namespace FBX { @@ -82,11 +84,12 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con std::string templateName; - const char* const sh = shading.c_str(); - if(!strcmp(sh,"phong")) { + // lower-case shading because Blender (for example) writes "Phong" + std::transform(shading.begin(), shading.end(), shading.begin(), ::tolower); + if(shading == "phong") { templateName = "Material.FbxSurfacePhong"; } - else if(!strcmp(sh,"lambert")) { + else if(shading == "lambert") { templateName = "Material.FbxSurfaceLambert"; } else {