[Bf-blender-cvs] [cedefe4ad9b] temp-io-alembic-changes-up-to-D7672: IO: ensure export path and export name are always consistent

Sybren A. Stüvel noreply at git.blender.org
Fri May 8 17:57:49 CEST 2020


Commit: cedefe4ad9b03f18431d478ae8adbda66ee778a4
Author: Sybren A. Stüvel
Date:   Fri May 8 15:51:23 2020 +0200
Branches: temp-io-alembic-changes-up-to-D7672
https://developer.blender.org/rBcedefe4ad9b03f18431d478ae8adbda66ee778a4

IO: ensure export path and export name are always consistent

Before this, there was one code path that set `context.export_path`,
and a different code path for `context.export_name`, allowing the two to
diverge.

Keeping track of the export path of the export parent (which can be but is
not always the Blender parent object) also allows a concrete subclass of
`AbstractHierarchyIterator` to find the `AbstractWriter` for the export
parent. In case of exporting to Alembic this is important, as it's not
possible to simply give the Alembic library the full export path of an
object (it needs the C++ object of the parent).

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

M	source/blender/io/common/IO_abstract_hierarchy_iterator.h
M	source/blender/io/common/intern/abstract_hierarchy_iterator.cc

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

diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h
index ed45f5d312f..e27c15447d6 100644
--- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h
+++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h
@@ -90,6 +90,14 @@ struct HierarchyContext {
    * exported objects, in which case this string is empty even though 'duplicator' is set. */
   std::string original_export_path;
 
+  /* Export path of the higher-up exported data. For transforms, this is the export path of the
+   * parent object. For object data, this is the export path of that object's transform.
+   *
+   * From the exported file's point of view, this is the path to the parent in that file. The term
+   * "parent" is not used here to avoid confusion with Blender's meaning of the word (which always
+   * refers to a different object). */
+  std::string higher_up_export_path;
+
   bool operator<(const HierarchyContext &other) const;
 
   /* Return a HierarchyContext representing the root of the export hierarchy. */
@@ -241,6 +249,10 @@ class AbstractHierarchyIterator {
   void make_writer_object_data(const HierarchyContext *context);
   void make_writers_particle_systems(const HierarchyContext *context);
 
+  /* Return the appropriate HierarchyContext for the data of the object represented by
+   * object_context. */
+  HierarchyContext context_for_object_data(const HierarchyContext *object_context) const;
+
   /* Convenience wrappers around get_id_name(). */
   std::string get_object_name(const Object *object) const;
   std::string get_object_data_name(const Object *object) const;
diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
index 70c6c82b429..e35be12dc6b 100644
--- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
+++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
@@ -385,6 +385,8 @@ void AbstractHierarchyIterator::visit_object(Object *object,
   context->animation_check_include_parent = false;
   context->export_path = "";
   context->original_export_path = "";
+  context->higher_up_export_path = "";
+
   copy_m4_m4(context->matrix_world, object->obmat);
 
   ExportGraph::key_type graph_index = determine_graph_index_object(context);
@@ -550,6 +552,9 @@ void AbstractHierarchyIterator::make_writers(const HierarchyContext *parent_cont
   for (HierarchyContext *context : graph_children(parent_context)) {
     // Update the context so that it is correct for this parent-child relation.
     copy_m4_m4(context->parent_matrix_inv_world, parent_matrix_inv_world);
+    if (parent_context != nullptr) {
+      context->higher_up_export_path = parent_context->export_path;
+    }
 
     // Get or create the transform writer.
     EnsuredWriter transform_writer = ensure_writer(
@@ -581,17 +586,24 @@ void AbstractHierarchyIterator::make_writers(const HierarchyContext *parent_cont
   // TODO(Sybren): iterate over all unused writers and call unused_during_iteration() or something.
 }
 
+HierarchyContext AbstractHierarchyIterator::context_for_object_data(
+    const HierarchyContext *object_context) const
+{
+  HierarchyContext data_context = *object_context;
+  data_context.higher_up_export_path = object_context->export_path;
+  data_context.export_name = get_object_data_name(data_context.object);
+  data_context.export_path = path_concatenate(data_context.higher_up_export_path,
+                                              data_context.export_name);
+  return data_context;
+}
+
 void AbstractHierarchyIterator::make_writer_object_data(const HierarchyContext *context)
 {
   if (context->object->data == nullptr) {
     return;
   }
 
-  HierarchyContext data_context = *context;
-  data_context.export_path = get_object_data_path(context);
-
-  /* data_context.original_export_path is just a copy from the context. It points to the object,
-   * but needs to point to the object data. */
+  HierarchyContext data_context = context_for_object_data(context);
   if (data_context.is_instance()) {
     ID *object_data = static_cast<ID *>(context->object->data);
     data_context.original_export_path = duplisource_export_path_[object_data];
@@ -623,8 +635,10 @@ void AbstractHierarchyIterator::make_writers_particle_systems(
     }
 
     HierarchyContext hair_context = *transform_context;
+    hair_context.export_name = make_valid_name(psys->name);
     hair_context.export_path = path_concatenate(transform_context->export_path,
-                                                make_valid_name(psys->name));
+                                                hair_context.export_name);
+    hair_context.higher_up_export_path = transform_context->export_path;
     hair_context.particle_system = psys;
 
     EnsuredWriter writer;



More information about the Bf-blender-cvs mailing list