33 #include <Alembic/Abc/OTypedArrayProperty.h>
34 #include <Alembic/Abc/OTypedScalarProperty.h>
39 using Alembic::Abc::ArraySample;
40 using Alembic::Abc::OArrayProperty;
41 using Alembic::Abc::OBoolArrayProperty;
42 using Alembic::Abc::OCompoundProperty;
43 using Alembic::Abc::ODoubleArrayProperty;
44 using Alembic::Abc::OFloatArrayProperty;
45 using Alembic::Abc::OInt32ArrayProperty;
46 using Alembic::Abc::OStringArrayProperty;
56 if (group ==
nullptr) {
63 if (
STREQ(id_property->name,
"_RNA_UI")) {
70 void CustomPropertiesExporter::write(
const IDProperty *id_property)
74 switch (id_property->
type) {
77 const std::string prop_value(
IDP_String(id_property), id_property->
len - 1);
78 set_scalar_property<OStringArrayProperty, std::string>(id_property->
name, prop_value);
82 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
83 set_scalar_property<OInt32ArrayProperty, int32_t>(id_property->
name,
IDP_Int(id_property));
86 set_scalar_property<OFloatArrayProperty, float>(id_property->
name,
IDP_Float(id_property));
89 set_scalar_property<ODoubleArrayProperty, double>(id_property->
name,
93 write_array(id_property);
96 write_idparray(id_property);
101 void CustomPropertiesExporter::write_array(
const IDProperty *id_property)
105 switch (id_property->
subtype) {
108 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
109 set_array_property<OInt32ArrayProperty, int32_t>(id_property->
name,
array, id_property->
len);
114 set_array_property<OFloatArrayProperty, float>(id_property->
name,
array, id_property->
len);
119 set_array_property<ODoubleArrayProperty, double>(id_property->
name,
array, id_property->
len);
125 void CustomPropertiesExporter::write_idparray(
const IDProperty *idp_array)
129 if (idp_array->
len == 0) {
139 for (
int i = 1; i < idp_array->
len; i++) {
140 if (idp_elements[i].
type == idp_elements[0].
type) {
143 std::cerr <<
"Custom property " << idp_array->
name <<
" has elements of varying type";
144 BLI_assert(!
"Mixed type IDP_ARRAY custom property found");
148 switch (idp_elements[0].
type) {
150 write_idparray_of_strings(idp_array);
153 write_idparray_of_numbers(idp_array);
158 void CustomPropertiesExporter::write_idparray_of_strings(
const IDProperty *idp_array)
165 std::vector<std::string> strings(idp_array->
len);
166 for (
int i = 0; i < idp_array->
len; i++) {
172 const std::string *array_of_strings = &strings[0];
173 set_array_property<OStringArrayProperty, std::string>(
174 idp_array->
name, array_of_strings, strings.size());
177 void CustomPropertiesExporter::write_idparray_of_numbers(
const IDProperty *idp_array)
186 const int subtype = idp_rows[0].
subtype;
194 static_assert(
sizeof(
int) ==
sizeof(
int32_t),
"Expecting 'int' to be 32-bit");
195 write_idparray_flattened_typed<OInt32ArrayProperty, int32_t>(idp_array);
198 write_idparray_flattened_typed<OFloatArrayProperty, float>(idp_array);
201 write_idparray_flattened_typed<ODoubleArrayProperty, double>(idp_array);
206 template<
typename ABCPropertyType,
typename BlenderValueType>
207 void CustomPropertiesExporter::write_idparray_flattened_typed(
const IDProperty *idp_array)
217 std::vector<BlenderValueType> matrix_values;
218 for (
size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
219 const BlenderValueType *row = (BlenderValueType *)
IDP_Array(&idp_rows[row_idx]);
220 for (
size_t col_idx = 0; col_idx < idp_rows[row_idx].
len; col_idx++) {
221 matrix_values.push_back(row[col_idx]);
225 set_array_property<ABCPropertyType, BlenderValueType>(
226 idp_array->
name, &matrix_values[0], matrix_values.size());
229 template<
typename ABCPropertyType,
typename BlenderValueType>
230 void CustomPropertiesExporter::set_scalar_property(
const StringRef property_name,
231 const BlenderValueType property_value)
233 set_array_property<ABCPropertyType, BlenderValueType>(property_name, &property_value, 1);
236 template<
typename ABCPropertyType,
typename BlenderValueType>
237 void CustomPropertiesExporter::set_array_property(
const StringRef property_name,
238 const BlenderValueType *array_values,
239 const size_t num_array_items)
241 auto create_callback = [
this, property_name]() -> OArrayProperty {
242 return create_abc_property<ABCPropertyType>(property_name);
245 OArrayProperty array_prop = abc_properties_.
lookup_or_add_cb(property_name, create_callback);
246 Alembic::Util::Dimensions array_dimensions(num_array_items);
247 ArraySample
sample(array_values, array_prop.getDataType(), array_dimensions);
251 template<
typename ABCPropertyType>
252 OArrayProperty CustomPropertiesExporter::create_abc_property(
const StringRef property_name)
259 ABCPropertyType abc_property(abc_prop_for_custom_props, property_name);
260 abc_property.setTimeSampling(timesample_index);
#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)
static void sample(SocketReader *reader, int x, int y, float color[4])
unsigned __int64 uint64_t