Blender V5.3
abc_writer_attribute.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8#include "BLI_string_ref.hh"
9
10#include <Alembic/AbcGeom/OGeomParam.h>
11
12namespace blender {
13
14struct MStringProperty;
15
16namespace bke {
17class AttributeIter;
18}
19
20namespace io::alembic {
21
22#define ENUMERATE_EXPORTED_TYPES(X) \
23 X(Alembic::AbcGeom::OBoolGeomParam, bool_params) \
24 X(Alembic::AbcGeom::OCharGeomParam, int8_params) \
25 X(Alembic::AbcGeom::OV2sGeomParam, short2_params) \
26 X(Alembic::AbcGeom::OInt32GeomParam, int32_params) \
27 X(Alembic::AbcGeom::OV2iGeomParam, int2_params) \
28 X(Alembic::AbcGeom::OFloatGeomParam, float_params) \
29 X(Alembic::AbcGeom::OV2fGeomParam, float2_params) \
30 X(Alembic::AbcGeom::OV3fGeomParam, float3_params) \
31 X(Alembic::AbcGeom::OC4fGeomParam, color_params) \
32 X(Alembic::AbcGeom::OC4cGeomParam, byte_color_params) \
33 X(Alembic::AbcGeom::OQuatfGeomParam, quat_params) \
34 X(Alembic::AbcGeom::OM44dGeomParam, float4x4_params) \
35 X(Alembic::AbcGeom::OStringGeomParam, string_params)
36
37/* This class holds maps from string to TypedGeomParam for each attribute type supported for
38 * export. We use it to keep track of exported GeomParams so that we can retrieve the proper
39 * GeomParam for each attribute for each frame as the Alembic API does not really allow to get
40 * a TypeGeomParam from a OCompound property after creation. */
42 /* Store params in maps so we can retrieve them across frames to properly account for animated
43 * data. */
44#define DECLARE_MAPS(abc_type, map_name) std::map<std::string, abc_type> map_name{};
46#undef DECLARE_MAPS
47
48 public:
49#define ENSURE_PARAM_FUNC(ParamType, map) \
50 void ensure_param(const Alembic::Abc::OCompoundProperty &prop, \
51 ParamType &param, \
52 const StringRefNull name, \
53 Alembic::AbcGeom::GeometryScope scope) \
54 { \
55 param = map[name]; \
56 if (!param.valid()) { \
57 param = ParamType(prop, name, false, scope, 1); \
58 map[name] = param; \
59 } \
60 }
62#undef ENSURE_PARAM_FUNC
63
64 /* Write empty samples so that the current number of samples matches the number of geometry
65 * samples. */
66 void write_empty_samples(const size_t num_geom_samples);
67};
68
69/* Create a TypedGeomParam for the given AttributeIter.
70 * `faces` are used to correct polygon winding for corner attributes.
71 * `object_name` is to give useful error messages
72 * `num_geom_samples` is to ensure that the attribute has the same number of samples as the
73 * underlying geometry. */
74void create_geom_param_for_attribute(const Alembic::Abc::OCompoundProperty &prop,
75 AttributeParamMaps &param_maps,
76 const bke::AttributeIter &attr,
77 const int timesample_index,
78 const OffsetIndices<int> faces,
79 const StringRefNull object_name,
80 const size_t num_geom_samples);
81
82} // namespace io::alembic
83} // namespace blender
#define DECLARE_MAPS(abc_type, map_name)
#define ENUMERATE_EXPORTED_TYPES(X)
#define ENSURE_PARAM_FUNC(ParamType, map)
void write_empty_samples(const size_t num_geom_samples)
void create_geom_param_for_attribute(const Alembic::Abc::OCompoundProperty &prop, AttributeParamMaps &param_maps, const bke::AttributeIter &attr, const int timesample_index, const OffsetIndices< int > faces, const StringRefNull object_name, const size_t num_geom_samples)
BMesh Iterators.