Blender  V2.93
abc_writer_abstract.h
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 #pragma once
20 
22 #include "abc_custom_props.h"
23 #include "abc_hierarchy_iterator.h"
24 
25 #include <Alembic/Abc/OObject.h>
26 #include <vector>
27 
28 #include "DEG_depsgraph_query.h"
29 #include "DNA_material_types.h"
30 
31 struct IDProperty;
32 struct Object;
33 
34 namespace blender::io::alembic {
35 
37  protected:
39 
43  Imath::Box3d bounding_box_;
44 
45  /* Visibility of this writer's data in Alembic. */
46  Alembic::Abc::OCharProperty abc_visibility_;
47 
48  /* Optional writer for custom properties. */
49  std::unique_ptr<CustomPropertiesExporter> custom_props_;
50 
51  public:
52  explicit ABCAbstractWriter(const ABCWriterConstructorArgs &args);
53 
54  virtual void write(HierarchyContext &context) override;
55 
56  /* Returns true if the data to be written is actually supported. This would, for example, allow a
57  * hypothetical camera writer accept a perspective camera but reject an orthogonal one.
58  *
59  * Returning false from a transform writer will prevent the object and all its descendants from
60  * being exported. Returning false from a data writer (object data, hair, or particles) will
61  * only prevent that data from being written (and thus cause the object to be exported as an
62  * Empty). */
63  virtual bool is_supported(const HierarchyContext *context) const;
64 
65  uint32_t timesample_index() const;
66  const Imath::Box3d &bounding_box() const;
67 
68  /* Called by AlembicHierarchyCreator after checking that the data is supported via
69  * is_supported(). */
71 
72  virtual Alembic::Abc::OObject get_alembic_object() const = 0;
73 
74  /* Return the Alembic object's CompoundProperty that'll contain the custom properties.
75  *
76  * This function is called whenever there are custom properties to be written to Alembic. It
77  * should call abc_schema_prop_for_custom_props() with the writer's Alembic schema object.
78  *
79  * If custom properties are not supported by a specific subclass, it should return an empty
80  * OCompoundProperty() and override ensure_custom_properties_exporter() to do nothing.
81  */
82  virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() = 0;
83 
84  protected:
85  virtual void do_write(HierarchyContext &context) = 0;
86 
87  virtual void update_bounding_box(Object *object);
88 
89  /* Return ID properties of whatever ID datablock is written by this writer. Defaults to the
90  * properties of the object data. Can return nullptr if no custom properties are to be written.
91  */
92  virtual const IDProperty *get_id_properties(const HierarchyContext &context) const;
93 
95 
97 
98  /* Return the Alembic schema's compound property, which will be used for writing custom
99  * properties.
100  *
101  * This can return either abc_schema.getUserProperties() or abc_schema.getArbGeomParams(). The
102  * former only holds values similar to Blender's custom properties, whereas the latter can also
103  * specify that certain custom properties vary per mesh component (so per face, vertex, etc.). As
104  * such, .userProperties is more suitable for custom properties. However, Maya, Houdini use
105  * .arbGeomParams for custom data.
106  *
107  * Because of this, the code uses this templated function so that there is one place that
108  * determines where custom properties are exporter to.
109  */
110  template<typename T>
111  Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
112  {
113  return abc_schema.getUserProperties();
114  }
115 };
116 
117 } // namespace blender::io::alembic
virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props()=0
void write_visibility(const HierarchyContext &context)
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
virtual void do_write(HierarchyContext &context)=0
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
virtual const IDProperty * get_id_properties(const HierarchyContext &context) const
virtual void create_alembic_objects(const HierarchyContext *context)=0
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
#define T
struct SELECTID_Context context
Definition: select_engine.c:47
unsigned int uint32_t
Definition: stdint.h:83