[Bf-blender-cvs] [0ae7883d7d3] master: IO: ensure export path and export name are always consistent

Sybren A. Stüvel noreply at git.blender.org
Fri Jun 19 10:22:12 CEST 2020


Commit: 0ae7883d7d34bb2553407a028e9510e407a36d00
Author: Sybren A. Stüvel
Date:   Fri May 8 15:51:23 2020 +0200
Branches: master
https://developer.blender.org/rB0ae7883d7d34bb2553407a028e9510e407a36d00

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 like we do in the Universal Scene Description (USD)
exporter; Alembic 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 9930b79f802..8cac3f4c72d 100644
--- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h
+++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h
@@ -91,6 +91,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. */
@@ -244,6 +252,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 053b22970dc..9a456bfaf69 100644
--- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
+++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
@@ -384,6 +384,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);
@@ -549,6 +551,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(
@@ -580,17 +585,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];
@@ -622,8 +634,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