瀏覽代碼

Add unit test for subdivision modifier on Blender importer (#5345)

* Add unit test for subdivision modifier on Blender importer

Blend file is composed of default cube with subdivision modifier applied
and same cube with subdivision modifier.

* Update utBlenderImportExport.cpp

Fix compiler warning.

---------

Co-authored-by: Kim Kulling <[email protected]>
Alexandre Avenel 2 周之前
父節點
當前提交
6401aa9744
共有 2 個文件被更改,包括 23 次插入0 次删除
  1. 二進制
      test/models/BLEND/subdivision_test_277.blend
  2. 23 0
      test/unit/utBlenderImportExport.cpp

二進制
test/models/BLEND/subdivision_test_277.blend


+ 23 - 0
test/unit/utBlenderImportExport.cpp

@@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <assimp/postprocess.h>
 #include <assimp/Importer.hpp>
 #include <assimp/scene.h>
+#include <assimp/SpatialSort.h>
 
 using namespace Assimp;
 
@@ -219,3 +220,25 @@ TEST(utBlenderImporter, importFleurOptonl) {
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_NONBSD_DIR "/BLEND/fleurOptonl.blend", aiProcess_ValidateDataStructure);
     ASSERT_NE(nullptr, scene);
 }
+
+/// This test contains a default cube with subdivision surface modifier and a default cube with subdivision surface applied.
+/// Vertices should be identical.
+TEST_F(utBlenderImporterExporter, importBlendWithSubdivisionSurface) {
+    Assimp::Importer importer;
+    const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/subdivision_test_277.blend", aiProcess_ValidateDataStructure);
+    EXPECT_NE(nullptr, scene);
+    EXPECT_EQ(scene->mNumMeshes, 2u);
+    EXPECT_EQ(scene->mMeshes[0]->mNumVertices, scene->mMeshes[1]->mNumVertices);
+
+    SpatialSort spatialSortVertices0;
+    spatialSortVertices0.Fill(scene->mMeshes[0]->mVertices, scene->mMeshes[0]->mNumVertices, sizeof(aiVector3D), true);
+
+    for (unsigned int i = 0; i < scene->mMeshes[1]->mNumVertices; ++i)
+    {
+        auto positionMesh1 = scene->mMeshes[1]->mVertices[i];
+        std::vector<unsigned int> spatialSortResult;
+        spatialSortVertices0.FindPositions(positionMesh1, 1.0e-6f, spatialSortResult);
+
+        EXPECT_TRUE(scene->mMeshes[0]->mVertices[spatialSortResult[0]].Equal(positionMesh1));
+    }
+}