15#include <Alembic/Abc/OTypedArrayProperty.h>
22using Alembic::Abc::ArraySample;
23using Alembic::Abc::OArrayProperty;
24using Alembic::Abc::OBoolArrayProperty;
25using Alembic::Abc::OCompoundProperty;
26using Alembic::Abc::ODoubleArrayProperty;
27using Alembic::Abc::OFloatArrayProperty;
28using Alembic::Abc::OInt32ArrayProperty;
29using Alembic::Abc::OStringArrayProperty;
37 if (group ==
nullptr) {
48void CustomPropertiesExporter::write(
const IDProperty *id_property)
52 switch (id_property->
type) {
56 set_scalar_property<OStringArrayProperty, std::string>(id_property->
name, prop_value);
60 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
61 set_scalar_property<OInt32ArrayProperty, int32_t>(id_property->
name,
65 set_scalar_property<OFloatArrayProperty, float>(id_property->
name,
69 set_scalar_property<ODoubleArrayProperty, double>(id_property->
name,
73 set_scalar_property<OBoolArrayProperty, bool>(id_property->
name,
IDP_bool_get(id_property));
76 write_array(id_property);
79 write_idparray(id_property);
84void CustomPropertiesExporter::write_array(
const IDProperty *id_property)
91 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
92 set_array_property<OInt32ArrayProperty, int32_t>(id_property->
name,
array, id_property->
len);
97 set_array_property<OFloatArrayProperty, float>(id_property->
name, array, id_property->
len);
102 set_array_property<ODoubleArrayProperty, double>(id_property->
name, array, id_property->
len);
107 set_array_property<OBoolArrayProperty, int8_t>(id_property->
name, array, id_property->
len);
113void CustomPropertiesExporter::write_idparray(
const IDProperty *idp_array)
117 if (idp_array->
len == 0) {
127 for (
int i = 1;
i < idp_array->
len;
i++) {
128 if (idp_elements[
i].type == idp_elements[0].type) {
131 std::cerr <<
"Custom property " << idp_array->
name <<
" has elements of varying type";
136 switch (idp_elements[0].type) {
138 write_idparray_of_strings(idp_array);
141 write_idparray_of_numbers(idp_array);
146void CustomPropertiesExporter::write_idparray_of_strings(
const IDProperty *idp_array)
153 std::vector<std::string> strings(idp_array->
len);
154 for (
int i = 0;
i < idp_array->
len;
i++) {
160 const std::string *array_of_strings = strings.data();
161 set_array_property<OStringArrayProperty, std::string>(
162 idp_array->
name, array_of_strings, strings.size());
165void CustomPropertiesExporter::write_idparray_of_numbers(
const IDProperty *idp_array)
174 const int subtype = idp_rows[0].
subtype;
182 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
183 write_idparray_flattened_typed<OInt32ArrayProperty, int32_t>(idp_array);
186 write_idparray_flattened_typed<OFloatArrayProperty, float>(idp_array);
189 write_idparray_flattened_typed<ODoubleArrayProperty, double>(idp_array);
192 write_idparray_flattened_typed<OBoolArrayProperty, int8_t>(idp_array);
197template<
typename ABCPropertyType,
typename BlenderValueType>
198void CustomPropertiesExporter::write_idparray_flattened_typed(
const IDProperty *idp_array)
208 std::vector<BlenderValueType> matrix_values;
209 for (
size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
211 for (
size_t col_idx = 0; col_idx < idp_rows[row_idx].
len; col_idx++) {
212 matrix_values.push_back(row[col_idx]);
216 set_array_property<ABCPropertyType, BlenderValueType>(
217 idp_array->
name, matrix_values.data(), matrix_values.size());
220template<
typename ABCPropertyType,
typename BlenderValueType>
221void CustomPropertiesExporter::set_scalar_property(
const StringRef property_name,
222 const BlenderValueType property_value)
224 set_array_property<ABCPropertyType, BlenderValueType>(property_name, &property_value, 1);
227template<
typename ABCPropertyType,
typename BlenderValueType>
228void CustomPropertiesExporter::set_array_property(
const StringRef property_name,
229 const BlenderValueType *array_values,
230 const size_t num_array_items)
232 auto create_callback = [
this, property_name]() -> OArrayProperty {
233 return create_abc_property<ABCPropertyType>(property_name);
236 OArrayProperty array_prop = abc_properties_.lookup_or_add_cb(property_name, create_callback);
237 Alembic::Util::Dimensions array_dimensions(num_array_items);
238 ArraySample
sample(array_values, array_prop.getDataType(), array_dimensions);
242template<
typename ABCPropertyType>
243OArrayProperty CustomPropertiesExporter::create_abc_property(
const StringRef property_name)
246 OCompoundProperty abc_prop_for_custom_props = owner_->abc_prop_for_custom_props();
247 const uint32_t timesample_index = owner_->timesample_index();
250 ABCPropertyType abc_property(abc_prop_for_custom_props, property_name);
251 abc_property.setTimeSampling(timesample_index);
#define IDP_float_get(prop)
#define IDP_array_voidp_get(prop)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_array_bool_get(prop)
#define IDP_array_int_get(prop)
#define IDP_property_array_get(prop)
#define IDP_array_float_get(prop)
#define IDP_bool_get(prop)
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
ID and Library types, which are fundamental for SDNA.
struct IDProperty IDProperty
unsigned long long int uint64_t
void write_all(const IDProperty *group)
CustomPropertiesExporter(ABCAbstractWriter *owner)