Blender V5.3
abc_writer_abstract.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
12#include "abc_custom_props.h"
14
15#include <Alembic/Abc/OObject.h>
16
17#include <memory>
18
19namespace blender {
20
21struct IDProperty;
22struct Object;
23
24namespace io::alembic {
25
27 protected:
29
33 Imath::Box3d bounding_box_;
34
35 /* Visibility of this writer's data in Alembic. */
36 Alembic::Abc::OCharProperty abc_visibility_;
37
38 /* Optional writer for custom properties. */
39 std::unique_ptr<CustomPropertiesExporter> custom_props_;
40
41 public:
42 explicit ABCAbstractWriter(const ABCWriterConstructorArgs &args);
43
44 void write(HierarchyContext &context) override;
45
46 /* Returns true if the data to be written is actually supported. This would, for example, allow a
47 * hypothetical camera writer accept a perspective camera but reject an orthogonal one.
48 *
49 * Returning false from a transform writer will prevent the object and all its descendants from
50 * being exported. Returning false from a data writer (object data, hair, or particles) will
51 * only prevent that data from being written (and thus cause the object to be exported as an
52 * Empty). */
53 virtual bool is_supported(const HierarchyContext *context) const;
54
56 const Imath::Box3d &bounding_box() const;
57
58 /* Called by AlembicHierarchyCreator after checking that the data is supported via
59 * is_supported(). */
60 virtual void create_alembic_objects(const HierarchyContext *context) = 0;
61
62 virtual Alembic::Abc::OObject get_alembic_object() const = 0;
63
64 /* Return the Alembic object's CompoundProperty that'll contain the custom properties.
65 *
66 * This function is called whenever there are custom properties to be written to Alembic. It
67 * should call abc_schema_prop_for_custom_props() with the writer's Alembic schema object.
68 *
69 * If custom properties are not supported by a specific subclass, it should return an empty
70 * OCompoundProperty() and override ensure_custom_properties_exporter() to do nothing.
71 */
72 virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() = 0;
73
74 protected:
75 virtual void do_write(HierarchyContext &context) = 0;
76
77 virtual void update_bounding_box(Object *object);
78
79 /* Return ID properties of whatever ID datablock is written by this writer. Defaults to the
80 * properties of the object data. Can return nullptr if no custom properties are to be written.
81 */
82 virtual const IDProperty *get_id_properties(const HierarchyContext &context) const;
83
84 virtual void ensure_custom_properties_exporter(const HierarchyContext &context);
85
86 void write_visibility(const HierarchyContext &context);
87
88 /* Return the Alembic schema's compound property, which will be used for writing custom
89 * properties.
90 *
91 * This can return either abc_schema.getUserProperties() or abc_schema.getArbGeomParams(). The
92 * former only holds values similar to Blender's custom properties, whereas the latter can also
93 * specify that certain custom properties vary per mesh component (so per face, vertex, etc.). As
94 * such, .userProperties is more suitable for custom properties. However, Maya, Houdini use
95 * .arbGeomParams for custom data.
96 *
97 * Because of this, the code uses this templated function so that there is one place that
98 * determines where custom properties are exporter to.
99 */
100 template<typename T>
101 Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
102 {
103 return abc_schema.getUserProperties();
104 }
105};
106
107} // namespace io::alembic
108} // namespace blender
virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props()=0
void write_visibility(const HierarchyContext &context)
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
virtual void do_write(HierarchyContext &context)=0
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
virtual const IDProperty * get_id_properties(const HierarchyContext &context) const
virtual void create_alembic_objects(const HierarchyContext *context)=0
std::unique_ptr< CustomPropertiesExporter > custom_props_
virtual void ensure_custom_properties_exporter(const HierarchyContext &context)
void write(HierarchyContext &context) override
const ABCWriterConstructorArgs args_
virtual bool is_supported(const HierarchyContext *context) const
virtual Alembic::Abc::OObject get_alembic_object() const =0
virtual void update_bounding_box(Object *object)
Alembic::Abc::OCharProperty abc_visibility_
#define T
BMesh Iterators.
unsigned int uint32_t
Definition BKE_text.h:81