diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-05-08 15:14:49 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-06-19 11:17:41 +0300 |
commit | 69c3d9804f03f637618e71b296aea279b27577f3 (patch) | |
tree | 658a5086fc4359c169f002d8c43d0d00c830d39d /source/blender/io/common/IO_abstract_hierarchy_iterator.h | |
parent | 084c5d6c7e2cf89bb9a7a9a9d00e9ee4475e222f (diff) |
IO: Allow exporting a subset of the writers
This is in order to prepare for compatibility with the Alembic exporter.
That exporter is capable of writing object transforms and object data at
different (sub)frames.
The rename from `created_writers` to `used_writers` is necessary, as not
all created writers will be actually used in each iteration.
The Universal Scene Description (USD) exporter does not make use of
this.
Reviewed By: mont29
Differential Revision: https://developer.blender.org/D7670
Diffstat (limited to 'source/blender/io/common/IO_abstract_hierarchy_iterator.h')
-rw-r--r-- | source/blender/io/common/IO_abstract_hierarchy_iterator.h | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h index 480b72ea0cf..9930b79f802 100644 --- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h +++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h @@ -120,6 +120,39 @@ class AbstractHierarchyWriter { virtual bool check_is_animated(const HierarchyContext &context) const; }; +/* Determines which subset of the writers actually gets to write. */ +struct ExportSubset { + bool transforms : 1; + bool shapes : 1; +}; + +/* EnsuredWriter represents an AbstractHierarchyWriter* combined with information whether it was + * newly created or not. It's returned by AbstractHierarchyIterator::ensure_writer(). */ +class EnsuredWriter { + private: + AbstractHierarchyWriter *writer_; + + /* Is set to truth when ensure_writer() did not find existing writer and created a new one. + * Is set to false when writer has been re-used or when allocation of the new one has failed + * (`writer` will be `nullptr` in that case and bool(ensured_writer) will be false). */ + bool newly_created_; + + EnsuredWriter(AbstractHierarchyWriter *writer, bool newly_created); + + public: + EnsuredWriter(); + + static EnsuredWriter empty(); + static EnsuredWriter existing(AbstractHierarchyWriter *writer); + static EnsuredWriter newly_created(AbstractHierarchyWriter *writer); + + bool is_newly_created() const; + + /* These operators make an EnsuredWriter* act as an AbstractHierarchyWriter* */ + operator bool() const; + AbstractHierarchyWriter *operator->(); +}; + /* AbstractHierarchyIterator iterates over objects in a dependency graph, and constructs export * writers. These writers are then called to perform the actual writing to a USD or Alembic file. * @@ -148,6 +181,7 @@ class AbstractHierarchyIterator { ExportPathMap duplisource_export_path_; Depsgraph *depsgraph_; WriterMap writers_; + ExportSubset export_subset_; public: explicit AbstractHierarchyIterator(Depsgraph *depsgraph); @@ -161,6 +195,15 @@ class AbstractHierarchyIterator { /* Release all writers. Call after all frames have been exported. */ void release_writers(); + /* Determine which subset of writers is used for exporting. + * Set this before calling iterate_and_write(). + * + * Note that writers are created for each iterated object, regardless of this option. When a + * writer is created it will also write the current iteration, to ensure the hierarchy is + * complete. The `export_subset` option is only in effect when the writer already existed from a + * previous iteration. */ + void set_export_subset(ExportSubset export_subset_); + /* Convert the given name to something that is valid for the exported file format. * This base implementation is a no-op; override in a concrete subclass. */ virtual std::string make_valid_name(const std::string &name) const; @@ -209,10 +252,11 @@ class AbstractHierarchyIterator { typedef AbstractHierarchyWriter *(AbstractHierarchyIterator::*create_writer_func)( const HierarchyContext *); - /* Ensure that a writer exists; if it doesn't, call create_func(context). The create_func - * function should be one of the create_XXXX_writer(context) functions declared below. */ - AbstractHierarchyWriter *ensure_writer(HierarchyContext *context, - create_writer_func create_func); + /* Ensure that a writer exists; if it doesn't, call create_func(context). + * + * The create_func function should be one of the create_XXXX_writer(context) functions declared + * below. */ + EnsuredWriter ensure_writer(HierarchyContext *context, create_writer_func create_func); protected: /* Construct a valid path for the export file format. This class concatenates by using '/' as a |