[Bf-blender-cvs] [cf8922ef577] master: Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases

Aras Pranckevicius noreply at git.blender.org
Sun Jun 19 16:43:30 CEST 2022


Commit: cf8922ef577083668a22d52b9b01fc545bafd206
Author: Aras Pranckevicius
Date:   Sun Jun 19 17:38:32 2022 +0300
Branches: master
https://developer.blender.org/rBcf8922ef577083668a22d52b9b01fc545bafd206

Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases

The new OBJ importer is producing "sharp" edges on some meshes that
should be completely smooth. Only observed on UV-Sphere type meshes
so far (see T97820).

I'm not 100% sure what is the root cause, but my theory was that
maybe due to limited number of float digits that are printed for
vertex normals in the file, the normals that are read in are not
always exactly 1.0 length. And then the Blender's "set custom loop
normals" function (which expects normalized inputs) wrongly marks
some edges as sharp.

Adding explicit normalization for the normals that are read from the
file fixes the wrongly-sharp edges in test cases from T97820. I
have not observed measurable performance impact in importing large
models (e.g. 6-level subdivided Monkey) that contain vertex normals.

Reviewed By: Howard Trickey
Differential Revision: https://developer.blender.org/D15202

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

M	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc

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

diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
index ee55dd1e45a..13e28be5668 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
@@ -6,6 +6,7 @@
 
 #include "BLI_map.hh"
 #include "BLI_math_color.h"
+#include "BLI_math_vector.h"
 #include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
 
@@ -129,6 +130,10 @@ static void geom_add_vertex_normal(Geometry *geom,
 {
   float3 normal;
   parse_floats(p, end, 0.0f, normal, 3);
+  /* Normals can be printed with only several digits in the file,
+   * making them ever-so-slightly non unit length. Make sure they are
+   * normalized. */
+  normalize_v3(normal);
   r_global_vertices.vertex_normals.append(normal);
   geom->has_vertex_normals_ = true;
 }



More information about the Bf-blender-cvs mailing list