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