[Bf-blender-cvs] [fed0cdf3cbf] soc-2021-adaptive-cloth: adaptive_cloth: test: MeshReader simple cube read

ishbosamiya noreply at git.blender.org
Mon Jun 28 08:28:22 CEST 2021


Commit: fed0cdf3cbf790c5d6ea3c4af6c942b51274f03e
Author: ishbosamiya
Date:   Tue Jun 22 23:31:06 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rBfed0cdf3cbf790c5d6ea3c4af6c942b51274f03e

adaptive_cloth: test: MeshReader simple cube read

===================================================================

M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index c1aa319fdf7..f17cc7ff863 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -49,6 +49,7 @@ void BKE_cloth_remesh(const struct Object *ob,
 #  include <bits/stdint-uintn.h>
 #  include <filesystem>
 #  include <fstream>
+#  include <istream>
 #  include <limits>
 #  include <sstream>
 #  include <string>
@@ -302,8 +303,13 @@ class MeshReader {
       return false;
     }
 
+    return read(std::move(fin), type);
+  }
+
+  bool read(std::istream &&in, FileType type)
+  {
     if (type == FILETYPE_OBJ) {
-      auto res = this->read_obj(std::move(fin));
+      auto res = this->read_obj(std::move(in));
       if (!res) {
         return false;
       }
@@ -315,6 +321,31 @@ class MeshReader {
     return true;
   }
 
+  const auto &get_positions() const
+  {
+    return this->positions;
+  }
+
+  const auto &get_uvs() const
+  {
+    return this->uvs;
+  }
+
+  const auto &get_normals() const
+  {
+    return this->normals;
+  }
+
+  const auto &get_face_indices() const
+  {
+    return this->face_indices;
+  }
+
+  const auto &get_line_indices() const
+  {
+    return this->line_indices;
+  }
+
  private:
   blender::Vector<std::string> tokenize(std::string const &str, const char delim)
   {
@@ -330,10 +361,10 @@ class MeshReader {
     return res;
   }
 
-  bool read_obj(std::fstream &&fin)
+  bool read_obj(std::istream &&in)
   {
     std::string line;
-    while (std::getline(fin, line)) {
+    while (std::getline(in, line)) {
       if (line.rfind('#', 0) == 0) {
         continue;
       }
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 112c1ccd164..a425f832600 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -773,6 +773,8 @@ if(WITH_GTESTS)
     intern/layer_test.cc
     intern/lib_id_test.cc
     intern/tracking_test.cc
+
+    tests/BKE_cloth_remesh_test.cc
   )
   set(TEST_INC
     ../editors/include
diff --git a/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc b/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc
new file mode 100644
index 00000000000..5e188b36ebb
--- /dev/null
+++ b/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc
@@ -0,0 +1,73 @@
+#include "BKE_cloth_remesh.hh"
+
+#include "testing/testing.h"
+#include <gtest/gtest.h>
+#include <sstream>
+
+namespace blender::bke::tests {
+
+using namespace internal;
+
+TEST(cloth_remesh, MeshReader)
+{
+  MeshReader reader;
+  std::string file =
+      "# Blender v3.0.0 Alpha OBJ File: ''\n"
+      "# www.blender.org\n"
+      "mtllib untitled.mtl\n"
+      "o Cube\n"
+      "v 1.000000 1.000000 -1.000000\n"
+      "v 1.000000 -1.000000 -1.000000\n"
+      "v 1.000000 1.000000 1.000000\n"
+      "v 1.000000 -1.000000 1.000000\n"
+      "v -1.000000 1.000000 -1.000000\n"
+      "v -1.000000 -1.000000 -1.000000\n"
+      "v -1.000000 1.000000 1.000000\n"
+      "v -1.000000 -1.000000 1.000000\n"
+      "vt 0.625000 0.500000\n"
+      "vt 0.875000 0.500000\n"
+      "vt 0.875000 0.750000\n"
+      "vt 0.625000 0.750000\n"
+      "vt 0.375000 0.750000\n"
+      "vt 0.625000 1.000000\n"
+      "vt 0.375000 1.000000\n"
+      "vt 0.375000 0.000000\n"
+      "vt 0.625000 0.000000\n"
+      "vt 0.625000 0.250000\n"
+      "vt 0.375000 0.250000\n"
+      "vt 0.125000 0.500000\n"
+      "vt 0.375000 0.500000\n"
+      "vt 0.125000 0.750000\n"
+      "vn 0.0000 1.0000 0.0000\n"
+      "vn 0.0000 0.0000 1.0000\n"
+      "vn -1.0000 0.0000 0.0000\n"
+      "vn 0.0000 -1.0000 0.0000\n"
+      "vn 1.0000 0.0000 0.0000\n"
+      "vn 0.0000 0.0000 -1.0000\n"
+      "usemtl Material\n"
+      "s off\n"
+      "f 1/1/1 5/2/1 7/3/1 3/4/1\n"
+      "f 4/5/2 3/4/2 7/6/2 8/7/2\n"
+      "f 8/8/3 7/9/3 5/10/3 6/11/3\n"
+      "f 6/12/4 2/13/4 4/5/4 8/14/4\n"
+      "f 2/13/5 1/1/5 3/4/5 4/5/5\n"
+      "f 6/11/6 5/10/6 1/1/6 2/13/6\n";
+  std::istringstream stream(file);
+  auto res = reader.read(std::move(stream), MeshReader::FILETYPE_OBJ);
+
+  EXPECT_TRUE(res);
+
+  const auto positions = reader.get_positions();
+  const auto uvs = reader.get_uvs();
+  const auto normals = reader.get_normals();
+  const auto face_indices = reader.get_face_indices();
+  const auto line_indices = reader.get_line_indices();
+
+  EXPECT_EQ(positions.size(), 8);
+  EXPECT_EQ(uvs.size(), 14);
+  EXPECT_EQ(normals.size(), 6);
+  EXPECT_EQ(face_indices.size(), 6);
+  EXPECT_EQ(line_indices.size(), 0);
+}
+
+} /* namespace blender::bke::tests */



More information about the Bf-blender-cvs mailing list