Blender V4.5
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 "DNA_object_types.h"
10
11#include <Alembic/AbcGeom/Visibility.h>
12
13#include "CLG_log.h"
14static CLG_LogRef LOG = {"io.alembic"};
15
16namespace blender::io::alembic {
17
18using Alembic::Abc::OObject;
19using Alembic::Abc::TimeSamplingPtr;
20
22 : args_(args),
25 timesample_index_(args_.abc_archive->time_sampling_index_shapes())
26{
27}
28
30{
31 return true;
32}
33
35{
37 is_animated_ = (args_.export_params->frame_start != args_.export_params->frame_end) &&
38 check_is_animated(context);
40 }
41 else if (!is_animated_) {
42 /* A frame has already been written, and without animation one frame is enough. */
43 return;
44 }
45
46 do_write(context);
47
48 if (custom_props_) {
49 custom_props_->write_all(get_id_properties(context));
50 }
51
53}
54
56{
57 if (!args_.export_params->export_custom_properties) {
58 return;
59 }
60
61 if (custom_props_) {
62 /* Custom properties exporter already created. */
63 return;
64 }
65
66 /* Avoid creating a custom properties exporter if there are no custom properties to export. */
67 const IDProperty *id_properties = get_id_properties(context);
68 if (id_properties == nullptr || id_properties->len == 0) {
69 return;
70 }
71
72 custom_props_ = std::make_unique<CustomPropertiesExporter>(this);
73}
74
76{
77 Object *object = context.object;
78 if (object->data == nullptr) {
79 return nullptr;
80 }
81
82 /* Most subclasses write object data, so default to the object data's ID properties. */
83 return static_cast<ID *>(object->data)->properties;
84}
85
87{
88 return timesample_index_;
89}
90
91const Imath::Box3d &ABCAbstractWriter::bounding_box() const
92{
93 return bounding_box_;
94}
95
97{
98 const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(object);
99 if (!bounds) {
100 if (object->type != OB_CAMERA) {
101 CLOG_WARN(&LOG, "Bounding box is null!");
102 }
103 bounding_box_.min.x = bounding_box_.min.y = bounding_box_.min.z = 0;
104 bounding_box_.max.x = bounding_box_.max.y = bounding_box_.max.z = 0;
105 return;
106 }
107
108 BoundBox bb;
110
111 /* Convert Z-up to Y-up. This also changes which vector goes into which min/max property. */
112 bounding_box_.min.x = bb.vec[0][0];
113 bounding_box_.min.y = bb.vec[0][2];
114 bounding_box_.min.z = -bb.vec[6][1];
115
116 bounding_box_.max.x = bb.vec[6][0];
117 bounding_box_.max.y = bb.vec[6][2];
118 bounding_box_.max.z = -bb.vec[0][1];
119}
120
122{
123 const bool is_visible = context.is_object_visible(args_.export_params->evaluation_mode);
124 Alembic::Abc::OObject abc_object = get_alembic_object();
125
126 if (!abc_visibility_.valid()) {
127 abc_visibility_ = Alembic::AbcGeom::CreateVisibilityProperty(abc_object, timesample_index_);
128 }
129 abc_visibility_.set(is_visible ? Alembic::AbcGeom::kVisibilityVisible :
130 Alembic::AbcGeom::kVisibilityHidden);
131}
132
133} // 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
Object is a sort of wrapper for general info.
@ OB_CAMERA
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)
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:32
float vec[8][3]
int len
Definition DNA_ID.h:165
Definition DNA_ID.h:404