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