Blender  V3.3
abc_writer_abstract.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 #include "abc_writer_abstract.h"
5 
6 #include "BKE_animsys.h"
7 #include "BKE_key.h"
8 #include "BKE_object.h"
9 
10 #include "DNA_modifier_types.h"
11 
12 #include "DEG_depsgraph.h"
13 
14 #include <Alembic/AbcGeom/Visibility.h>
15 
16 #include "CLG_log.h"
17 static CLG_LogRef LOG = {"io.alembic"};
18 
19 namespace blender::io::alembic {
20 
21 using Alembic::Abc::OObject;
22 using Alembic::Abc::TimeSamplingPtr;
23 
25  : args_(args),
26  frame_has_been_written_(false),
27  is_animated_(false),
28  timesample_index_(args_.abc_archive->time_sampling_index_shapes())
29 {
30 }
31 
32 bool ABCAbstractWriter::is_supported(const HierarchyContext * /*context*/) const
33 {
34  return true;
35 }
36 
38 {
43  }
44  else if (!is_animated_) {
45  /* A frame has already been written, and without animation one frame is enough. */
46  return;
47  }
48 
50 
51  if (custom_props_) {
53  }
54 
56 }
57 
59 {
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 
94 const Imath::Box3d &ABCAbstractWriter::bounding_box() const
95 {
96  return bounding_box_;
97 }
98 
100 {
101  const BoundBox *bb = BKE_object_boundbox_get(object);
102 
103  if (!bb) {
104  if (object->type != OB_CAMERA) {
105  CLOG_WARN(&LOG, "Bounding box is null!");
106  }
107  bounding_box_.min.x = bounding_box_.min.y = bounding_box_.min.z = 0;
108  bounding_box_.max.x = bounding_box_.max.y = bounding_box_.max.z = 0;
109  return;
110  }
111 
112  /* Convert Z-up to Y-up. This also changes which vector goes into which min/max property. */
113  bounding_box_.min.x = bb->vec[0][0];
114  bounding_box_.min.y = bb->vec[0][2];
115  bounding_box_.min.z = -bb->vec[6][1];
116 
117  bounding_box_.max.x = bb->vec[6][0];
118  bounding_box_.max.y = bb->vec[6][2];
119  bounding_box_.max.z = -bb->vec[0][1];
120 }
121 
123 {
124  const bool is_visible = context.is_object_visible(args_.export_params->evaluation_mode);
125  Alembic::Abc::OObject abc_object = get_alembic_object();
126 
127  if (!abc_visibility_.valid()) {
128  abc_visibility_ = Alembic::AbcGeom::CreateVisibilityProperty(abc_object, timesample_index_);
129  }
130  abc_visibility_.set(is_visible ? Alembic::AbcGeom::kVisibilityVisible :
131  Alembic::AbcGeom::kVisibilityHidden);
132 }
133 
134 } // namespace blender::io::alembic
General operations, lookup, etc. for blender objects.
const struct BoundBox * BKE_object_boundbox_get(struct Object *ob)
Definition: object.cc:3684
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:189
@ 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
unsigned int uint32_t
Definition: stdint.h:80
enum eEvaluationMode evaluation_mode
Definition: ABC_alembic.h:53
bool export_custom_properties
Definition: ABC_alembic.h:51
float vec[8][3]
int len
Definition: DNA_ID.h:121
Definition: DNA_ID.h:368
void * data