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
This commit is contained in:
Aras Pranckevicius 2022-06-14 10:23:28 +03:00
parent 2287b98e7e
commit b6c5763b8e
Notes: blender-bot 2023-02-14 06:42:53 +01:00
Referenced by issue #98782, New .obj importer fails to import faces that refer to non-existing normal indices
Referenced by issue #98661, 3.2: Potential candidates for corrective releases
1 changed files with 5 additions and 2 deletions

View File

@ -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;