Fix T100017: OBJ: new importer does not import vertices that aren't part of any face
The Python based importer had a special case handling of "no faces in the whole file at all", where it ended up treating the whole file as essentially a point-cloud-like object (just loose vertices, no faces or edges). The new importer code was missing this special case. Fixes T100017. Added gtest coverage that was failing without the fix.
This commit is contained in:
parent
ccb9d5d307
commit
c49717a824
Notes:
blender-bot
2023-02-14 05:43:04 +01:00
Referenced by issue #100017, OBJ: new importer does not import vertices that aren't part of any face Referenced by issue #98661, 3.2: Potential candidates for corrective releases
|
@ -13,6 +13,7 @@
|
|||
#include "obj_import_file_reader.hh"
|
||||
#include "obj_import_string_utils.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
@ -394,6 +395,23 @@ static bool parse_keyword(const char *&p, const char *end, StringRef keyword)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Special case: if there were no faces/edges in any geometries,
|
||||
* treat all the vertices as a point cloud. */
|
||||
static void use_all_vertices_if_no_faces(Geometry *geom,
|
||||
const Vector<std::unique_ptr<Geometry>> &all_geometries,
|
||||
const GlobalVertices &global_vertices)
|
||||
{
|
||||
if (!global_vertices.vertices.is_empty() && geom && geom->geom_type_ == GEOM_MESH) {
|
||||
if (std::all_of(
|
||||
all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr<Geometry> &g) {
|
||||
return g->get_vertex_count() == 0;
|
||||
})) {
|
||||
geom->track_vertex_index(0);
|
||||
geom->track_vertex_index(global_vertices.vertices.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
|
||||
GlobalVertices &r_global_vertices)
|
||||
{
|
||||
|
@ -571,6 +589,7 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
|
|||
buffer_offset = left_size;
|
||||
}
|
||||
|
||||
use_all_vertices_if_no_faces(curr_geom, r_all_geometries, r_global_vertices);
|
||||
add_default_mtl_library();
|
||||
}
|
||||
|
||||
|
|
|
@ -664,4 +664,14 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors_mrgb)
|
|||
import_and_check("cubes_vertex_colors_mrgb.obj", expect, std::size(expect), 0);
|
||||
}
|
||||
|
||||
TEST_F(obj_importer_test, import_vertices)
|
||||
{
|
||||
Expectation expect[] = {
|
||||
{"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
|
||||
/* Loose vertices without faces or edges. */
|
||||
{"OBCube.001", OB_MESH, 8, 0, 0, 0, float3(1, 1, -1), float3(-1, 1, 1)},
|
||||
};
|
||||
import_and_check("vertices.obj", expect, std::size(expect), 0);
|
||||
}
|
||||
|
||||
} // namespace blender::io::obj
|
||||
|
|
Loading…
Reference in New Issue