16#include <Alembic/Abc/OTypedArrayProperty.h>
25using Alembic::Abc::ArraySample;
26using Alembic::Abc::OArrayProperty;
27using Alembic::Abc::OBoolArrayProperty;
28using Alembic::Abc::OCompoundProperty;
29using Alembic::Abc::ODoubleArrayProperty;
30using Alembic::Abc::OFloatArrayProperty;
31using Alembic::Abc::OInt32ArrayProperty;
32using Alembic::Abc::OStringArrayProperty;
40 if (group ==
nullptr) {
51void CustomPropertiesExporter::write(
const IDProperty *id_property)
55 switch (id_property->
type) {
59 set_scalar_property<OStringArrayProperty, std::string>(id_property->
name, prop_value);
63 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
64 set_scalar_property<OInt32ArrayProperty, int32_t>(id_property->
name,
68 set_scalar_property<OFloatArrayProperty, float>(id_property->
name,
72 set_scalar_property<ODoubleArrayProperty, double>(id_property->
name,
76 set_scalar_property<OBoolArrayProperty, bool>(id_property->
name,
IDP_bool_get(id_property));
79 write_array(id_property);
82 write_idparray(id_property);
91void CustomPropertiesExporter::write_array(
const IDProperty *id_property)
95 switch (id_property->subtype) {
98 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
99 set_array_property<OInt32ArrayProperty, int32_t>(id_property->name,
array, id_property->len);
104 set_array_property<OFloatArrayProperty, float>(id_property->name, array, id_property->len);
109 set_array_property<ODoubleArrayProperty, double>(id_property->name, array, id_property->len);
114 set_array_property<OBoolArrayProperty, int8_t>(id_property->name, array, id_property->len);
120void CustomPropertiesExporter::write_idparray(
const IDProperty *idp_array)
124 if (idp_array->len == 0) {
134 for (
int i = 1; i < idp_array->len; i++) {
135 if (idp_elements[i].type == idp_elements[0].type) {
138 std::cerr <<
"Custom property " << idp_array->name <<
" has elements of varying type";
143 switch (idp_elements[0].type) {
145 write_idparray_of_strings(idp_array);
148 write_idparray_of_numbers(idp_array);
156void CustomPropertiesExporter::write_idparray_of_strings(
const IDProperty *idp_array)
163 std::vector<std::string> strings(idp_array->len);
164 for (
int i = 0; i < idp_array->len; i++) {
170 const std::string *array_of_strings = strings.data();
171 set_array_property<OStringArrayProperty, std::string>(
172 idp_array->name, array_of_strings, strings.size());
175void CustomPropertiesExporter::write_idparray_of_numbers(
const IDProperty *idp_array)
184 const int subtype = idp_rows[0].subtype;
192 static_assert(
sizeof(int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
193 write_idparray_flattened_typed<OInt32ArrayProperty, int32_t>(idp_array);
196 write_idparray_flattened_typed<OFloatArrayProperty, float>(idp_array);
199 write_idparray_flattened_typed<ODoubleArrayProperty, double>(idp_array);
202 write_idparray_flattened_typed<OBoolArrayProperty, int8_t>(idp_array);
207template<
typename ABCPropertyType,
typename BlenderValueType>
208void CustomPropertiesExporter::write_idparray_flattened_typed(
const IDProperty *idp_array)
217 const uint64_t num_rows = idp_array->len;
218 std::vector<BlenderValueType> matrix_values;
219 for (
size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
222 for (
size_t col_idx = 0; col_idx < idp_rows[row_idx].len; col_idx++) {
223 matrix_values.push_back(row[col_idx]);
227 set_array_property<ABCPropertyType, BlenderValueType>(
228 idp_array->name, matrix_values.data(), matrix_values.size());
231template<
typename ABCPropertyType,
typename BlenderValueType>
232void CustomPropertiesExporter::set_scalar_property(
const StringRef property_name,
233 const BlenderValueType property_value)
235 set_array_property<ABCPropertyType, BlenderValueType>(property_name, &property_value, 1);
238template<
typename ABCPropertyType,
typename BlenderValueType>
239void CustomPropertiesExporter::set_array_property(
const StringRef property_name,
240 const BlenderValueType *array_values,
241 const size_t num_array_items)
243 auto create_callback = [
this, property_name]() -> OArrayProperty {
244 return create_abc_property<ABCPropertyType>(property_name);
247 OArrayProperty array_prop = abc_properties_.lookup_or_add_cb(property_name, create_callback);
248 Alembic::Util::Dimensions array_dimensions(num_array_items);
249 ArraySample
sample(array_values, array_prop.getDataType(), array_dimensions);
253template<
typename ABCPropertyType>
254OArrayProperty CustomPropertiesExporter::create_abc_property(
const StringRef property_name)
257 OCompoundProperty abc_prop_for_custom_props = owner_->abc_prop_for_custom_props();
258 const uint32_t timesample_index = owner_->timesample_index();
261 ABCPropertyType abc_property(abc_prop_for_custom_props, property_name);
262 abc_property.setTimeSampling(timesample_index);
269 points.resize(positions.
size());
286 velocities.resize(attr.
size());
#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)
ID and Library types, which are fundamental for SDNA.
#define BLI_assert_msg(a, msg)
constexpr int64_t size() const
constexpr IndexRange index_range() const
GAttributeReader lookup(const StringRef name) const
constexpr bool is_empty() const
constexpr IndexRange index_range() const
constexpr int64_t size() const
void write_all(const IDProperty *group)
CustomPropertiesExporter(ABCAbstractWriter *owner)
BLI_INLINE void copy_yup_from_zup(float yup[3], const float zup[3])
bool get_velocities(const bke::AttributeAccessor &attributes, std::vector< Imath::V3f > &velocities)
void get_positions(const Span< float3 > positions, std::vector< Imath::V3f > &points)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
VecBase< float, 3 > float3
ListBaseT< struct IDProperty > group