Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/common/IO_abstract_hierarchy_iterator.h
| Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | public: | ||||
| virtual void write(HierarchyContext &context) = 0; | virtual void write(HierarchyContext &context) = 0; | ||||
| // TODO(Sybren): add function like absent() that's called when a writer was previously created, | // TODO(Sybren): add function like absent() that's called when a writer was previously created, | ||||
| // but wasn't used while exporting the current frame (for example, a particle-instanced mesh of | // but wasn't used while exporting the current frame (for example, a particle-instanced mesh of | ||||
| // which the particle is no longer alive). | // which the particle is no longer alive). | ||||
| protected: | protected: | ||||
| virtual bool check_is_animated(const HierarchyContext &context) const; | 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 | /* 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. | * writers. These writers are then called to perform the actual writing to a USD or Alembic file. | ||||
| * | * | ||||
| * Dealing with file- and scene-level data (for example, creating a USD scene, setting the frame | * Dealing with file- and scene-level data (for example, creating a USD scene, setting the frame | ||||
| * rate, etc.) is not part of the AbstractHierarchyIterator class structure, and should be done | * rate, etc.) is not part of the AbstractHierarchyIterator class structure, and should be done | ||||
| * in separate code. | * in separate code. | ||||
| */ | */ | ||||
| class AbstractHierarchyIterator { | class AbstractHierarchyIterator { | ||||
| Show All 12 Lines | public: | ||||
| * instanced datablock, the export path of the original can be looked up. */ | * instanced datablock, the export path of the original can be looked up. */ | ||||
| typedef std::map<ID *, std::string> ExportPathMap; | typedef std::map<ID *, std::string> ExportPathMap; | ||||
| protected: | protected: | ||||
| ExportGraph export_graph_; | ExportGraph export_graph_; | ||||
| ExportPathMap duplisource_export_path_; | ExportPathMap duplisource_export_path_; | ||||
| Depsgraph *depsgraph_; | Depsgraph *depsgraph_; | ||||
| WriterMap writers_; | WriterMap writers_; | ||||
| ExportSubset export_subset_; | |||||
| public: | public: | ||||
| explicit AbstractHierarchyIterator(Depsgraph *depsgraph); | explicit AbstractHierarchyIterator(Depsgraph *depsgraph); | ||||
| virtual ~AbstractHierarchyIterator(); | virtual ~AbstractHierarchyIterator(); | ||||
| /* Iterate over the depsgraph, create writers, and tell the writers to write. | /* Iterate over the depsgraph, create writers, and tell the writers to write. | ||||
| * Main entry point for the AbstractHierarchyIterator, must be called for every to-be-exported | * Main entry point for the AbstractHierarchyIterator, must be called for every to-be-exported | ||||
| * frame. */ | * frame. */ | ||||
| void iterate_and_write(); | void iterate_and_write(); | ||||
| /* Release all writers. Call after all frames have been exported. */ | /* Release all writers. Call after all frames have been exported. */ | ||||
| void release_writers(); | 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. | /* 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. */ | * This base implementation is a no-op; override in a concrete subclass. */ | ||||
| virtual std::string make_valid_name(const std::string &name) const; | virtual std::string make_valid_name(const std::string &name) const; | ||||
| /* Return the name of this ID datablock that is valid for the exported file format. Overriding is | /* Return the name of this ID datablock that is valid for the exported file format. Overriding is | ||||
| * only necessary if make_valid_name(id->name+2) is not suitable for the exported file format. | * only necessary if make_valid_name(id->name+2) is not suitable for the exported file format. | ||||
| * NULL-safe: when `id == nullptr` this returns an empty string. */ | * NULL-safe: when `id == nullptr` this returns an empty string. */ | ||||
| virtual std::string get_id_name(const ID *id) const; | virtual std::string get_id_name(const ID *id) const; | ||||
| Show All 32 Lines | private: | ||||
| /* Convenience wrappers around get_id_name(). */ | /* Convenience wrappers around get_id_name(). */ | ||||
| std::string get_object_name(const Object *object) const; | std::string get_object_name(const Object *object) const; | ||||
| std::string get_object_data_name(const Object *object) const; | std::string get_object_data_name(const Object *object) const; | ||||
| AbstractHierarchyWriter *get_writer(const std::string &export_path) const; | AbstractHierarchyWriter *get_writer(const std::string &export_path) const; | ||||
| typedef AbstractHierarchyWriter *(AbstractHierarchyIterator::*create_writer_func)( | typedef AbstractHierarchyWriter *(AbstractHierarchyIterator::*create_writer_func)( | ||||
| const HierarchyContext *); | const HierarchyContext *); | ||||
| /* Ensure that a writer exists; if it doesn't, call create_func(context). The create_func | /* Ensure that a writer exists; if it doesn't, call create_func(context). | ||||
| * function should be one of the create_XXXX_writer(context) functions declared below. */ | * | ||||
| AbstractHierarchyWriter *ensure_writer(HierarchyContext *context, | * The create_func function should be one of the create_XXXX_writer(context) functions declared | ||||
| create_writer_func create_func); | * below. */ | ||||
| EnsuredWriter ensure_writer(HierarchyContext *context, create_writer_func create_func); | |||||
| protected: | protected: | ||||
| /* Construct a valid path for the export file format. This class concatenates by using '/' as a | /* Construct a valid path for the export file format. This class concatenates by using '/' as a | ||||
| * path separator, which is valid for both Alembic and USD. */ | * path separator, which is valid for both Alembic and USD. */ | ||||
| virtual std::string path_concatenate(const std::string &parent_path, | virtual std::string path_concatenate(const std::string &parent_path, | ||||
| const std::string &child_path) const; | const std::string &child_path) const; | ||||
| /* Return whether this object should be marked as 'weak export' or not. | /* Return whether this object should be marked as 'weak export' or not. | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||