diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-05-08 16:51:23 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-06-19 11:17:41 +0300 |
commit | 0ae7883d7d34bb2553407a028e9510e407a36d00 (patch) | |
tree | b19dbc16748038d60e87c7550016b3dbf827ef91 /source/blender/io/common/intern | |
parent | 69c3d9804f03f637618e71b296aea279b27577f3 (diff) |
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.
Diffstat (limited to 'source/blender/io/common/intern')
-rw-r--r-- | source/blender/io/common/intern/abstract_hierarchy_iterator.cc | 26 |
1 files changed, 20 insertions, 6 deletions
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; |