diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-08-10 13:34:42 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-08-10 13:34:58 +0300 |
commit | d76583cb4a16315c196f07f4acb9340f341bee47 (patch) | |
tree | e9e6f9b1db31d3ff7839c710a5b77fdcf8277343 /source/blender/io/wavefront_obj/importer/obj_import_objects.hh | |
parent | b114993305336be9d1c3403a6cfde6ebf13a0a28 (diff) |
Fix T100302: New OBJ importer produces too many vertices when faces don't span a continuous range
As part of the previous fix (D15410), the importer got code to track
min & max vertex indices used as part of the mesh faces. However, if
faces refer to a "sparse" (i.e. non-contiguous) subset of all vertices,
then the imported mesh would contain all the vertices between min & max
range.
Replace that with proper tracking of actually used vertex indices
for each imported mesh. Fixes T100302.
This does affect import performance a tiny bit, e.g. importing Blender
3.0 splash scene goes 21.7s -> 22.1s, and importing rungholt.obj
goes 2.37s -> 2.48s.
Importer related tests have a bunch of vertex changes in them, since
now vertices are added in the order that the faces are referring
to them. Which incidentally matches the order that the Python based
importer was creating them too.
Diffstat (limited to 'source/blender/io/wavefront_obj/importer/obj_import_objects.hh')
-rw-r--r-- | source/blender/io/wavefront_obj/importer/obj_import_objects.hh | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh index 9f0079d7c53..f48b6dd55e8 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh @@ -9,6 +9,7 @@ #include "BKE_lib_id.h" #include "BLI_map.hh" +#include "BLI_math_base.hh" #include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BLI_vector_set.hh" @@ -92,6 +93,8 @@ struct Geometry { int vertex_index_min_ = INT_MAX; int vertex_index_max_ = -1; + VectorSet<int> vertices_; + Map<int, int> global_to_local_vertices_; /** Edges written in the file in addition to (or even without polygon) elements. */ Vector<MEdge> edges_; @@ -105,14 +108,26 @@ struct Geometry { int get_vertex_count() const { - if (vertex_index_max_ < vertex_index_min_) - return 0; - return vertex_index_max_ - vertex_index_min_ + 1; + return (int)vertices_.size(); } void track_vertex_index(int index) { - vertex_index_min_ = std::min(vertex_index_min_, index); - vertex_index_max_ = std::max(vertex_index_max_, index); + if (vertices_.add(index)) { + global_to_local_vertices_.add_new(index, (int)vertices_.size() - 1); + } + math::min_inplace(vertex_index_min_, index); + math::max_inplace(vertex_index_max_, index); + } + void track_all_vertices(int count) + { + vertices_.reserve(count); + global_to_local_vertices_.reserve(count); + for (int i = 0; i < count; ++i) { + vertices_.add(i); + global_to_local_vertices_.add(i, i); + } + vertex_index_min_ = 0; + vertex_index_max_ = count - 1; } }; |