diff options
Diffstat (limited to 'source')
3 files changed, 33 insertions, 4 deletions
diff --git a/source/blender/io/common/IO_dupli_persistent_id.hh b/source/blender/io/common/IO_dupli_persistent_id.hh index dc70c1cdf31..5dc54164684 100644 --- a/source/blender/io/common/IO_dupli_persistent_id.hh +++ b/source/blender/io/common/IO_dupli_persistent_id.hh @@ -48,6 +48,13 @@ class PersistentID { /* Construct the persistent ID of this instance's instancer. */ PersistentID instancer_pid() const; + /* Construct a string representation by reversing the persistent ID. + * In case of a duplicator that is duplicated itself as well, this + * results in strings like: + * "3" for the duplicated duplicator, and + * "3-0", "3-1", etc. for its duplis. */ + std::string as_object_name_suffix() const; + friend bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b); friend bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b); friend std::ostream &operator<<(std::ostream &os, const PersistentID &persistent_id); diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc index c8d916c0950..3622c1eb7cd 100644 --- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc +++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc @@ -427,10 +427,10 @@ void AbstractHierarchyIterator::visit_dupli_object(DupliObject *dupli_object, copy_m4_m4(context->matrix_world, dupli_object->mat); // Construct export name for the dupli-instance. - std::stringstream suffix_stream; - suffix_stream << std::hex; - suffix_stream << "-" << context->persistent_id; - context->export_name = make_valid_name(get_object_name(context->object) + suffix_stream.str()); + std::stringstream export_name_stream; + export_name_stream << get_object_name(context->object) << "-" + << context->persistent_id.as_object_name_suffix(); + context->export_name = make_valid_name(export_name_stream.str()); ExportGraph::key_type graph_index = determine_graph_index_dupli( context, dupli_object, dupli_parent_finder); diff --git a/source/blender/io/common/intern/dupli_persistent_id.cc b/source/blender/io/common/intern/dupli_persistent_id.cc index 8563fd5cea6..f0f3079a75c 100644 --- a/source/blender/io/common/intern/dupli_persistent_id.cc +++ b/source/blender/io/common/intern/dupli_persistent_id.cc @@ -22,6 +22,7 @@ #include <climits> #include <cstring> #include <ostream> +#include <sstream> namespace blender::io { @@ -84,6 +85,27 @@ PersistentID PersistentID::instancer_pid() const return PersistentID(new_pid_values); } +std::string PersistentID::as_object_name_suffix() const +{ + std::stringstream stream; + + /* Find one past the last index. */ + int index; + for (index = 0; index < array_length_ && persistent_id_[index] < INT_MAX; ++index) + ; + + /* Iterate backward to construct the string. */ + --index; + for (; index >= 0; --index) { + stream << persistent_id_[index]; + if (index > 0) { + stream << "-"; + } + } + + return stream.str(); +} + bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b) { const PersistentID::PIDArray &pid_a = persistent_id_a.persistent_id_; |