From cf8922ef577083668a22d52b9b01fc545bafd206 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Sun, 19 Jun 2022 17:38:32 +0300 Subject: [PATCH] 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 --- .../io/wavefront_obj/importer/obj_import_file_reader.cc | 5 +++++ 1 file changed, 5 insertions(+) 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; }