Blender V4.3
abc_writer_abstract.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6
7#include "BKE_object.hh"
8
9#include <Alembic/AbcGeom/Visibility.h>
10
11#include "CLG_log.h"
12static CLG_LogRef LOG = {"io.alembic"};
13
14namespace blender::io::alembic {
15
16using Alembic::Abc::OObject;
17using Alembic::Abc::TimeSamplingPtr;
18
20 : args_(args),
21 frame_has_been_written_(false),
22 is_animated_(false),
23 timesample_index_(args_.abc_archive->time_sampling_index_shapes())
24{
25}
26
28{
29 return true;
30}
31
33{
36 check_is_animated(context);
38 }
39 else if (!is_animated_) {
40 /* A frame has already been written, and without animation one frame is enough. */
41 return;
42 }
43
44 do_write(context);
45
46 if (custom_props_) {
47 custom_props_->write_all(get_id_properties(context));
48 }
49
51}
52
54{
56 return;
57 }
58
59 if (custom_props_) {
60 /* Custom properties exporter already created. */
61 return;
62 }
63
64 /* Avoid creating a custom properties exporter if there are no custom properties to export. */
65 const IDProperty *id_properties = get_id_properties(context);
66 if (id_properties == nullptr || id_properties->len == 0) {
67 return;
68 }
69
70 custom_props_ = std::make_unique<CustomPropertiesExporter>(this);
71}
72
74{
75 Object *object = context.object;
76 if (object->data == nullptr) {
77 return nullptr;
78 }
79
80 /* Most subclasses write object data, so default to the object data's ID properties. */
81 return static_cast<ID *>(object->data)->properties;
82}
83
88
89const Imath::Box3d &ABCAbstractWriter::bounding_box() const
90{
91 return bounding_box_;
92}
93
95{
96 const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(object);
97 if (!bounds) {
98 if (object->type != OB_CAMERA) {
99 CLOG_WARN(&LOG, "Bounding box is null!");
100 }
101 bounding_box_.min.x = bounding_box_.min.y = bounding_box_.min.z = 0;
102 bounding_box_.max.x = bounding_box_.max.y = bounding_box_.max.z = 0;
103 return;
104 }
105
106 BoundBox bb;
107 BKE_boundbox_init_from_minmax(&bb, bounds->min, bounds->max);
108
109 /* Convert Z-up to Y-up. This also changes which vector goes into which min/max property. */
110 bounding_box_.min.x = bb.vec[0][0];
111 bounding_box_.min.y = bb.vec[0][2];
112 bounding_box_.min.z = -bb.vec[6][1];
113
114 bounding_box_.max.x = bb.vec[6][0];
115 bounding_box_.max.y = bb.vec[6][2];
116 bounding_box_.max.z = -bb.vec[0][1];
117}
118
120{
121 const bool is_visible = context.is_object_visible(args_.export_params->evaluation_mode);
122 Alembic::Abc::OObject abc_object = get_alembic_object();
123
124 if (!abc_visibility_.valid()) {
125 abc_visibility_ = Alembic::AbcGeom::CreateVisibilityProperty(abc_object, timesample_index_);
126 }
127 abc_visibility_.set(is_visible ? Alembic::AbcGeom::kVisibilityVisible :
128 Alembic::AbcGeom::kVisibilityHidden);
129}
130
131} // namespace blender::io::alembic
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
std::optional< blender::Bounds< blender::float3 > > BKE_object_boundbox_get(const Object *ob)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:181
@ OB_CAMERA
static CLG_LogRef LOG
virtual bool check_is_animated(const HierarchyContext &context) const
void write_visibility(const HierarchyContext &context)
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
virtual void do_write(HierarchyContext &context)=0
virtual const IDProperty * get_id_properties(const HierarchyContext &context) const
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
#define LOG(severity)
Definition log.h:33
unsigned int uint32_t
Definition stdint.h:80
enum eEvaluationMode evaluation_mode
Definition ABC_alembic.h:54
float vec[8][3]
float3 min
Definition boundbox.h:21
int len
Definition DNA_ID.h:174
Definition DNA_ID.h:413