Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAras Pranckevicius <aras@nesnausk.org>2022-06-19 17:38:32 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-06-22 12:45:39 +0300
commitf02d54440dea3716893962c6fcbe6e2f9173666f (patch)
treef37a3e6966fea8c14e2c6f25451753bc16094db6
parentfb64ee005ae9ff60b556ca41361833682ab7c803 (diff)
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
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc5
1 files changed, 5 insertions, 0 deletions
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 d14401224ed..c069093ac06 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
@@ -5,6 +5,7 @@
*/
#include "BLI_map.hh"
+#include "BLI_math_vector.h"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
@@ -82,6 +83,10 @@ static void geom_add_vertex_normal(Geometry *geom,
{
float3 normal;
parse_floats(line, 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;
}