diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-06-19 17:38:32 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-06-19 17:38:32 +0300 |
commit | cf8922ef577083668a22d52b9b01fc545bafd206 (patch) | |
tree | 93735ec4db234f3c1a465e6950226d47ca44ddb4 /source/blender/io | |
parent | b7e193cdada3c5cf931a25283e7ad05ed38a2ec0 (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
Diffstat (limited to 'source/blender/io')
-rw-r--r-- | source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc | 5 |
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 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; } |