Blender V4.3
abc_custom_props.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include <Alembic/Abc/OArrayProperty.h>
12#include <Alembic/Abc/OCompoundProperty.h>
13
14#include "BLI_map.hh"
15
16#include <string>
17
18struct IDProperty;
19
20namespace blender::io::alembic {
21
22class ABCAbstractWriter;
23
24/* Write values of Custom Properties (a.k.a. ID Properties) to Alembic.
25 *
26 * Each Alembic Writer instance optionally has one CustomPropertiesExporter (CPE). This CPE not
27 * only writes the custom properties to Alembic, but also keeps references in memory so that the
28 * Alembic library doesn't prematurely finalize the data. */
30 private:
31 /* Owner is used to get the OCompoundProperty and time sample index. The former should only be
32 * requested from the Alembic library when it's actually going to be used to add custom
33 * properties (otherwise an invalid Alembic file is written). */
34 ABCAbstractWriter *owner_;
35
36 /* The Compound Property that will contain the exported custom properties.
37 *
38 * Typically this the return value of abc_schema.getArbGeomParams() or
39 * abc_schema.getUserProperties(). */
40 Alembic::Abc::OCompoundProperty abc_compound_prop_;
41
42 /* Mapping from property name in Blender to property in Alembic.
43 * Here Blender does the same as other software (Maya, Houdini), and writes
44 * scalar properties as single-element arrays. */
46
47 public:
49 virtual ~CustomPropertiesExporter() = default;
50
51 void write_all(const IDProperty *group);
52
53 private:
54 void write(const IDProperty *id_property);
55 void write_array(const IDProperty *id_property);
56
57 /* IDProperty arrays are used to store arrays-of-arrays or arrays-of-strings. */
58 void write_idparray(const IDProperty *idp_array);
59 void write_idparray_of_strings(const IDProperty *idp_array);
60 void write_idparray_of_numbers(const IDProperty *idp_array);
61
62 /* Flatten an array-of-arrays into one long array, then write that.
63 * It is tempting to write an array of NxM numbers as a matrix, but there is
64 * no guarantee that the data actually represents a matrix. */
65 template<typename ABCPropertyType, typename BlenderValueType>
66 void write_idparray_flattened_typed(const IDProperty *idp_array);
67
68 /* Write a single scalar (i.e. non-array) property as single-value array. */
69 template<typename ABCPropertyType, typename BlenderValueType>
70 void set_scalar_property(StringRef property_name, const BlenderValueType property_value);
71
72 template<typename ABCPropertyType, typename BlenderValueType>
73 void set_array_property(StringRef property_name,
74 const BlenderValueType *array_values,
75 size_t num_array_items);
76
77 template<typename ABCPropertyType>
78 Alembic::Abc::OArrayProperty create_abc_property(StringRef property_name);
79};
80
81} // namespace blender::io::alembic