[Bf-blender-cvs] [031c4732f45] soc-2020-io-performance: Importer: Support smooth shading for polygons.

Ankit Meel noreply at git.blender.org
Thu Jul 16 12:34:23 CEST 2020


Commit: 031c4732f45639fb53f466d4a128355b4a46b68c
Author: Ankit Meel
Date:   Thu Jul 16 15:59:42 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB031c4732f45639fb53f466d4a128355b4a46b68c

Importer: Support smooth shading for polygons.

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

M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc

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

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 978df62646b..06e43ebbbb7 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -76,6 +76,9 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
    * TODO ankitm Try to move the rest of the data parsing code in a conditional
    * depending on a valid "o" object. */
   std::unique_ptr<OBJRawObject> *curr_ob;
+  /* State-setting variable: if set, they remain the same for the remaining elements. */
+  bool shaded_smooth = false;
+
   while (std::getline(infile_, line)) {
     string line_key = first_word_of_string(line);
     std::stringstream s_line(line.substr(line_key.size()));
@@ -108,8 +111,31 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
       curr_tex_vert.flag = false;
       (*curr_ob)->texture_vertices.append(curr_tex_vert);
     }
+    else if (line_key == "s") {
+      string str_shading;
+      s_line >> str_shading;
+      if (str_shading != "0" && str_shading.find("off") == string::npos &&
+          str_shading.find("null") == string::npos) {
+        try {
+          std::stoi(str_shading);
+          shaded_smooth = true;
+        }
+        catch (const std::invalid_argument &inv_arg) {
+          fprintf(stderr,
+                  "Bad argument for smooth shading: %s:%s\n",
+                  inv_arg.what(),
+                  str_shading.c_str());
+          shaded_smooth = false;
+        }
+      }
+      else {
+        shaded_smooth = false;
+      }
+    }
     else if (line_key == "f") {
       OBJFaceElem curr_face;
+      curr_face.shaded_smooth = shaded_smooth;
+
       Vector<string> str_corners_split;
       split_by_char(s_line.str(), ' ', str_corners_split);
       for (auto str_corner : str_corners_split) {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index f10b5822fa9..888c1d578f3 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -52,6 +52,9 @@ OBJMeshFromRaw::OBJMeshFromRaw(class OBJRawObject &curr_object)
     MPoly &mpoly = mesh_from_bm_->mpoly[i];
     mpoly.totloop = curr_face.face_corners.size();
     mpoly.loopstart = curr_loop_idx;
+    if (curr_face.shaded_smooth) {
+      mpoly.flag |= ME_SMOOTH;
+    }
 
     for (int j = 0; j < mpoly.totloop; ++j) {
       MLoop *mloop = &mesh_from_bm_->mloop[curr_loop_idx];



More information about the Bf-blender-cvs mailing list