Blender  V2.93
abc_writer_abstract.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 #include "abc_writer_abstract.h"
20 #include "abc_hierarchy_iterator.h"
21 
22 #include "BKE_animsys.h"
23 #include "BKE_key.h"
24 #include "BKE_object.h"
25 
26 #include "DNA_modifier_types.h"
27 
28 #include "DEG_depsgraph.h"
29 
30 #include <Alembic/AbcGeom/Visibility.h>
31 
32 #include "CLG_log.h"
33 static CLG_LogRef LOG = {"io.alembic"};
34 
35 namespace blender::io::alembic {
36 
37 using Alembic::Abc::OObject;
38 using Alembic::Abc::TimeSamplingPtr;
39 
41  : args_(args),
42  frame_has_been_written_(false),
43  is_animated_(false),
44  timesample_index_(args_.abc_archive->time_sampling_index_shapes())
45 {
46 }
47 
48 bool ABCAbstractWriter::is_supported(const HierarchyContext * /*context*/) const
49 {
50  return true;
51 }
52 
54 {
59  }
60  else if (!is_animated_) {
61  /* A frame has already been written, and without animation one frame is enough. */
62  return;
63  }
64 
66 
67  if (custom_props_) {
69  }
70 
72 }
73 
75 {
77  return;
78  }
79 
80  if (custom_props_) {
81  /* Custom properties exporter already created. */
82  return;
83  }
84 
85  /* Avoid creating a custom properties exporter if there are no custom properties to export. */
86  const IDProperty *id_properties = get_id_properties(context);
87  if (id_properties == nullptr || id_properties->len == 0) {
88  return;
89  }
90 
91  custom_props_ = std::make_unique<CustomPropertiesExporter>(this);
92 }
93 
95 {
96  Object *object = context.object;
97  if (object->data == nullptr) {
98  return nullptr;
99  }
100 
101  /* Most subclasses write object data, so default to the object data's ID properties. */
102  return static_cast<ID *>(object->data)->properties;
103 }
104 
106 {
107  return timesample_index_;
108 }
109 
110 const Imath::Box3d &ABCAbstractWriter::bounding_box() const
111 {
112  return bounding_box_;
113 }
114 
116 {
117  BoundBox *bb = BKE_object_boundbox_get(object);
118 
119  if (!bb) {
120  if (object->type != OB_CAMERA) {
121  CLOG_WARN(&LOG, "Bounding box is null!\n");
122  }
123  bounding_box_.min.x = bounding_box_.min.y = bounding_box_.min.z = 0;
124  bounding_box_.max.x = bounding_box_.max.y = bounding_box_.max.z = 0;
125  return;
126  }
127 
128  /* Convert Z-up to Y-up. This also changes which vector goes into which min/max property. */
129  bounding_box_.min.x = bb->vec[0][0];
130  bounding_box_.min.y = bb->vec[0][2];
131  bounding_box_.min.z = -bb->vec[6][1];
132 
133  bounding_box_.max.x = bb->vec[6][0];
134  bounding_box_.max.y = bb->vec[6][2];
135  bounding_box_.max.z = -bb->vec[0][1];
136 }
137 
139 {
140  const bool is_visible = context.is_object_visible(args_.export_params->evaluation_mode);
141  Alembic::Abc::OObject abc_object = get_alembic_object();
142 
143  if (!abc_visibility_.valid()) {
144  abc_visibility_ = Alembic::AbcGeom::CreateVisibilityProperty(abc_object, timesample_index_);
145  }
146  abc_visibility_.set(is_visible ? Alembic::AbcGeom::kVisibilityVisible :
147  Alembic::AbcGeom::kVisibilityHidden);
148 }
149 
150 } // namespace blender::io::alembic
General operations, lookup, etc. for blender objects.
struct BoundBox * BKE_object_boundbox_get(struct Object *ob)
Definition: object.c:3817
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:203
@ 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
struct SELECTID_Context context
Definition: select_engine.c:47
unsigned int uint32_t
Definition: stdint.h:83
enum eEvaluationMode evaluation_mode
Definition: ABC_alembic.h:66
bool export_custom_properties
Definition: ABC_alembic.h:64
float vec[8][3]
int len
Definition: DNA_ID.h:84
Definition: DNA_ID.h:273
void * data