[Bf-blender-cvs] [3e1a971259a] temp-T50725-alembic-export-custom-properties: Tweaks and adjustments and abstractions and generalisations and tests
Sybren A. Stüvel
noreply at git.blender.org
Thu Sep 10 19:45:40 CEST 2020
Commit: 3e1a971259acb829400a456fb66067e9ae2ca3c8
Author: Sybren A. Stüvel
Date: Thu Sep 10 18:35:02 2020 +0200
Branches: temp-T50725-alembic-export-custom-properties
https://developer.blender.org/rB3e1a971259acb829400a456fb66067e9ae2ca3c8
Tweaks and adjustments and abstractions and generalisations and tests
===================================================================
M source/blender/io/alembic/exporter/abc_custom_props.cc
M source/blender/io/alembic/exporter/abc_custom_props.h
M source/blender/io/alembic/exporter/abc_writer_abstract.cc
M source/blender/io/alembic/exporter/abc_writer_abstract.h
M source/blender/io/alembic/exporter/abc_writer_camera.cc
M source/blender/io/alembic/exporter/abc_writer_mesh.cc
M source/blender/io/alembic/exporter/abc_writer_transform.cc
M source/blender/io/alembic/exporter/abc_writer_transform.h
M tests/python/alembic_export_tests.py
===================================================================
diff --git a/source/blender/io/alembic/exporter/abc_custom_props.cc b/source/blender/io/alembic/exporter/abc_custom_props.cc
index 69b6423006d..d4410b52798 100644
--- a/source/blender/io/alembic/exporter/abc_custom_props.cc
+++ b/source/blender/io/alembic/exporter/abc_custom_props.cc
@@ -54,12 +54,12 @@ CustomPropertiesExporter::~CustomPropertiesExporter()
{
}
-void CustomPropertiesExporter::write_all(IDProperty *group)
+void CustomPropertiesExporter::write_all(const IDProperty *group)
{
if (group == nullptr) {
return;
}
- BLI_assert(group->type = IDP_GROUP);
+ BLI_assert(group->type == IDP_GROUP);
/* Loop over the properties, just like IDP_foreach_property() does, but without the recursion. */
LISTBASE_FOREACH (IDProperty *, id_property, &group->data.group) {
@@ -70,7 +70,7 @@ void CustomPropertiesExporter::write_all(IDProperty *group)
}
}
-void CustomPropertiesExporter::write(IDProperty *id_property)
+void CustomPropertiesExporter::write(const IDProperty *id_property)
{
BLI_assert(id_property->name[0] != '\0');
@@ -101,7 +101,7 @@ void CustomPropertiesExporter::write(IDProperty *id_property)
}
}
-void CustomPropertiesExporter::write_array(IDProperty *id_property)
+void CustomPropertiesExporter::write_array(const IDProperty *id_property)
{
BLI_assert(id_property->type == IDP_ARRAY);
@@ -125,7 +125,7 @@ void CustomPropertiesExporter::write_array(IDProperty *id_property)
}
}
-void CustomPropertiesExporter::write_idparray(IDProperty *idp_array)
+void CustomPropertiesExporter::write_idparray(const IDProperty *idp_array)
{
BLI_assert(idp_array->type == IDP_IDPARRAY);
@@ -158,7 +158,7 @@ void CustomPropertiesExporter::write_idparray(IDProperty *idp_array)
}
}
-void CustomPropertiesExporter::write_idparray_of_strings(IDProperty *idp_array)
+void CustomPropertiesExporter::write_idparray_of_strings(const IDProperty *idp_array)
{
BLI_assert(idp_array->type == IDP_IDPARRAY);
BLI_assert(idp_array->len > 0);
@@ -177,7 +177,7 @@ void CustomPropertiesExporter::write_idparray_of_strings(IDProperty *idp_array)
idp_array->name, array_of_strings, strings.size());
}
-void CustomPropertiesExporter::write_idparray_of_numbers(IDProperty *idp_array)
+void CustomPropertiesExporter::write_idparray_of_numbers(const IDProperty *idp_array)
{
BLI_assert(idp_array->type == IDP_IDPARRAY);
BLI_assert(idp_array->len > 0);
@@ -207,7 +207,7 @@ void CustomPropertiesExporter::write_idparray_of_numbers(IDProperty *idp_array)
}
template<typename ABCPropertyType, typename BlenderValueType>
-void CustomPropertiesExporter::write_idparray_flattened_typed(IDProperty *idp_array)
+void CustomPropertiesExporter::write_idparray_flattened_typed(const IDProperty *idp_array)
{
BLI_assert(idp_array->type == IDP_IDPARRAY);
BLI_assert(idp_array->len > 0);
diff --git a/source/blender/io/alembic/exporter/abc_custom_props.h b/source/blender/io/alembic/exporter/abc_custom_props.h
index 56a60964794..2c096afcb08 100644
--- a/source/blender/io/alembic/exporter/abc_custom_props.h
+++ b/source/blender/io/alembic/exporter/abc_custom_props.h
@@ -56,22 +56,22 @@ class CustomPropertiesExporter {
uint32_t timesample_index);
virtual ~CustomPropertiesExporter();
- void write_all(IDProperty *group);
+ void write_all(const IDProperty *group);
private:
- void write(IDProperty *id_property);
- void write_array(IDProperty *id_property);
+ void write(const IDProperty *id_property);
+ void write_array(const IDProperty *id_property);
/* IDProperty arrays are used to store arrays-of-arrays or arrays-of-strings. */
- void write_idparray(IDProperty *id_property);
- void write_idparray_of_strings(IDProperty *id_property);
- void write_idparray_of_numbers(IDProperty *id_property);
+ void write_idparray(const IDProperty *id_property);
+ void write_idparray_of_strings(const IDProperty *id_property);
+ void write_idparray_of_numbers(const IDProperty *id_property);
/* Flatten an array-of-arrays into one long array, then write that.
* It is tempting to write an array of NxM numbers as a matrix, but there is
* no guarantee that the data actually represents a matrix. */
template<typename ABCPropertyType, typename BlenderValueType>
- void write_idparray_flattened_typed(IDProperty *idp_array);
+ void write_idparray_flattened_typed(const IDProperty *idp_array);
/* Write a single scalar (i.e. non-array) property as single-value array. */
template<typename ABCPropertyType, typename BlenderValueType>
diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.cc b/source/blender/io/alembic/exporter/abc_writer_abstract.cc
index 0b08d8c4e58..bdae946de66 100644
--- a/source/blender/io/alembic/exporter/abc_writer_abstract.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_abstract.cc
@@ -54,6 +54,12 @@ bool ABCAbstractWriter::is_supported(const HierarchyContext * /*context*/) const
return true;
}
+void ABCAbstractWriter::create_custom_properties_exporter(
+ Alembic::Abc::OCompoundProperty abc_compound_prop)
+{
+ custom_props_ = std::make_unique<CustomPropertiesExporter>(abc_compound_prop, timesample_index_);
+}
+
void ABCAbstractWriter::write(HierarchyContext &context)
{
if (!frame_has_been_written_) {
@@ -67,9 +73,24 @@ void ABCAbstractWriter::write(HierarchyContext &context)
do_write(context);
+ if (custom_props_) {
+ custom_props_->write_all(get_id_properties(context));
+ }
+
frame_has_been_written_ = true;
}
+const IDProperty *ABCAbstractWriter::get_id_properties(const HierarchyContext &context) const
+{
+ Object *object = context.object;
+ if (object->data == nullptr) {
+ return nullptr;
+ }
+
+ /* Most subclasses write object data, so default to the object data's ID properties. */
+ return static_cast<ID *>(object->data)->properties;
+}
+
const Imath::Box3d &ABCAbstractWriter::bounding_box() const
{
return bounding_box_;
diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.h b/source/blender/io/alembic/exporter/abc_writer_abstract.h
index 59c55330443..ec868b93c3e 100644
--- a/source/blender/io/alembic/exporter/abc_writer_abstract.h
+++ b/source/blender/io/alembic/exporter/abc_writer_abstract.h
@@ -19,6 +19,7 @@
#pragma once
#include "IO_abstract_hierarchy_iterator.h"
+#include "abc_custom_props.h"
#include "abc_hierarchy_iterator.h"
#include <Alembic/Abc/OObject.h>
@@ -27,6 +28,7 @@
#include "DEG_depsgraph_query.h"
#include "DNA_material_types.h"
+struct IDProperty;
struct Material;
struct Object;
@@ -44,6 +46,8 @@ class ABCAbstractWriter : public AbstractHierarchyWriter {
/* Visibility of this writer's data in Alembic. */
Alembic::Abc::OCharProperty abc_visibility_;
+ std::unique_ptr<CustomPropertiesExporter> custom_props_;
+
public:
explicit ABCAbstractWriter(const ABCWriterConstructorArgs &args);
virtual ~ABCAbstractWriter();
@@ -72,6 +76,12 @@ class ABCAbstractWriter : public AbstractHierarchyWriter {
virtual void update_bounding_box(Object *object);
+ /* Return ID properties of whatever ID datablock is written by this writer. Defaults to the
+ * properties of the object data. Can return nullptr if no custom properties are to be written.
+ */
+ virtual const IDProperty *get_id_properties(const HierarchyContext &context) const;
+
+ void create_custom_properties_exporter(Alembic::Abc::OCompoundProperty abc_compound_prop);
void write_visibility(const HierarchyContext &context);
};
diff --git a/source/blender/io/alembic/exporter/abc_writer_camera.cc b/source/blender/io/alembic/exporter/abc_writer_camera.cc
index 0ce6c3dc07f..ac0ec3715a0 100644
--- a/source/blender/io/alembic/exporter/abc_writer_camera.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_camera.cc
@@ -52,6 +52,7 @@ void ABCCameraWriter::create_alembic_objects(const HierarchyContext * /*context*
CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
abc_camera_ = OCamera(args_.abc_parent, args_.abc_name, timesample_index_);
abc_camera_schema_ = abc_camera_.getSchema();
+ create_custom_properties_exporter(abc_camera_schema_.getUserProperties());
abc_custom_data_container_ = abc_camera_schema_.getUserProperties();
abc_stereo_distance_ = OFloatProperty(
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
index b762ad47932..96607f93292 100644
--- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
@@ -98,11 +98,13 @@ void ABCGenericMeshWriter::create_alembic_objects(const HierarchyContext *contex
CLOG_INFO(&LOG, 2, "exporting OSubD %s", args_.abc_path.c_str());
abc_subdiv_ = OSubD(args_.abc_parent, args_.abc_name, timesample_index_);
abc_subdiv_schema_ = abc_subdiv_.getSchema();
+ create_custom_properties_exporter(abc_subdiv_schema_.getUserProperties());
}
else {
CLOG_INFO(&LOG, 2, "exporting OPolyMesh %s", args_.abc_path.c_str());
abc_poly_mesh_ = OPolyMesh(args_.abc_parent, args_.abc_name, timesample_index_);
abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema();
+ create_custom_properties_exporter(abc_poly_mesh_schema_.getUserProperties());
OCompoundProperty typeContainer = abc_poly_mesh_.getSchema().getUserProperties();
OBoolProperty type(typeContainer, "meshtype");
diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.cc b/source/blender/io/alembic/exporter/abc_writer_transform.cc
index 3177a4dc879..70791488cb6 100644
--- a/source/blender/io/alembic/exporter/abc_writer_transform.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_transform.cc
@@ -51,9 +51,13 @@ void ABCTransformWriter::create_alembic_objects(const HierarchyContext * /*conte
CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
abc_xform_ = OXform(args_.abc_parent, args_.abc_name, timesample_index_);
abc_xform_schema_ = abc_xform_.getSchema();
+ create_custom_properties_exporter(abc_xform_schema_.getUserProperties());
+}
- custom_props_ = std::make_unique<CustomPropertiesExporter>(abc_xform_schema_.getUserProperties(),
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list