Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAras Pranckevicius <aras@nesnausk.org>2022-08-11 17:05:54 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-08-11 17:05:54 +0300
commit4cbd799373d07498813ad84f8cee5f3a8c269631 (patch)
tree86c65832d55244d1dabe336919af87e7a86e540b /source/blender/io/wavefront_obj
parentc4a0438522b7eadccb5c2d723521d5b3933fc5e9 (diff)
obj: support importing multiple files at once
Implemented the same way as STL or GPencil SVG importers: loop over the input files, import one by one. Has been requested by the community for quite a long time (e.g. https://blender.community/c/rightclickselect/Jhbbbc/), as well as 3rd party addons to implement just this (https://github.com/p2or/blender-batch-import-wavefront-obj).
Diffstat (limited to 'source/blender/io/wavefront_obj')
-rw-r--r--source/blender/io/wavefront_obj/IO_wavefront_obj.cc17
-rw-r--r--source/blender/io/wavefront_obj/IO_wavefront_obj.h1
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_importer.cc4
-rw-r--r--source/blender/io/wavefront_obj/tests/obj_importer_tests.cc1
4 files changed, 20 insertions, 3 deletions
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc
index fb0b4a1aca9..2fd2973ee73 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc
@@ -4,6 +4,7 @@
* \ingroup obj
*/
+#include "BLI_path_util.h"
#include "BLI_timeit.hh"
#include "IO_wavefront_obj.h"
@@ -11,14 +12,26 @@
#include "obj_exporter.hh"
#include "obj_importer.hh"
+using namespace blender::timeit;
+
+static void report_duration(const char *job, const TimePoint &start_time, const char *path)
+{
+ Nanoseconds duration = Clock::now() - start_time;
+ std::cout << "OBJ " << job << " of '" << BLI_path_basename(path) << "' took ";
+ print_duration(duration);
+ std::cout << '\n';
+}
+
void OBJ_export(bContext *C, const OBJExportParams *export_params)
{
- SCOPED_TIMER("OBJ export");
+ TimePoint start_time = Clock::now();
blender::io::obj::exporter_main(C, *export_params);
+ report_duration("export", start_time, export_params->filepath);
}
void OBJ_import(bContext *C, const OBJImportParams *import_params)
{
- SCOPED_TIMER(__func__);
+ TimePoint start_time = Clock::now();
blender::io::obj::importer_main(C, *import_params);
+ report_duration("import", start_time, import_params->filepath);
}
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 6ad96083e37..847b02d3fd1 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -75,6 +75,7 @@ struct OBJImportParams {
bool import_vertex_groups;
bool validate_meshes;
bool relative_paths;
+ bool clear_selection;
};
/**
diff --git a/source/blender/io/wavefront_obj/importer/obj_importer.cc b/source/blender/io/wavefront_obj/importer/obj_importer.cc
index bb32776d2be..5d3f75e7f38 100644
--- a/source/blender/io/wavefront_obj/importer/obj_importer.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_importer.cc
@@ -39,7 +39,6 @@ static void geometry_to_blender_objects(Main *bmain,
Map<std::string, std::unique_ptr<MTLMaterial>> &materials,
Map<std::string, Material *> &created_materials)
{
- BKE_view_layer_base_deselect_all(view_layer);
LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
/* Don't do collection syncs for each object, will do once after the loop. */
@@ -122,6 +121,9 @@ void importer_main(Main *bmain,
mtl_parser.parse_and_store(materials);
}
+ if (import_params.clear_selection) {
+ BKE_view_layer_base_deselect_all(view_layer);
+ }
geometry_to_blender_objects(bmain,
scene,
view_layer,
diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
index f97546fe4f5..132bb03357f 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -62,6 +62,7 @@ class obj_importer_test : public BlendfileLoadingBaseTest {
params.validate_meshes = true;
params.import_vertex_groups = false;
params.relative_paths = true;
+ params.clear_selection = true;
std::string obj_path = blender::tests::flags_test_asset_dir() + "/io_tests/obj/" + path;
strncpy(params.filepath, obj_path.c_str(), FILE_MAX - 1);