diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-06-14 10:23:28 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-06-14 10:23:28 +0300 |
commit | e1f15e3b323e9e0dd4a2514395934ec44969ecfb (patch) | |
tree | 7eda8fe653f6a0b86be361206fc7b7e8e5f00a2b /source/blender/io/wavefront_obj/importer | |
parent | 1b4f35f6a5889d8d2e65c6231e84f8b1744c4f96 (diff) |
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
Diffstat (limited to 'source/blender/io/wavefront_obj/importer')
-rw-r--r-- | source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc | 7 |
1 files changed, 5 insertions, 2 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 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; |