[Bf-blender-cvs] [08895f8] alembic_basic_io: Perform the import and export inside of dedicated jobs (for a bonus progress bar).

Kévin Dietrich noreply at git.blender.org
Tue May 24 15:45:37 CEST 2016


Commit: 08895f895c5912b597234a831b58f472fbe7e188
Author: Kévin Dietrich
Date:   Tue May 24 15:40:09 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB08895f895c5912b597234a831b58f472fbe7e188

Perform the import and export inside of dedicated jobs (for a bonus
progress bar).

===================================================================

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_export_options.cc
M	source/blender/alembic/intern/abc_export_options.h
M	source/blender/alembic/intern/abc_exporter.cc
M	source/blender/alembic/intern/abc_exporter.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/editors/io/io_alembic.c
M	source/blender/makesrna/intern/rna_scene_api.c
M	source/blender/windowmanager/WM_api.h

===================================================================

diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index e26afdb78..db43c87 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -38,7 +38,7 @@ enum {
 #define BL_ABC_NO_ERR 0
 #define BL_ABC_UNKNOWN_ERROR 1
 
-int ABC_export(struct Scene *sce, const char *filename,
+int ABC_export(struct Scene *scene, struct bContext *C, const char *filename,
                double start, double end,
                double xformstep, double geomstep,
                double shutter_open, double shutter_close,
diff --git a/source/blender/alembic/intern/abc_export_options.cc b/source/blender/alembic/intern/abc_export_options.cc
index e7fa2ba..675bf48 100644
--- a/source/blender/alembic/intern/abc_export_options.cc
+++ b/source/blender/alembic/intern/abc_export_options.cc
@@ -33,8 +33,8 @@ extern "C" {
 #include "BKE_idprop.h"
 }
 
-ExportSettings::ExportSettings(Scene *scene)
-    : m_scene(scene)
+ExportSettings::ExportSettings()
+    : scene(NULL)
 {
 	selected_only = false;
 	visible_layers_only = false;
@@ -109,7 +109,7 @@ bool ExportSettings::exportObject(Object *obj) const
 		return false;
 	}
 
-	if (visible_layers_only && !(m_scene->lay & obj->lay)) {
+	if (visible_layers_only && !(scene->lay & obj->lay)) {
 		return false;
 	}
 
diff --git a/source/blender/alembic/intern/abc_export_options.h b/source/blender/alembic/intern/abc_export_options.h
index ad89713..ced2f53 100644
--- a/source/blender/alembic/intern/abc_export_options.h
+++ b/source/blender/alembic/intern/abc_export_options.h
@@ -27,7 +27,7 @@ struct Object;
 struct Scene;
 
 struct ExportSettings {
-	explicit ExportSettings(Scene *scene);
+	ExportSettings();
 
 	bool exportTransform(Object *obj) const;
 	bool isAbcRoot(Object *obj) const;
@@ -64,8 +64,7 @@ struct ExportSettings {
 	bool do_convert_axis;
 	float convert_matrix[3][3];
 
-private:
-	Scene *m_scene;
+	Scene *scene;
 };
 
 #endif  /* __ABC_EXPORT_OPTIONS_H__ */
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 1c1f128..e45e330 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -135,7 +135,7 @@ void AbcExporter::getFrameSet(double step, std::set<double> &frames)
 	}
 }
 
-void AbcExporter::operator()()
+void AbcExporter::operator()(float &progress)
 {
 	/* Create archive here */
 	std::string scene_name;
@@ -211,17 +211,22 @@ void AbcExporter::operator()()
 
 	/* export all frames */
 
-	/* TODO : progress report */
 	std::set<double>::const_iterator begin = frames.begin();
 	std::set<double>::const_iterator end = frames.end();
 
+	const float size = static_cast<float>(frames.size());
+	size_t i = 0;
+
 	for (; begin != end; ++begin) {
+		progress = (++i / size);
+
 		double f = *begin;
 		setCurrentFrame(f);
 
 		if (shape_frames.count(f) != 0) {
-			for (int i = 0, e = m_shapes.size(); i != e; ++i)
+			for (int i = 0, e = m_shapes.size(); i != e; ++i) {
 				m_shapes[i]->write();
+			}
 		}
 
 		if (xform_frames.count(f) == 0) {
diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h
index 43f97ce..1bb126a 100644
--- a/source/blender/alembic/intern/abc_exporter.h
+++ b/source/blender/alembic/intern/abc_exporter.h
@@ -47,7 +47,7 @@ public:
 	AbcExporter(Scene *scene, const char *filename, ExportSettings &settings);
 	~AbcExporter();
 
-	void operator()();
+	void operator()(float &progress);
 
 protected:
 	double getCurrentFrame() const;
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 7250930..b30b796 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -32,6 +32,8 @@
 #include "abc_util.h"
 
 extern "C" {
+#include "MEM_guardedalloc.h"
+
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
@@ -40,6 +42,7 @@ extern "C" {
 #include "BKE_depsgraph.h"
 
 #include "BLI_math.h"
+#include "BLI_string.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -219,7 +222,38 @@ int ABC_check_subobject_valid(const char *name, const char *sub_obj)
 	return (found && ob.valid());
 }
 
-int ABC_export(Scene *sce, const char *filename,
+struct ExportJobData {
+	Scene *scene;
+
+	char filename[1024];
+	ExportSettings settings;
+
+	short *stop;
+	short *do_update;
+	float *progress;
+};
+
+void export_startjob(void *cjv, short *stop, short *do_update, float *progress)
+{
+	ExportJobData *data = static_cast<ExportJobData *>(cjv);
+
+	data->stop = stop;
+	data->do_update = do_update;
+	data->progress = progress;
+
+	try {
+		AbcExporter exporter(data->scene, data->filename, data->settings);
+		exporter(*data->progress);
+	}
+	catch (const std::exception &e) {
+		std::cerr << "Abc Export error: " << e.what() << '\n';
+	}
+	catch (...) {
+		std::cerr << "Abc Export error\n";
+	}
+}
+
+int ABC_export(Scene *scene, bContext *C, const char *filename,
                double start, double end,
                double xformstep, double geomstep,
                double shutter_open, double shutter_close,
@@ -234,55 +268,61 @@ int ABC_export(Scene *sce, const char *filename,
                int use_subdiv_schema, int compression, bool packuv,
                int to_forward, int to_up, float scale)
 {
-	try {
-		ExportSettings opts(sce);
-		opts.startframe = start;
-		opts.endframe = end;
-		opts.xform_frame_step = xformstep;
-		opts.shape_frame_step = geomstep;
-		opts.shutter_open = shutter_open;
-		opts.shutter_close = shutter_close;
-		opts.selected_only = selected_only;
-		opts.export_uvs = uvs;
-		opts.export_normals = normals;
-		opts.export_vcols = vcolors;
-		opts.export_subsurfs_as_meshes = force_meshes;
-		opts.flatten_hierarchy = flatten_hierarchy;
-		opts.export_props_as_geo_params = custom_props_as_geodata;
-		opts.visible_layers_only = vislayers;
-		opts.renderable_only = renderable;
-		opts.use_subdiv_schema = use_subdiv_schema;
-		opts.export_ogawa = (compression == ABC_ARCHIVE_OGAWA);
-		opts.pack_uv = packuv;
-		opts.global_scale = scale;
-
-		// Deprecated
-		opts.export_face_sets = facesets;
-		opts.export_mat_indices = matindices;
-
-		if (opts.startframe > opts.endframe) {
-			std::swap(opts.startframe, opts.endframe);
-		}
+	ExportJobData *job = static_cast<ExportJobData *>(MEM_mallocN(sizeof(ExportJobData), "ExportJobData"));
+	job->scene = scene;
+	BLI_strncpy(job->filename, filename, 1024);
+
+	job->settings.scene = job->scene;
+	job->settings.startframe = start;
+	job->settings.endframe = end;
+	job->settings.xform_frame_step = xformstep;
+	job->settings.shape_frame_step = geomstep;
+	job->settings.shutter_open = shutter_open;
+	job->settings.shutter_close = shutter_close;
+	job->settings.selected_only = selected_only;
+	job->settings.export_uvs = uvs;
+	job->settings.export_normals = normals;
+	job->settings.export_vcols = vcolors;
+	job->settings.export_subsurfs_as_meshes = force_meshes;
+	job->settings.flatten_hierarchy = flatten_hierarchy;
+	job->settings.export_props_as_geo_params = custom_props_as_geodata;
+	job->settings.visible_layers_only = vislayers;
+	job->settings.renderable_only = renderable;
+	job->settings.use_subdiv_schema = use_subdiv_schema;
+	job->settings.export_ogawa = (compression == ABC_ARCHIVE_OGAWA);
+	job->settings.pack_uv = packuv;
+	job->settings.global_scale = scale;
+
+	// Deprecated
+	job->settings.export_face_sets = facesets;
+	job->settings.export_mat_indices = matindices;
+
+	if (job->settings.startframe > job->settings.endframe) {
+		std::swap(job->settings.startframe, job->settings.endframe);
+	}
 
-		opts.do_convert_axis = false;
-		if (mat3_from_axis_conversion(1, 2, to_forward, to_up, opts.convert_matrix)) {
-			opts.do_convert_axis = true;
-		}
+	job->settings.do_convert_axis = mat3_from_axis_conversion(
+	                                    1, 2, to_forward, to_up, job->settings.convert_matrix);
 
-		AbcExporter exporter(sce, filename, opts);
-		exporter();
-	}
-	catch (const std::exception &e) {
-		std::cout << "Abc Export error: " << e.what() << '\n';
-		return BL_ABC_UNKNOWN_ERROR;
-	}
-	catch (...) {
-		return BL_ABC_UNKNOWN_ERROR;
-	}
+	wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
+	                            CTX_wm_window(C),
+	                            job->scene,
+	                            "Alembic Export",
+	                            WM_JOB_PROGRESS,
+	                            WM_JOB_TYPE_ALEMBIC);
+
+	/* setup job */
+	WM_jobs_customdata_set(wm_job, job, MEM_freeN);
+	WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT);
+	WM_jobs_callbacks(wm_job, export_startjob, NULL, NULL, NULL);
+
+	WM_jobs_start(CTX_wm_manager(C), wm_job);
 
 	return BL_ABC_NO_ERR;
 }
 
+/* ********************** Import file ********************** */
+
 /* Return whether or not this object is a Maya locator, which is similar to
  * empties used as parent object in Blender. */
 static bool is_locator(const IObject &object)
@@ -337,9 +377,8 @@ static void create_readers(IArchive &archive,
 	visit_object(archive.getTop(), readers, settings);
 }
 
-static Object *find_object(bContext *C, const std::string &name)
+static Object *find_object(Scene *scene, const std::string &name)
 {
-	Scene *scene = CTX_data_scene(C);
 	Base *base;
 
 	for (base = static_cast<Base *>(scene->base.first); base; base = base->next) {
@@ -353,7 +392,7 @@ static Object *find_object(bContext *C, const std::string &name)
 	return NULL;
 }
 
-static void create_hierarchy(bContext *C, AbcObjectReader *root)
+static void create_hierarchy(Main *bmain, Scene *scene, AbcObjectReader *root)
 {
 	const IObject &iobjet = root->iobject();
 	const std::string &full_name = iobjet.getFullName();
@@ -371,14 +410,14 @@ static void create_hierarchy(bContext *C, AbcObjectReader *root)
 
 	std::vector<std::string>::reverse_iterator iter;
 	for (iter = parts.rbegin() + 2; iter != parts.rend(); ++iter) {
-		parent = find_object(C, *iter);
+		parent = find_object(scene, *iter);
 
 		if (parent != NULL && root->object() != parent) {
 			Object *ob = root->object();
 			ob->parent = parent;
 
 			DAG_id_tag_update(&ob->id, OB_RECALC_OB);
-			DA

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list