From ecb64c5949b534a416726ed5f8e2fbfdc8962ebd Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 3 Mar 2018 16:44:15 +0100 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 9f02c8a97c530e4d5d3ccf70688fd0f84e9c1923 Mon Sep 17 00:00:00 2001 From: Tommy Date: Thu, 1 Mar 2018 18:03:04 +0100 Subject: [PATCH 5/5] 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 {