17 #include <Alembic/Abc/OTypedArrayProperty.h>
18 #include <Alembic/Abc/OTypedScalarProperty.h>
23 using Alembic::Abc::ArraySample;
24 using Alembic::Abc::OArrayProperty;
25 using Alembic::Abc::OBoolArrayProperty;
26 using Alembic::Abc::OCompoundProperty;
27 using Alembic::Abc::ODoubleArrayProperty;
28 using Alembic::Abc::OFloatArrayProperty;
29 using Alembic::Abc::OInt32ArrayProperty;
30 using Alembic::Abc::OStringArrayProperty;
40 if (group ==
nullptr) {
51 void CustomPropertiesExporter::write(
const IDProperty *id_property)
55 switch (id_property->
type) {
58 const std::string prop_value(
IDP_String(id_property), id_property->
len - 1);
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,
IDP_Int(id_property));
67 set_scalar_property<OFloatArrayProperty, float>(id_property->
name,
IDP_Float(id_property));
70 set_scalar_property<ODoubleArrayProperty, double>(id_property->
name,
74 write_array(id_property);
77 write_idparray(id_property);
82 void 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);
106 void CustomPropertiesExporter::write_idparray(
const IDProperty *idp_array)
110 if (idp_array->
len == 0) {
120 for (
int i = 1; i < idp_array->
len; i++) {
121 if (idp_elements[i].
type == idp_elements[0].
type) {
124 std::cerr <<
"Custom property " << idp_array->
name <<
" has elements of varying type";
129 switch (idp_elements[0].
type) {
131 write_idparray_of_strings(idp_array);
134 write_idparray_of_numbers(idp_array);
139 void CustomPropertiesExporter::write_idparray_of_strings(
const IDProperty *idp_array)
146 std::vector<std::string> strings(idp_array->
len);
147 for (
int i = 0; i < idp_array->
len; i++) {
153 const std::string *array_of_strings = strings.data();
154 set_array_property<OStringArrayProperty, std::string>(
155 idp_array->
name, array_of_strings, strings.size());
158 void CustomPropertiesExporter::write_idparray_of_numbers(
const IDProperty *idp_array)
167 const int subtype = idp_rows[0].
subtype;
175 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
176 write_idparray_flattened_typed<OInt32ArrayProperty, int32_t>(idp_array);
179 write_idparray_flattened_typed<OFloatArrayProperty, float>(idp_array);
182 write_idparray_flattened_typed<ODoubleArrayProperty, double>(idp_array);
187 template<
typename ABCPropertyType,
typename BlenderValueType>
188 void CustomPropertiesExporter::write_idparray_flattened_typed(
const IDProperty *idp_array)
198 std::vector<BlenderValueType> matrix_values;
199 for (
size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
200 const BlenderValueType *row = (BlenderValueType *)
IDP_Array(&idp_rows[row_idx]);
201 for (
size_t col_idx = 0; col_idx < idp_rows[row_idx].
len; col_idx++) {
202 matrix_values.push_back(row[col_idx]);
206 set_array_property<ABCPropertyType, BlenderValueType>(
207 idp_array->
name, matrix_values.data(), matrix_values.size());
210 template<
typename ABCPropertyType,
typename BlenderValueType>
211 void CustomPropertiesExporter::set_scalar_property(
const StringRef property_name,
212 const BlenderValueType property_value)
214 set_array_property<ABCPropertyType, BlenderValueType>(property_name, &property_value, 1);
217 template<
typename ABCPropertyType,
typename BlenderValueType>
218 void CustomPropertiesExporter::set_array_property(
const StringRef property_name,
219 const BlenderValueType *array_values,
220 const size_t num_array_items)
222 auto create_callback = [
this, property_name]() -> OArrayProperty {
223 return create_abc_property<ABCPropertyType>(property_name);
226 OArrayProperty array_prop = abc_properties_.
lookup_or_add_cb(property_name, create_callback);
227 Alembic::Util::Dimensions array_dimensions(num_array_items);
228 ArraySample
sample(array_values, array_prop.getDataType(), array_dimensions);
232 template<
typename ABCPropertyType>
233 OArrayProperty CustomPropertiesExporter::create_abc_property(
const StringRef property_name)
240 ABCPropertyType abc_property(abc_prop_for_custom_props, property_name);
241 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.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
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)
unsigned __int64 uint64_t