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