Commit: e1f15e3b323e9e0dd4a2514395934ec44969ecfb
Author: Aras Pranckevicius
Date:   Tue Jun 14 10:23:28 2022 +0300
Branches: master
https://developer.blender.org/rBe1f15e3b323e9e0dd4a2514395934ec44969ecfb

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 4a27d734819..9cfce5c2257 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
@@ -195,7 +195,7 @@ static void geom_add_polygon(Geometry *geom,
       if (p < end && *p == '/') {
         ++p;
         p = parse_int(p, end, 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. */
@@ -218,7 +218,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;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to