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