[Bf-blender-cvs] [ae6e9401ab] blender2.8: Alembic: using Base* instead of Object* to get selection

Sybren A. Stüvel noreply at git.blender.org
Fri Feb 10 11:53:31 CET 2017


Commit: ae6e9401abb7cf147367aaa84d04b186e6805d7c
Author: Sybren A. Stüvel
Date:   Thu Feb 9 14:42:08 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBae6e9401abb7cf147367aaa84d04b186e6805d7c

Alembic: using Base* instead of Object* to get selection

I also added some remarks & TODOs to indicate work in progress.

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

M	source/blender/alembic/intern/abc_exporter.cc
M	source/blender/alembic/intern/abc_exporter.h
M	source/blender/alembic/intern/abc_util.cc
M	source/blender/alembic/intern/abc_util.h
M	source/blender/alembic/intern/alembic_capi.cc

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

diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index cf9498878c..28d54672d2 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -123,19 +123,19 @@ static bool object_is_shape(Object *ob)
 	}
 }
 
-static bool export_object(const ExportSettings * const settings, Object *ob)
+static bool export_object(const ExportSettings * const settings, const Base * const ob_base)
 {
-	if (settings->selected_only && !object_selected(ob)) {
+	if (settings->selected_only && !object_selected(ob_base)) {
 		return false;
 	}
-
-	if (settings->visible_layers_only && !(settings->scene->lay & ob->lay)) {
+	// FIXME Sybren: handle these cleanly (maybe just remove code), now using active scene layer instead.
+	if (settings->visible_layers_only && (ob_base->flag & BASE_VISIBLED) == 0) {
 		return false;
 	}
 
-	if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) {
-		return false;
-	}
+	//	if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) {
+	//		return false;
+	//	}
 
 	return true;
 }
@@ -341,12 +341,10 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
 
 void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
 {
-	BaseLegacy *base = static_cast<BaseLegacy *>(m_scene->base.first);
-
-	while (base) {
+	for(Base *base = static_cast<Base *>(m_settings.sl->object_bases.first); base; base = base->next) {
 		Object *ob = base->object;
 
-		if (export_object(&m_settings, ob)) {
+		if (export_object(&m_settings, base)) {
 			switch(ob->type) {
 				case OB_LAMP:
 				case OB_LATTICE:
@@ -356,53 +354,49 @@ void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
 					break;
 
 				default:
-					exploreTransform(eval_ctx, ob, ob->parent, NULL);
+					exploreTransform(eval_ctx, base, ob->parent, NULL);
 			}
 		}
-
-		base = base->next;
 	}
 }
 
 void AbcExporter::createTransformWritersFlat()
 {
-	BaseLegacy *base = static_cast<BaseLegacy *>(m_scene->base.first);
-
-	while (base) {
+	for(Base *base = static_cast<Base *>(m_settings.sl->object_bases.first); base; base = base->next) {
 		Object *ob = base->object;
 
-		if (export_object(&m_settings, ob) && object_is_shape(ob)) {
+		if (!export_object(&m_settings, base)) {
 			std::string name = get_id_name(ob);
 			m_xforms[name] = new AbcTransformWriter(ob, m_writer->archive().getTop(), 0, m_trans_sampling_index, m_settings);
 		}
-
-		base = base->next;
 	}
 }
 
-void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent)
+void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent)
 {
+	Object *ob = ob_base->object;
 
-	if (export_object(&m_settings, ob) && object_is_shape(ob)) {
+	if (export_object(&m_settings, ob_base) && object_is_shape(ob)) {
 		createTransformWriter(ob, parent, dupliObParent);
 	}
 
 	ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
 
 	if (lb) {
-		DupliObject *link = static_cast<DupliObject *>(lb->first);
-		Object *dupli_ob = NULL;
-		Object *dupli_parent = NULL;
-		
-		while (link) {
+		Base fake_base = *ob_base;  // copy flags (like selection state) from the real object.
+		fake_base.next = fake_base.prev = NULL;
+
+		for (DupliObject *link = static_cast<DupliObject *>(lb->first); link; link = link->next) {
+			Object *dupli_ob = NULL;
+			Object *dupli_parent = NULL;
+
 			if (link->type == OB_DUPLIGROUP) {
 				dupli_ob = link->ob;
 				dupli_parent = (dupli_ob->parent) ? dupli_ob->parent : ob;
 
-				exploreTransform(eval_ctx, dupli_ob, dupli_parent, ob);
+				fake_base.object = dupli_ob;
+				exploreTransform(eval_ctx, &fake_base, dupli_parent, ob);
 			}
-
-			link = link->next;
 		}
 	}
 
@@ -460,44 +454,42 @@ void AbcExporter::createTransformWriter(Object *ob, Object *parent, Object *dupl
 
 void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx)
 {
-	BaseLegacy *base = static_cast<BaseLegacy *>(m_scene->base.first);
-
-	while (base) {
-		Object *ob = base->object;
-		exploreObject(eval_ctx, ob, NULL);
-
-		base = base->next;
+	for(Base *base = static_cast<Base *>(m_settings.sl->object_bases.first); base; base = base->next) {
+		exploreObject(eval_ctx, base, NULL);
 	}
 }
 
-void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent)
+void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent)
 {
+	Object *ob = ob_base->object;
 	ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
 	
-	createShapeWriter(ob, dupliObParent);
+	createShapeWriter(ob_base, dupliObParent);
 	
 	if (lb) {
-		DupliObject *dupliob = static_cast<DupliObject *>(lb->first);
+		Base fake_base = *ob_base;  // copy flags (like selection state) from the real object.
+		fake_base.next = fake_base.prev = NULL;
 
-		while (dupliob) {
+		for (DupliObject *dupliob = static_cast<DupliObject *>(lb->first); dupliob; dupliob = dupliob->next) {
 			if (dupliob->type == OB_DUPLIGROUP) {
-				exploreObject(eval_ctx, dupliob->ob, ob);
+				fake_base.object = dupliob->ob;
+				exploreObject(eval_ctx, &fake_base, ob);
 			}
-
-			dupliob = dupliob->next;
 		}
 	}
 
 	free_object_duplilist(lb);
 }
 
-void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
+void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent)
 {
+	Object *ob = ob_base->object;
+
 	if (!object_is_shape(ob)) {
 		return;
 	}
 
-	if (!export_object(&m_settings, ob)) {
+	if (!export_object(&m_settings, ob_base)) {
 		return;
 	}
 
diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h
index b0eb8e185d..80fee067c0 100644
--- a/source/blender/alembic/intern/abc_exporter.h
+++ b/source/blender/alembic/intern/abc_exporter.h
@@ -36,11 +36,14 @@ struct EvaluationContext;
 struct Main;
 struct Object;
 struct Scene;
+struct SceneLayer;
+struct Base;
 
 struct ExportSettings {
 	ExportSettings();
 
 	Scene *scene;
+	SceneLayer *sl;  // Scene layer to export; all its objects will be exported, unless selected_only=true
 
 	bool selected_only;
 	bool visible_layers_only;
@@ -105,10 +108,10 @@ private:
 	void createTransformWritersHierarchy(EvaluationContext *eval_ctx);
 	void createTransformWritersFlat();
 	void createTransformWriter(Object *ob,  Object *parent, Object *dupliObParent);
-	void exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent = NULL);
-	void exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent);
+	void exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent);
+	void exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent);
 	void createShapeWriters(EvaluationContext *eval_ctx);
-	void createShapeWriter(Object *ob, Object *dupliObParent);
+	void createShapeWriter(Base *ob_base, Object *dupliObParent);
 
 	AbcTransformWriter *getXForm(const std::string &name);
 
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 73aeca1bfd..bb375eb956 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -35,6 +35,7 @@
 
 extern "C" {
 #include "DNA_object_types.h"
+#include "DNA_layer_types.h"
 
 #include "BLI_math.h"
 }
@@ -58,6 +59,16 @@ std::string get_id_name(ID *id)
 	return name;
 }
 
+
+/**
+ * @brief get_object_dag_path_name returns the name under which the object
+ *  will be exported in the Alembic file. It is of the form
+ *  "[../grandparent/]parent/object" if dupli_parent is NULL, or
+ *  "dupli_parent/[../grandparent/]parent/object" otherwise.
+ * @param ob
+ * @param dupli_parent
+ * @return
+ */
 std::string get_object_dag_path_name(Object *ob, Object *dupli_parent)
 {
 	std::string name = get_id_name(ob);
@@ -76,9 +87,9 @@ std::string get_object_dag_path_name(Object *ob, Object *dupli_parent)
 	return name;
 }
 
-bool object_selected(Object *ob)
+bool object_selected(const Base * const ob_base)
 {
-	return ob->flag & SELECT;
+	return ob_base->flag & SELECT;
 }
 
 Imath::M44d convert_matrix(float mat[4][4])
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 52e9fb93a6..328f2c41a8 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -43,12 +43,13 @@ struct ImportSettings;
 
 struct ID;
 struct Object;
+struct Base;
 
 std::string get_id_name(ID *id);
 std::string get_id_name(Object *ob);
 std::string get_object_dag_path_name(Object *ob, Object *dupli_parent);
 
-bool object_selected(Object *ob);
+bool object_selected(const Base * const ob_base);
 
 Imath::M44d convert_matrix(float mat[4][4]);
 void create_transform_matrix(float r_mat[4][4]);
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index d8d017119b..fcfe634924 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -332,21 +332,37 @@ void ABC_export(
 	BLI_strncpy(job->filename, filepath, 1024);
 
 	job->settings.scene = job->scene;
+
+	/* Sybren: for now we only export the active scene layer.
+	 * Later in the 2.8 development process this may be replaced by using
+	 * a specific collection for Alembic I/O, which can then be toggled
+	 * between "real" objects and cached Alembic files. */
+	job->settings.sl = CTX_data_scene_layer(C);
+
 	job->settings.frame_start = params->frame_start;
 	job->settings.frame_end = params->frame_end;
 	job->settings.frame_step_xform = params->frame_step_xform;
 	job->settings.frame_step_shape = params->frame_step_shape;
 	job->settings.shutter_open = params->shutter_open;
 	job->settings.shutter_close = params->shutter_close;
+
+	/* Sybren: For now this is ignored, until we can get selection
+	 * detection working through Base pointers (instead of ob->flags). */
 	job->settings.selected_only = params->selected_only;
+
 	job->settings.export_face_sets = params->face_sets;
 	job->settings.export_normals = par

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list