diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-07-07 13:45:30 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-07-07 14:01:07 +0300 |
commit | 70b1c09d7a40912b5dccc69fc95cbee2e2388eab (patch) | |
tree | b800b41b424407aa89c3f262e4a82f1f7672fa0b /source/blender/io/alembic/exporter | |
parent | f2175e06a7455be6ec5affa42444cfae1d9c1726 (diff) |
IO: Fix bug exporting dupli parent/child relations
Exporting a scene to USD or Alembic would fail when there are multiple
duplicates of parent & child objects, duplicated by the same object. For
example, this happens when such a hierarchy of objects is contained in a
collection, and that collection is instanced multiple times by mesh
vertices. The problem here is that the 'parent' pointer of each
duplicated object points to the real parent; Blender would not figure
out properly which duplicated parent should be used.
This is now resolved by keeping track of the persistent ID of each
duplicated instance, which makes it possible to reconstruct the
parent-child relations of duplicated objects. This does use up some
memory for each dupli, so it could be heavy to export a Spring scene
(with all the pebbles and leaves), but it's only a small addition on top
of the USD/Alembic writer objects that have to be created anyway. At
least with this patch, they're created correctly.
Code-wise, the following changes are made:
- The export graph (that maps export parent to its export children) used
to have as its key (Object, Duplicator). This is insufficient to
correctly distinguish between multiple duplis of the same object by
the same duplicator, so this is now extended to (Object, Duplicator,
Persistent ID). To make this possible, new classes `ObjectIdentifier`
and `PersistentID` are introduced.
- Finding the parent of a duplicated object is done via its persistent
ID. In Python notation, the code first tries to find the parent
instance where `child_persistent_id[1:] == parent_persistent_id[1:]`.
If that fails, the dupli with persistent ID `child_persistent_id[1:]`
is used as parent.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8233
Diffstat (limited to 'source/blender/io/alembic/exporter')
-rw-r--r-- | source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc | 11 | ||||
-rw-r--r-- | source/blender/io/alembic/exporter/abc_hierarchy_iterator.h | 4 |
2 files changed, 10 insertions, 5 deletions
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc index 90004c0e85b..c83eaf3eede 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc @@ -107,20 +107,23 @@ AbstractHierarchyIterator::ExportGraph::key_type ABCHierarchyIterator:: determine_graph_index_object(const HierarchyContext *context) { if (params_.flatten_hierarchy) { - return std::make_pair(nullptr, nullptr); + return ObjectIdentifier::for_graph_root(); } return AbstractHierarchyIterator::determine_graph_index_object(context); } AbstractHierarchyIterator::ExportGraph::key_type ABCHierarchyIterator::determine_graph_index_dupli( - const HierarchyContext *context, const std::set<Object *> &dupli_set) + const HierarchyContext *context, + const DupliObject *dupli_object, + const DupliParentFinder &dupli_parent_finder) { if (params_.flatten_hierarchy) { - return std::make_pair(nullptr, nullptr); + return ObjectIdentifier::for_graph_root(); } - return AbstractHierarchyIterator::determine_graph_index_dupli(context, dupli_set); + return AbstractHierarchyIterator::determine_graph_index_dupli( + context, dupli_object, dupli_parent_finder); } Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_parent( diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h index edcb31806ba..3fe2d2c43d2 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h @@ -67,7 +67,9 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator { virtual ExportGraph::key_type determine_graph_index_object( const HierarchyContext *context) override; virtual AbstractHierarchyIterator::ExportGraph::key_type determine_graph_index_dupli( - const HierarchyContext *context, const std::set<Object *> &dupli_set) override; + const HierarchyContext *context, + const DupliObject *dupli_object, + const DupliParentFinder &dupli_parent_finder) override; virtual AbstractHierarchyWriter *create_transform_writer( const HierarchyContext *context) override; |