From fd3086833afea8b414506de6bb9ab6a5beaa7faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 14 Aug 2020 16:45:35 +0200 Subject: Cleanup: IO, reduce code duplication in USD and Alembic exporters Move the object visibility check from Alembic/USD-specific code into the `io/common` module. No functional changes. --- .../blender/io/alembic/exporter/abc_writer_mesh.cc | 22 +------------------- .../io/common/IO_abstract_hierarchy_iterator.h | 4 ++++ .../common/intern/abstract_hierarchy_iterator.cc | 24 ++++++++++++++++++++++ source/blender/io/usd/intern/usd_writer_mesh.cc | 22 +------------------- 4 files changed, 30 insertions(+), 42 deletions(-) (limited to 'source/blender/io') diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 89cb76db9a6..5c005164bcc 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -159,27 +159,7 @@ ModifierData *ABCGenericMeshWriter::get_liquid_sim_modifier(Scene *scene, Object bool ABCGenericMeshWriter::is_supported(const HierarchyContext *context) const { - Object *object = context->object; - bool is_dupli = context->duplicator != nullptr; - int base_flag; - - if (is_dupli) { - /* Construct the object's base flags from its dupli-parent, just like is done in - * deg_objects_dupli_iterator_next(). Without this, the visibility check below will fail. Doing - * this here, instead of a more suitable location in AbstractHierarchyIterator, prevents - * copying the Object for every dupli. */ - base_flag = object->base_flag; - object->base_flag = context->duplicator->base_flag | BASE_FROM_DUPLI; - } - - int visibility = BKE_object_visibility( - object, DAG_EVAL_RENDER /* TODO(Sybren): add evaluation mode to export options? */); - - if (is_dupli) { - object->base_flag = base_flag; - } - - return (visibility & OB_VISIBLE_SELF) != 0; + return context->is_object_visible(DAG_EVAL_RENDER); } void ABCGenericMeshWriter::do_write(HierarchyContext &context) diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h index d0d9d72b880..1d78cc38746 100644 --- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h +++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h @@ -37,6 +37,8 @@ #include "IO_dupli_persistent_id.hh" +#include "DEG_depsgraph.h" + #include #include #include @@ -111,6 +113,8 @@ struct HierarchyContext { bool is_instance() const; void mark_as_instance_of(const std::string &reference_export_path); void mark_as_not_instanced(); + + bool is_object_visible(const enum eEvaluationMode evaluation_mode) const; }; /* Abstract writer for objects. Create concrete subclasses to write to USD, Alembic, etc. diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc index fbefc8c8e7e..93e7e677118 100644 --- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc +++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc @@ -28,6 +28,7 @@ #include "BKE_anim_data.h" #include "BKE_duplilist.h" #include "BKE_key.h" +#include "BKE_object.h" #include "BKE_particle.h" #include "BLI_assert.h" @@ -77,6 +78,29 @@ void HierarchyContext::mark_as_not_instanced() original_export_path.clear(); } +bool HierarchyContext::is_object_visible(const enum eEvaluationMode evaluation_mode) const +{ + bool is_dupli = duplicator != nullptr; + int base_flag; + + if (is_dupli) { + /* Construct the object's base flags from its dupli-parent, just like is done in + * deg_objects_dupli_iterator_next(). Without this, the visibility check below will fail. Doing + * this here, instead of a more suitable location in AbstractHierarchyIterator, prevents + * copying the Object for every dupli. */ + base_flag = object->base_flag; + object->base_flag = duplicator->base_flag | BASE_FROM_DUPLI; + } + + int visibility = BKE_object_visibility(object, evaluation_mode); + + if (is_dupli) { + object->base_flag = base_flag; + } + + return (visibility & OB_VISIBLE_SELF) != 0; +} + EnsuredWriter::EnsuredWriter() : writer_(nullptr), newly_created_(false) { } diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index bd2c549e729..b27c68a41f6 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -52,27 +52,7 @@ USDGenericMeshWriter::USDGenericMeshWriter(const USDExporterContext &ctx) : USDA bool USDGenericMeshWriter::is_supported(const HierarchyContext *context) const { - Object *object = context->object; - bool is_dupli = context->duplicator != nullptr; - int base_flag; - - if (is_dupli) { - /* Construct the object's base flags from its dupli-parent, just like is done in - * deg_objects_dupli_iterator_next(). Without this, the visibility check below will fail. Doing - * this here, instead of a more suitable location in AbstractHierarchyIterator, prevents - * copying the Object for every dupli. */ - base_flag = object->base_flag; - object->base_flag = context->duplicator->base_flag | BASE_FROM_DUPLI; - } - - int visibility = BKE_object_visibility(object, - usd_export_context_.export_params.evaluation_mode); - - if (is_dupli) { - object->base_flag = base_flag; - } - - return (visibility & OB_VISIBLE_SELF) != 0; + return context->is_object_visible(usd_export_context_.export_params.evaluation_mode); } void USDGenericMeshWriter::do_write(HierarchyContext &context) -- cgit v1.2.3