[Bf-blender-cvs] [181d2263aed] temp-alembic-exporter-T73363-ms2: Alembic: much cleaner way to get the parent Alembic object

Sybren A. Stüvel noreply at git.blender.org
Fri Apr 24 11:23:13 CEST 2020


Commit: 181d2263aed58fb0002191b95bd1dccb42d5d0d7
Author: Sybren A. Stüvel
Date:   Fri Apr 24 11:18:40 2020 +0200
Branches: temp-alembic-exporter-T73363-ms2
https://developer.blender.org/rB181d2263aed58fb0002191b95bd1dccb42d5d0d7

Alembic: much cleaner way to get the parent Alembic object

Rather than juggling pointers around, the iterator's writer map is used.
This makes it possible to construct the Alembic object in the writer's
constructor, and makes the writers much simpler to understand.

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

M	source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
M	source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
M	source/blender/io/alembic/intern/export/abc_writer_abstract.cc
M	source/blender/io/alembic/intern/export/abc_writer_abstract.h
M	source/blender/io/alembic/intern/export/abc_writer_mesh.cc
M	source/blender/io/alembic/intern/export/abc_writer_transform.cc
M	source/blender/io/alembic/intern/export/abc_writer_transform.h
M	source/blender/io/usd/intern/abstract_hierarchy_iterator.cc
M	source/blender/io/usd/intern/abstract_hierarchy_iterator.h

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

diff --git a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
index 818924d8f0b..1183bd5d8c0 100644
--- a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
@@ -71,17 +71,37 @@ std::string ABCHierarchyIterator::make_valid_name(const std::string &name) const
   return abc_name;
 }
 
