[Bf-blender-cvs] [c0b4a93faed] master: Cleanup: Alembic export, split function into two

Sybren A. Stüvel noreply at git.blender.org
Tue Sep 8 16:21:50 CEST 2020


Commit: c0b4a93faedbbf53761fa86aafcc458f140700a2
Author: Sybren A. Stüvel
Date:   Tue Sep 8 14:14:04 2020 +0200
Branches: master
https://developer.blender.org/rBc0b4a93faedbbf53761fa86aafcc458f140700a2

Cleanup: Alembic export, split function into two

Split the `ABCHierarchyIterator::create_data_writer()` function into two
functions. This is to prepare for the creation of writers not just by
object type, but also by goal, for example writers that reference other
Alembic data instead of writing their own (i.e. instancing).

No functional changes.

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

M	source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
M	source/blender/io/alembic/exporter/abc_hierarchy_iterator.h

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

diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
index 5b1b1b60b48..e8ca06d75fc 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
@@ -171,34 +171,37 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_transform_writer(
 AbstractHierarchyWriter *ABCHierarchyIterator::create_data_writer(const HierarchyContext *context)
 {
   const ABCWriterConstructorArgs writer_args = writer_constructor_args(context);
-  ABCAbstractWriter *data_writer = nullptr;
+  ABCAbstractWriter *data_writer = create_data_writer_for_object_type(context, writer_args);
 
+  if (data_writer == nullptr || !data_writer->is_supported(context)) {
+    delete data_writer;
+    return nullptr;
+  }
+
+  data_writer->create_alembic_objects(context);
+  return data_writer;
+}
+
+ABCAbstractWriter *ABCHierarchyIterator::create_data_writer_for_object_type(
+    const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args)
+{
   switch (context->object->type) {
     case OB_MESH:
-      data_writer = new ABCMeshWriter(writer_args);
-      break;
+      return new ABCMeshWriter(writer_args);
     case OB_CAMERA:
-      data_writer = new ABCCameraWriter(writer_args);
-      break;
+      return new ABCCameraWriter(writer_args);
     case OB_CURVE:
       if (params_.curves_as_mesh) {
-        data_writer = new ABCCurveMeshWriter(writer_args);
+        return new ABCCurveMeshWriter(writer_args);
       }
-      else {
-        data_writer = new ABCCurveWriter(writer_args);
-      }
-      break;
+      return new ABCCurveWriter(writer_args);
     case OB_SURF:
       if (params_.curves_as_mesh) {
-        data_writer = new ABCCurveMeshWriter(writer_args);
-      }
-      else {
-        data_writer = new ABCNurbsWriter(writer_args);
+        return new ABCCurveMeshWriter(writer_args);
       }
-      break;
+      return new ABCNurbsWriter(writer_args);
     case OB_MBALL:
-      data_writer = new ABCMetaballWriter(writer_args);
-      break;
+      return new ABCMetaballWriter(writer_args);
 
     case OB_EMPTY:
     case OB_LAMP:
@@ -214,13 +217,8 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_data_writer(const Hierarch
       return nullptr;
   }
 
-  if (!data_writer->is_supported(context)) {
-    delete data_writer;
-    return nullptr;
-  }
-
-  data_writer->create_alembic_objects(context);
-  return data_writer;
+  /* Just to please the compiler, all cases should be handled by the above switch. */
+  return nullptr;
 }
 
 AbstractHierarchyWriter *ABCHierarchyIterator::create_hair_writer(const HierarchyContext *context)
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
index bd7e3f27c67..b8abfd74c4c 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
@@ -36,6 +36,7 @@ namespace blender {
 namespace io {
 namespace alembic {
 
+class ABCAbstractWriter;
 class ABCHierarchyIterator;
 
 struct ABCWriterConstructorArgs {
@@ -85,6 +86,9 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
   ABCWriterConstructorArgs writer_constructor_args(const HierarchyContext *context) const;
   void update_archive_bounding_box();
   void update_bounding_box_recursive(Imath::Box3d &bounds, const HierarchyContext *context);
+
+  ABCAbstractWriter *create_data_writer_for_object_type(
+      const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args);
 };
 
 }  // namespace alembic



More information about the Bf-blender-cvs mailing list