Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/io/alembic')
-rw-r--r--source/blender/io/alembic/ABC_alembic.h1
-rw-r--r--source/blender/io/alembic/CMakeLists.txt2
-rw-r--r--source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc76
-rw-r--r--source/blender/io/alembic/exporter/abc_hierarchy_iterator.h6
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_instance.cc74
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_instance.h48
6 files changed, 177 insertions, 30 deletions
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index 28e3d0dd1f5..9a2c74c64a3 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -60,6 +60,7 @@ struct AlembicExportParams {
bool triangulate;
bool export_hair;
bool export_particles;
+ bool use_instancing;
/* See MOD_TRIANGULATE_NGON_xxx and MOD_TRIANGULATE_QUAD_xxx
* in DNA_modifier_types.h */
diff --git a/source/blender/io/alembic/CMakeLists.txt b/source/blender/io/alembic/CMakeLists.txt
index de99a2c9d65..2b44146e475 100644
--- a/source/blender/io/alembic/CMakeLists.txt
+++ b/source/blender/io/alembic/CMakeLists.txt
@@ -63,6 +63,7 @@ set(SRC
exporter/abc_writer_camera.cc
exporter/abc_writer_curves.cc
exporter/abc_writer_hair.cc
+ exporter/abc_writer_instance.cc
exporter/abc_writer_mball.cc
exporter/abc_writer_mesh.cc
exporter/abc_writer_nurbs.cc
@@ -89,6 +90,7 @@ set(SRC
exporter/abc_writer_camera.h
exporter/abc_writer_curves.h
exporter/abc_writer_hair.h
+ exporter/abc_writer_instance.h
exporter/abc_writer_mball.h
exporter/abc_writer_mesh.h
exporter/abc_writer_nurbs.h
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
index 5b1b1b60b48..4cb6ca0c601 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
@@ -22,6 +22,7 @@
#include "abc_writer_camera.h"
#include "abc_writer_curves.h"
#include "abc_writer_hair.h"
+#include "abc_writer_instance.h"
#include "abc_writer_mball.h"
#include "abc_writer_mesh.h"
#include "abc_writer_nurbs.h"
@@ -126,17 +127,27 @@ AbstractHierarchyIterator::ExportGraph::key_type ABCHierarchyIterator::determine
context, dupli_object, dupli_parent_finder);
}
-Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_parent(
- const HierarchyContext *context) const
+Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_object(
+ const std::string &export_path) const
{
- Alembic::Abc::OObject parent;
+ if (export_path.empty()) {
+ return Alembic::Abc::OObject();
+ }
- if (!context->higher_up_export_path.empty()) {
- AbstractHierarchyWriter *writer = get_writer(context->higher_up_export_path);
- ABCAbstractWriter *abc_writer = static_cast<ABCAbstractWriter *>(writer);
- parent = abc_writer->get_alembic_object();
+ AbstractHierarchyWriter *writer = get_writer(export_path);
+ if (writer == nullptr) {
+ return Alembic::Abc::OObject();
}
+ ABCAbstractWriter *abc_writer = static_cast<ABCAbstractWriter *>(writer);
+ return abc_writer->get_alembic_object();
+}
+
+Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_parent(
+ const HierarchyContext *context) const
+{
+ Alembic::Abc::OObject parent = get_alembic_object(context->higher_up_export_path);
+
if (!parent.valid()) {
/* An invalid parent object means "no parent", which should be translated to Alembic's top
* archive object. */
@@ -173,32 +184,42 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_data_writer(const Hierarch
const ABCWriterConstructorArgs writer_args = writer_constructor_args(context);
ABCAbstractWriter *data_writer = nullptr;
+ if (params_.use_instancing && context->is_instance()) {
+ data_writer = new ABCInstanceWriter(writer_args);
+ }
+ else {
+ data_writer = create_data_writer_for_object_type(context, writer_args);
+ }
+
+ if (data_writer == nullptr || !data_writer->is_supported(context)) {
+ delete data_writer;
+ return nullptr;
+ }
+
+ data_writer->create_alembic_objects(context);
+ return data_writer;
+}
+
+ABCAbstractWriter *ABCHierarchyIterator::create_data_writer_for_object_type(
+ const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args)
+{
switch (context->object->type) {
case OB_MESH:
- data_writer = new ABCMeshWriter(writer_args);
- break;
+ return new ABCMeshWriter(writer_args);
case OB_CAMERA:
- data_writer = new ABCCameraWriter(writer_args);
- break;
+ return new ABCCameraWriter(writer_args);
case OB_CURVE:
if (params_.curves_as_mesh) {
- data_writer = new ABCCurveMeshWriter(writer_args);
- }
- else {
- data_writer = new ABCCurveWriter(writer_args);
+ return new ABCCurveMeshWriter(writer_args);
}
- break;
+ return new ABCCurveWriter(writer_args);
case OB_SURF:
if (params_.curves_as_mesh) {
- data_writer = new ABCCurveMeshWriter(writer_args);
+ return new ABCCurveMeshWriter(writer_args);
}
- else {
- data_writer = new ABCNurbsWriter(writer_args);
- }
- break;
+ return new ABCNurbsWriter(writer_args);
case OB_MBALL:
- data_writer = new ABCMetaballWriter(writer_args);
- break;
+ return new ABCMetaballWriter(writer_args);
case OB_EMPTY:
case OB_LAMP:
@@ -214,13 +235,8 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_data_writer(const Hierarch
return nullptr;
}
- if (!data_writer->is_supported(context)) {
- delete data_writer;
- return nullptr;
- }
-
- data_writer->create_alembic_objects(context);
- return data_writer;
+ /* Just to please the compiler, all cases should be handled by the above switch. */
+ return nullptr;
}
AbstractHierarchyWriter *ABCHierarchyIterator::create_hair_writer(const HierarchyContext *context)
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
index bd7e3f27c67..5bc82564cdb 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
@@ -36,6 +36,7 @@ namespace blender {
namespace io {
namespace alembic {
+class ABCAbstractWriter;
class ABCHierarchyIterator;
struct ABCWriterConstructorArgs {
@@ -61,6 +62,8 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
virtual void iterate_and_write() override;
virtual std::string make_valid_name(const std::string &name) const override;
+ Alembic::Abc::OObject get_alembic_object(const std::string &export_path) const;
+
protected:
virtual bool mark_as_weak_export(const Object *object) const override;
@@ -85,6 +88,9 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
ABCWriterConstructorArgs writer_constructor_args(const HierarchyContext *context) const;
void update_archive_bounding_box();
void update_bounding_box_recursive(Imath::Box3d &bounds, const HierarchyContext *context);
+
+ ABCAbstractWriter *create_data_writer_for_object_type(
+ const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args);
};
} // namespace alembic
diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.cc b/source/blender/io/alembic/exporter/abc_writer_instance.cc
new file mode 100644
index 00000000000..581d94ee961
--- /dev/null
+++ b/source/blender/io/alembic/exporter/abc_writer_instance.cc
@@ -0,0 +1,74 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup balembic
+ */
+
+#include "abc_writer_instance.h"
+#include "abc_hierarchy_iterator.h"
+
+#include "BLI_assert.h"
+
+#include "CLG_log.h"
+static CLG_LogRef LOG = {"io.alembic"};
+
+namespace blender {
+namespace io {
+namespace alembic {
+
+using Alembic::Abc::OObject;
+
+ABCInstanceWriter::ABCInstanceWriter(const ABCWriterConstructorArgs &args)
+ : ABCAbstractWriter(args)
+{
+}
+
+ABCInstanceWriter::~ABCInstanceWriter()
+{
+}
+
+void ABCInstanceWriter::create_alembic_objects(const HierarchyContext *context)
+{
+ OObject original = args_.hierarchy_iterator->get_alembic_object(context->original_export_path);
+ OObject abc_parent = args_.abc_parent;
+ if (!abc_parent.addChildInstance(original, args_.abc_name)) {
+ CLOG_WARN(&LOG, "unable to export %s as instance", args_.abc_path.c_str());
+ return;
+ }
+ CLOG_INFO(&LOG, 2, "exporting instance %s", args_.abc_path.c_str());
+}
+
+OObject ABCInstanceWriter::get_alembic_object() const
+{
+ /* There is no OObject for an instance. */
+ BLI_assert(!"ABCInstanceWriter cannot return its Alembic OObject");
+ return OObject();
+}
+
+bool ABCInstanceWriter::is_supported(const HierarchyContext *context) const
+{
+ return context->is_instance();
+}
+
+void ABCInstanceWriter::do_write(HierarchyContext & /*context*/)
+{
+ /* Instances don't have data to be written. Just creating them is enough. */
+}
+
+} // namespace alembic
+} // namespace io
+} // namespace blender
diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.h b/source/blender/io/alembic/exporter/abc_writer_instance.h
new file mode 100644
index 00000000000..74379b9d6bd
--- /dev/null
+++ b/source/blender/io/alembic/exporter/abc_writer_instance.h
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#pragma once
+
+/** \file
+ * \ingroup balembic
+ */
+
+#include "abc_writer_abstract.h"
+
+namespace blender {
+namespace io {
+namespace alembic {
+
+/* Writer for Alembic instances, i.e. data that references another Alembic object.
+ *
+ * Note that the Alembic object created by this writer cannot be used as a
+ * parent, because it already instantiates the entire hierarchy of the
+ * referenced object. */
+class ABCInstanceWriter : public ABCAbstractWriter {
+ public:
+ explicit ABCInstanceWriter(const ABCWriterConstructorArgs &args);
+ virtual ~ABCInstanceWriter();
+
+ virtual void create_alembic_objects(const HierarchyContext *context) override;
+ virtual Alembic::Abc::OObject get_alembic_object() const override;
+
+ protected:
+ virtual bool is_supported(const HierarchyContext *context) const override;
+ virtual void do_write(HierarchyContext &context) override;
+};
+
+} // namespace alembic
+} // namespace io
+} // namespace blender