-ABCWriterConstructorArgs ABCHierarchyIterator::writer_constructor_args(
-    const HierarchyContext *context)
+Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_parent(
+    const HierarchyContext *context) const
 {
-  if (DEG_is_original_object(context->object)) {
-    printf("writer_constructor_args: object is \033[93moriginal\033[0m\n");
+  Alembic::Abc::OObject parent;
+
+  if (!context->higher_up_export_path.empty()) {
+    AbstractHierarchyWriter *writer = get_writer(context->higher_up_export_path);
+    ABCAbstractWriter *abc_writer = static_cast<ABCAbstractWriter *>(writer);
+    parent = abc_writer->get_alembic_object();
   }
-  else {
-    printf("writer_constructor_args: object is \033[96mCOPY\033[0m\n");
+
+  if (!parent.valid()) {
+    /* An invalid parent object means "no parent", which should be translated to Alembic's top
+     * archive object. */
+    return abc_archive_->archive->getTop();
   }
-  return ABCWriterConstructorArgs{
-      context->object, depsgraph_, abc_archive_, context->export_path, this, params_};
+
+  return parent;
+}
+
+ABCWriterConstructorArgs ABCHierarchyIterator::writer_constructor_args(
+    const HierarchyContext *context) const
+{
+  return ABCWriterConstructorArgs{context->object,
+                                  depsgraph_,
+                                  abc_archive_,
+                                  get_alembic_parent(context),
+                                  context->export_name,
+                                  context->export_path,
+                                  this,
+                                  params_};
 }
 
 AbstractHierarchyWriter *ABCHierarchyIterator::create_transform_writer(
diff --git a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
index ac77105e2b2..59e44719d49 100644
--- a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
@@ -26,6 +26,7 @@
 #include <string>
 
 #include <Alembic/Abc/OArchive.h>
+#include <Alembic/Abc/OObject.h>
 
 struct Depsgraph;
 struct ID;
@@ -33,8 +34,6 @@ struct Object;
 
 namespace ABC {
 
-using Alembic::Abc::OArchive;
-
 /* TODO(Sybren): move these out of the USD namespace into something more generic. */
 using USD::AbstractHierarchyIterator;
 using USD::AbstractHierarchyWriter;
@@ -46,6 +45,8 @@ struct ABCWriterConstructorArgs {
   Object *object; /* Evaluated object */
   Depsgraph *depsgraph;
   ABCArchive *abc_archive;
+  Alembic::Abc::OObject abc_parent;
+  const std::string abc_name;
   const std::string abc_path;
   const ABCHierarchyIterator *hierarchy_iterator;
   const AlembicExportParams &export_params;
@@ -76,7 +77,8 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
   virtual void delete_object_writer(AbstractHierarchyWriter *writer) override;
 
  private:
-  ABCWriterConstructorArgs writer_constructor_args(const HierarchyContext *context);
+  Alembic::Abc::OObject get_alembic_parent(const HierarchyContext *context) const;
+  ABCWriterConstructorArgs writer_constructor_args(const HierarchyContext *context) const;
 };
 
 }  // namespace ABC
diff --git a/source/blender/io/alembic/intern/export/abc_writer_abstract.cc b/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
index 1627b1e5e8c..333de76ee95 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
+++ b/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
@@ -67,36 +67,6 @@ void ABCAbstractWriter::write(HierarchyContext &context)
   frame_has_been_written_ = true;
 }
 
-const OObject ABCAbstractWriter::get_alembic_parent(HierarchyContext &context,
-                                                    bool is_obdata) const
-{
-  OObject parent;
-
-  if (is_obdata) {
-    /* The Alembic parent of object data is always the transform of the object. */
-    if (context.custom_data != nullptr) {
-      ABCAbstractWriter *xform_writer = reinterpret_cast<ABCAbstractWriter *>(context.custom_data);
-      parent = xform_writer->get_alembic_object();
-    }
-  }
-  else {
-    /* If there is a parent context known, try to find its Alembic object. */
-    if (context.parent_context != nullptr && context.parent_context->custom_data != nullptr) {
-      ABCAbstractWriter *parent_writer = reinterpret_cast<ABCAbstractWriter *>(
-          context.parent_context->custom_data);
-      parent = parent_writer->get_alembic_object();
-    }
-  }
-
-  if (!parent.valid()) {
-    /* An invalid parent object means "no parent", which should be translated to Alembic's top
-     * archive object. */
-    return args_.abc_archive->archive->getTop();
-  }
-
-  return parent;
-}
-
 void ABCAbstractWriter::update_bounding_box(Object *object)
 {
   BoundBox *bb = BKE_object_boundbox_get(object);
diff --git a/source/blender/io/alembic/intern/export/abc_writer_abstract.h b/source/blender/io/alembic/intern/export/abc_writer_abstract.h
index c61ef9d3388..632505dd2b0 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_abstract.h
+++ b/source/blender/io/alembic/intern/export/abc_writer_abstract.h
@@ -69,8 +69,6 @@ class ABCAbstractWriter : public AbstractHierarchyWriter {
   /* TODO(Sybren): bring back support for writing the bounding box. */
 
   virtual const Alembic::Abc::OObject get_alembic_object() const = 0;
-  virtual const Alembic::Abc::OObject get_alembic_parent(HierarchyContext &context,
-                                                         bool is_obdata) const;
 
  protected:
   virtual void do_write(HierarchyContext &context) = 0;
diff --git a/source/blender/io/alembic/intern/export/abc_writer_mesh.cc b/source/blender/io/alembic/intern/export/abc_writer_mesh.cc
index 340108ce7ac..57c98604e1c 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_mesh.cc
+++ b/source/blender/io/alembic/intern/export/abc_writer_mesh.cc
@@ -90,6 +90,20 @@ ABCGenericMeshWriter::ABCGenericMeshWriter(const ABCWriterConstructorArgs &args)
     is_subd_ = args_.export_params.use_subdiv_schema;
   }
 
+  OObject abc_parent = args.abc_parent;
+  if (is_subd_ && !abc_subdiv_.valid()) {
+    abc_subdiv_ = OSubD(abc_parent, args.abc_name, timesample_index_);
+    abc_subdiv_schema_ = abc_subdiv_.getSchema();
+  }
+  else if (!is_subd_ && !abc_poly_mesh_.valid()) {
+    abc_poly_mesh_ = OPolyMesh(abc_parent, args.abc_name, timesample_index_);
+    abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema();
+
+    OCompoundProperty typeContainer = abc_poly_mesh_.getSchema().getUserProperties();
+    OBoolProperty type(typeContainer, "meshtype");
+    type.set(subsurf_modifier_ == nullptr);
+  }
+
   // TODO(Sybren): does this have to use the original or the evaluated data?
   // TODO(Sybren): avoid keeping ModifierData pointers around?
   Scene *scene_eval = DEG_get_evaluated_scene(args_.depsgraph);
@@ -168,22 +182,6 @@ void ABCGenericMeshWriter::do_write(HierarchyContext &context)
   Object *object = context.object;
   bool needsfree = false;
 
-  if (!frame_has_been_written_) {
-    OObject abc_parent = get_alembic_parent(context, true);
-    if (is_subd_ && !abc_subdiv_.valid()) {
-      abc_subdiv_ = OSubD(abc_parent, context.export_name, timesample_index_);
-      abc_subdiv_schema_ = abc_subdiv_.getSchema();
-    }
-    else if (!is_subd_ && !abc_poly_mesh_.valid()) {
-      abc_poly_mesh_ = OPolyMesh(abc_parent, context.export_name, timesample_index_);
-      abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema();
-
-      OCompoundProperty typeContainer = abc_poly_mesh_.getSchema().getUserProperties();
-      OBoolProperty type(typeContainer, "meshtype");
-      type.set(subsurf_modifier_ == nullptr);
-    }
-  }
-
   Mesh *mesh = get_export_mesh(object, needsfree);
 
   if (mesh == nullptr) {
diff --git a/source/blender/io/alembic/intern/export/abc_writer_transform.cc b/source/blender/io/alembic/intern/export/abc_writer_transform.cc
index d79be341811..f0f6c23727e 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_transform.cc
+++ b/source/blender/io/alembic/intern/export/abc_writer_transform.cc
@@ -39,6 +39,9 @@ using Alembic::AbcGeom::XformSample;
 ABCTransformWriter::ABCTransformWriter(const ABCWriterConstructorArgs &args)
     : ABCAbstractWriter(args)
 {
+  uint32_t ts_index = args_.abc_archive->time_sampling_index_transforms();
+  abc_xform_ = OXform(args.abc_parent, args.abc_name, ts_index);
+  abc_xform_schema_ = abc_xform_.getSchema();
 }
 
 void ABCTransformWriter::do_write(HierarchyContext &context)
@@ -49,20 +52,10 @@ void ABCTransformWriter::do_write(HierarchyContext &context)
   // After this, parent_relative_matrix uses Y=up.
   copy_m44_axis_swap(parent_relative_matrix, parent_relative_matrix, ABC_YUP_FROM_ZUP);
 
-  if (!abc_xform_.valid()) {
-    printf("\033[96mCreating\033[0m %s OXform(%s) parent=%s\n",
-           context.export_path.c_str(),
-           context.export_name.c_str(),
-           get_alembic_parent(context, false).getFullName().c_str());
-    uint32_t ts_index = args_.abc_archive->time_sampling_index_transforms();
-    abc_xform_ = OXform(get_alembic_parent(context, false), context.export_name, ts_index);
-    context.custom_data = this;
-  }
-
   XformSample xform_sample;
   xform_sample.setMatrix(convert_matrix_datatype(parent_relative_matrix));
   xform_sample.setInheritsXforms(true);
-  abc_xform_.getSchema().set(xform_sample);
+  abc_xform_schema_.set(xform_sample);
 }
 
 const OObject ABCTransformWriter::get_alembic_object() const
diff --git a/source/blender/io/alembic/intern/export/abc_writer_transform.h b/source/blender/io/alembic/intern/export/abc_writer_transform.h
index 540238fadf8..1e14eedd39b 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_transfor

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list