[Bf-blender-cvs] [b6c5763b8ea] blender-v3.2-release: Fix T98782: ignore OBJ face normal indices if no normals are present

Aras Pranckevicius noreply at git.blender.org
Sun Jun 26 11:55:27 CEST 2022


Commit: b6c5763b8eaec697a714a070409cdc5109a67ba5
Author: Aras Pranckevicius
Date:   Tue Jun 14 10:23:28 2022 +0300
Branches: blender-v3.2-release
https://developer.blender.org/rBb6c5763b8eaec697a714a070409cdc5109a67ba5

Fix T98782: ignore OBJ face normal indices if no normals are present

Some OBJ files out there (see T98782) have face definitions that
contain vertex normal indices, but the files themselves don't
contain any vertex normals. The code was doing a "hey, that's an
invalid index" and skipping these faces. But the old python importer
was silently ignoring these normal indices, so do the same here.

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

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

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 5720aadf39c..94d723cacf5 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
@@ -151,7 +151,7 @@ static void geom_add_polygon(Geometry *geom,
       if (!line.is_empty() && line[0] == '/') {
         line = line.drop_prefix(1);
         line = parse_int(line, INT32_MAX, corner.vertex_normal_index, false);
-        got_normal = corner.uv_vert_index != INT32_MAX;
+        got_normal = corner.vertex_normal_index != INT32_MAX;
       }
     }
     /* Always keep stored indices non-negative and zero-based. */
@@ -174,7 +174,10 @@ static void geom_add_polygon(Geometry *geom,
         face_valid = false;
       }
     }
-    if (got_normal) {
+    /* Ignore corner normal index, if the geometry does not have any normals.
+     * Some obj files out there do have face definitions that refer to normal indices,
+     * without any normals being present (T98782). */
+    if (got_normal && geom->has_vertex_normals_) {
       corner.vertex_normal_index += corner.vertex_normal_index < 0 ?
                                         global_vertices.vertex_normals.size() :
                                         -1;



More information about the Bf-blender-cvs mailing list