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) {
55 const std::string prop_value(
IDP_String(id_property), id_property->
len - 1);
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,
IDP_Int(id_property));
64 set_scalar_property<OFloatArrayProperty, float>(id_property->
name,
IDP_Float(id_property));
67 set_scalar_property<ODoubleArrayProperty, double>(id_property->
name,
71 set_scalar_property<OBoolArrayProperty, bool>(id_property->
name,
IDP_Bool(id_property));
74 write_array(id_property);
77 write_idparray(id_property);
82void CustomPropertiesExporter::write_array(
const IDProperty *id_property)
89 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
90 set_array_property<OInt32ArrayProperty, int32_t>(id_property->
name,
array, id_property->
len);
95 set_array_property<OFloatArrayProperty, float>(id_property->
name,
array, id_property->
len);
100 set_array_property<ODoubleArrayProperty, double>(id_property->
name,
array, id_property->
len);
105 set_array_property<OBoolArrayProperty, int8_t>(id_property->
name,
array, id_property->
len);
111void CustomPropertiesExporter::write_idparray(
const IDProperty *idp_array)
115 if (idp_array->
len == 0) {
125 for (
int i = 1; i < idp_array->
len; i++) {
126 if (idp_elements[i].type == idp_elements[0].type) {
129 std::cerr <<
"Custom property " << idp_array->
name <<
" has elements of varying type";
134 switch (idp_elements[0].type) {
136 write_idparray_of_strings(idp_array);
139 write_idparray_of_numbers(idp_array);
144void CustomPropertiesExporter::write_idparray_of_strings(
const IDProperty *idp_array)
151 std::vector<std::string> strings(idp_array->
len);
152 for (
int i = 0; i < idp_array->
len; i++) {
158 const std::string *array_of_strings = strings.data();
159 set_array_property<OStringArrayProperty, std::string>(
160 idp_array->
name, array_of_strings, strings.size());
163void CustomPropertiesExporter::write_idparray_of_numbers(
const IDProperty *idp_array)
172 const int subtype = idp_rows[0].
subtype;
180 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
181 write_idparray_flattened_typed<OInt32ArrayProperty, int32_t>(idp_array);
184 write_idparray_flattened_typed<OFloatArrayProperty, float>(idp_array);
187 write_idparray_flattened_typed<ODoubleArrayProperty, double>(idp_array);
190 write_idparray_flattened_typed<OBoolArrayProperty, int8_t>(idp_array);
195template<
typename ABCPropertyType,
typename BlenderValueType>
196void CustomPropertiesExporter::write_idparray_flattened_typed(
const IDProperty *idp_array)
206 std::vector<BlenderValueType> matrix_values;
207 for (
size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
208 const BlenderValueType *row = (BlenderValueType *)
IDP_Array(&idp_rows[row_idx]);
209 for (
size_t col_idx = 0; col_idx < idp_rows[row_idx].
len; col_idx++) {
210 matrix_values.push_back(row[col_idx]);
214 set_array_property<ABCPropertyType, BlenderValueType>(
215 idp_array->
name, matrix_values.data(), matrix_values.size());
218template<
typename ABCPropertyType,
typename BlenderValueType>
219void CustomPropertiesExporter::set_scalar_property(
const StringRef property_name,
220 const BlenderValueType property_value)
222 set_array_property<ABCPropertyType, BlenderValueType>(property_name, &property_value, 1);
225template<
typename ABCPropertyType,
typename BlenderValueType>
226void CustomPropertiesExporter::set_array_property(
const StringRef property_name,
227 const BlenderValueType *array_values,
228 const size_t num_array_items)
230 auto create_callback = [
this, property_name]() -> OArrayProperty {
231 return create_abc_property<ABCPropertyType>(property_name);
234 OArrayProperty array_prop = abc_properties_.
lookup_or_add_cb(property_name, create_callback);
235 Alembic::Util::Dimensions array_dimensions(num_array_items);
236 ArraySample
sample(array_values, array_prop.getDataType(), array_dimensions);
240template<
typename ABCPropertyType>
241OArrayProperty CustomPropertiesExporter::create_abc_property(
const StringRef property_name)
248 ABCPropertyType abc_property(abc_prop_for_custom_props, property_name);
249 abc_property.setTimeSampling(timesample_index);
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
ID and Library types, which are fundamental for SDNA.
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props()=0
uint32_t timesample_index() const
void write_all(const IDProperty *group)
CustomPropertiesExporter(ABCAbstractWriter *owner)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
unsigned __int64 uint64_t