Blender V5.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
8
9#pragma once
10
11#include <Alembic/Abc/OArrayProperty.h>
12#include <Alembic/Abc/OCompoundProperty.h>
13
14#include "BLI_map.hh"
16
17#include <string>
18
19namespace blender {
20
21struct IDProperty;
22
23namespace bke {
25}
26
27namespace io::alembic {
28
30
31/* Write values of Custom Properties (a.k.a. ID Properties) to Alembic.
32 *
33 * Each Alembic Writer instance optionally has one CustomPropertiesExporter (CPE). This CPE not
34 * only writes the custom properties to Alembic, but also keeps references in memory so that the
35 * Alembic library doesn't prematurely finalize the data. */
37 private:
38 /* Owner is used to get the OCompoundProperty and time sample index. The former should only be
39 * requested from the Alembic library when it's actually going to be used to add custom
40 * properties (otherwise an invalid Alembic file is written). */
41 ABCAbstractWriter *owner_;
42
43 /* The Compound Property that will contain the exported custom properties.
44 *
45 * Typically this the return value of abc_schema.getArbGeomParams() or
46 * abc_schema.getUserProperties(). */
47 Alembic::Abc::OCompoundProperty abc_compound_prop_;
48
49 /* Mapping from property name in Blender to property in Alembic.
50 * Here Blender does the same as other software (Maya, Houdini), and writes
51 * scalar properties as single-element arrays. */
53
54 public:
56 virtual ~CustomPropertiesExporter() = default;
57
58 void write_all(const IDProperty *group);
59
60 private:
61 void write(const IDProperty *id_property);
62 void write_array(const IDProperty *id_property);
63
64 /* IDProperty arrays are used to store arrays-of-arrays or arrays-of-strings. */
65 void write_idparray(const IDProperty *idp_array);
66 void write_idparray_of_strings(const IDProperty *idp_array);
67 void write_idparray_of_numbers(const IDProperty *idp_array);
68
69 /* Flatten an array-of-arrays into one long array, then write that.
70 * It is tempting to write an array of NxM numbers as a matrix, but there is
71 * no guarantee that the data actually represents a matrix. */
72 template<typename ABCPropertyType, typename BlenderValueType>
73 void write_idparray_flattened_typed(const IDProperty *idp_array);
74
75 /* Write a single scalar (i.e. non-array) property as single-value array. */
76 template<typename ABCPropertyType, typename BlenderValueType>
77 void set_scalar_property(StringRef property_name, const BlenderValueType property_value);
78
79 template<typename ABCPropertyType, typename BlenderValueType>
80 void set_array_property(StringRef property_name,
81 const BlenderValueType *array_values,
82 size_t num_array_items);
83
84 template<typename ABCPropertyType>
85 Alembic::Abc::OArrayProperty create_abc_property(StringRef property_name);
86};
87
88void get_positions(const Span<float3> positions, std::vector<Imath::V3f> &points);
89
90/* Returns true if the attributes have a velocity attribute on the point domain which was used
91 * to fill the velocities. */
92bool get_velocities(const bke::AttributeAccessor &attributes, std::vector<Imath::V3f> &velocities);
93
94} // namespace io::alembic
95} // namespace blender
bool get_velocities(const bke::AttributeAccessor &attributes, std::vector< Imath::V3f > &velocities)
void get_positions(const Span< float3 > positions, std::vector< Imath::V3f > &points)
BMesh Iterators.